Skip to content

Commit e1ecd8b

Browse files
committed
[sil] Teach VariableNameUtils how to look through function conversion thunk patterns.
1 parent 9154082 commit e1ecd8b

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

lib/SILOptimizer/Utils/VariableNameUtils.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,19 @@ VariableNameInferrer::findDebugInfoProvidingValue(SILValue searchValue) {
180180
}
181181
}
182182

183+
// Look through a function conversion thunk if we have one.
184+
if (auto *pai = dyn_cast<PartialApplyInst>(searchValue)) {
185+
if (auto *fn = pai->getCalleeFunction()) {
186+
if (fn->isThunk() && ApplySite(pai).getNumArguments() == 1) {
187+
SILValue value = ApplySite(pai).getArgument(0);
188+
if (value->getType().isFunction()) {
189+
searchValue = value;
190+
continue;
191+
}
192+
}
193+
}
194+
}
195+
183196
// If we do not do an exact match, see if we can find a debug_var inst. If
184197
// we do, we always break since we have a root value.
185198
if (auto *use = getAnyDebugUse(searchValue)) {
@@ -197,7 +210,8 @@ VariableNameInferrer::findDebugInfoProvidingValue(SILValue searchValue) {
197210
if (isa<BeginBorrowInst>(searchValue) || isa<LoadInst>(searchValue) ||
198211
isa<LoadBorrowInst>(searchValue) || isa<BeginAccessInst>(searchValue) ||
199212
isa<MarkUnresolvedNonCopyableValueInst>(searchValue) ||
200-
isa<ProjectBoxInst>(searchValue) || isa<CopyValueInst>(searchValue)) {
213+
isa<ProjectBoxInst>(searchValue) || isa<CopyValueInst>(searchValue) ||
214+
isa<ConvertFunctionInst>(searchValue)) {
201215
searchValue = cast<SingleValueInstruction>(searchValue)->getOperand(0);
202216
continue;
203217
}

test/SILOptimizer/variable_name_inference.sil

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ContainsKlass {
1919
sil @getKlass : $@convention(thin) () -> @owned Klass
2020
sil @getContainsKlass : $@convention(thin) () -> @owned ContainsKlass
2121
sil @useIndirect : $@convention(thin) <T> (@in_guaranteed T) -> ()
22+
sil @sideEffect : $@convention(thin) () -> ()
2223

2324
//===----------------------------------------------------------------------===//
2425
// MARK: Tests
@@ -113,3 +114,37 @@ bb0:
113114
%13 = tuple ()
114115
return %13 : $()
115116
}
117+
118+
sil [thunk] @test_reabstraction_thunk : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> @out ()
119+
120+
// CHECK-LABEL: begin running test {{.*}} of {{.*}} on handle_function_conversion_reabstraction_thunks: variable-name-inference with: @trace[0]
121+
// CHECK: Name: 'namedClosure'
122+
// CHECK: Root: %0 = alloc_stack [lexical] $@callee_guaranteed () -> (), var, name "namedClosure"
123+
// CHECK: end running test {{.*}} of {{.*}} on handle_function_conversion_reabstraction_thunks: variable-name-inference with: @trace[0]
124+
sil [ossa] @handle_function_conversion_reabstraction_thunks : $@convention(thin) () -> () {
125+
bb0:
126+
specify_test "variable-name-inference @trace[0]"
127+
%namedStack = alloc_stack [lexical] $@callee_guaranteed () -> (), var, name "namedClosure"
128+
%f = function_ref @sideEffect : $@convention(thin) () -> ()
129+
%pa = partial_apply [callee_guaranteed] %f() : $@convention(thin) () -> ()
130+
store %pa to [init] %namedStack : $*@callee_guaranteed () -> ()
131+
132+
%temp = alloc_stack $@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>
133+
%access = begin_access [read] [static] %namedStack : $*@callee_guaranteed () -> ()
134+
%load = load [copy] %access : $*@callee_guaranteed () -> ()
135+
end_access %access : $*@callee_guaranteed () -> ()
136+
137+
%reabstract = function_ref @test_reabstraction_thunk : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> @out ()
138+
%reabstract_partially_applied = partial_apply [callee_guaranteed] %reabstract(%load) : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> @out ()
139+
%cvt = convert_function %reabstract_partially_applied : $@callee_guaranteed () -> @out () to $@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>
140+
store %cvt to [init] %temp : $*@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>
141+
debug_value [trace] %temp : $*@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>
142+
143+
destroy_addr %temp : $*@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>
144+
dealloc_stack %temp : $*@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>
145+
destroy_addr %namedStack : $*@callee_guaranteed () -> ()
146+
dealloc_stack %namedStack : $*@callee_guaranteed () -> ()
147+
148+
%9999 = tuple ()
149+
return %9999 : $()
150+
}

0 commit comments

Comments
 (0)