Skip to content

Commit 83b54f8

Browse files
committed
more coverage for SILGen async_initializer test
1 parent 1070afe commit 83b54f8

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

test/SILGen/async_initializer.swift

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -emit-silgen %s -module-name initializers -swift-version 5 -enable-experimental-concurrency | %FileCheck --enable-var-scope %s
1+
// RUN: %target-swift-frontend -emit-silgen %s -module-name initializers -swift-version 5 -enable-experimental-concurrency | %FileCheck %s --enable-var-scope --implicit-check-not=hop_to_executor
22
// REQUIRES: concurrency
33

44
// CHECK: protocol Person {
@@ -57,8 +57,6 @@ enum MyEnum {
5757

5858
actor MyActor {
5959
// CHECK-DAG: sil hidden [ossa] @$s12initializers7MyActorCACyYacfc : $@convention(method) @async (@owned MyActor) -> @owned MyActor
60-
// CHECK-NOT: hop_to_executor
61-
// CHECK-DAG: } // end sil function '$s12initializers7MyActorCACyYacfc'
6260
init() async {}
6361
}
6462

@@ -153,4 +151,48 @@ func makeDog() async {
153151
// CHECK: } // end sil function '$s12initializers8makeBirbyyYaF'
154152
func makeBirb() async {
155153
_ = await Birb(name: "Chirpy")
154+
}
155+
156+
actor SomeActor {
157+
var x: Int = 0
158+
159+
// NOTE: during SILGen, we don't expect any hop_to_executors in here.
160+
// The implicit check-not covers that for us. The hops are inserted later.
161+
init() async {}
162+
163+
// CHECK-LABEL: sil hidden [ossa] @$s12initializers9SomeActorC10someMethodyyYaF : $@convention(method) @async (@guaranteed SomeActor) -> () {
164+
// CHECK: hop_to_executor {{%[0-9]+}} : $SomeActor
165+
// CHECK: } // end sil function '$s12initializers9SomeActorC10someMethodyyYaF'
166+
func someMethod() async {}
167+
}
168+
169+
// CHECK-LABEL: sil hidden [ossa] @$s12initializers9makeActorAA04SomeC0CyYaF : $@convention(thin) @async () -> @owned SomeActor {
170+
// CHECK: hop_to_executor {{%[0-9]+}} : $MainActor
171+
// CHECK: [[INIT:%[0-9]+]] = function_ref @$s12initializers9SomeActorCACyYacfC : $@convention(method) @async (@thick SomeActor.Type) -> @owned SomeActor
172+
// CHECK: {{%[0-9]+}} = apply [[INIT]]({{%[0-9]+}}) : $@convention(method) @async (@thick SomeActor.Type) -> @owned SomeActor
173+
// CHECK: hop_to_executor {{%[0-9]+}} : $MainActor
174+
// CHECK: } // end sil function '$s12initializers9makeActorAA04SomeC0CyYaF'
175+
@MainActor
176+
func makeActor() async -> SomeActor {
177+
return await SomeActor()
178+
}
179+
180+
// None of the below calls are expected to have a hop before or after the call.
181+
182+
func makeActorFromGeneric() async -> SomeActor {
183+
return await SomeActor()
184+
}
185+
186+
func callActorMethodFromGeneric(a: SomeActor) async {
187+
await a.someMethod()
188+
}
189+
190+
@available(SwiftStdlib 5.5, *)
191+
func makeActorInTask() async {
192+
Task.detached { await SomeActor() }
193+
}
194+
195+
@available(SwiftStdlib 5.5, *)
196+
func callActorMethodInTask(a: SomeActor) async {
197+
Task.detached { await a.someMethod() }
156198
}

0 commit comments

Comments
 (0)