Files
swift-mirror/test/Concurrency/attr_execution/attr_execution.swift
Konrad Malawski c8e9b5bd9e Cleanups: remove redundant special-casing, fix rebase-dropped test content
- Remove redundant isCrossingCheck ternary in MismatchedIsolatedConformances:
  printStringForDiagnostics now correctly returns "@concurrent" for
  NonisolatedConcurrent and "nonisolated" for Nonisolated, so the manual
  override is unnecessary. Remove the isCrossingCheck field entirely.
- Change isolated_conformance_wrong_domain and
  isolated_conformance_may_cross_isolation diagnostics to accept
  ActorIsolation directly instead of StringRef, letting the diagnostic
  engine call printForDiagnostics.
- Rename ASTDumper flag from "isolated_to_caller_isolation" to
  "nonisolated_nonsending".
- Restore SIL test CHECK lines that lost @caller_isolated annotations
  during rebase conflict resolution (optimize_hop_to_executor.sil,
  attr_execution tests, SILGen tests, Serialization tests).
- Apply caller_isolation_inheriting -> nonisolated(nonsending) rename
  to restored test files.
2026-04-28 09:21:46 -07:00

130 lines
7.4 KiB
Swift

// RUN: %target-swift-emit-silgen -enable-upcoming-feature NonisolatedNonsendingByDefault %s | %FileCheck %s
// REQUIRES: swift_feature_NonisolatedNonsendingByDefault
// CHECK-LABEL: // concurrentTest()
// CHECK: // Isolation: @concurrent
// CHECK: sil hidden [ossa] @$s14attr_execution14concurrentTestyyYaF : $@convention(thin) @async () -> () {
@concurrent
func concurrentTest() async {}
// CHECK-LABEL: // callerTest()
// CHECK: // Isolation: nonisolated(nonsending)
// CHECK: sil hidden [ossa] @$s14attr_execution10callerTestyyYaF : $@convention(thin) @caller_isolated @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> () {
nonisolated(nonsending)
func callerTest() async {}
struct Test {
// CHECK-LABEL: // closure #1 in variable initialization expression of Test.x
// CHECK: // Isolation: nonisolated(nonsending)
// CHECK: sil private [ossa] @$s14attr_execution4TestV1xyyYaYCcvpfiyyYaYCcfU_ : $@convention(thin) @caller_isolated @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()
var x: () async -> Void = {}
// CHECK-LABEL: // Test.test()
// CHECK: // Isolation: nonisolated(nonsending)
// CHECK: sil hidden [ossa] @$s14attr_execution4TestV4testyyYaF : $@convention(method) @caller_isolated @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor, @guaranteed Test) -> ()
// CHECK: bb0([[ISOLATION:%.*]] : @guaranteed $Builtin.ImplicitActor, [[SELF:%.*]] : @guaranteed $Test)
// CHECK: [[X_REF:%.*]] = struct_extract %1, #Test.x
// CHECK: [[X_REF_COPY:%.]] = copy_value [[X_REF]]
// CHECK: [[BORROWED_X:%.*]] = begin_borrow [[X_REF_COPY]]
// CHECK: apply [[BORROWED_X]]([[ISOLATION]]) : $@caller_isolated @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()
// CHECK: } // end sil function '$s14attr_execution4TestV4testyyYaF'
func test() async {
await x()
}
// CHECK-LABEL: // Test.testParam(fn:)
// CHECK: // Isolation: nonisolated(nonsending)
// CHECK: sil hidden [ossa] @$s14attr_execution4TestV9testParam2fnyyyYaYCcSg_tYaF : $@convention(method) @caller_isolated @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor, @guaranteed Optional<@caller_isolated @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()>, @guaranteed Test) -> ()
// CHECK: bb0([[ISOLATION:%.*]] : @guaranteed $Builtin.ImplicitActor, [[OPT_FN:%.*]] : @guaranteed $Optional<@caller_isolated @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()>, [[SELF:%.*]] : @guaranteed $Test)
// CHECK: bb1([[FN:%.*]] : @owned $@caller_isolated @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ())
// CHECK: [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
// CHECK: apply [[BORROWED_FN]]([[ISOLATION]]) : $@caller_isolated @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()
// CHECK: } // end sil function '$s14attr_execution4TestV9testParam2fnyyyYaYCcSg_tYaF'
func testParam(fn: (() async -> Void)?) async {
await fn?()
}
}
// CHECK-LABEL: // testLocal()
// CHECK: // Isolation: nonisolated(nonsending)
// CHECK: sil hidden [ossa] @$s14attr_execution9testLocalyyYaF : $@convention(thin) @caller_isolated @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> () {
// CHECK: bb0([[ISOLATION:%.*]] : @guaranteed $Builtin.ImplicitActor)
// CHECK: bb1([[FN:%.*]] : @owned $@caller_isolated @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ())
// CHECK: [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
// CHECK: apply [[BORROWED_FN]]([[ISOLATION]]) : $@caller_isolated @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()
// CHECK: } // end sil function '$s14attr_execution9testLocalyyYaF'
func testLocal() async {
let fn: (() async -> Void)? = nil
await fn?()
}
// CHECK-LABEL: // takesClosure(fn:)
// CHECK: // Isolation: unspecified
// CHECK: sil hidden [ossa] @$s14attr_execution12takesClosure2fnyyyYaYCXE_tF : $@convention(thin) (@guaranteed @caller_isolated @noescape @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()) -> ()
func takesClosure(fn: () async -> Void) {
}
// CHECK-LABEL: sil hidden [ossa] @$s14attr_execution11testClosureyyF : $@convention(thin) () -> ()
// CHECK: [[CLOSURE:%.*]] = function_ref @$s14attr_execution11testClosureyyFyyYaYCXEfU_ : $@convention(thin) @caller_isolated @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()
// CHECK: [[THUNKED_CLOSURE:%.*]] = thin_to_thick_function %0 to $@caller_isolated @noescape @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()
// CHECK: [[TAKES_CLOSURE:%.*]] = function_ref @$s14attr_execution12takesClosure2fnyyyYaYCXE_tF : $@convention(thin) (@guaranteed @caller_isolated @noescape @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()) -> ()
// CHECK: apply [[TAKES_CLOSURE]]([[THUNKED_CLOSURE]])
// CHECK: } // end sil function '$s14attr_execution11testClosureyyF'
// CHECK-LABEL: // closure #1 in testClosure()
// CHECK: // Isolation: nonisolated(nonsending)
// CHECK: sil private [ossa] @$s14attr_execution11testClosureyyFyyYaYCXEfU_ : $@convention(thin) @caller_isolated @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()
func testClosure() {
takesClosure {
}
}
protocol P {
}
func open<T: P>(_: T) async {}
// CHECK-LABEL: sil hidden [ossa] @$s14attr_execution19testOpenExistential11existentialyAA1P_p_tYaF : $@convention(thin) @caller_isolated @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor, @in_guaranteed any P) -> ()
// CHECK: bb0([[ISOLATION:%.*]] : @guaranteed $Builtin.ImplicitActor, [[EXISTENTIAL:%.*]] : $*any P):
// CHECK: [[OPEN_REF:%.*]] = function_ref @$s14attr_execution4openyyxYaAA1PRzlF
// CHECK: apply [[OPEN_REF]]<@opened("{{.*}}", any P) Self>([[ISOLATION]], {{.*}})
// CHECK: } // end sil function '$s14attr_execution19testOpenExistential11existentialyAA1P_p_tYaF'
func testOpenExistential(existential: any P) async {
await _openExistential(existential, do: open)
}
func testWithoutActuallyEscaping(_ f: () async -> (), _ f2: (Int) async -> Void) async {
// CHECK-LABEL: // closure #1 in testWithoutActuallyEscaping(_:_:)
// CHECK-NEXT: // Isolation: nonisolated(nonsending)
await withoutActuallyEscaping(f) {
await $0()
}
// CHECK-LABEL: // closure #2 in testWithoutActuallyEscaping(_:_:)
// CHECK-NEXT: // Isolation: global_actor. type: MainActor
await withoutActuallyEscaping(f) { @MainActor in
await $0()
}
// CHECK-LABEL: // closure #3 in testWithoutActuallyEscaping(_:_:)
// CHECK-NEXT: // Isolation: nonisolated(nonsending)
await withoutActuallyEscaping(f2) { body in
await body(42)
}
actor Test {
// CHECK-LABEL: // closure #1 in testActorIsolatedCapture() in Test #1 in testWithoutActuallyEscaping(_:_:)
// CHECK-NEXT: // Isolation: actor_instance. name: 'self'
func testActorIsolatedCapture() async {
await withoutActuallyEscaping(compute) {
_ = self
await $0()
}
}
func compute() async {}
}
}