Skip to content

Commit 9736694

Browse files
authored
Merge pull request swiftlang#74912 from gottesmm/release/6.0-rdar130915737-part2
[6.0][siloptimizer] Teach VariableNameInference how to look through convert_escape_to_no_escape.
2 parents 06485c2 + 523457b commit 9736694

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

lib/SILOptimizer/Utils/VariableNameUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@ SILValue VariableNameInferrer::findDebugInfoProvidingValueHelper(
626626
isa<MoveOnlyWrapperToCopyableAddrInst>(searchValue) ||
627627
isa<MoveOnlyWrapperToCopyableValueInst>(searchValue) ||
628628
isa<CopyableToMoveOnlyWrapperValueInst>(searchValue) ||
629-
isa<EndInitLetRefInst>(searchValue)) {
629+
isa<EndInitLetRefInst>(searchValue) ||
630+
isa<ConvertEscapeToNoEscapeInst>(searchValue)) {
630631
searchValue = cast<SingleValueInstruction>(searchValue)->getOperand(0);
631632
continue;
632633
}

test/Concurrency/transfernonsendable_region_based_sendability.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ func test_closure_capture(a : A) async {
102102
print(ns3)
103103

104104
// this should consume ns0
105-
await a.run_closure(captures0) // expected-tns-warning {{sending value of non-Sendable type '() -> ()' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
105+
await a.run_closure(captures0)
106+
// expected-tns-warning @-1 {{sending 'captures0' risks causing data races}}
107+
// expected-tns-note @-2 {{sending 'captures0' to actor-isolated instance method 'run_closure' risks causing data races between actor-isolated and local nonisolated uses}}
108+
106109
// expected-complete-warning @-1 {{passing argument of non-sendable type '() -> ()' into actor-isolated context may introduce data races}}
107110
// expected-complete-note @-2 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
108111

@@ -112,7 +115,9 @@ func test_closure_capture(a : A) async {
112115
print(ns3)
113116

114117
// this should consume ns1 and ns2
115-
await a.run_closure(captures12) // expected-tns-warning {{sending value of non-Sendable type '() -> ()' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
118+
await a.run_closure(captures12)
119+
// expected-tns-warning @-1 {{sending 'captures12' risks causing data races}}
120+
// expected-tns-note @-2 {{sending 'captures12' to actor-isolated instance method 'run_closure' risks causing data races between actor-isolated and local nonisolated uses}}
116121
// expected-complete-warning @-1 {{passing argument of non-sendable type '() -> ()' into actor-isolated context may introduce data races}}
117122
// expected-complete-note @-2 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
118123

@@ -123,7 +128,9 @@ func test_closure_capture(a : A) async {
123128
print(ns3)
124129

125130
// this should consume ns3
126-
await a.run_closure(captures3indirect) // expected-tns-warning {{sending value of non-Sendable type '() -> ()' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
131+
await a.run_closure(captures3indirect)
132+
// expected-tns-warning @-1 {{sending 'captures3indirect' risks causing data races}}
133+
// expected-tns-note @-2 {{sending 'captures3indirect' to actor-isolated instance method 'run_closure' risks causing data races between actor-isolated and local nonisolated uses}}
127134
// expected-complete-warning @-1 {{passing argument of non-sendable type '() -> ()' into actor-isolated context may introduce data races}}
128135
// expected-complete-note @-2 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
129136

test/SILOptimizer/variable_name_inference.sil

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,4 +896,26 @@ bb0(%0 : @owned $Klass):
896896
%1 = end_init_let_ref %0 : $Klass
897897
debug_value [trace] %1 : $Klass
898898
return %1 : $Klass
899-
}
899+
}
900+
901+
// CHECK-LABEL: begin running test 1 of 1 on infer_for_closure: variable-name-inference with: @trace[0]
902+
// CHECK: Input Value: %5 = convert_escape_to_noescape [not_guaranteed] %4 : $@callee_guaranteed () -> () to $@noescape @callee_guaranteed () -> ()
903+
// CHECK: Name: 'closure1'
904+
// CHECK: Root: %2 = move_value [lexical] [var_decl] %1 : $@callee_guaranteed () -> ()
905+
// CHECK: end running test 1 of 1 on infer_for_closure: variable-name-inference with: @trace[0]
906+
sil [ossa] @infer_for_closure : $@convention(thin) () -> () {
907+
bb0:
908+
specify_test "variable-name-inference @trace[0]"
909+
%0 = function_ref @sideEffect : $@convention(thin) () -> ()
910+
%1 = partial_apply [callee_guaranteed] %0() : $@convention(thin) () -> ()
911+
%2 = move_value [lexical] [var_decl] %1 : $@callee_guaranteed () -> ()
912+
debug_value %2 : $@callee_guaranteed () -> (), let, name "closure1"
913+
%3 = copy_value %2 : $@callee_guaranteed () -> ()
914+
%4 = convert_escape_to_noescape [not_guaranteed] %3 : $@callee_guaranteed () -> () to $@noescape @callee_guaranteed () -> ()
915+
debug_value [trace] %4 : $@noescape @callee_guaranteed () -> ()
916+
destroy_value %4 : $@noescape @callee_guaranteed () -> ()
917+
destroy_value %3 : $@callee_guaranteed () -> ()
918+
destroy_value %2 : $@callee_guaranteed () -> ()
919+
%9999 = tuple ()
920+
return %9999 : $()
921+
}

0 commit comments

Comments
 (0)