Allow module aliases to use escaped identifiers as the alias name.

The original module names themselves must still be valid unescaped identifiers; most of the serialization logic in the compiler depends on the name of a module matching its name on the file system, and it would be very complex to turn escaped identifiers into file-safe names.
This commit is contained in:
Tony Allevato
2024-06-29 14:48:29 -04:00
committed by Tony Allevato
parent 329261593e
commit 2b0f9aa765
7 changed files with 192 additions and 19 deletions

View File

@@ -936,9 +936,12 @@ bool ModuleAliasesConverter::computeModuleAliases(std::vector<std::string> args,
// it should be called only once
options.ModuleAliasMap.clear();
auto validate = [&options, &diags](StringRef value, bool allowModuleName) -> bool
{
if (!allowModuleName) {
// validatingModuleName should be true if validating the alias target (an
// actual module name), or true if validating the alias name (which can be
// an escaped identifier).
auto validate = [&options, &diags](StringRef value,
bool validatingModuleName) -> bool {
if (!validatingModuleName) {
if (value == options.ModuleName ||
value == options.ModuleABIName ||
value == options.ModuleLinkName ||
@@ -947,7 +950,8 @@ bool ModuleAliasesConverter::computeModuleAliases(std::vector<std::string> args,
return false;
}
}
if (!Lexer::isIdentifier(value)) {
if ((validatingModuleName && !Lexer::isIdentifier(value)) ||
!Lexer::isValidAsEscapedIdentifier(value)) {
diags.diagnose(SourceLoc(), diag::error_bad_module_name, value, false);
return false;
}