Skip to content

Commit 7496701

Browse files
committed
Limit ConcurrentValue inference to non-public, non-frozen structs and enums
1 parent 71b7c92 commit 7496701

File tree

13 files changed

+62
-42
lines changed

13 files changed

+62
-42
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2504,10 +2504,21 @@ bool swift::checkConcurrentValueConformance(
25042504

25052505
NormalProtocolConformance *GetImplicitConcurrentValueRequest::evaluate(
25062506
Evaluator &evaluator, NominalTypeDecl *nominal) const {
2507-
// Only structs and enums get implicit ConcurrentValue conformances.
2507+
// Only structs and enums can get implicit ConcurrentValue conformances.
25082508
if (!isa<StructDecl>(nominal) && !isa<EnumDecl>(nominal))
25092509
return nullptr;
25102510

2511+
// Public, non-frozen structs and enums defined in Swift don't get implicit
2512+
// ConcurrentValue conformances.
2513+
if (nominal->getFormalAccessScope(
2514+
/*useDC=*/nullptr,
2515+
/*treatUsableFromInlineAsPublic=*/true).isPublic() &&
2516+
!(nominal->hasClangNode() ||
2517+
nominal->getAttrs().hasAttribute<FixedLayoutAttr>() ||
2518+
nominal->getAttrs().hasAttribute<FrozenAttr>())) {
2519+
return nullptr;
2520+
}
2521+
25112522
// Check the context in which the conformance occurs.
25122523
if (auto *file = dyn_cast<FileUnit>(nominal->getModuleScopeContext())) {
25132524
switch (file->getKind()) {

test/ClangImporter/objc_async.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,9 @@ actor MySubclassCheckingSwiftAttributes : ProtocolWithSwiftAttributes {
9393

9494
func uiActorMethod() { }
9595
}
96+
97+
// ConcurrentValue conformance inference for imported types.
98+
func acceptCV<T: ConcurrentValue>(_: T) { }
99+
func testCV(r: NSRange) {
100+
acceptCV(r)
101+
}

test/Concurrency/concurrent_value_inference.swift

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-typecheck-verify-swift -enable-library-evolution
22

33
class C1 { }
44
final class C2: ConcurrentValue { }
@@ -26,7 +26,7 @@ struct GS2<T> {
2626
}
2727

2828
func acceptCV<T: ConcurrentValue>(_: T) { }
29-
// expected-note@-1 4{{where 'T' =}}
29+
// expected-note@-1 6{{where 'T' =}}
3030

3131
// Example that was triggering circular dependencies.
3232
struct Signature { }
@@ -62,10 +62,28 @@ enum BitcodeElement {
6262
case record(Record)
6363
}
6464

65+
// Public structs and enums do not get implicit ConcurrentValue unless they
66+
// are frozen.
67+
public struct PublicStruct {
68+
var i: Int
69+
}
70+
71+
public enum PublicEnum {
72+
case some
73+
}
74+
75+
@frozen public struct FrozenPublicStruct {
76+
var i: Int
77+
}
78+
79+
@frozen public enum FrozenPublicEnum {
80+
case some
81+
}
6582

6683
func testCV(
6784
c1: C1, c2: C2, s1: S1, e1: E1, e2: E2, gs1: GS1<Int>, gs2: GS2<Int>,
68-
bc: Bitcode
85+
bc: Bitcode, ps: PublicStruct, pe: PublicEnum,
86+
fps: FrozenPublicStruct, fpe: FrozenPublicEnum
6987
) {
7088
acceptCV(c1) // expected-error{{'C1' conform to 'ConcurrentValue'}}
7189
acceptCV(c2)
@@ -75,6 +93,14 @@ func testCV(
7593
acceptCV(gs1)
7694
acceptCV(gs2) // expected-error{{'GS2<Int>' conform to 'ConcurrentValue'}}
7795

78-
// Note available due to recursive conformance dependencies.
96+
// Not available due to recursive conformance dependencies.
7997
acceptCV(bc) // expected-error{{global function 'acceptCV' requires that 'Bitcode' conform to 'ConcurrentValue'}}
98+
99+
// Not available due to "public".
100+
acceptCV(ps) // expected-error{{global function 'acceptCV' requires that 'PublicStruct' conform to 'ConcurrentValue'}}
101+
acceptCV(pe) // expected-error{{global function 'acceptCV' requires that 'PublicEnum' conform to 'ConcurrentValue'}}
102+
103+
// Public is okay when also @frozen.
104+
acceptCV(fps)
105+
acceptCV(fpe)
80106
}

test/Incremental/Verifier/multi-file-private/Inputs/Inner.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ public func blah(foo: Foo) {}
1212
public var defaultFoo: Foo = {
1313
return Inner()
1414
}
15-
// expected-superclass{{main.Inner}}

test/Serialization/multi-file-type-eraser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Ensure we don't crash during merge-modules - no matter the order of inputs.
99

1010
// CHECK: Statistics
11-
// CHECK: 3 Serialization - # of normal protocol conformances completed
11+
// CHECK: 2 Serialization - # of normal protocol conformances completed
1212

1313
public struct AnyWindows : Vista {
1414
public init<V: Vista>(erasing vista: V) {

test/SymbolGraph/Relationships/ConformsTo/Basic.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public struct S: P {
1111
public var x: Int
1212
}
1313

14-
// CHECK-DAG: "kind": "conformsTo"
15-
// CHECK-DAG: "source": "s:5Basic1SV"
16-
// CHECK-DAG: "target": "s:5Basic1PP"
14+
// CHECK: "kind": "conformsTo"
15+
// CHECK-NEXT: "source": "s:5Basic1SV"
16+
// CHECK-NEXT: "target": "s:5Basic1PP"

test/SymbolGraph/Relationships/TargetFallback.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ public struct S: CustomStringConvertible {
1010
}
1111
}
1212

13-
// CHECK-DAG: "kind": "conformsTo",
14-
// CHECK-DAG: "source": "s:14TargetFallback1SV",
15-
// CHECK-DAG: "target": "s:s15ConcurrentValueP",
16-
// CHECK-DAG: "targetFallback": "Swift.ConcurrentValue"
17-
18-
// CHECK-DAG: "kind": "conformsTo",
19-
// CHECK-DAG: "source": "s:14TargetFallback1SV",
20-
// CHECK-DAG: "target": "s:s23CustomStringConvertibleP",
21-
// CHECK-DAG: "targetFallback": "Swift.CustomStringConvertible"
13+
// CHECK: "kind": "conformsTo",
14+
// CHECK-NEXT: "source": "s:14TargetFallback1SV",
15+
// CHECK-NEXT: "target": "s:s23CustomStringConvertibleP",
16+
// CHECK-NEXT: "targetFallback": "Swift.CustomStringConvertible"

test/SymbolGraph/Something/Something.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ public struct MyStruct: P {
1010
public func foo() {}
1111
}
1212

13-
// CHECK-DAG: "kind": "conformsTo",
14-
// CHECK-DAG: "source": "s:9Something8MyStructV",
15-
// CHECK-DAG: "target": "s:s15ConcurrentValueP",
16-
17-
// CHECK-DAG: "kind": "conformsTo",
18-
// CHECK-DAG: "source": "s:9Something8MyStructV",
19-
// CHECK-DAG: "target": "s:12SomeProtocol1PP",
13+
// CHECK: "kind": "conformsTo",
14+
// CHECK-NEXT: "source": "s:9Something8MyStructV",
15+
// CHECK-NEXT: "target": "s:12SomeProtocol1PP",

test/SymbolGraph/Symbols/SkipsPublicUnderscore.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,4 @@ extension _ShouldntAppear.InnerShouldntAppear {
6060

6161
extension _ShouldntAppear.InnerShouldntAppear: Equatable {}
6262

63-
// CHECK: "relationships": [
64-
// CHECK: "kind": "conformsTo",
65-
// CHECK: "source": "s:21SkipsPublicUnderscore0B5OuterV",
66-
// CHECK-NEXT: "target": "s:s15ConcurrentValueP",
63+
// CHECK: "relationships": []

test/api-digester/Outputs/Cake-abi.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ cake: Var fixedLayoutStruct2.NoLongerWithFixedBinaryOrder is no longer a stored
9090
/* Protocol Conformance Change */
9191
cake: Class C7 has added a conformance to an existing protocol P1
9292
cake: Class SuperClassChange has added a conformance to an existing protocol P1
93+
cake: Enum IceKind has removed conformance to ConcurrentValue
9394
cake: Protocol P3 has added inherited protocol P4
9495
cake: Protocol P3 has removed inherited protocol P2
9596
cake: Struct fixedLayoutStruct has added a conformance to an existing protocol P2

test/api-digester/Outputs/Cake.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ cake: Var C1.CIIns2 changes from strong to weak
4848
cake: EnumElement FrozenKind.AddedCase has been added as a new enum case
4949

5050
/* Conformance changes */
51+
cake: Enum IceKind has removed conformance to ConcurrentValue
5152
cake: Func ObjCProtocol.removeOptional() is no longer an optional requirement
5253
cake: Protocol P3 has added inherited protocol P4
5354
cake: Protocol P3 has removed inherited protocol P2

test/api-digester/Outputs/cake-abi.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,6 @@
655655
}
656656
],
657657
"usr": "s:SY"
658-
},
659-
{
660-
"kind": "Conformance",
661-
"name": "ConcurrentValue",
662-
"printedName": "ConcurrentValue",
663-
"usr": "s:s15ConcurrentValueP"
664658
}
665659
]
666660
},

test/api-digester/Outputs/cake.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -675,12 +675,6 @@
675675
}
676676
],
677677
"usr": "s:SY"
678-
},
679-
{
680-
"kind": "Conformance",
681-
"name": "ConcurrentValue",
682-
"printedName": "ConcurrentValue",
683-
"usr": "s:s15ConcurrentValueP"
684678
}
685679
]
686680
},

0 commit comments

Comments
 (0)