@@ -286,6 +286,12 @@ class LifetimeDependenceChecker {
286286 }
287287 }
288288
289+ LifetimeDependenceChecker (EnumElementDecl *eed)
290+ : decl(eed), dc(eed->getDeclContext ()), ctx(dc->getASTContext ()) {
291+ auto *paramList = eed->getParameterList ();
292+ resultIndex = paramList ? eed->getParameterList ()->size () + 1 : 1 ;
293+ }
294+
289295 std::optional<llvm::ArrayRef<LifetimeDependenceInfo>>
290296 currentDependencies () const {
291297 if (lifetimeDependencies.empty ()) {
@@ -351,6 +357,45 @@ class LifetimeDependenceChecker {
351357 return currentDependencies ();
352358 }
353359
360+ std::optional<llvm::ArrayRef<LifetimeDependenceInfo>> checkEnumElementDecl () {
361+ auto *eed = cast<EnumElementDecl>(decl);
362+ auto enumType = eed->getParentEnum ()->mapTypeIntoContext (
363+ eed->getParentEnum ()->getDeclaredInterfaceType ());
364+ // Escapable enum, bailout.
365+ if (!isDiagnosedNonEscapable (enumType)) {
366+ return std::nullopt ;
367+ }
368+ auto *params = eed->getParameterList ();
369+ // No payload, bailout.
370+ if (!params) {
371+ return std::nullopt ;
372+ }
373+
374+ auto resultIndex = params->size () + /* selfType*/ 1 ;
375+ auto capacity = resultIndex + 1 ;
376+ SmallBitVector inheritIndices (capacity);
377+ SmallVector<LifetimeDependenceInfo, 1 > lifetimeDependencies;
378+
379+ // Add all indices of ~Escapable parameters as lifetime dependence sources.
380+ for (size_t i = 0 ; i < params->size (); i++) {
381+ auto paramType = params->get (i)->getTypeInContext ();
382+ if (!isDiagnosedNonEscapable (paramType)) {
383+ continue ;
384+ }
385+ inheritIndices.set (i);
386+ }
387+ if (inheritIndices.none ()) {
388+ return std::nullopt ;
389+ }
390+ auto lifetimeDependenceInfo = LifetimeDependenceInfo (
391+ IndexSubset::get (eed->getASTContext (), inheritIndices), nullptr ,
392+ resultIndex,
393+ /* isImmortal*/ false );
394+ lifetimeDependencies.push_back (lifetimeDependenceInfo);
395+
396+ return eed->getASTContext ().AllocateCopy (lifetimeDependencies);
397+ }
398+
354399protected:
355400 template <typename ...ArgTypes>
356401 InFlightDiagnostic diagnose (
@@ -1417,8 +1462,12 @@ class LifetimeDependenceChecker {
14171462};
14181463
14191464std::optional<llvm::ArrayRef<LifetimeDependenceInfo>>
1420- LifetimeDependenceInfo::get (AbstractFunctionDecl *afd) {
1421- return LifetimeDependenceChecker (afd).checkFuncDecl ();
1465+ LifetimeDependenceInfo::get (ValueDecl *decl) {
1466+ if (auto *afd = dyn_cast<AbstractFunctionDecl>(decl)) {
1467+ return LifetimeDependenceChecker (afd).checkFuncDecl ();
1468+ }
1469+ auto *eed = cast<EnumElementDecl>(decl);
1470+ return LifetimeDependenceChecker (eed).checkEnumElementDecl ();
14221471}
14231472
14241473// This implements the logic for SIL type descriptors similar to source-level
0 commit comments