Skip to content

Commit c2b14c2

Browse files
Merge pull request #5156 from swiftwasm/release/5.8
[pull] swiftwasm-release/5.8 from release/5.8
2 parents a70a728 + acaa7db commit c2b14c2

16 files changed

+97
-1
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ ERROR(error_stdlib_module_name,none,
180180
"module name \"%0\" is reserved for the standard library"
181181
"%select{|; use -module-name flag to specify an alternate name}1",
182182
(StringRef, bool))
183+
ERROR(error_bad_package_name,none,
184+
"package name \"%0\" is not a valid identifier",
185+
(StringRef))
186+
ERROR(error_stdlib_package_name,none,
187+
"package name \"%0\" is reserved for the standard library",
188+
(StringRef))
183189
ERROR(error_stdlib_not_found,Fatal,
184190
"unable to load standard library for target '%0'", (StringRef))
185191
ERROR(error_module_alias_invalid_format,none,

include/swift/AST/Module.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class ModuleDecl
173173
/// The ABI name of the module, if it differs from the module name.
174174
mutable Identifier ModuleABIName;
175175

176+
/// The name of the package this module belongs to
177+
mutable Identifier PackageName;
176178
public:
177179
/// Produces the components of a given module's full name in reverse order.
178180
///
@@ -400,6 +402,14 @@ class ModuleDecl
400402
ModuleABIName = name;
401403
}
402404

405+
/// Get the package name of the module
406+
Identifier getPackageName() const { return PackageName; }
407+
408+
/// Set the name of the package this module belongs to
409+
void setPackageName(Identifier name) {
410+
PackageName = name;
411+
}
412+
403413
/// Retrieve the actual module name of an alias used for this module (if any).
404414
///
405415
/// For example, if '-module-alias Foo=Bar' is passed in when building the main module,

include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class FrontendOptions {
6464
/// The name of the library to link against when using this module.
6565
std::string ModuleLinkName;
6666

67+
/// The name of the package this module belongs to.
68+
std::string PackageName;
69+
6770
/// Arguments which should be passed in immediate mode.
6871
std::vector<std::string> ImmediateArgv;
6972

include/swift/Option/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ def autolink_force_load : Flag<["-"], "autolink-force-load">,
481481
def module_abi_name : Separate<["-"], "module-abi-name">,
482482
Flags<[FrontendOption, ModuleInterfaceOption]>,
483483
HelpText<"ABI name to use for the contents of this module">;
484+
def package_name : Separate<["-"], "package-name">,
485+
Flags<[FrontendOption, ModuleInterfaceOptionIgnorable]>,
486+
HelpText<"Name of the package the module belongs to">;
484487

485488
def emit_module : Flag<["-"], "emit-module">,
486489
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>,

include/swift/Serialization/Validation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class ExtendedValidationInfo {
107107
SmallVector<StringRef, 4> ExtraClangImporterOpts;
108108
std::string SDKPath;
109109
StringRef ModuleABIName;
110+
StringRef ModulePackageName;
110111
struct {
111112
unsigned ArePrivateImportsEnabled : 1;
112113
unsigned IsSIB : 1;
@@ -179,6 +180,9 @@ class ExtendedValidationInfo {
179180
StringRef getModuleABIName() const { return ModuleABIName; }
180181
void setModuleABIName(StringRef name) { ModuleABIName = name; }
181182

183+
StringRef getModulePackageName() const { return ModulePackageName; }
184+
void setModulePackageName(StringRef name) { ModulePackageName = name; }
185+
182186
bool isConcurrencyChecked() const {
183187
return Bits.IsConcurrencyChecked;
184188
}

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
252252
inputArgs.AddLastArg(arguments, options::OPT_module_cache_path);
253253
inputArgs.AddLastArg(arguments, options::OPT_module_link_name);
254254
inputArgs.AddLastArg(arguments, options::OPT_module_abi_name);
255+
inputArgs.AddLastArg(arguments, options::OPT_package_name);
255256
inputArgs.AddLastArg(arguments, options::OPT_nostdimport);
256257
inputArgs.AddLastArg(arguments, options::OPT_parse_stdlib);
257258
inputArgs.AddLastArg(arguments, options::OPT_resource_dir);

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,16 @@ bool ArgsToFrontendOptionsConverter::convert(
269269
if (const Arg *A = Args.getLastArg(OPT_module_link_name))
270270
Opts.ModuleLinkName = A->getValue();
271271

272+
if (const Arg *A = Args.getLastArg(OPT_package_name)) {
273+
auto pkgName = A->getValue();
274+
if (!Lexer::isIdentifier(pkgName))
275+
Diags.diagnose(SourceLoc(), diag::error_bad_package_name, pkgName);
276+
else if (pkgName == STDLIB_NAME)
277+
Diags.diagnose(SourceLoc(), diag::error_stdlib_package_name, pkgName);
278+
else
279+
Opts.PackageName = pkgName;
280+
}
281+
272282
// This must be called after computing module name, module abi name,
273283
// and module link name. If computing module aliases is unsuccessful,
274284
// return early.

lib/Frontend/Frontend.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,10 @@ ModuleDecl *CompilerInstance::getMainModule() const {
10591059
MainModule->setABIName(getASTContext().getIdentifier(
10601060
Invocation.getFrontendOptions().ModuleABIName));
10611061
}
1062+
if (!Invocation.getFrontendOptions().PackageName.empty()) {
1063+
MainModule->setPackageName(getASTContext().getIdentifier(
1064+
Invocation.getFrontendOptions().PackageName));
1065+
}
10621066
if (Invocation.getFrontendOptions().EnableLibraryEvolution)
10631067
MainModule->setResilienceStrategy(ResilienceStrategy::Resilient);
10641068
if (Invocation.getLangOptions().isSwiftVersionAtLeast(6))

lib/Serialization/ModuleFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,9 @@ class ModuleFile
532532
return Core->Name;
533533
}
534534

535+
StringRef getModulePackageName() const {
536+
return Core->ModulePackageName;
537+
}
535538
/// The ABI name of the module.
536539
StringRef getModuleABIName() const {
537540
return Core->ModuleABIName;

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
163163
case options_block::IS_CONCURRENCY_CHECKED:
164164
extendedInfo.setIsConcurrencyChecked(true);
165165
break;
166+
case options_block::MODULE_PACKAGE_NAME:
167+
extendedInfo.setModulePackageName(blobData);
168+
break;
166169
default:
167170
// Unknown options record, possibly for use by a future version of the
168171
// module format.
@@ -1346,6 +1349,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
13461349
Bits.IsConcurrencyChecked = extInfo.isConcurrencyChecked();
13471350
MiscVersion = info.miscVersion;
13481351
ModuleABIName = extInfo.getModuleABIName();
1352+
ModulePackageName = extInfo.getModulePackageName();
13491353

13501354
hasValidControlBlock = true;
13511355
break;

0 commit comments

Comments
 (0)