Skip to content

[embedded] Avoid materializing generic functions for debuginfo purposes in embedded Swift #69682

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

Merged
merged 1 commit into from
Nov 7, 2023
Merged
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
6 changes: 5 additions & 1 deletion lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2328,7 +2328,11 @@ llvm::DIScope *IRGenDebugInfoImpl::getOrCreateScope(const SILDebugScope *DS) {
// Force the debug info for the function to be emitted, even if it
// is external or has been inlined.
llvm::Function *Fn = nullptr;
if (!SILFn->getName().empty() && !SILFn->isZombie())
// Avoid materializing generic functions in embedded Swift mode.
bool genericInEmbedded =
IGM.Context.LangOpts.hasFeature(Feature::Embedded) &&
SILFn->isGeneric();
if (!SILFn->getName().empty() && !SILFn->isZombie() && !genericInEmbedded)
Fn = IGM.getAddrOfSILFunction(SILFn, NotForDefinition);
auto *SP = emitFunction(*SILFn, Fn);

Expand Down
49 changes: 49 additions & 0 deletions test/embedded/generic-classes-debuginfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// RUN: %target-run-simple-swift(-g %S/Inputs/print.swift -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
// RUN: %target-run-simple-swift(-g -Osize %S/Inputs/print.swift -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s

// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx

struct User {
let o: BaseClass
}

class BaseClass {
func foo() {}
}

protocol Protocol {
func protofoo()
}

class Implementor: Protocol {
func protofoo() { print("Implementor.protofoo") }
}

class GenericSubClass<P: Protocol>: BaseClass {
let p: P

init(p: P) {
self.p = p
}

override func foo() {
let x = { self.p.protofoo() }
x()
}
}

@main
struct Main {
static func main() {
let p = Implementor()
let o = GenericSubClass(p: p)
let user = User(o: o)
user.o.foo()
}
}

// CHECK: Implementor.protofoo