-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
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.
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()) { |
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.
Nit: If the list is empty, the loop will run zero times. Will that have the same effect as skipping the loop?
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.
Leaving this check as is since I'm allocating a lambda.
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 |
@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 |
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.
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.
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 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)) { |
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 that mean that emojis are accepted? 🤔
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.
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.
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.
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
@swift-ci smoke test |
@swift-ci smoke test |
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
Validate the module alias input and format and convert to the module alias map to be used by import resolution and sema. Rdar://83316886