-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Mangling] [NFC] Prepare for a new mangling prefix for Embedded Swift: $e #77115
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
[Mangling] [NFC] Prepare for a new mangling prefix for Embedded Swift: $e #77115
Conversation
14f8784
to
3de5ea9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In ASTContext.cpp I see a handful of places where we call getASTContext() on a Type or Decl we have sitting nearby. Do you mind also changing those calls to directly use the new Context
instance member that you added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the new prefix be documented? docs/ABI/Mangling.rst
Added. |
Added the test: test/Index/index_embedded.swift. |
@swift-ci please test |
Fixed, added test. |
@swift-ci please test |
@@ -400,6 +401,10 @@ class TypeRefBuilder { | |||
TypeRefBuilder(const TypeRefBuilder &other) = delete; | |||
TypeRefBuilder &operator=(const TypeRefBuilder &other) = delete; | |||
|
|||
Mangle::ManglingFlavor getManglingFlavor() { | |||
return Mangle::ManglingFlavor::Default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this a parameter in the constructor? It can be defaulted to true. Reason being that LLDB uses TypeRefBuilder to process types found in DWARF.
@@ -185,6 +185,7 @@ int swift::Demangle::getManglingPrefixLength(llvm::StringRef mangledName) { | |||
/*Swift 4*/ "_T0", | |||
/*Swift 4.x*/ "$S", "_$S", | |||
/*Swift 5+*/ "$s", "_$s", | |||
/*Swift 5+ Embedded Swift*/ "$e", "_$e", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a function here that returns the Mangling Flavor of a string, and declare it on Demangle.h
as well?
Something like:
std::optional<Mangle::ManglingFlavor> getManglingFlavor(llvm::StringRef mangledName) {
if (!isSwiftSymbol(mangledName))
return {};
if (mangledName.starts_with("$e") || mangledName.starts_with("_$e"))
return Mangle::ManglingFlavor::Embedded;
return Mangle::ManglingFlavor::Default;
}
0a19011
to
6dbff5f
Compare
Given the size of this PR and the revlock with LLDB, I'm going to break this PR up, and stage the changes over a series of PRs. I have changed this PR to be a NFC, i.e. not actually changing the mangling just yet. Also added a legacy constructor on ASTMangler that does not require a ASTContext& passed in, to avoid this being a breaking API change. Subsequent separate PRs will adapt LLDB, actually enable the $e prefix, and drop the legacy ASTMangler constructor. |
1d630ae
to
6acc3cd
Compare
@swift-ci please test |
1 similar comment
@swift-ci please test |
…cpp instead of getASTContext() calls
…ges and Embedded Swift prefix
…t_feature_Embedded
94f6433
to
b760541
Compare
@swift-ci please test |
@swift-ci please test Linux platform |
@swift-ci please test |
Given that Embedded Swift's ABI and layout of class metadata is (intentionally) different and incompatible with regular Swift, this PR is introducing a different mangling for all Embedded Swift. Concretely, it changes the mangling prefix from $s to $e.
For reviewing, I recommend looking at commits individually: The first commit is a mechanical change to pass an ASTContext to all instantiations of ASTMangler and its derivatives, which is a large diff but essentially an NFC.
This PR is a large diff, but it's an NFC, just preparing for an actual mangling change in a subsequent commit.