Skip to content

Commit 258d47a

Browse files
committed
Thin and C functions conform to ConcurrentValue
1 parent 2f2c0ba commit 258d47a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,20 @@ static bool isConcurrentValueType(const DeclContext *dc, Type type) {
768768

769769
bool visitFunctionType(FunctionType *type) {
770770
// Concurrent function types meet the requirements.
771-
return type->isConcurrent();
771+
if (type->isConcurrent())
772+
return true;
773+
774+
// C and thin function types meeting the requirements because they
775+
// cannot have captures.
776+
switch (type->getExtInfo().getRepresentation()) {
777+
case FunctionTypeRepresentation::Block:
778+
case FunctionTypeRepresentation::Swift:
779+
return false;
780+
781+
case FunctionTypeRepresentation::CFunctionPointer:
782+
case FunctionTypeRepresentation::Thin:
783+
return true;
784+
}
772785
}
773786

774787
bool visitProtocolCompositionType(ProtocolCompositionType *type) {

test/Concurrency/concurrent_value_inference.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,16 @@ public enum PublicEnum {
8080
case some
8181
}
8282

83+
struct HasFunctions {
84+
var tfp: @convention(thin) () -> Void
85+
var cfp: @convention(c) () -> Void
86+
}
87+
8388
func testCV(
8489
c1: C1, c2: C2, s1: S1, e1: E1, e2: E2, gs1: GS1<Int>, gs2: GS2<Int>,
8590
bc: Bitcode, ps: PublicStruct, pe: PublicEnum,
86-
fps: FrozenPublicStruct, fpe: FrozenPublicEnum
91+
fps: FrozenPublicStruct, fpe: FrozenPublicEnum,
92+
hf: HasFunctions
8793
) {
8894
acceptCV(c1) // expected-error{{'C1' conform to 'ConcurrentValue'}}
8995
acceptCV(c2)
@@ -103,4 +109,7 @@ func testCV(
103109
// Public is okay when also @frozen.
104110
acceptCV(fps)
105111
acceptCV(fpe)
112+
113+
// Thin and C function types are ConcurrentValue.
114+
acceptCV(hf)
106115
}

0 commit comments

Comments
 (0)