mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Make NonEscapableTypes as a suppressible experimental feature
This commit is contained in:
@@ -130,7 +130,75 @@ UNINTERESTING_FEATURE(Embedded)
|
||||
UNINTERESTING_FEATURE(Volatile)
|
||||
UNINTERESTING_FEATURE(SuppressedAssociatedTypes)
|
||||
UNINTERESTING_FEATURE(StructLetDestructuring)
|
||||
UNINTERESTING_FEATURE(NonescapableTypes)
|
||||
|
||||
static bool usesFeatureNonescapableTypes(Decl *decl) {
|
||||
auto containsNonEscapable =
|
||||
[](SmallVectorImpl<InverseRequirement> &inverseReqs) {
|
||||
auto foundIt =
|
||||
llvm::find_if(inverseReqs, [](InverseRequirement inverseReq) {
|
||||
if (inverseReq.getKind() == InvertibleProtocolKind::Escapable) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return foundIt != inverseReqs.end();
|
||||
};
|
||||
|
||||
if (auto *valueDecl = dyn_cast<ValueDecl>(decl)) {
|
||||
if (isa<StructDecl, EnumDecl, ClassDecl>(decl)) {
|
||||
auto *nominalDecl = cast<NominalTypeDecl>(valueDecl);
|
||||
InvertibleProtocolSet inverses;
|
||||
bool anyObject = false;
|
||||
getDirectlyInheritedNominalTypeDecls(nominalDecl, inverses, anyObject);
|
||||
if (inverses.containsEscapable()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (auto proto = dyn_cast<ProtocolDecl>(decl)) {
|
||||
auto reqSig = proto->getRequirementSignature();
|
||||
|
||||
SmallVector<Requirement, 2> reqs;
|
||||
SmallVector<InverseRequirement, 2> inverses;
|
||||
reqSig.getRequirementsWithInverses(proto, reqs, inverses);
|
||||
if (containsNonEscapable(inverses))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isa<AbstractFunctionDecl>(valueDecl) ||
|
||||
isa<AbstractStorageDecl>(valueDecl)) {
|
||||
if (valueDecl->getInterfaceType().findIf([&](Type type) -> bool {
|
||||
if (auto *nominalDecl = type->getAnyNominal()) {
|
||||
if (isa<StructDecl, EnumDecl, ClassDecl>(nominalDecl))
|
||||
return usesFeatureNonescapableTypes(nominalDecl);
|
||||
}
|
||||
return false;
|
||||
})) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (auto *ext = dyn_cast<ExtensionDecl>(decl)) {
|
||||
if (auto *nominal = ext->getExtendedNominal())
|
||||
if (usesFeatureNonescapableTypes(nominal))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (auto *genCtx = decl->getAsGenericContext()) {
|
||||
if (auto genericSig = genCtx->getGenericSignature()) {
|
||||
SmallVector<Requirement, 2> reqs;
|
||||
SmallVector<InverseRequirement, 2> inverseReqs;
|
||||
genericSig->getRequirementsWithInverses(reqs, inverseReqs);
|
||||
if (containsNonEscapable(inverseReqs)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
UNINTERESTING_FEATURE(StaticExclusiveOnly)
|
||||
UNINTERESTING_FEATURE(ExtractConstantsFromMembers)
|
||||
UNINTERESTING_FEATURE(FixedArrays)
|
||||
|
||||
Reference in New Issue
Block a user