Skip to content

Commit ce87bd8

Browse files
Merge pull request #38987 from adrian-prantl/73490741-5.5
Enter a new debug scope for every let binding.
2 parents 41f8abf + 173c0b4 commit ce87bd8

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

lib/SILGen/SILGenFunction.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
305305
std::vector<PatternMatchContext*> SwitchStack;
306306
/// Keep track of our current nested scope.
307307
///
308-
/// The boolean tracks whether this is a 'guard' scope, which should be
308+
/// The boolean tracks whether this is a binding scope, which should be
309309
/// popped automatically when we leave the innermost BraceStmt scope.
310310
std::vector<llvm::PointerIntPair<const SILDebugScope *, 1>> DebugScopeStack;
311311

@@ -576,19 +576,20 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
576576

577577
/// Enter the debug scope for \p Loc, creating it if necessary.
578578
///
579-
/// \param isGuardScope If true, this is a scope for the bindings introduced by
580-
/// a 'guard' statement. This scope ends when the next innermost BraceStmt ends.
581-
void enterDebugScope(SILLocation Loc, bool isGuardScope=false) {
582-
auto *Parent =
583-
DebugScopeStack.size() ? DebugScopeStack.back().getPointer() : F.getDebugScope();
579+
/// \param isBindingScope If true, this is a scope for the bindings introduced
580+
/// by a let expression. This scope ends when the next innermost BraceStmt
581+
/// ends.
582+
void enterDebugScope(SILLocation Loc, bool isBindingScope = false) {
583+
auto *Parent = DebugScopeStack.size() ? DebugScopeStack.back().getPointer()
584+
: F.getDebugScope();
584585
auto *DS = Parent;
585586
// Don't create a pointless scope for the function body's BraceStmt.
586587
if (!DebugScopeStack.empty())
587588
// Don't nest a scope for Loc under Parent unless it's actually different.
588589
if (RegularLocation(DS->getLoc()) != RegularLocation(Loc))
589590
DS = new (SGM.M)
590591
SILDebugScope(RegularLocation(Loc), &getFunction(), DS);
591-
DebugScopeStack.emplace_back(DS, isGuardScope);
592+
DebugScopeStack.emplace_back(DS, isBindingScope);
592593
B.setCurrentDebugScope(DS);
593594
}
594595

lib/SILGen/SILGenStmt.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,6 @@ void StmtEmitter::visitGuardStmt(GuardStmt *S) {
730730
// Emit the condition bindings, branching to the bodyBB if they fail.
731731
auto NumFalseTaken = SGF.loadProfilerCount(S->getBody());
732732
auto NumNonTaken = SGF.loadProfilerCount(S);
733-
// Begin a new 'guard' scope, which is popped when the next innermost debug
734-
// scope ends.
735-
SGF.enterDebugScope(S, /*isGuardScope=*/true);
736733
SGF.emitStmtCondition(S->getCond(), bodyBB, S, NumNonTaken, NumFalseTaken);
737734
}
738735

lib/SILGen/SwitchEnumBuilder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ void SwitchEnumBuilder::emit() && {
137137
// Don't allow cleanups to escape the conditional block.
138138
SwitchCaseFullExpr presentScope(builder.getSILGenFunction(),
139139
CleanupLocation(loc), branchDest);
140+
// Begin a new binding scope, which is popped when the next innermost debug
141+
// scope ends. The cleanup location loc isn't the perfect source location
142+
// but it's close enough.
143+
builder.getSILGenFunction().enterDebugScope(loc,
144+
/*isBindingScope=*/true);
140145

141146
builder.emitBlock(caseBlock);
142147

test/DebugInfo/guard-let-scope.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
func f(c: AnyObject?) {
44
let x = c
55
// CHECK: sil_scope [[S1:[0-9]+]] { {{.*}} parent @{{.*}}1f
6-
// CHECK: sil_scope [[S2:[0-9]+]] { loc "{{.*}}":[[@LINE+3]]:3 parent [[S1]] }
6+
// CHECK: sil_scope [[S2:[0-9]+]] { loc "{{.*}}":[[@LINE+3]]:17 parent [[S1]] }
77
// CHECK: debug_value %{{.*}} : $Optional<AnyObject>, let, name "x"{{.*}} scope [[S1]]
88
// CHECK: debug_value %{{.*}} : $AnyObject, let, name "x", {{.*}} scope [[S2]]
99
guard let x = x else {

test/SILOptimizer/constantprop-wrongscope.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// Make sure that the destroy_addr instruction has the same scope of the
1313
// instructions surrounding it.
1414

15-
// CHECK: destroy_addr %7 : $*Any, loc {{.*}}:22:19, scope 1
16-
// CHECK: dealloc_stack %12 : $*Optional<Any>, loc {{.*}}:22:23, scope 1
17-
// CHECK: dealloc_stack %7 : $*Any, loc {{.*}}:22:23, scope 1
18-
// CHECK: dealloc_stack %6 : $*A, loc {{.*}}:22:7, scope 1
15+
// CHECK: destroy_addr %7 : $*Any, loc {{.*}}:22:19, scope 2
16+
// CHECK: dealloc_stack %12 : $*Optional<Any>, loc {{.*}}:22:23, scope 2
17+
// CHECK: dealloc_stack %7 : $*Any, loc {{.*}}:22:23, scope 2
18+
// CHECK: dealloc_stack %6 : $*A, loc {{.*}}:22:7, scope 2
1919

2020
import Foundation
2121
func indexedSubscripting(b b: B, idx: Int, a: A) {

test/SILOptimizer/definite-init-wrongscope.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ public class M {
3333

3434
// CHECK-LABEL: sil [ossa] @$s3del1MC4fromAcA12WithDelegate_p_tKcfc : $@convention(method) (@in WithDelegate, @owned M) -> (@owned M, @error Error)
3535

36-
// CHECK: [[I:%.*]] = integer_literal $Builtin.Int2, 1, loc {{.*}}:23:12, scope 2
37-
// CHECK: [[V:%.*]] = load [trivial] %2 : $*Builtin.Int2, loc {{.*}}:23:12, scope 2
38-
// CHECK: [[OR:%.*]] = builtin "or_Int2"([[V]] : $Builtin.Int2, [[I]] : $Builtin.Int2) : $Builtin.Int2, loc {{.*}}:23:12, scope 2
39-
// CHECK: store [[OR]] to [trivial] %2 : $*Builtin.Int2, loc {{.*}}:23:12, scope 2
40-
// CHECK: store %{{.*}} to [init] %{{.*}} : $*C, loc {{.*}}:26:20, scope 2
36+
// CHECK: [[I:%.*]] = integer_literal $Builtin.Int2, 1, loc {{.*}}:23:12, scope 4
37+
// CHECK: [[V:%.*]] = load [trivial] %2 : $*Builtin.Int2, loc {{.*}}:23:12, scope 4
38+
// CHECK: [[OR:%.*]] = builtin "or_Int2"([[V]] : $Builtin.Int2, [[I]] : $Builtin.Int2) : $Builtin.Int2, loc {{.*}}:23:12, scope 4
39+
// CHECK: store [[OR]] to [trivial] %2 : $*Builtin.Int2, loc {{.*}}:23:12, scope 4
40+
// CHECK: store %{{.*}} to [init] %{{.*}} : $*C, loc {{.*}}:26:20, scope 4
4141

4242
// Make sure the dealloc_stack gets the same scope of the instructions surrounding it.
4343

44-
// CHECK: destroy_addr %0 : $*WithDelegate, loc {{.*}}:29:5, scope 2
45-
// CHECK: dealloc_stack %2 : $*Builtin.Int2, loc {{.*}}:23:12, scope 2
44+
// CHECK: destroy_addr %0 : $*WithDelegate, loc {{.*}}:29:5, scope 4
45+
// CHECK: dealloc_stack %2 : $*Builtin.Int2, loc {{.*}}:23:12, scope 4
4646
// CHECK: throw %{{.*}} : $Error, loc {{.*}}:23:12, scope 1

0 commit comments

Comments
 (0)