Skip to content

Commit 52aea72

Browse files
committed
Eagerly emit getters at Onone.
Force SILGen to also eagerly emit getters when compiling at Onone. The reason for this is that getters (even not user-written ones, generated by result builders) can, and are often called by users debugging swift programs, and should be available for that reason. rdar://133329303
1 parent a07caa8 commit 52aea72

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

include/swift/SIL/SILDeclRef.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ struct SILDeclRef {
576576
/// for e.g a lazy variable getter.
577577
bool hasUserWrittenCode() const;
578578

579+
/// True if the referenced entity is a getter function.
580+
bool isGetter() const;
581+
579582
/// Return the scope in which the parent class of a method (i.e. class
580583
/// containing this declaration) can be subclassed, returning NotApplicable if
581584
/// this is not a method, there is no such class, or the class cannot be

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ bool SILDeclRef::hasUserWrittenCode() const {
387387
llvm_unreachable("Unhandled case in switch!");
388388
}
389389

390+
bool SILDeclRef::isGetter() const {
391+
if (auto *accessor = dyn_cast_or_null<AccessorDecl>(getFuncDecl()))
392+
return accessor->isGetter();
393+
return false;
394+
}
395+
390396
namespace {
391397
enum class LinkageLimit {
392398
/// No limit.

lib/SILGen/SILGen.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,9 +1197,16 @@ void SILGenModule::emitOrDelayFunction(SILDeclRef constant) {
11971197

11981198
auto emitAfter = lastEmittedFunction;
11991199

1200+
// When compiling at Onone, getters shouldn't be delayed, even if they don't
1201+
// have user written code because they can still be accessible in the
1202+
// debugger.
1203+
bool isOnoneGetter =
1204+
constant.isGetter() &&
1205+
M.getOptions().OptMode == OptimizationMode::NoOptimization;
1206+
12001207
// Implicit decls may be delayed if they can't be used externally.
12011208
auto linkage = constant.getLinkage(ForDefinition);
1202-
bool mayDelay = !constant.hasUserWrittenCode() &&
1209+
bool mayDelay = !isOnoneGetter && !constant.hasUserWrittenCode() &&
12031210
!constant.isDynamicallyReplaceable() &&
12041211
!isPossiblyUsedExternally(linkage, M.isWholeModule());
12051212

test/IRGen/preserve_for_debugger.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class Baz: Foo {
5555

5656
struct Qux {
5757
@Bar(wrappedValue: Baz()) private var baz: Baz
58+
// Baz instance that is never accessed.
59+
@Bar(wrappedValue: Baz()) private var baz2: Baz
5860

5961
func f() {
6062
print(self.baz) // break here
@@ -64,3 +66,4 @@ let qux = Qux()
6466
qux.f()
6567

6668
// CHECK: !DISubprogram(name: "baz.get"
69+
// CHECK: !DISubprogram(name: "baz2.get"

0 commit comments

Comments
 (0)