@@ -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 }
@@ -418,6 +418,7 @@ class LifetimeDependenceChecker {
418418 }
419419
420420 std::string diagnosticQualifier () const {
421+ auto *afd = cast<AbstractFunctionDecl>(decl);
421422 if (afd->isImplicit ()) {
422423 if (isInit ()) {
423424 return " an implicit initializer" ;
@@ -462,6 +463,7 @@ class LifetimeDependenceChecker {
462463 // initializers, the inout self parameter is actually considered the result
463464 // type so is not handled here.
464465 void diagnoseMissingSelfDependencies (DiagID diagID) {
466+ auto *afd = cast<AbstractFunctionDecl>(decl);
465467 if (!hasImplicitSelfParam ()) {
466468 return ;
467469 }
@@ -482,6 +484,7 @@ class LifetimeDependenceChecker {
482484 }
483485
484486 void diagnoseMissingInoutDependencies (DiagID diagID) {
487+ auto *afd = cast<AbstractFunctionDecl>(decl);
485488 unsigned paramIndex = 0 ;
486489 for (auto *param : *afd->getParameters ()) {
487490 SWIFT_DEFER { paramIndex++; };
@@ -528,6 +531,7 @@ class LifetimeDependenceChecker {
528531
529532 bool isCompatibleWithOwnership (LifetimeDependenceKind kind, Type type,
530533 ValueOwnership ownership) const {
534+ auto *afd = cast<AbstractFunctionDecl>(decl);
531535 if (kind == LifetimeDependenceKind::Inherit) {
532536 return true ;
533537 }
@@ -568,6 +572,7 @@ class LifetimeDependenceChecker {
568572 };
569573
570574 TargetDeps createDeps (unsigned targetIndex) {
575+ auto *afd = cast<AbstractFunctionDecl>(decl);
571576 unsigned capacity = afd->hasImplicitSelfDecl ()
572577 ? (afd->getParameters ()->size () + 1 )
573578 : afd->getParameters ()->size ();
@@ -598,6 +603,7 @@ class LifetimeDependenceChecker {
598603 }
599604
600605 Type getResultOrYield () const {
606+ auto *afd = cast<AbstractFunctionDecl>(decl);
601607 if (auto *accessor = dyn_cast<AccessorDecl>(afd)) {
602608 if (accessor->isCoroutine ()) {
603609 auto yieldTyInContext = accessor->mapTypeIntoContext (
@@ -617,11 +623,12 @@ class LifetimeDependenceChecker {
617623
618624 std::optional<LifetimeDependenceKind>
619625 getDependenceKindFromDescriptor (LifetimeDescriptor descriptor,
620- ParamDecl *decl) {
626+ ParamDecl *paramDecl) {
627+ auto *afd = cast<AbstractFunctionDecl>(decl);
621628 auto loc = descriptor.getLoc ();
622- auto type = decl ->getTypeInContext ();
629+ auto type = paramDecl ->getTypeInContext ();
623630 auto parsedLifetimeKind = descriptor.getParsedLifetimeDependenceKind ();
624- auto ownership = decl ->getValueOwnership ();
631+ auto ownership = paramDecl ->getValueOwnership ();
625632 auto loweredOwnership = ownership != ValueOwnership::Default
626633 ? ownership
627634 : getLoweredOwnership (afd);
@@ -703,6 +710,7 @@ class LifetimeDependenceChecker {
703710 // Finds the ParamDecl* and its index from a LifetimeDescriptor
704711 std::optional<std::pair<ParamDecl *, unsigned >>
705712 getParamDeclFromDescriptor (LifetimeDescriptor descriptor) {
713+ auto *afd = cast<AbstractFunctionDecl>(decl);
706714 switch (descriptor.getDescriptorKind ()) {
707715 case LifetimeDescriptor::DescriptorKind::Named: {
708716 unsigned paramIndex = 0 ;
@@ -751,6 +759,7 @@ class LifetimeDependenceChecker {
751759 }
752760
753761 std::optional<ArrayRef<LifetimeDependenceInfo>> checkAttribute () {
762+ auto *afd = cast<AbstractFunctionDecl>(decl);
754763 SmallVector<LifetimeDependenceInfo, 1 > lifetimeDependencies;
755764 llvm::SmallSet<unsigned , 1 > lifetimeDependentTargets;
756765 auto lifetimeAttrs = afd->getAttrs ().getAttributes <LifetimeAttr>();
@@ -775,6 +784,7 @@ class LifetimeDependenceChecker {
775784
776785 std::optional<LifetimeDependenceInfo>
777786 checkAttributeEntry (LifetimeEntry *entry) {
787+ auto *afd = cast<AbstractFunctionDecl>(decl);
778788 auto capacity = afd->hasImplicitSelfDecl ()
779789 ? (afd->getParameters ()->size () + 1 )
780790 : afd->getParameters ()->size ();
@@ -896,6 +906,7 @@ class LifetimeDependenceChecker {
896906 // / If the current function is a mutating method and 'self' is non-Escapable,
897907 // / return 'self's ParamDecl.
898908 bool isMutatingNonEscapableSelf () {
909+ auto *afd = cast<AbstractFunctionDecl>(decl);
899910 if (!hasImplicitSelfParam ())
900911 return false ;
901912
@@ -912,6 +923,7 @@ class LifetimeDependenceChecker {
912923
913924 // Infer method dependence: result depends on self. This includes _modify.
914925 void inferNonEscapableResultOnSelf () {
926+ auto *afd = cast<AbstractFunctionDecl>(decl);
915927 Type selfTypeInContext = dc->getSelfTypeInContext ();
916928 if (selfTypeInContext->hasError ()) {
917929 return ;
@@ -963,6 +975,7 @@ class LifetimeDependenceChecker {
963975
964976 std::optional<LifetimeDependenceKind>
965977 inferLifetimeDependenceKind (Type sourceType, ValueOwnership ownership) {
978+ auto *afd = cast<AbstractFunctionDecl>(decl);
966979 if (!sourceType->isEscapable ()) {
967980 return LifetimeDependenceKind::Inherit;
968981 }
@@ -985,6 +998,7 @@ class LifetimeDependenceChecker {
985998 // to an implicit setter, because the implementation is simply an assignment
986999 // to stored property.
9871000 void inferImplicitInit () {
1001+ auto *afd = cast<AbstractFunctionDecl>(decl);
9881002 if (afd->getParameters ()->size () == 0 ) {
9891003 // Empty ~Escapable types can be implicitly initialized without any
9901004 // dependencies. In SIL, implicit initializers become explicit. Set
@@ -1024,6 +1038,7 @@ class LifetimeDependenceChecker {
10241038 // inference if any exist, infer scoped dependency, or infer no
10251039 // dependency. Implicit setters for Escapable properties are not inferred.
10261040 void inferNonEscapableResultOnParam () {
1041+ auto *afd = cast<AbstractFunctionDecl>(decl);
10271042 // This is only called when there is no 'self' argument that can be the
10281043 // source of a dependence.
10291044 assert (!hasImplicitSelfParam ());
@@ -1073,6 +1088,7 @@ class LifetimeDependenceChecker {
10731088 // Lazy inference for .swiftinterface backward compatibility and
10741089 // experimentation. Inference cases can be added but not removed.
10751090 void lazillyInferNonEscapableResultOnParam () {
1091+ auto *afd = cast<AbstractFunctionDecl>(decl);
10761092 std::optional<unsigned > candidateParamIndex;
10771093 std::optional<LifetimeDependenceKind> candidateLifetimeKind;
10781094 unsigned paramIndex = 0 ;
@@ -1119,6 +1135,7 @@ class LifetimeDependenceChecker {
11191135 // Infer a mutating 'self' dependency when 'self' is non-Escapable and the
11201136 // result is 'void'.
11211137 void inferMutatingSelf () {
1138+ auto *afd = cast<AbstractFunctionDecl>(decl);
11221139 if (!isMutatingNonEscapableSelf ()) {
11231140 return ;
11241141 }
@@ -1144,6 +1161,7 @@ class LifetimeDependenceChecker {
11441161
11451162 // Infer a mutating accessor's non-Escapable 'self' dependencies.
11461163 void inferMutatingAccessor (AccessorDecl *accessor) {
1164+ auto *afd = cast<AbstractFunctionDecl>(decl);
11471165 if (!isImplicitOrSIL () && !useLazyInference ()) {
11481166 // Explicit setters require explicit lifetime dependencies.
11491167 return ;
@@ -1231,6 +1249,7 @@ class LifetimeDependenceChecker {
12311249 // Do not issue any diagnostics. This inference is triggered even when the
12321250 // feature is disabled!
12331251 void inferInoutParams () {
1252+ auto *afd = cast<AbstractFunctionDecl>(decl);
12341253 if (isMutatingNonEscapableSelf ()) {
12351254 return ;
12361255 }
@@ -1263,6 +1282,7 @@ class LifetimeDependenceChecker {
12631282 }
12641283
12651284 void inferUnambiguousInoutParams () {
1285+ auto *afd = cast<AbstractFunctionDecl>(decl);
12661286 if (afd->getParameters ()->size () != 1 ) {
12671287 return ;
12681288 }
@@ -1280,6 +1300,7 @@ class LifetimeDependenceChecker {
12801300 }
12811301
12821302 void inferBuiltin () {
1303+ auto *afd = cast<AbstractFunctionDecl>(decl);
12831304 // Normal inout parameter inference works for most generic Builtins.
12841305 inferUnambiguousInoutParams ();
12851306 if (!lifetimeDependencies.empty ()) {
0 commit comments