Skip to content

Commit 4998c1c

Browse files
Merge pull request #10915 from adrian-prantl/146273066
[lldb] Add support for symbolic extended existentials
2 parents 5f01da1 + ebf079b commit 4998c1c

File tree

7 files changed

+137
-0
lines changed

7 files changed

+137
-0
lines changed

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,7 @@ uint32_t TypeSystemSwiftTypeRef::CollectTypeInfo(
18691869
swift_flags |= eTypeHasValue;
18701870
break;
18711871

1872+
case Node::Kind::ConstrainedExistential:
18721873
case Node::Kind::BoundGenericProtocol:
18731874
case Node::Kind::Protocol:
18741875
swift_flags |= eTypeHasChildren | eTypeIsStructUnion | eTypeIsProtocol;
@@ -3178,6 +3179,7 @@ bool TypeSystemSwiftTypeRef::IsPossibleDynamicType(opaque_compiler_type_t type,
31783179
switch (node->getKind()) {
31793180
case Node::Kind::Class:
31803181
case Node::Kind::BoundGenericClass:
3182+
case Node::Kind::ConstrainedExistential:
31813183
case Node::Kind::Protocol:
31823184
case Node::Kind::ProtocolList:
31833185
case Node::Kind::ProtocolListWithClass:
@@ -3188,6 +3190,7 @@ bool TypeSystemSwiftTypeRef::IsPossibleDynamicType(opaque_compiler_type_t type,
31883190
case Node::Kind::Enum:
31893191
case Node::Kind::BoundGenericEnum:
31903192
return true;
3193+
31913194
case Node::Kind::BoundGenericStructure: {
31923195
if (node->getNumChildren() < 2)
31933196
return false;
@@ -5031,6 +5034,7 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
50315034
is_base_class);
50325035
return false;
50335036
}
5037+
case Node::Kind::ConstrainedExistential:
50345038
case Node::Kind::ProtocolList:
50355039
return false;
50365040
default:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
3+
include Makefile.rules
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
7+
class TestSwiftConstrainedExistential(lldbtest.TestBase):
8+
@swiftTest
9+
def test(self):
10+
"""Test constrained existential types"""
11+
12+
self.build()
13+
lldbutil.run_to_source_breakpoint(self, "break here",
14+
lldb.SBFileSpec("main.swift"))
15+
s0 = self.frame().FindVariable("s0")
16+
self.assertEqual(s0.GetStaticValue().GetNumChildren(), 3+1+2)
17+
self.assertEqual(s0.GetNumChildren(), 1)
18+
i = s0.GetChildMemberWithName("i")
19+
lldbutil.check_variable(self, i, value='23')
20+
21+
s = self.frame().FindVariable("s")
22+
s = s.GetChildAtIndex(0)
23+
self.assertEqual(s.GetStaticValue().GetNumChildren(), 6)
24+
self.assertEqual(s.GetNumChildren(), 1)
25+
i = s.GetChildMemberWithName("i")
26+
lldbutil.check_variable(self, i, value='23')
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
protocol P1<U> {
2+
associatedtype U
3+
func get1() -> U
4+
}
5+
6+
protocol P2<V> {
7+
associatedtype V
8+
func get2() -> V
9+
}
10+
11+
struct Impl : P1<Int>, P2<(Int, Int)> {
12+
let i = 23
13+
func get1() -> Int { return i }
14+
func get2() -> (Int, Int) { return (4, 2) }
15+
}
16+
17+
struct S<T> {
18+
let s: any P1<T> & P2<(T, T)>
19+
}
20+
21+
func f() {
22+
let s0: any P1<Int> & P2<(Int, Int)> = Impl()
23+
let s = S(s: Impl())
24+
print("break here")
25+
}
26+
27+
f()
28+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
3+
include Makefile.rules
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
7+
class TestSwiftSymbolicExtendedExistential(lldbtest.TestBase):
8+
9+
@swiftTest
10+
def test(self):
11+
"""Test symbolic extended existentials"""
12+
self.build()
13+
lldbutil.run_to_source_breakpoint(
14+
self, 'break here', lldb.SBFileSpec('main.swift'))
15+
16+
if self.TraceOn():
17+
self.runCmd("v -d run -L s")
18+
frame = self.frame()
19+
var_s = frame.FindVariable("s")
20+
var_s_l0 = var_s.GetChildMemberWithName("l0")
21+
var_s_l1 = var_s.GetChildMemberWithName("l1")
22+
var_s_l2 = var_s.GetChildMemberWithName("l2")
23+
var_s_l3 = var_s.GetChildMemberWithName("l3")
24+
var_s_l4 = var_s.GetChildMemberWithName("l4")
25+
var_s_l5 = var_s.GetChildMemberWithName("l5")
26+
var_s_l6 = var_s.GetChildMemberWithName("l6")
27+
lldbutil.check_variable(self, var_s_l0, value="0")
28+
lldbutil.check_variable(self, var_s_l1, value="10")
29+
lldbutil.check_variable(self, var_s_l2, value="20")
30+
lldbutil.check_variable(self, var_s_l3, value="30")
31+
lldbutil.check_variable(self, var_s_l4, value="40")
32+
lldbutil.check_variable(self, var_s_l5, value="50")
33+
lldbutil.check_variable(self, var_s_l6, value="60")
34+
var_s_s1 = var_s.GetChildMemberWithName("s1")
35+
var_s_s2 = var_s.GetChildMemberWithName("s2")
36+
var_s_s3 = var_s.GetChildMemberWithName("s3")
37+
var_s_s4 = var_s.GetChildMemberWithName("s4")
38+
var_s_s5 = var_s.GetChildMemberWithName("s5")
39+
var_s_s6 = var_s.GetChildMemberWithName("s6")
40+
lldbutil.check_variable(self, var_s_s1, use_dynamic=True, summary="1...1")
41+
lldbutil.check_variable(self, var_s_s2, use_dynamic=True, summary="1...200")
42+
lldbutil.check_variable(self, var_s_s3, use_dynamic=True, summary="1...2")
43+
lldbutil.check_variable(self, var_s_s4, use_dynamic=True, summary="nil")
44+
lldbutil.check_variable(self, var_s_s5, use_dynamic=True, typename="a.C")
45+
# FIXME:
46+
# lldbutil.check_variable(self, var_s_s6, use_dynamic=True, summary="Int")
47+
48+
self.expect("expression -- s.s1", substrs=['1...1'])
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class C {}
2+
3+
struct S {
4+
let l0 = 0
5+
let s1 : any Sequence<Int> = 1...1
6+
let l1 = 10
7+
let s2 : any Sequence<Int> = 1...200
8+
let l2 = 20
9+
let s3 : (any Sequence<Int>)? = 1...2
10+
let l3 = 30
11+
let s4 : (any Sequence<Int>)? = nil
12+
let l4 = 40
13+
let s5 : any AnyObject = C()
14+
let l5 = 50
15+
let s6 : any Any.Type = Int.self
16+
let l6 = 60
17+
}
18+
19+
func main() {
20+
var s = S()
21+
print("break here")
22+
}
23+
24+
main()
25+

0 commit comments

Comments
 (0)