Skip to content

Commit c238840

Browse files
authored
Merge pull request #82382 from xedin/rdar-153680826
[Concurrency] Don't infer `nonisolated(nonsending)` on synchronous wi…
2 parents 97ddc4e + a964282 commit c238840

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5253,9 +5253,18 @@ getIsolationFromWitnessedRequirements(ValueDecl *value) {
52535253
case ActorIsolation::Erased:
52545254
llvm_unreachable("requirement cannot have erased isolation");
52555255

5256+
case ActorIsolation::CallerIsolationInheriting: {
5257+
if (value->isAsync())
5258+
break;
5259+
5260+
// It's possible to witness requirement with an non-async
5261+
// declaration, in such cases `nonisolated(nonsending)` does
5262+
// not apply.
5263+
continue;
5264+
}
5265+
52565266
case ActorIsolation::GlobalActor:
52575267
case ActorIsolation::Nonisolated:
5258-
case ActorIsolation::CallerIsolationInheriting:
52595268
case ActorIsolation::NonisolatedUnsafe:
52605269
break;
52615270
}

test/Concurrency/attr_execution/protocols_silgen.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ protocol P {
1313
@MainActor func mainActorTest() async
1414
}
1515

16+
protocol Q {
17+
nonisolated(nonsending) var test: String { get async throws }
18+
nonisolated(nonsending) func fnTest() async
19+
}
20+
1621
struct AllDefault : P {
1722
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s21attr_execution_silgen10AllDefaultVAA1PA2aDP10callerTestyyYaFTW : $@convention(witness_method: P) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @in_guaranteed AllDefault) -> () {
1823
// CHECK: bb0([[ACTOR:%.*]] : @guaranteed $Optional<any Actor>, [[SELF:%.*]] : $*AllDefault):
@@ -120,3 +125,49 @@ struct AllMainActor : P {
120125
// CHECK: } // end sil function '$s21attr_execution_silgen12AllMainActorVAA1PA2aDP04mainF4TestyyYaFTW'
121126
@MainActor func mainActorTest() async {}
122127
}
128+
129+
// Make sure that stored/non-async witness doesn't inherit `nonisolated(nonsending)` but thunk dismatches correctly
130+
131+
struct TestWitnessWithStorage: Q {
132+
// CHECK-LABEL: sil hidden [transparent] [ossa] @$s21attr_execution_silgen22TestWitnessWithStorageV4testSSvg : $@convention(method) (@guaranteed TestWitnessWithStorage) -> @owned String
133+
// CHECK-LABEL: sil hidden [transparent] [ossa] @$s21attr_execution_silgen22TestWitnessWithStorageV4testSSvs : $@convention(method) (@owned String, @inout TestWitnessWithStorage) -> ()
134+
var test: String
135+
136+
// CHECK-LABEL: sil hidden [ossa] @$s21attr_execution_silgen22TestWitnessWithStorageV02fnD0yyF : $@convention(method) (@guaranteed TestWitnessWithStorage) -> ()
137+
func fnTest() {}
138+
139+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s21attr_execution_silgen22TestWitnessWithStorageVAA1QA2aDP4testSSvgTW : $@convention(witness_method: Q) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @in_guaranteed TestWitnessWithStorage) -> (@owned String, @error any Error)
140+
// CHECK: bb0([[ISOLATION:%.*]] : @guaranteed $Optional<any Actor>, [[SELF:%.*]] : $*TestWitnessWithStorage):
141+
// CHECK-NEXT: [[BORROWED_SELF:%.*]] = load_borrow [[SELF]]
142+
// CHECK: [[WITNESS:%.*]] = function_ref @$s21attr_execution_silgen22TestWitnessWithStorageV4testSSvg : $@convention(method) (@guaranteed TestWitnessWithStorage) -> @owned String
143+
// CHECK-NEXT: [[RESULT:%.*]] = apply [[WITNESS]]([[BORROWED_SELF]]) : $@convention(method) (@guaranteed TestWitnessWithStorage) -> @owned String
144+
// CHECK-NEXT: end_borrow [[BORROWED_SELF]]
145+
// CHECK-NEXT: return [[RESULT]]
146+
// CHECK-NEXT: } // end sil function '$s21attr_execution_silgen22TestWitnessWithStorageVAA1QA2aDP4testSSvgTW'
147+
148+
// CHECK: sil private [transparent] [thunk] [ossa] @$s21attr_execution_silgen22TestWitnessWithStorageVAA1QA2aDP02fnD0yyYaFTW : $@convention(witness_method: Q) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @in_guaranteed TestWitnessWithStorage) -> ()
149+
// CHECK: bb0([[ISOLATION:%.*]] : @guaranteed $Optional<any Actor>, [[SELF:%.*]] : $*TestWitnessWithStorage):
150+
// CHECK-NEXT: [[BORROWED_SELF]] = load_borrow [[SELF]]
151+
// CHECK: [[WITNESS:%.*]] = function_ref @$s21attr_execution_silgen22TestWitnessWithStorageV02fnD0yyF : $@convention(method) (@guaranteed TestWitnessWithStorage) -> ()
152+
// CHECK-NEXT: {{.*}} = apply [[WITNESS]]([[BORROWED_SELF]]) : $@convention(method) (@guaranteed TestWitnessWithStorage) -> ()
153+
// CHECK-NEXT: [[RESULT:%.*]] = tuple ()
154+
// CHECK-NEXT: end_borrow [[BORROWED_SELF]]
155+
// CHECK-NEXT: return [[RESULT]]
156+
// CHECK-NEXT: } // end sil function '$s21attr_execution_silgen22TestWitnessWithStorageVAA1QA2aDP02fnD0yyYaFTW'
157+
}
158+
159+
struct TestSyncWitness: Q {
160+
// CHECK-LABEL: sil hidden [ossa] @$s21attr_execution_silgen15TestSyncWitnessV4testSSvg : $@convention(method) (TestSyncWitness) -> @owned String
161+
var test: String { "" }
162+
163+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s21attr_execution_silgen15TestSyncWitnessVAA1QA2aDP4testSSvgTW : $@convention(witness_method: Q) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @in_guaranteed TestSyncWitness) -> (@owned String, @error any Error)
164+
// CHECK: bb0([[ISOLATION:%.*]] : @guaranteed $Optional<any Actor>, [[SELF:%.*]] : $*TestSyncWitness):
165+
// CHECK-NEXT: [[BORROWED_SELF:%.*]] = load [trivial] [[SELF]]
166+
// CHECK: [[WITNESS:%.*]] = function_ref @$s21attr_execution_silgen15TestSyncWitnessV4testSSvg : $@convention(method) (TestSyncWitness) -> @owned String
167+
// CHECK-NEXT: [[RESULT:%.*]] = apply [[WITNESS]]([[BORROWED_SELF]]) : $@convention(method) (TestSyncWitness) -> @owned String
168+
// CHECK-NEXT: return [[RESULT]]
169+
// CHECK-NEXT: } // end sil function '$s21attr_execution_silgen15TestSyncWitnessVAA1QA2aDP4testSSvgTW'
170+
171+
// Tested in the `TestWitnessWithStorage`
172+
func fnTest() {}
173+
}

0 commit comments

Comments
 (0)