Skip to content

[lldb][swift] ] Fix GetParentIfClosure for didSet/settters/getters #10954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1554,9 +1554,10 @@ std::string SwiftLanguageRuntime::GetParentNameIfClosure(Function &func) {
// entity.
static const auto closure_kinds = {Kind::ImplicitClosure,
Kind::ExplicitClosure};
static const auto function_kinds = {Kind::ImplicitClosure,
Kind::ExplicitClosure, Kind::Function,
Kind::Constructor, Kind::Static};
static const auto function_kinds = {
Kind::ImplicitClosure, Kind::ExplicitClosure, Kind::Function,
Kind::Constructor, Kind::Static, Kind::Getter,
Kind::Setter, Kind::DidSet};
auto *closure_node = swift_demangle::GetFirstChildOfKind(node, closure_kinds);
auto *parent_func_node =
swift_demangle::GetFirstChildOfKind(closure_node, function_kinds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,34 @@ def test_ctor_class_closure(self):
)
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me_static")

for kind in ["getter", "setter"]:
lldbutil.continue_to_source_breakpoint(
self,
process,
f"break_class_computed_property_{kind}",
lldb.SBFileSpec("main.swift"),
)
check_not_captured_error(
self,
thread.frames[0],
"find_me",
f"MY_CLASS.class_computed_property.{kind}",
)
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me")
lldbutil.continue_to_source_breakpoint(
self,
process,
f"break_class_computed_property_didset",
lldb.SBFileSpec("main.swift"),
)
check_not_captured_error(
self,
thread.frames[0],
"find_me",
f"MY_CLASS.class_computed_property_didset.didset",
)
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me")

@swiftTest
def test_ctor_struct_closure(self):
self.build()
Expand Down Expand Up @@ -164,6 +192,34 @@ def test_ctor_struct_closure(self):
)
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me_static")

for kind in ["getter", "setter"]:
lldbutil.continue_to_source_breakpoint(
self,
process,
f"break_struct_computed_property_{kind}",
lldb.SBFileSpec("main.swift"),
)
check_not_captured_error(
self,
thread.frames[0],
"find_me",
f"MY_STRUCT.struct_computed_property.{kind}",
)
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me")
lldbutil.continue_to_source_breakpoint(
self,
process,
f"break_struct_computed_property_didset",
lldb.SBFileSpec("main.swift"),
)
check_not_captured_error(
self,
thread.frames[0],
"find_me",
f"MY_STRUCT.struct_computed_property_didset.didset",
)
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me")

@swiftTest
def test_ctor_enum_closure(self):
self.build()
Expand Down
72 changes: 70 additions & 2 deletions lldb/test/API/lang/swift/closures_var_not_captured/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,37 @@ class MY_CLASS {
}
let dont_find_me_static = "hello"
}

public var class_computed_property: Int {
get {
let find_me = "hello"
let _ = {
print("break_class_computed_property_getter")
return 10
}()
let dont_find_me = "hello"
return 42
}
set {
let find_me = "hello"
let _ = {
print("break_class_computed_property_setter")
return 10
}()
let dont_find_me = "hello"
}
}

public var class_computed_property_didset: Int = 0 {
didSet {
let find_me = "hello"
let _ = {
print("break_class_computed_property_didset")
return 10
}()
let dont_find_me = "hello"
}
}
}

struct MY_STRUCT {
Expand All @@ -123,6 +154,37 @@ struct MY_STRUCT {
}
let dont_find_me_static = "hello"
}

public var struct_computed_property: Int {
get {
let find_me = "hello"
let _ = {
print("break_struct_computed_property_getter")
return 10
}()
let dont_find_me = "hello"
return 42
}
set {
let find_me = "hello"
let _ = {
print("break_struct_computed_property_setter")
return 10
}()
let dont_find_me = "hello"
}
}

public var struct_computed_property_didset: Int = 0 {
didSet {
let find_me = "hello"
let _ = {
print("break_struct_computed_property_didset")
return 10
}()
let dont_find_me = "hello"
}
}
}

enum MY_ENUM {
Expand Down Expand Up @@ -153,9 +215,15 @@ enum MY_ENUM {
func_1(arg: 42)
func_2(arg: 42)
await func_3(arg: 42)
let _ = MY_CLASS(input: [1, 2])
var my_class = MY_CLASS(input: [1, 2])
MY_CLASS.static_func(input_static: [42])
let _ = MY_STRUCT(input: [1, 2])
print(my_class.class_computed_property)
my_class.class_computed_property = 10
my_class.class_computed_property_didset = 10;
var my_struct = MY_STRUCT(input: [1, 2])
MY_STRUCT.static_func(input_static: [42])
print(my_struct.struct_computed_property)
my_struct.struct_computed_property = 10
my_struct.struct_computed_property_didset = 10
let _ = MY_ENUM(input: [1,2])
MY_ENUM.static_func(input_static: [42])