File tree 4 files changed +43
-2
lines changed 4 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -576,6 +576,10 @@ struct SILDeclRef {
576
576
// / for e.g a lazy variable getter.
577
577
bool hasUserWrittenCode () const ;
578
578
579
+ // / Returns true if this is a function that should be emitted because it is
580
+ // / accessible in the debugger.
581
+ bool shouldBeEmittedForDebugger () const ;
582
+
579
583
// / Return the scope in which the parent class of a method (i.e. class
580
584
// / containing this declaration) can be subclassed, returning NotApplicable if
581
585
// / this is not a method, there is no such class, or the class cannot be
Original file line number Diff line number Diff line change @@ -387,6 +387,39 @@ bool SILDeclRef::hasUserWrittenCode() const {
387
387
llvm_unreachable (" Unhandled case in switch!" );
388
388
}
389
389
390
+ bool SILDeclRef::shouldBeEmittedForDebugger () const {
391
+ if (!isFunc ())
392
+ return false ;
393
+
394
+ if (getASTContext ().SILOpts .OptMode != OptimizationMode::NoOptimization)
395
+ return false ;;
396
+
397
+ if (!getASTContext ().SILOpts .ShouldFunctionsBePreservedToDebugger )
398
+ return false ;
399
+
400
+ if (getASTContext ().LangOpts .hasFeature (Feature::Embedded))
401
+ return false ;
402
+
403
+ ValueDecl *decl = getDecl ();
404
+ DeclAttributes &attrs = decl->getAttrs ();
405
+ if (attrs.hasSemanticsAttr (" no.preserve.debugger" ))
406
+ return false ;
407
+
408
+ if (getLinkage (ForDefinition) == SILLinkage::Shared)
409
+ return false ;
410
+
411
+ if (auto decl = getDecl ())
412
+ if (!decl->isImplicit ())
413
+ return true ;
414
+
415
+ // Synthesized getters are still callable in the debugger.
416
+ if (auto *accessor = dyn_cast_or_null<AccessorDecl>(getFuncDecl ())) {
417
+ return accessor->isSynthesized () && accessor->isGetterOrSetter ();
418
+ };
419
+
420
+ return false ;
421
+ }
422
+
390
423
namespace {
391
424
enum class LinkageLimit {
392
425
// / No limit.
Original file line number Diff line number Diff line change @@ -1203,8 +1203,9 @@ void SILGenModule::emitOrDelayFunction(SILDeclRef constant) {
1203
1203
auto emitAfter = lastEmittedFunction;
1204
1204
1205
1205
// Implicit decls may be delayed if they can't be used externally.
1206
- auto linkage = constant.getLinkage (ForDefinition);
1207
- bool mayDelay = !constant.hasUserWrittenCode () &&
1206
+ auto linkage = constant.getLinkage (ForDefinition);;
1207
+ bool mayDelay = !constant.shouldBeEmittedForDebugger () &&
1208
+ !constant.hasUserWrittenCode () &&
1208
1209
!constant.isDynamicallyReplaceable () &&
1209
1210
!isPossiblyUsedExternally (linkage, M.isWholeModule ());
1210
1211
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ class Baz: Foo {
55
55
56
56
struct Qux {
57
57
@Bar ( wrappedValue: Baz ( ) ) private var baz : Baz
58
+ // Baz instance that is never accessed.
59
+ @Bar ( wrappedValue: Baz ( ) ) private var baz2 : Baz
58
60
59
61
func f( ) {
60
62
print ( self . baz) // break here
@@ -64,3 +66,4 @@ let qux = Qux()
64
66
qux. f ( )
65
67
66
68
// CHECK: !DISubprogram(name: "baz.get"
69
+ // CHECK: !DISubprogram(name: "baz2.get"
You can’t perform that action at this time.
0 commit comments