@@ -147,36 +147,42 @@ UNINTERESTING_FEATURE(SendingArgsAndResults)
147147UNINTERESTING_FEATURE(CheckImplementationOnly)
148148UNINTERESTING_FEATURE(CheckImplementationOnlyStrict)
149149
150- static bool findUnderscoredLifetimeAttr (Decl *decl) {
151- auto hasUnderscoredLifetimeAttr = [](Decl *decl) {
150+ static bool findLifetimeAttr (Decl *decl, bool findUnderscored ) {
151+ auto hasLifetimeAttr = [& ](Decl *decl) {
152152 if (!decl->getAttrs ().hasAttribute <LifetimeAttr>()) {
153153 return false ;
154154 }
155155 // Since we ban mixing @lifetime and @_lifetime on the same decl, checking
156156 // any one LifetimeAttr on the decl is sufficient.
157157 // FIXME: Implement the ban.
158- return decl->getAttrs ().getAttribute <LifetimeAttr>()->isUnderscored ();
158+ if (findUnderscored) {
159+ return decl->getAttrs ().getAttribute <LifetimeAttr>()->isUnderscored ();
160+ }
161+ return !decl->getAttrs ().getAttribute <LifetimeAttr>()->isUnderscored ();
159162 };
160163
161164 switch (decl->getKind ()) {
162165 case DeclKind::Var: {
163166 auto *var = cast<VarDecl>(decl);
164- return llvm::any_of (var->getAllAccessors (), hasUnderscoredLifetimeAttr );
167+ return llvm::any_of (var->getAllAccessors (), hasLifetimeAttr );
165168 }
166169 default :
167- return hasUnderscoredLifetimeAttr (decl);
170+ return hasLifetimeAttr (decl);
168171 }
169172}
170173
171174static bool usesFeatureLifetimeDependence (Decl *decl) {
172- if (decl->getAttrs ().hasAttribute <LifetimeAttr>()) {
173- if (findUnderscoredLifetimeAttr (decl)) {
174- // Experimental feature Lifetimes will guard the decl.
175- return false ;
176- }
175+ if (findLifetimeAttr (decl, /* findUnderscored*/ false )) {
177176 return true ;
178177 }
179178
179+ // Guard inferred lifetime dependencies with LifetimeDependence if it was
180+ // enabled.
181+ if (!decl->getASTContext ().LangOpts .hasFeature (Feature::LifetimeDependence)) {
182+ return false ;
183+ }
184+
185+ // Check for inferred lifetime dependencies
180186 if (auto *afd = dyn_cast<AbstractFunctionDecl>(decl)) {
181187 return afd->getInterfaceType ()
182188 ->getAs <AnyFunctionType>()
@@ -189,7 +195,25 @@ static bool usesFeatureLifetimeDependence(Decl *decl) {
189195}
190196
191197static bool usesFeatureLifetimes (Decl *decl) {
192- return findUnderscoredLifetimeAttr (decl);
198+ if (findLifetimeAttr (decl, /* findUnderscored*/ true )) {
199+ return true ;
200+ }
201+
202+ // Guard inferred lifetime dependencies with Lifetimes if it was enabled.
203+ if (!decl->getASTContext ().LangOpts .hasFeature (Feature::Lifetimes)) {
204+ return false ;
205+ }
206+
207+ // Check for inferred lifetime dependencies
208+ if (auto *afd = dyn_cast<AbstractFunctionDecl>(decl)) {
209+ return afd->getInterfaceType ()
210+ ->getAs <AnyFunctionType>()
211+ ->hasLifetimeDependencies ();
212+ }
213+ if (auto *varDecl = dyn_cast<VarDecl>(decl)) {
214+ return !varDecl->getTypeInContext ()->isEscapable ();
215+ }
216+ return false ;
193217}
194218
195219static bool usesFeatureInoutLifetimeDependence (Decl *decl) {
0 commit comments