-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[NFC] Add module alias map and lookup func to ASTContext #39496
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
Conversation
@swift-ci smoke test |
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.
Does this make any testable changes? If so, you should add tests; if not, you should put "[NFC]" (No Functional Change) at the beginning of the commit title.
Other than that, just a couple of minor suggestions—this looks pretty sound fundamentally.
@swift-ci smoke test |
for (auto k: aliasMap.keys()) { | ||
auto val = aliasMap.lookup(k); | ||
if (!val.empty()) { | ||
ModuleAliasMap[getIdentifier(k)] = getIdentifier(val); |
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.
Does this (or something else) copy the strings storage to the AST context?
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.
I've had issues in the past with StringRef
s parsed from arguments being lost in long running SourceKit process. I'm not sure if we could see the same thing here.
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.
getIdentifier
allocates an entry and the ModuleAliasMap
is a DenseMap so it'll be stored. Also the StringRefs in the argument map contains allocated data so they won't be lost either by the time this func is called. We could perhaps clear the argument map after the loop for better optimization if needed.
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.
Sounds good. Thanks for the details!
@swift-ci smoke test |
Set module underlying name in ModuleDecl if a module alias exists rdar://83682112
Add examples to documentation comment
@swift-ci smoke test |
@swift-ci smoke test |
@swift-ci smoke test |
@@ -1564,6 +1563,11 @@ ImportedModule::removeDuplicates(SmallVectorImpl<ImportedModule> &imports) { | |||
imports.erase(last, imports.end()); | |||
} | |||
|
|||
Identifier ModuleDecl::getRealName() const { | |||
// This will return the real name for an alias (if used) or getName() | |||
return getASTContext().getRealModuleName(getName()); |
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.
Cute.
[NFC] Add a module alias map and a lookup func to ASTContext.
Add a getter for the actual module name in ModuleDecl if a module alias is used.
rdar://83682112