Introduce a new suppressible experimental feature to guard @_lifetime

This commit is contained in:
Meghana Gupta
2025-06-06 14:18:31 -07:00
parent 0dfa1fc312
commit dcf072f9d0
9 changed files with 73 additions and 17 deletions

View File

@@ -258,10 +258,36 @@ static bool usesFeatureSendingArgsAndResults(Decl *decl) {
return false;
}
static bool findUnderscoredLifetimeAttr(Decl *decl) {
auto hasUnderscoredLifetimeAttr = [](Decl *decl) {
if (!decl->getAttrs().hasAttribute<LifetimeAttr>()) {
return false;
}
// Since we ban mixing @lifetime and @_lifetime on the same decl, checking
// any one LifetimeAttr on the decl is sufficient.
// FIXME: Implement the ban.
return decl->getAttrs().getAttribute<LifetimeAttr>()->isUnderscored();
};
switch (decl->getKind()) {
case DeclKind::Var: {
auto *var = cast<VarDecl>(decl);
return llvm::any_of(var->getAllAccessors(), hasUnderscoredLifetimeAttr);
}
default:
return hasUnderscoredLifetimeAttr(decl);
}
}
static bool usesFeatureLifetimeDependence(Decl *decl) {
if (decl->getAttrs().hasAttribute<LifetimeAttr>()) {
if (findUnderscoredLifetimeAttr(decl)) {
// Experimental feature Lifetimes will guard the decl.
return false;
}
return true;
}
if (auto *afd = dyn_cast<AbstractFunctionDecl>(decl)) {
return afd->getInterfaceType()
->getAs<AnyFunctionType>()
@@ -273,6 +299,10 @@ static bool usesFeatureLifetimeDependence(Decl *decl) {
return false;
}
static bool usesFeatureLifetimes(Decl *decl) {
return findUnderscoredLifetimeAttr(decl);
}
static bool usesFeatureInoutLifetimeDependence(Decl *decl) {
auto hasInoutLifetimeDependence = [](Decl *decl) {
for (auto attr : decl->getAttrs().getAttributes<LifetimeAttr>()) {