Skip to content

[lldb] Build DeclContext vector from a Swift demangle tree #8465

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

Conversation

augusto2112
Copy link

Replace the current GetNominal function, which would only handle finding
a module + a type with a more complete BuildDeclContext function, which
will recursively build a DeclContext, taking into account nested and
private types.

rdar://125044318

@augusto2112
Copy link
Author

@swift-ci test

@augusto2112
Copy link
Author

Depends on #8464

@augusto2112 augusto2112 force-pushed the build-decl-context branch 3 times, most recently from af8fca4 to 8f84352 Compare March 25, 2024 17:59
@augusto2112
Copy link
Author

@swift-ci test

@augusto2112 augusto2112 marked this pull request as ready for review March 25, 2024 17:59
@augusto2112
Copy link
Author

@swift-ci test Windows

static std::optional<std::pair<StringRef, StringRef>>
GetNominal(swift::Demangle::Demangler &dem, swift::Demangle::NodePointer node) {
bool
TypeSystemSwiftTypeRef::IsBuiltinType(CompilerType type) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this IsSwiftBuiltinType?
alternatively — is this different from CmpilerType.IsIntegerType() || CmpilerType.IsFloatingPointType() || CmpilerType.IsVectorType()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this even used in the patch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is unrelated, the diff is probably highlighting it because I changed code above and below it?

if (!first)
return false;
if (first->getKind() == Node::Kind::Module) {
assert(first->hasText() && "Module node should have text!");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also needs to be a dynamic check.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I see at least two other places in the same file that disect TypeAlias nodes, so factoring this out into a helper might be best.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should the helper do though? There aren't many assumptions you can make about the type's children, as both nodes could be many different things.

The first can be the module, another type, I believe also a function.

The second one can be an identifier, a private decl, or a local decl.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could add a generic

[declcontext, type] = extractBinaryNode(node)

facility. If you don't think that's worth it, then not.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added two helpers for nodes that I thought made sense, but left the rest as is

return false;

auto *first = node->getChild(0);
auto *second = node->getChild(1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here about factoring this out. I think this will get a lot more readable if it starts with:

std::optional<std::pair<StringRef, StringRef>> module_ident = extractFunctionNode(node);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like, the other comment, there's not much we can assume about the children, so the helper couldn't do much besides verifying the number of children and just returning them.

/// Return a pair of module name and type name, given a mangled name.
static std::optional<std::pair<StringRef, StringRef>>
GetNominal(llvm::StringRef mangled_name, swift::Demangle::Demangler &dem) {
static std::optional<std::vector<CompilerContext>>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doxygen comment would be nice.

struct S2 {
func s2() {
func s2_2() {
struct S3 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this get noticeable different if, e.g., S3 were a class?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I changed this to use classes, enums and structs, plus a private discriminator

Replace the current GetNominal function, which would only handle finding
a module + a type with a more complete BuildDeclContext function, which
will recursively build a DeclContext, taking into account nested and
private types.

rdar://125044318
@augusto2112
Copy link
Author

@swift-ci test

@augusto2112
Copy link
Author

@swift-ci test Windows

@adrian-prantl adrian-prantl merged commit c7c963a into swiftlang:swift/release/6.0 Apr 5, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants