Skip to content

Commit b396371

Browse files
committed
AST: Promote RethrowsProtocol feature to baseline.
1 parent 8093783 commit b396371

File tree

3 files changed

+6
-87
lines changed

3 files changed

+6
-87
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ BASELINE_LANGUAGE_FEATURE(EffectfulProp, 310, "Effectful properties")
136136
BASELINE_LANGUAGE_FEATURE(MarkerProtocol, 0, "@_marker protocol")
137137
BASELINE_LANGUAGE_FEATURE(Actors, 0, "actors")
138138
BASELINE_LANGUAGE_FEATURE(ConcurrentFunctions, 0, "@concurrent functions")
139-
LANGUAGE_FEATURE(RethrowsProtocol, 0, "@rethrows protocol")
139+
BASELINE_LANGUAGE_FEATURE(RethrowsProtocol, 0, "@rethrows protocol")
140140
BASELINE_LANGUAGE_FEATURE(GlobalActors, 316, "Global actors")
141141
BASELINE_LANGUAGE_FEATURE(BuiltinJob, 0, "Builtin.Job type")
142142
BASELINE_LANGUAGE_FEATURE(Sendable, 0, "Sendable and @Sendable")

lib/AST/FeatureSet.cpp

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -49,81 +49,6 @@ static bool usesTypeMatching(Decl *decl, llvm::function_ref<bool(Type)> fn) {
4949
#define UNINTERESTING_FEATURE(FeatureName) \
5050
static bool usesFeature##FeatureName(Decl *decl) { return false; }
5151

52-
static bool usesFeatureRethrowsProtocol(Decl *decl,
53-
SmallPtrSet<Decl *, 16> &checked) {
54-
// Make sure we don't recurse.
55-
if (!checked.insert(decl).second)
56-
return false;
57-
58-
// Check an inheritance clause for a marker protocol.
59-
auto checkInherited = [&](InheritedTypes inherited) -> bool {
60-
for (unsigned i : inherited.getIndices()) {
61-
if (auto inheritedType = inherited.getResolvedType(i)) {
62-
if (inheritedType->isExistentialType()) {
63-
auto layout = inheritedType->getExistentialLayout();
64-
for (ProtocolDecl *proto : layout.getProtocols()) {
65-
if (usesFeatureRethrowsProtocol(proto, checked))
66-
return true;
67-
}
68-
}
69-
}
70-
}
71-
72-
return false;
73-
};
74-
75-
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
76-
if (checkInherited(nominal->getInherited()))
77-
return true;
78-
}
79-
80-
if (auto proto = dyn_cast<ProtocolDecl>(decl)) {
81-
if (proto->getAttrs().hasAttribute<AtRethrowsAttr>())
82-
return true;
83-
}
84-
85-
if (auto ext = dyn_cast<ExtensionDecl>(decl)) {
86-
if (auto nominal = ext->getSelfNominalTypeDecl())
87-
if (usesFeatureRethrowsProtocol(nominal, checked))
88-
return true;
89-
90-
if (checkInherited(ext->getInherited()))
91-
return true;
92-
}
93-
94-
if (auto genericSig =
95-
decl->getInnermostDeclContext()->getGenericSignatureOfContext()) {
96-
for (const auto &req : genericSig.getRequirements()) {
97-
if (req.getKind() == RequirementKind::Conformance &&
98-
usesFeatureRethrowsProtocol(req.getProtocolDecl(), checked))
99-
return true;
100-
}
101-
}
102-
103-
if (auto value = dyn_cast<ValueDecl>(decl)) {
104-
if (Type type = value->getInterfaceType()) {
105-
bool hasRethrowsProtocol = type.findIf([&](Type type) {
106-
if (auto nominal = type->getAnyNominal()) {
107-
if (usesFeatureRethrowsProtocol(nominal, checked))
108-
return true;
109-
}
110-
111-
return false;
112-
});
113-
114-
if (hasRethrowsProtocol)
115-
return true;
116-
}
117-
}
118-
119-
return false;
120-
}
121-
122-
static bool usesFeatureRethrowsProtocol(Decl *decl) {
123-
SmallPtrSet<Decl *, 16> checked;
124-
return usesFeatureRethrowsProtocol(decl, checked);
125-
}
126-
12752
static bool usesFeatureNewCxxMethodSafetyHeuristics(Decl *decl) {
12853
return decl->hasClangNode();
12954
}

test/ModuleInterface/features.swift

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,39 +81,33 @@ public class OldSchool2: MP {
8181
public func takeClass() async { }
8282
}
8383

84-
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
85-
// CHECK-NEXT: @rethrows public protocol RP
84+
// CHECK: @rethrows public protocol RP
8685
@rethrows public protocol RP {
8786
func f() throws -> Bool
8887
}
8988

9089
// CHECK: public struct UsesRP {
9190
public struct UsesRP {
92-
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
93-
// CHECK-NEXT: public var value: (any FeatureTest.RP)? {
94-
// CHECK-NOT: #if compiler(>=5.3) && $RethrowsProtocol
95-
// CHECK: get
91+
// CHECK: public var value: (any FeatureTest.RP)? {
92+
// CHECK-NEXT: get
9693
public var value: RP? {
9794
nil
9895
}
9996
}
10097

101-
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
102-
// CHECK-NEXT: public struct IsRP
98+
// CHECK: public struct IsRP
10399
public struct IsRP: RP {
104100
// CHECK-NEXT: public func f()
105101
public func f() -> Bool { }
106102

107-
// CHECK-NOT: $RethrowsProtocol
108103
// CHECK-NEXT: public var isF:
109104
// CHECK-NEXT: get
110105
public var isF: Bool {
111106
f()
112107
}
113108
}
114109

115-
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
116-
// CHECK-NEXT: public func acceptsRP
110+
// CHECK: public func acceptsRP
117111
public func acceptsRP<T: RP>(_: T) { }
118112

119113
// CHECK: extension Swift.Array : FeatureTest.MP where Element : FeatureTest.MP {

0 commit comments

Comments
 (0)