@@ -252,7 +252,7 @@ void LifetimeDependenceInfo::getConcatenatedData(
252252}
253253
254254class LifetimeDependenceChecker {
255- AbstractFunctionDecl *afd ;
255+ ValueDecl *decl ;
256256
257257 DeclContext *dc;
258258 ASTContext &ctx;
@@ -273,9 +273,8 @@ class LifetimeDependenceChecker {
273273 bool performedDiagnostics = false ;
274274
275275public:
276- LifetimeDependenceChecker (AbstractFunctionDecl *afd):
277- afd (afd), dc(afd->getDeclContext ()), ctx(dc->getASTContext ())
278- {
276+ LifetimeDependenceChecker (AbstractFunctionDecl *afd)
277+ : decl(afd), dc(afd->getDeclContext ()), ctx(dc->getASTContext ()) {
279278 auto resultTypeRepr = afd->getResultTypeRepr ();
280279 returnLoc = resultTypeRepr ? resultTypeRepr->getLoc () : afd->getLoc ();
281280
@@ -292,13 +291,14 @@ class LifetimeDependenceChecker {
292291 if (lifetimeDependencies.empty ()) {
293292 return std::nullopt ;
294293 }
295- return afd ->getASTContext ().AllocateCopy (lifetimeDependencies);
294+ return decl ->getASTContext ().AllocateCopy (lifetimeDependencies);
296295 }
297296
298297 std::optional<llvm::ArrayRef<LifetimeDependenceInfo>> checkFuncDecl () {
299- assert (isa<FuncDecl>(afd ) || isa<ConstructorDecl>(afd ));
298+ assert (isa<FuncDecl>(decl ) || isa<ConstructorDecl>(decl ));
300299 assert (lifetimeDependencies.empty ());
301300
301+ auto *afd = cast<AbstractFunctionDecl>(decl);
302302 // Handle Builtins first because, even though Builtins require
303303 // LifetimeDependence, we don't force the experimental feature
304304 // to be enabled when importing the Builtin module.
@@ -367,9 +367,7 @@ class LifetimeDependenceChecker {
367367 return ctx.Diags .diagnose (decl, Diagnostic (id, std::move (args)...));
368368 }
369369
370- bool isInit () const {
371- return isa<ConstructorDecl>(afd);
372- }
370+ bool isInit () const { return isa<ConstructorDecl>(decl); }
373371
374372 // For initializers, the implicit self parameter is ignored and instead shows
375373 // up as the result type.
@@ -381,11 +379,13 @@ class LifetimeDependenceChecker {
381379 // the extra formal self parameter, a dependency targeting the formal result
382380 // index would incorrectly target the SIL metatype parameter.
383381 bool hasImplicitSelfParam () const {
382+ auto *afd = cast<AbstractFunctionDecl>(decl);
384383 return !isInit () && afd->hasImplicitSelfDecl ();
385384 }
386385
387386 // In SIL, implicit initializers and accessors become explicit.
388387 bool isImplicitOrSIL () const {
388+ auto *afd = cast<AbstractFunctionDecl>(decl);
389389 if (afd->isImplicit ()) {
390390 return true ;
391391 }
@@ -404,7 +404,7 @@ class LifetimeDependenceChecker {
404404 bool isInterfaceFile () const {
405405 // TODO: remove this check once all compilers that are rev-locked to the
406406 // stdlib print the 'copy' dependence kind in the interface (Aug '25)
407- if (auto *sf = afd ->getParentSourceFile ()) {
407+ if (auto *sf = decl-> getDeclContext () ->getParentSourceFile ()) {
408408 if (sf->Kind == SourceFileKind::Interface) {
409409 return true ;
410410 }
@@ -419,6 +419,7 @@ class LifetimeDependenceChecker {
419419 }
420420
421421 std::string diagnosticQualifier () const {
422+ auto *afd = cast<AbstractFunctionDecl>(decl);
422423 if (afd->isImplicit ()) {
423424 if (isInit ()) {
424425 return " an implicit initializer" ;
@@ -463,6 +464,7 @@ class LifetimeDependenceChecker {
463464 // initializers, the inout self parameter is actually considered the result
464465 // type so is not handled here.
465466 void diagnoseMissingSelfDependencies (DiagID diagID) {
467+ auto *afd = cast<AbstractFunctionDecl>(decl);
466468 if (!hasImplicitSelfParam ()) {
467469 return ;
468470 }
@@ -483,6 +485,7 @@ class LifetimeDependenceChecker {
483485 }
484486
485487 void diagnoseMissingInoutDependencies (DiagID diagID) {
488+ auto *afd = cast<AbstractFunctionDecl>(decl);
486489 unsigned paramIndex = 0 ;
487490 for (auto *param : *afd->getParameters ()) {
488491 SWIFT_DEFER { paramIndex++; };
@@ -529,6 +532,7 @@ class LifetimeDependenceChecker {
529532
530533 bool isCompatibleWithOwnership (LifetimeDependenceKind kind, Type type,
531534 ValueOwnership ownership) const {
535+ auto *afd = cast<AbstractFunctionDecl>(decl);
532536 if (kind == LifetimeDependenceKind::Inherit) {
533537 return true ;
534538 }
@@ -569,6 +573,7 @@ class LifetimeDependenceChecker {
569573 };
570574
571575 TargetDeps createDeps (unsigned targetIndex) {
576+ auto *afd = cast<AbstractFunctionDecl>(decl);
572577 unsigned capacity = afd->hasImplicitSelfDecl ()
573578 ? (afd->getParameters ()->size () + 1 )
574579 : afd->getParameters ()->size ();
@@ -599,6 +604,7 @@ class LifetimeDependenceChecker {
599604 }
600605
601606 Type getResultOrYield () const {
607+ auto *afd = cast<AbstractFunctionDecl>(decl);
602608 if (auto *accessor = dyn_cast<AccessorDecl>(afd)) {
603609 if (accessor->isCoroutine ()) {
604610 auto yieldTyInContext = accessor->mapTypeIntoContext (
@@ -618,11 +624,12 @@ class LifetimeDependenceChecker {
618624
619625 std::optional<LifetimeDependenceKind>
620626 getDependenceKindFromDescriptor (LifetimeDescriptor descriptor,
621- ParamDecl *decl) {
627+ ParamDecl *paramDecl) {
628+ auto *afd = cast<AbstractFunctionDecl>(decl);
622629 auto loc = descriptor.getLoc ();
623- auto type = decl ->getTypeInContext ();
630+ auto type = paramDecl ->getTypeInContext ();
624631 auto parsedLifetimeKind = descriptor.getParsedLifetimeDependenceKind ();
625- auto ownership = decl ->getValueOwnership ();
632+ auto ownership = paramDecl ->getValueOwnership ();
626633 auto loweredOwnership = ownership != ValueOwnership::Default
627634 ? ownership
628635 : getLoweredOwnership (afd);
@@ -704,6 +711,7 @@ class LifetimeDependenceChecker {
704711 // Finds the ParamDecl* and its index from a LifetimeDescriptor
705712 std::optional<std::pair<ParamDecl *, unsigned >>
706713 getParamDeclFromDescriptor (LifetimeDescriptor descriptor) {
714+ auto *afd = cast<AbstractFunctionDecl>(decl);
707715 switch (descriptor.getDescriptorKind ()) {
708716 case LifetimeDescriptor::DescriptorKind::Named: {
709717 unsigned paramIndex = 0 ;
@@ -752,6 +760,7 @@ class LifetimeDependenceChecker {
752760 }
753761
754762 std::optional<ArrayRef<LifetimeDependenceInfo>> checkAttribute () {
763+ auto *afd = cast<AbstractFunctionDecl>(decl);
755764 SmallVector<LifetimeDependenceInfo, 1 > lifetimeDependencies;
756765 llvm::SmallSet<unsigned , 1 > lifetimeDependentTargets;
757766 auto lifetimeAttrs = afd->getAttrs ().getAttributes <LifetimeAttr>();
@@ -776,6 +785,7 @@ class LifetimeDependenceChecker {
776785
777786 std::optional<LifetimeDependenceInfo>
778787 checkAttributeEntry (LifetimeEntry *entry) {
788+ auto *afd = cast<AbstractFunctionDecl>(decl);
779789 auto capacity = afd->hasImplicitSelfDecl ()
780790 ? (afd->getParameters ()->size () + 1 )
781791 : afd->getParameters ()->size ();
@@ -897,6 +907,7 @@ class LifetimeDependenceChecker {
897907 // / If the current function is a mutating method and 'self' is non-Escapable,
898908 // / return 'self's ParamDecl.
899909 bool isMutatingNonEscapableSelf () {
910+ auto *afd = cast<AbstractFunctionDecl>(decl);
900911 if (!hasImplicitSelfParam ())
901912 return false ;
902913
@@ -914,6 +925,7 @@ class LifetimeDependenceChecker {
914925 // Infer method dependence of result on self for
915926 // methods, getters, and _modify accessors.
916927 void inferNonEscapableResultOnSelf () {
928+ auto *afd = cast<AbstractFunctionDecl>(decl);
917929 Type selfTypeInContext = dc->getSelfTypeInContext ();
918930 if (selfTypeInContext->hasError ()) {
919931 return ;
@@ -980,6 +992,7 @@ class LifetimeDependenceChecker {
980992 // stored property (for getters or initializers).
981993 std::optional<LifetimeDependenceKind>
982994 inferLifetimeDependenceKind (Type sourceType, ValueOwnership ownership) {
995+ auto *afd = cast<AbstractFunctionDecl>(decl);
983996 if (!sourceType->isEscapable ()) {
984997 return LifetimeDependenceKind::Inherit;
985998 }
@@ -1003,6 +1016,7 @@ class LifetimeDependenceChecker {
10031016 // to an implicit setter, because the implementation is simply an assignment
10041017 // to stored property.
10051018 void inferImplicitInit () {
1019+ auto *afd = cast<AbstractFunctionDecl>(decl);
10061020 if (afd->getParameters ()->size () == 0 ) {
10071021 // Empty ~Escapable types can be implicitly initialized without any
10081022 // dependencies. In SIL, implicit initializers become explicit. Set
@@ -1042,6 +1056,7 @@ class LifetimeDependenceChecker {
10421056 // inference if any exist, infer scoped dependency, or infer no
10431057 // dependency. Implicit setters for Escapable properties are not inferred.
10441058 void inferNonEscapableResultOnParam () {
1059+ auto *afd = cast<AbstractFunctionDecl>(decl);
10451060 // This is only called when there is no 'self' argument that can be the
10461061 // source of a dependence.
10471062 assert (!hasImplicitSelfParam ());
@@ -1091,6 +1106,7 @@ class LifetimeDependenceChecker {
10911106 // Lazy inference for .swiftinterface backward compatibility and
10921107 // experimentation. Inference cases can be added but not removed.
10931108 void lazillyInferNonEscapableResultOnParam () {
1109+ auto *afd = cast<AbstractFunctionDecl>(decl);
10941110 std::optional<unsigned > candidateParamIndex;
10951111 std::optional<LifetimeDependenceKind> candidateLifetimeKind;
10961112 unsigned paramIndex = 0 ;
@@ -1137,6 +1153,7 @@ class LifetimeDependenceChecker {
11371153 // Infer a mutating 'self' dependency when 'self' is non-Escapable and the
11381154 // result is 'void'.
11391155 void inferMutatingSelf () {
1156+ auto *afd = cast<AbstractFunctionDecl>(decl);
11401157 if (!isMutatingNonEscapableSelf ()) {
11411158 return ;
11421159 }
@@ -1166,7 +1183,7 @@ class LifetimeDependenceChecker {
11661183 // Infer dependence for an accessor whose non-escapable result depends on
11671184 // self. This includes _read and _modify.
11681185 void inferAccessor (AccessorDecl *accessor, Type selfTypeInContext) {
1169- // Explicit accessors require explicit lifetime dependencies.
1186+ auto *afd = cast<AbstractFunctionDecl>(decl);
11701187 if (!isImplicitOrSIL () && !useLazyInference ()) {
11711188 return ;
11721189 }
@@ -1315,6 +1332,7 @@ class LifetimeDependenceChecker {
13151332 // Do not issue any diagnostics. This inference is triggered even when the
13161333 // feature is disabled!
13171334 void inferInoutParams () {
1335+ auto *afd = cast<AbstractFunctionDecl>(decl);
13181336 if (isMutatingNonEscapableSelf ()) {
13191337 return ;
13201338 }
@@ -1347,6 +1365,7 @@ class LifetimeDependenceChecker {
13471365 }
13481366
13491367 void inferUnambiguousInoutParams () {
1368+ auto *afd = cast<AbstractFunctionDecl>(decl);
13501369 if (afd->getParameters ()->size () != 1 ) {
13511370 return ;
13521371 }
@@ -1364,6 +1383,7 @@ class LifetimeDependenceChecker {
13641383 }
13651384
13661385 void inferBuiltin () {
1386+ auto *afd = cast<AbstractFunctionDecl>(decl);
13671387 // Normal inout parameter inference works for most generic Builtins.
13681388 inferUnambiguousInoutParams ();
13691389 if (!lifetimeDependencies.empty ()) {
0 commit comments