Skip to content

Commit 1d9e085

Browse files
committed
AST: Re-baseline NonescapableTypes feature.
1 parent dd28a3e commit 1d9e085

File tree

8 files changed

+6
-112
lines changed

8 files changed

+6
-112
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ BASELINE_LANGUAGE_FEATURE(BorrowingSwitch, 432, "Noncopyable type pattern matchi
253253
BASELINE_LANGUAGE_FEATURE(IsolatedAny, 431, "@isolated(any) function types")
254254
LANGUAGE_FEATURE(IsolatedAny2, 431, "@isolated(any) function types")
255255
LANGUAGE_FEATURE(ObjCImplementation, 436, "@objc @implementation extensions")
256-
LANGUAGE_FEATURE(NonescapableTypes, 446, "Nonescapable types")
256+
BASELINE_LANGUAGE_FEATURE(NonescapableTypes, 446, "Nonescapable types")
257257
BASELINE_LANGUAGE_FEATURE(BuiltinEmplaceTypedThrows, 0, "Builtin.emplace typed throws")
258258
BASELINE_LANGUAGE_FEATURE(MemorySafetyAttributes, 458, "@unsafe attribute")
259259
BASELINE_LANGUAGE_FEATURE(ValueGenerics, 452, "Value generics feature (integer generics)")

lib/AST/FeatureSet.cpp

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -130,74 +130,6 @@ UNINTERESTING_FEATURE(NoExplicitNonIsolated)
130130
// TODO: Return true for inlinable function bodies with module selectors in them
131131
UNINTERESTING_FEATURE(ModuleSelector)
132132

133-
static bool usesFeatureNonescapableTypes(Decl *decl) {
134-
auto containsNonEscapable =
135-
[](SmallVectorImpl<InverseRequirement> &inverseReqs) {
136-
auto foundIt =
137-
llvm::find_if(inverseReqs, [](InverseRequirement inverseReq) {
138-
if (inverseReq.getKind() == InvertibleProtocolKind::Escapable) {
139-
return true;
140-
}
141-
return false;
142-
});
143-
return foundIt != inverseReqs.end();
144-
};
145-
146-
if (auto *valueDecl = dyn_cast<ValueDecl>(decl)) {
147-
if (isa<StructDecl, EnumDecl, ClassDecl>(decl)) {
148-
auto *nominalDecl = cast<NominalTypeDecl>(valueDecl);
149-
InvertibleProtocolSet inverses;
150-
bool anyObject = false;
151-
getDirectlyInheritedNominalTypeDecls(nominalDecl, inverses, anyObject);
152-
if (inverses.containsEscapable()) {
153-
return true;
154-
}
155-
}
156-
157-
if (auto proto = dyn_cast<ProtocolDecl>(decl)) {
158-
auto reqSig = proto->getRequirementSignature();
159-
160-
SmallVector<Requirement, 2> reqs;
161-
SmallVector<InverseRequirement, 2> inverses;
162-
reqSig.getRequirementsWithInverses(proto, reqs, inverses);
163-
if (containsNonEscapable(inverses))
164-
return true;
165-
}
166-
167-
if (isa<AbstractFunctionDecl>(valueDecl) ||
168-
isa<AbstractStorageDecl>(valueDecl)) {
169-
if (valueDecl->getInterfaceType().findIf([&](Type type) -> bool {
170-
if (auto *nominalDecl = type->getAnyNominal()) {
171-
if (isa<StructDecl, EnumDecl, ClassDecl>(nominalDecl))
172-
return usesFeatureNonescapableTypes(nominalDecl);
173-
}
174-
return false;
175-
})) {
176-
return true;
177-
}
178-
}
179-
}
180-
181-
if (auto *ext = dyn_cast<ExtensionDecl>(decl)) {
182-
if (auto *nominal = ext->getExtendedNominal())
183-
if (usesFeatureNonescapableTypes(nominal))
184-
return true;
185-
}
186-
187-
if (auto *genCtx = decl->getAsGenericContext()) {
188-
if (auto genericSig = genCtx->getGenericSignature()) {
189-
SmallVector<Requirement, 2> reqs;
190-
SmallVector<InverseRequirement, 2> inverseReqs;
191-
genericSig->getRequirementsWithInverses(reqs, inverseReqs);
192-
if (containsNonEscapable(inverseReqs)) {
193-
return true;
194-
}
195-
}
196-
}
197-
198-
return false;
199-
}
200-
201133
static bool usesFeatureInlineArrayTypeSugar(Decl *D) {
202134
return usesTypeMatching(D, [&](Type ty) {
203135
return isa<InlineArrayType>(ty.getPointer());

test/Concurrency/sending_conditional_suppression.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ public struct TestInStruct {
206206
// Make sure that we emit compiler(>= 5.3) when emitting the suppressing check
207207
// to make sure we do not fail if we fail to parse sending in the if block.
208208

209-
// CHECK: #if compiler(>=5.3) && $NonescapableTypes // Suppression Count: 24
210-
// CHECK-NEXT: #if compiler(>=5.3) && $SendingArgsAndResults // Suppression Count: 25
209+
// CHECK: #if compiler(>=5.3) && $SendingArgsAndResults // Suppression Count: 24
211210
// CHECK-NEXT: @inlinable public func withCheckedContinuation<T>(isolation: isolated (any _Concurrency.Actor)? = #isolation, function: Swift.String = #function, _ body: (_Concurrency.CheckedContinuation<T, Swift.Never>) -> Swift.Void) async -> sending T {
212211
// CHECK-NEXT: fatalError()
213212
// CHECK-NEXT: }
@@ -216,7 +215,6 @@ public struct TestInStruct {
216215
// CHECK-NEXT: fatalError()
217216
// CHECK-NEXT: }
218217
// CHECK-NEXT: #endif
219-
// CHECK-NEXT: #endif
220218
@inlinable public func withCheckedContinuation<T>(
221219
isolation: isolated (any _Concurrency.Actor)? = #isolation,
222220
function: String = #function,
@@ -225,14 +223,14 @@ public struct TestInStruct {
225223
fatalError()
226224
}
227225

228-
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults // Suppression Count: 26
226+
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults // Suppression Count: 25
229227
// CHECK-NEXT: public var publicGlobal: (sending test.NonSendableKlass) -> ()
230228
// CHECK-NEXT: #else
231229
// CHECK-NEXT: public var publicGlobal: (__owned test.NonSendableKlass) -> ()
232230
// CHECK-NEXT: #endif
233231
public var publicGlobal: (sending NonSendableKlass) -> () = { x in fatalError() }
234232

235-
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults // Suppression Count: 27
233+
// CHECK-LABEL: #if compiler(>=5.3) && $SendingArgsAndResults // Suppression Count: 26
236234
// CHECK-NEXT: @usableFromInline
237235
// CHECK-NEXT: internal var usableFromInlineGlobal: (sending test.NonSendableKlass) -> ()
238236
// CHECK-NEXT: #else

test/ModuleInterface/lifetime_dependence_test.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import lifetime_dependence
4040
// Check that an implicitly dependent variable accessor is guarded by LifetimeDependence.
4141
//
4242
// CHECK: extension lifetime_dependence.Container {
43-
// CHECK-NEXT: #if compiler(>=5.3) && $NonescapableTypes && $LifetimeDependence
43+
// CHECK-NEXT: #if compiler(>=5.3) && $LifetimeDependence
4444
// CHECK-NEXT: public var storage: lifetime_dependence.BufferView {
4545

4646
// CHECK-LABEL: extension Swift.UnsafeMutableBufferPointer where Element : ~Copyable {

test/ModuleInterface/lifetime_underscored_dependence_test.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ import lifetime_underscored_dependence
108108
// Check that an implicitly dependent variable accessor is guarded by LifetimeDependence.
109109
//
110110
// CHECK: extension lifetime_underscored_dependence.Container {
111-
// CHECK-NEXT: #if compiler(>=5.3) && $NonescapableTypes && $LifetimeDependence
111+
// CHECK-NEXT: #if compiler(>=5.3) && $LifetimeDependence
112112
// CHECK-NEXT: public var storage: lifetime_underscored_dependence.BufferView {

test/ModuleInterface/noncopyable_generics.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ import NoncopyableGenerics_Misc
121121
// CHECK-MISC: extension {{.*}}.Outer.InnerVariation2 : Swift.Escapable where D : Swift.Escapable, A : ~Copyable {
122122

123123
// CHECK-MISC: extension {{.*}}.Outer.InnerStruct {
124-
// CHECK-MISC-NEXT: #if compiler(>=5.3) && $NonescapableTypes
125124
// CHECK-MISC-NEXT: public func hello<T>(_ t: T) where T : ~Escapable
126-
// CHECK-MISC-NEXT: #endif
127125

128126
// CHECK-MISC: @_preInverseGenerics public func old_swap<T>(_ a: inout T, _ b: inout T) where T : ~Copyable
129127

@@ -138,19 +136,11 @@ import NoncopyableGenerics_Misc
138136
// CHECK-MISC-NEXT: public func referToLoudProperGuarding(_ t: {{.*}}.LoudlyNC<Swift.String>)
139137
// CHECK-MISC-NEXT: public struct NoCopyPls : ~Swift.Copyable {
140138
// CHECK-MISC-NEXT: }
141-
// CHECK-MISC-NEXT: #if compiler(>=5.3) && $NonescapableTypes
142139
// CHECK-MISC-NEXT: public func substCopyable(_ t: Swift.String?)
143-
// CHECK-MISC-NEXT: #endif
144-
// CHECK-MISC-NEXT: #if compiler(>=5.3) && $NonescapableTypes
145140
// CHECK-MISC-NEXT: public func substGenericCopyable<T>(_ t: T?)
146-
// CHECK-MISC-NEXT: #endif
147141

148-
// CHECK-MISC-NEXT: #if compiler(>=5.3) && $NonescapableTypes
149142
// CHECK-MISC-NEXT: public func substNC(_ t: borrowing {{.*}}.NoCopyPls?)
150-
// CHECK-MISC-NEXT: #endif
151-
// CHECK-MISC-NEXT: #if compiler(>=5.3) && $NonescapableTypes
152143
// CHECK-MISC-NEXT: public func substGenericNC<T>(_ t: borrowing T?) where T : ~Copyable
153-
// CHECK-MISC-NEXT: #endif
154144

155145
// CHECK-MISC: public protocol Publik : ~Copyable {
156146
// CHECK-MISC-NEXT: }

test/ModuleInterface/nonescapable_types.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,31 @@
55

66
// REQUIRES: swift_feature_LifetimeDependence
77

8-
// CHECK: #if compiler(>=5.3) && $NonescapableTypes
98
// CHECK: public protocol P : ~Escapable {
109
// CHECK: associatedtype A
1110
// CHECK: }
12-
// CHECK: #endif
1311
public protocol P: ~Escapable {
1412
associatedtype A
1513
}
1614

17-
// CHECK: #if compiler(>=5.3) && $NonescapableTypes
1815
// CHECK: public struct X<T> : ~Swift.Escapable where T : ~Escapable {
1916
// CHECK: }
20-
// CHECK: #endif
2117
public struct X<T: ~Escapable>: ~Escapable { }
2218

23-
// CHECK: #if compiler(>=5.3) && $NonescapableTypes
2419
// CHECK: extension Test.X {
2520
// CHECK-NEXT: func f()
2621
// CHECK: }
2722
extension X where T: Escapable {
2823
public func f() { }
2924
}
3025

31-
// CHECK: #if compiler(>=5.3) && $NonescapableTypes
3226
// CHECK: extension Test.X where T : ~Escapable {
3327
// CHECK: public func g(other: borrowing T)
3428
// CHECK: }
35-
// CHECK: #endif
3629
extension X where T: ~Escapable {
3730
public func g(other: borrowing T) { }
3831
}
3932

40-
// CHECK: #if compiler(>=5.3) && $NonescapableTypes
4133
// CHECK: public enum Y<T> : ~Swift.Escapable where T : ~Escapable {
4234
// CHECK: case none
4335
// CHECK: case some(T)
@@ -49,19 +41,15 @@ public enum Y<T: ~Escapable>: ~Escapable {
4941

5042
extension Y: Escapable where T: Escapable { }
5143

52-
// CHECK: #if compiler(>=5.3) && $NonescapableTypes
5344
// CHECK: @lifetime(copy y)
5445
// CHECK: public func derive<T>(_ y: Test.Y<T>) -> Test.Y<T> where T : ~Escapable
55-
// CHECK: #endif
5646
@lifetime(copy y)
5747
public func derive<T : ~Escapable>(_ y: Y<T>) -> Y<T> {
5848
y
5949
}
6050

61-
// CHECK: #if compiler(>=5.3) && $NonescapableTypes
6251
// CHECK: @lifetime(copy x)
6352
// CHECK: public func derive<T>(_ x: Test.X<T>) -> Test.X<T> where T : ~Escapable
64-
// CHECK: #endif
6553
@lifetime(copy x)
6654
public func derive<T : ~Escapable>(_ x: X<T>) -> X<T> {
6755
x

test/stdlib/OptionalGeneralizations.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,37 @@ func isCopyable<T: ~Escapable>(_: T.Type) -> Bool { true }
1616
func isBitwiseCopyable<T: ~Copyable & ~Escapable>(_: T.Type) -> Bool { false }
1717
func isBitwiseCopyable<T: BitwiseCopyable & ~Escapable>(_: T.Type) -> Bool { true }
1818

19-
#if $NonescapableTypes
2019
func isEscapable<T: ~Escapable & ~Copyable>(_: T.Type) -> Bool { false }
2120
func isEscapable<T: ~Copyable>(_: T.Type) -> Bool { true }
22-
#endif
2321

2422
struct TrivialStruct {}
2523
struct NoncopyableStruct: ~Copyable {}
2624
class RegularClass {}
2725

28-
#if $NonescapableTypes
2926
struct NonescapableStruct: ~Escapable, BitwiseCopyable {}
3027
struct NoncopyableNonescapableStruct: ~Copyable, ~Escapable {}
3128
struct NonescapableNontrivialStruct: ~Escapable {
3229
let foo: RegularClass? = nil
3330
}
34-
#endif
3531

3632
suite.test("Copyability") {
3733
expectTrue(isCopyable(Optional<TrivialStruct>.self))
3834
expectFalse(isCopyable(Optional<NoncopyableStruct>.self))
3935
expectTrue(isCopyable(Optional<RegularClass>.self))
40-
#if $NonescapableTypes
4136
expectTrue(isCopyable(Optional<NonescapableStruct>.self))
4237
expectFalse(isCopyable(Optional<NoncopyableNonescapableStruct>.self))
4338
expectTrue(isCopyable(Optional<NonescapableNontrivialStruct>.self))
44-
#endif
4539
}
4640

4741
suite.test("BitwiseCopyability") {
4842
expectTrue(isBitwiseCopyable(Optional<TrivialStruct>.self))
4943
expectFalse(isBitwiseCopyable(Optional<NoncopyableStruct>.self))
5044
expectFalse(isBitwiseCopyable(Optional<RegularClass>.self))
51-
#if $NonescapableTypes
5245
expectTrue(isBitwiseCopyable(Optional<NonescapableStruct>.self))
5346
expectFalse(isBitwiseCopyable(Optional<NoncopyableNonescapableStruct>.self))
5447
expectFalse(isBitwiseCopyable(Optional<NonescapableNontrivialStruct>.self))
55-
#endif
5648
}
5749

58-
#if $NonescapableTypes
5950
suite.test("Escapability") {
6051
expectTrue(isEscapable(Optional<TrivialStruct>.self))
6152
expectTrue(isEscapable(Optional<NoncopyableStruct>.self))
@@ -64,7 +55,6 @@ suite.test("Escapability") {
6455
expectFalse(isEscapable(Optional<NoncopyableNonescapableStruct>.self))
6556
expectFalse(isEscapable(Optional<NonescapableNontrivialStruct>.self))
6657
}
67-
#endif
6858

6959
func apply<T, U>(
7060
_ input: T,
@@ -97,7 +87,6 @@ suite.test("expectNotNil()") {
9787
_ = expectNotNil(opt1(TrivialStruct()))
9888
_ = expectNotNil(opt1(NoncopyableStruct()))
9989
_ = expectNotNil(opt1(RegularClass()))
100-
#if $NonescapableTypes
10190
@_lifetime(copy t)
10291
func opt2<T: ~Copyable & ~Escapable>(_ t: consuming T) -> T? { t }
10392

@@ -109,15 +98,13 @@ suite.test("expectNotNil()") {
10998

11099
let nent = NonescapableNontrivialStruct()
111100
_ = expectNotNil(opt2(nent))
112-
#endif // $NonescapableTypes
113101
}
114102

115103
suite.test("expectNil()") {
116104
func opt1<T: ~Copyable>(_ t: consuming T) -> T? { nil }
117105
expectNil(opt1(TrivialStruct()))
118106
expectNil(opt1(NoncopyableStruct()))
119107
expectNil(opt1(RegularClass()))
120-
#if $NonescapableTypes
121108
@_lifetime(copy t)
122109
func opt2<T: ~Copyable & ~Escapable>(_ t: consuming T) -> T? { nil }
123110

@@ -129,5 +116,4 @@ suite.test("expectNil()") {
129116

130117
let nent = NonescapableNontrivialStruct()
131118
expectNil(opt2(nent))
132-
#endif // $NonescapableTypes
133119
}

0 commit comments

Comments
 (0)