Skip to content

[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

Merged
merged 5 commits into from
Sep 30, 2021
Merged

Conversation

elsh
Copy link
Contributor

@elsh elsh commented Sep 28, 2021

[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

@elsh elsh requested review from tomerd, xymus and beccadax September 28, 2021 23:23
@elsh
Copy link
Contributor Author

elsh commented Sep 28, 2021

@swift-ci smoke test

@elsh elsh changed the title Add module alias map and underlying name to ModuleDecl Add module alias map and lookup func to ASTContext Sep 29, 2021
Copy link
Contributor

@beccadax beccadax left a 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.

@elsh elsh changed the title Add module alias map and lookup func to ASTContext [NFC] Add module alias map and lookup func to ASTContext Sep 29, 2021
@elsh
Copy link
Contributor Author

elsh commented Sep 29, 2021

@swift-ci smoke test

for (auto k: aliasMap.keys()) {
auto val = aliasMap.lookup(k);
if (!val.empty()) {
ModuleAliasMap[getIdentifier(k)] = getIdentifier(val);
Copy link
Contributor

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?

Copy link
Contributor

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 StringRefs parsed from arguments being lost in long running SourceKit process. I'm not sure if we could see the same thing here.

Copy link
Contributor Author

@elsh elsh Sep 29, 2021

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.

Copy link
Contributor

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!

@elsh
Copy link
Contributor Author

elsh commented Sep 29, 2021

@swift-ci smoke test

Set module underlying name in ModuleDecl if a module alias exists
rdar://83682112
Add examples to documentation comment
@elsh
Copy link
Contributor Author

elsh commented Sep 29, 2021

@swift-ci smoke test

@elsh
Copy link
Contributor Author

elsh commented Sep 30, 2021

@swift-ci smoke test

@elsh
Copy link
Contributor Author

elsh commented Sep 30, 2021

@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());
Copy link
Contributor

Choose a reason for hiding this comment

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

Cute.

@elsh elsh merged commit 028b964 into main Sep 30, 2021
@elsh elsh deleted the es-malias2 branch September 30, 2021 23:42
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.

3 participants