File: execution_attr.swift

package info (click to toggle)
swiftlang 6.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,856,264 kB
  • sloc: cpp: 9,995,718; ansic: 2,234,019; asm: 1,092,167; python: 313,940; objc: 82,726; f90: 80,126; lisp: 38,373; pascal: 25,580; sh: 20,378; ml: 5,058; perl: 4,751; makefile: 4,725; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (99 lines) | stat: -rw-r--r-- 6,374 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// RUN: %target-swift-emit-silgen %s  | %FileCheck -check-prefix CHECK -check-prefix DISABLED %s
// RUN: %target-swift-emit-silgen %s -enable-upcoming-feature NonisolatedNonsendingByDefault | %FileCheck -check-prefix CHECK -check-prefix ENABLED %s

// REQUIRES: concurrency
// REQUIRES: swift_feature_NonisolatedNonsendingByDefault

// Validate that both with and without the experimental flag we properly codegen
// `@concurrent` and `nonisolated(nonsending)`

// CHECK-LABEL: // executionCaller()
// CHECK-NEXT: // Isolation: caller_isolation_inheriting
// CHECK-NEXT: sil hidden [ossa] @$s14execution_attr0A6CalleryyYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> () {
nonisolated(nonsending)
func executionCaller() async {}

// CHECK-LABEL: // executionConcurrent()
// CHECK: // Isolation: nonisolated
// CHECK: sil hidden [ossa] @$s14execution_attr0A10ConcurrentyyYaF : $@convention(thin) @async () -> () {
@concurrent
func executionConcurrent() async {}

// DISABLED: sil hidden [ossa] @$s14execution_attr0A15CallerParameteryyyyYaYCXEYaF : $@convention(thin) @async (@guaranteed @noescape @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()) -> () {
// ENABLED: sil hidden [ossa] @$s14execution_attr0A15CallerParameteryyyyYaYCXEYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor, @guaranteed @noescape @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()) -> () {
// CHECK: } // end sil function '$s14execution_attr0A15CallerParameteryyyyYaYCXEYaF'
func executionCallerParameter(_ x: nonisolated(nonsending) () async -> ()) async {
  await x()
}

// DISABLED-LABEL: sil hidden [ossa] @$s14execution_attr0A19ConcurrentParameteryyyyYaXEYaF : $@convention(thin) @async (@guaranteed @noescape @async @callee_guaranteed () -> ()) -> () {
// ENABLED-LABEL: sil hidden [ossa] @$s14execution_attr0A19ConcurrentParameteryyyyYaXEYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor, @guaranteed @noescape @async @callee_guaranteed () -> ()) -> () {
func executionConcurrentParameter(_ x: @concurrent () async -> ()) async {
  await x()
}

struct S {
  let field: nonisolated(nonsending) () async -> ()
}

// DISABLED: sil hidden [ossa] @$s14execution_attr0A11CallerFieldyyAA1SVYaF : $@convention(thin) @async (@guaranteed S) -> () {
// DISABLED: bb0([[ARG:%.*]] : @guaranteed $S):
// DISABLED:   [[ACTOR_NONE:%.*]] = enum $Optional<any Actor>, #Optional.none!enumelt
// DISABLED:   hop_to_executor [[ACTOR_NONE]]
// DISABLED:   [[FIELD:%.*]] = struct_extract [[ARG]]
// DISABLED:   [[FIELD_COPY:%.*]] = copy_value [[FIELD]]
// DISABLED:   [[ACTOR_NONE_CAST:%.*]] = unchecked_value_cast [[ACTOR_NONE]] to $Builtin.ImplicitActor
// DISABLED:   [[BORROWED_FIELD:%.*]] = begin_borrow [[FIELD_COPY]]
// DISABLED:   apply [[BORROWED_FIELD]]([[ACTOR_NONE_CAST]])
// DISABLED: } // end sil function '$s14execution_attr0A11CallerFieldyyAA1SVYaF'

