mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Introduce a new suppressible experimental feature to guard @_lifetime
This commit is contained in:
@@ -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>()) {
|
||||
|
||||
Reference in New Issue
Block a user