Skip to content

Commit b05972b

Browse files
committed
SILDebugScopes: Don't ignore ConditionalClauseInitializerScope.
ConditionalClauseInitializerScope often create redundant scopes, however, they are needed to correctly represent the scopes in an expression such as: if case .something(let foo), let foo = foo. This patch changes SILGen to lower them 1:1 from ASTScopes. rdar://110841130
1 parent b140bc3 commit b05972b

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

include/swift/AST/ASTScope.h

-1
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,6 @@ class ConditionalClauseInitializerScope final : public ASTScopeImpl {
990990
SourceRange
991991
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
992992
std::string getClassName() const override;
993-
bool ignoreInDebugInfo() const override { return true; }
994993

995994
private:
996995
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);

test/DebugInfo/case-scope3.swift

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-frontend -module-name a -parse-as-library -emit-sil -g %s | %FileCheck %s
2+
3+
enum E {
4+
case integerValue(Int?)
5+
}
6+
7+
func getE() -> E? { return .integerValue(0) }
8+
9+
func f() -> Int {
10+
if case .integerValue(let nextValue) = getE(), let nextValue = nextValue {
11+
// CHECK: sil_scope [[F:[0-9]+]] { loc "{{.*}}":9:6 parent @$s1a1fSiyF
12+
// CHECK: sil_scope [[S0:[0-9]+]] { loc "{{.*}}":10:5 parent [[F]] }
13+
// CHECK: sil_scope [[S1:[0-9]+]] { loc "{{.*}}":10:44 parent [[S0]] }
14+
// CHECK: sil_scope [[S2:[0-9]+]] { loc "{{.*}}":10:44 parent [[S0]] }
15+
// CHECK: sil_scope [[S3:[0-9]+]] { loc "{{.*}}":10:68 parent [[S2]] }
16+
// CHECK: sil_scope [[S4:[0-9]+]] { loc "{{.*}}":10:78 parent [[S3]] }
17+
// CHECK: debug_value {{.*}}: $Optional<Int>, let, name "nextValue", {{.*}}:10:31, scope [[S0]]
18+
// CHECK: debug_value {{.*}}: $Int, let, name "nextValue", {{.*}}:10:56, scope [[S2]]
19+
return nextValue
20+
}
21+
return 0
22+
}

test/DebugInfo/guard-let-scope.swift

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ func f(c: AnyObject??) {
1010
// CHECK: sil_scope [[S5:[0-9]+]] { {{.*}} parent [[S3]] }
1111
// CHECK: sil_scope [[S6:[0-9]+]] { loc "{{.*}}":7:3 parent [[S5]] }
1212
// CHECK: sil_scope [[S7:[0-9]+]] { loc "{{.*}}":7:17 parent [[S6]] }
13-
// CHECK: sil_scope [[S8:[0-9]+]] { loc "{{.*}}":7:28 parent [[S7]] }
13+
// CHECK: sil_scope [[S8:[0-9]+]] { loc "{{.*}}":7:17 parent [[S6]] }
14+
// CHECK: sil_scope [[S9:[0-9]+]] { loc "{{.*}}":7:28 parent [[S8]] }
15+
// CHECK: sil_scope [[S10:[0-9]+]] { loc "{{.*}}":7:28 parent [[S8]] }
1416
// CHECK: debug_value %{{.*}} : $Optional<Optional<AnyObject>>, let, name "x"{{.*}} scope [[S5]]
15-
// CHECK: debug_value %{{.*}} : $Optional<AnyObject>, let, name "x", {{.*}} scope [[S7]]
17+
// CHECK: debug_value %{{.*}} : $Optional<AnyObject>, let, name "x", {{.*}} scope [[S6]]
1618
// CHECK: debug_value %{{.*}} : $AnyObject, let, name "x", {{.*}} scope [[S8]]
1719
fatalError()
1820
}
19-
// CHECK: function_ref {{.*3use.*}} scope [[S8]]
21+
// CHECK: function_ref {{.*3use.*}} scope [[S10]]
2022
use(x)
2123
}

test/DebugInfo/guard-let-scope3.swift

+9-6
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ public class S {
77
private var c = [Int : C?]()
88
public func f(_ i: Int) throws -> C {
99
guard let x = c[i], let x else {
10-
// CHECK: sil_scope [[P:[0-9]+]] { loc "{{.*}}":[[@LINE-1]]:5
11-
// CHECK: sil_scope [[X1:[0-9]+]] { loc "{{.*}}":[[@LINE-2]]:19 parent [[P]]
12-
// CHECK: sil_scope [[X2:[0-9]+]] { loc "{{.*}}":[[@LINE-3]]:29 parent [[X1]]
13-
// CHECK: sil_scope [[GUARD:[0-9]+]] { loc "{{.*}}":[[@LINE-4]]:36 parent [[P]]
14-
// CHECK: debug_value {{.*}} : $Optional<C>, let, name "x", {{.*}}, scope [[X1]]
10+
// CHECK: sil_scope [[P:[0-9]+]] { loc "{{.*}}":9:5
11+
// CHECK: sil_scope [[X1_:[0-9]+]] { loc "{{.*}}":9:19 parent [[P]]
12+
// CHECK: sil_scope [[X1:[0-9]+]] { loc "{{.*}}":9:19 parent [[P]]
13+
// CHECK: sil_scope [[X2:[0-9]+]] { loc "{{.*}}":9:29 parent [[X1]]
14+
// CHECK: sil_scope [[X2_:[0-9]+]] { loc "{{.*}}":9:29 parent [[X1]]
15+
// CHECK: sil_scope [[GUARD:[0-9]+]] { loc "{{.*}}":9:36 parent [[P]]
16+
// CHECK: debug_value {{.*}} : $Optional<C>, let, name "x", {{.*}}, scope [[P]]
1517
// CHECK: debug_value {{.*}} : $C, let, name "x", {{.*}}, scope [[X2]]
16-
// CHECK-NEXT: scope [[X2]]
18+
// FIXME: This source location & scope are a little wild.
19+
// CHECK-NEXT: strong_retain{{.*}}:[[@LINE+4]]:12, scope [[X2_]]
1720
throw MyError()
1821
// CHECK: function_ref {{.*}}MyError{{.*}}:[[@LINE-1]]:13, scope [[GUARD]]
1922
}

test/DebugInfo/if-let-scope.swift

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// RUN: %target-swift-frontend -g -emit-sil %s -parse-as-library -module-name a | %FileCheck %s
22
func use<T>(_ t: T) {}
33
public func f(value: String?) {
4-
// CHECK: sil_scope [[S0:[0-9]+]] { loc "{{.*}}":[[@LINE-1]]:13
4+
// CHECK: sil_scope [[S0:[0-9]+]] { loc "{{.*}}":3:13
55
if let value, let value = Int(value) {
6-
// CHECK: sil_scope [[S1:[0-9]+]] { loc "{{.*}}":[[@LINE-1]]:10
7-
// CHECK: sil_scope [[S2:[0-9]+]] { loc "{{.*}}":[[@LINE-2]]:29 parent [[S1]] }
6+
// CHECK: sil_scope [[S1:[0-9]+]] { loc "{{.*}}":5:10
7+
// CHECK: sil_scope [[S2:[0-9]+]] { loc "{{.*}}":5:10
8+
// CHECK: sil_scope [[S3:[0-9]+]] { loc "{{.*}}":5:29 parent [[S2]] }
9+
// CHECK: sil_scope [[S4:[0-9]+]] { loc "{{.*}}":5:29 parent [[S2]] }
810
// CHECK: debug_value {{.*}} : $Optional<String>, let, name "value", {{.*}}, scope [[S0]]
911
// CHECK: debug_value {{.*}} : $String, let, name "value", {{.*}}, scope [[S1]]
1012
// CHECK: debug_value {{.*}} : $Int, let, name "value", {{.*}}, scope [[S2]]

0 commit comments

Comments
 (0)