Skip to content

[DebugInfo] Dont generate info for __swift_async_resume_project_conte… #75553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/IRGen/GenFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2590,8 +2590,9 @@ IRGenFunction::emitAsyncResumeProjectContext(llvm::Value *calleeContext) {
}

llvm::Function *IRGenFunction::getOrCreateResumePrjFn(bool forPrologue) {
// The prologue version lacks artificial debug info as this would cause
// verification errors when it gets inlined.
// Never emit debug info for these alwaysinline functions, as it would create
// an inline frame without any user code. These can also be involved in tail
// calls, which confuse the debugger.
auto name = forPrologue ? "__swift_async_resume_project_context_prologue"
: "__swift_async_resume_project_context";
auto Fn = cast<llvm::Function>(IGM.getOrCreateHelperFunction(
Expand All @@ -2603,7 +2604,7 @@ llvm::Function *IRGenFunction::getOrCreateResumePrjFn(bool forPrologue) {
auto callerContext = IGF.emitAsyncResumeProjectContext(addr);
Builder.CreateRet(callerContext);
},
false /*isNoInline*/, forPrologue));
false /*isNoInline*/, true/*for prologue*/));
Copy link
Contributor

@jasonmolenda jasonmolenda Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the forPrologue parameter from getOrCreateResumePrjFn?

Copy link
Contributor Author

@felipepiovezan felipepiovezan Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't, because this function is used in a ton of places, most of them with "for prologue" == false.

What it would be nice is to rename this parameter to something more meaningful like "skip debug info", since this is what this parameter does. The original patch mixed the motivation from call sites with the effect inside this function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry I missed that this could be called for one of two async resume functions, and it uses forPrologue to pick the name.

Fn->addFnAttr(llvm::Attribute::AlwaysInline);
return Fn;
}
Expand Down Expand Up @@ -2694,14 +2695,17 @@ void IRGenFunction::emitSuspensionPoint(Explosion &toExecutor,
}

llvm::Function *IRGenFunction::getOrCreateResumeFromSuspensionFn() {
// Never emit debug info for these alwaysinline functions, as it would create
// an inline frame without any user code. These can also be involved in tail
// calls, which confuse the debugger.
auto name = "__swift_async_resume_get_context";
auto fn = cast<llvm::Function>(IGM.getOrCreateHelperFunction(
name, IGM.Int8PtrTy, {IGM.Int8PtrTy},
[&](IRGenFunction &IGF) {
auto &Builder = IGF.Builder;
Builder.CreateRet(&*IGF.CurFn->arg_begin());
},
false /*isNoInline*/));
false /*isNoInline*/, true /*forPrologue*/));
fn->addFnAttr(llvm::Attribute::AlwaysInline);
return fn;
}
Expand Down
48 changes: 48 additions & 0 deletions test/IRGen/async/no_debug_info_in_projections.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// RUN: %target-swift-frontend %s -g -emit-irgen | %IRGenFileCheck %s

// We don't want any debug info for these helper functions:

// CHECK: define {{.*}} @__swift_async_resume_project_context
// CHECK-NOT: !dbg
// CHECK-SAME: {
// CHECK: define {{.*}} @__swift_async_resume_get_context
// CHECK-NOT: !dbg
// CHECK-SAME: {

sil_stage canonical

import Builtin
import Swift
import SwiftShims

@_silgen_name("some_async_func")
public func some_async_func() async -> Int

func foo() async -> Int

sil_scope 1 { parent @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 }

sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
%2 = integer_literal $Builtin.Int32, 0, scope 1 // user: %3
%3 = struct $Int32 (%2 : $Builtin.Int32), scope 1 // user: %4
return %3 : $Int32, scope 1 // id: %4
}

sil_scope 2 { loc "test.swift":4:6 parent @$s4test3fooSiyYaF : $@convention(thin) @async () -> Int }
sil_scope 3 { loc "test.swift":5:16 parent 2 }
sil_scope 4 { loc "test.swift":5:7 parent 2 }

sil @$s4test3fooSiyYaF : $@convention(thin) @async () -> Int {
bb0:
%0 = enum $Optional<Builtin.Executor>, #Optional.none!enumelt, loc * "test.swift":4:6, scope 2 // user: %3
// function_ref some_async_func
%1 = function_ref @some_async_func : $@convention(thin) @async () -> Int, loc "test.swift":5:22, scope 3 // user: %2
%2 = apply %1() : $@convention(thin) @async () -> Int, loc "test.swift":5:22, scope 3 // users: %6, %4
hop_to_executor %0 : $Optional<Builtin.Executor>, loc * "test.swift":5:22, scope 3 // id: %3
debug_value %2 : $Int, let, name "result", loc "test.swift":5:7, scope 4 // id: %4
return %2 : $Int, loc "test.swift":6:3, scope 4 // id: %13
}


sil @some_async_func : $@convention(thin) @async () -> Int