Skip to content

Introduce a module alias option to the frontend #39376

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 28, 2021
Merged

Introduce a module alias option to the frontend #39376

merged 5 commits into from
Sep 28, 2021

Conversation

elsh
Copy link
Contributor

@elsh elsh commented Sep 20, 2021

Validate the module alias input and format and convert to the module alias map to be used by import resolution and sema. Rdar://83316886

@elsh elsh self-assigned this Sep 20, 2021
@elsh
Copy link
Contributor Author

elsh commented Sep 20, 2021

@swift-ci smoke test

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.

The basics are right, but I have a lot of refinements to suggest.

@@ -498,6 +503,40 @@ bool ArgsToFrontendOptionsConverter::setUpImmediateArgs() {
return false;
}

bool ArgsToFrontendOptionsConverter::computeModuleAliases() {
auto list = Args.getAllArgValues(options::OPT_module_alias);
if (!list.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: If the list is empty, the loop will run zero times. Will that have the same effect as skipping the loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving this check as is since I'm allocating a lambda.

@beccadax
Copy link
Contributor

beccadax commented Sep 20, 2021

One other thing: There should probably be tests for this PR. Since you haven't actually started implementing the feature, these would probably just check that you're catching ill-formed -module-alias flags. Your test might look something like test/Frontend/invalid-module-name.swift.

@elsh
Copy link
Contributor Author

elsh commented Sep 23, 2021

@swift-ci smoke test

// Tests for invalid module alias format and values.

// RUN: not %target-swift-frontend -emit-silgen -parse-as-library %S/Inputs/invalid-module-alias.swift -module-name foo -module-alias foo=bar 2>&1 | %FileCheck -check-prefix=INVALID_MODULE_ALIAS %s
// INVALID_MODULE_ALIAS: error: invalid module alias "foo"; make sure the alias differs from the module name, module ABI name, module link name, and a standard library name
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a standard library name possible value only Swift in practice or does it concern other core libraries? If it has just one possible value we could pass down the string value of STDLIB_NAME in the diagnostic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant to make it sound more general, so names like lib- are not passed in either.

Diags.diagnose(SourceLoc(), diag::error_module_alias_forbidden_name, value);
return false;
}
if (!Lexer::isIdentifier(value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does that mean that emojis are accepted? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point :) It's the same checked used by computing module name. Most likely a c99 identifier will be used in practice, but we can add a check to enforce that later if needed.

Copy link
Contributor

@xymus xymus left a comment

Choose a reason for hiding this comment

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

This looks good! And I must say that the computeModuleAliases implementation is refreshingly elegant.

Validate input and set up the module alias map
rdar://83316886
More specific diag msgs
Add tests
@elsh
Copy link
Contributor Author

elsh commented Sep 24, 2021

@swift-ci smoke test

@elsh
Copy link
Contributor Author

elsh commented Sep 24, 2021

@swift-ci smoke test

@elsh elsh requested a review from tomerd September 27, 2021 18:36
@elsh elsh merged commit 14eefd1 into main Sep 28, 2021
@elsh elsh deleted the es-mod-alias1 branch September 28, 2021 18:28
elsh added a commit that referenced this pull request Sep 28, 2021
Introduce a module alias option to the frontend. Validate and convert the input to a module alias map to be used by import resolution and sema. rdar://83316886
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