// ENABLED: sil hidden [ossa] @$s14execution_attr0A11CallerFieldyyAA1SVYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor, @guaranteed S) -> () {
// ENABLED: bb0([[ACTOR:%.*]] : @guaranteed $Builtin.ImplicitActor, [[ARG:%.*]] : @guaranteed $S):
// ENABLED:   [[FIELD:%.*]] = struct_extract [[ARG]]
// ENABLED:   [[FIELD_COPY:%.*]] = copy_value [[FIELD]]
// ENABLED:   [[BORROWED_FIELD:%.*]] = begin_borrow [[FIELD_COPY]]
// ENABLED:   apply [[BORROWED_FIELD]]([[ACTOR]])
// ENABLED: } // end sil function '$s14execution_attr0A11CallerFieldyyAA1SVYaF'
func executionCallerField(_ s: S) async {
  await s.field()
}

extension S {
  // CHECK-LABEL: // S.executionCallerFieldMethod(_:)
  // CHECK: // Isolation: unspecified
  // CHECK: sil hidden [ossa] @$s14execution_attr1SV0A17CallerFieldMethodyyyyYaYCXEF : $@convention(method) (@guaranteed @noescape @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> (), @guaranteed S) -> () {
  func executionCallerFieldMethod(_ x: nonisolated(nonsending) () async -> ()) {}
}

// CHECK-LABEL: sil hidden [ossa] @$s14execution_attr24testWithDynamicIsolation2fnyyyYAXE_tYaF : $@convention(thin) @async (@guaranteed @isolated(any) @noescape @callee_guaranteed () -> ()) -> () {
// CHECK: bb0([[PARAM_FN:%.*]] : @guaranteed $@isolated(any) @noescape @callee_guaranteed () -> ()):
// CHECK:   [[GENERIC_EXEC:%.*]] = enum $Optional<any Actor>, #Optional.none!enumelt
// CHECK-NEXT:   hop_to_executor [[GENERIC_EXEC]]
// CHECK-NEXT:   [[FN:%.*]] = copy_value [[PARAM_FN]]
// CHECK-NEXT:   [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
// CHECK-NEXT:   [[FN_ISOLATION:%.*]] = function_extract_isolation [[BORROWED_FN]]
// CHECK-NEXT:   hop_to_executor [[FN_ISOLATION]]
// CHECK-NEXT:   [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
// CHECK-NEXT:   apply [[BORROWED_FN]]()
// CHECK: hop_to_executor [[GENERIC_EXEC]]
// CHECK: } // end sil function '$s14execution_attr24testWithDynamicIsolation2fnyyyYAXE_tYaF'
@concurrent
func testWithDynamicIsolation(fn: @isolated(any) () -> Void) async {
  await fn()
}

// CHECK-LABEL: sil hidden [ossa] @$s14execution_attr38testCallerIsolatedWithDynamicIsolation2fnyyyYAXE_tYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor, @guaranteed @isolated(any) @noescape @callee_guaranteed () -> ()) -> () {
// CHECK: bb0([[ISOLATION:%.*]] : @guaranteed $Builtin.ImplicitActor, [[PARAM_FN:%.*]] : @guaranteed $@isolated(any) @noescape @callee_guaranteed () -> ()):
// CHECK:   hop_to_executor [[ISOLATION]]
// CHECK-NEXT:   [[FN:%.*]] = copy_value [[PARAM_FN]]
// CHECK-NEXT:   [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
// CHECK-NEXT:   [[FN_ISOLATION:%.*]] = function_extract_isolation [[BORROWED_FN]]
// CHECK-NEXT:   hop_to_executor [[FN_ISOLATION]]
// CHECK-NEXT:   [[BORROWED_FN:%.*]] = begin_borrow [[FN]]
// CHECK-NEXT:   apply [[BORROWED_FN]]()
// CHECK: hop_to_executor [[ISOLATION]]
// CHECK: } // end sil function '$s14execution_attr38testCallerIsolatedWithDynamicIsolation2fnyyyYAXE_tYaF'
nonisolated(nonsending)
func testCallerIsolatedWithDynamicIsolation(fn: @isolated(any) () -> Void) async {
  await fn()
}