Skip to content

Commit b526205

Browse files
authored
Merge pull request #62044 from xymus/module-alias-disambiguate-fix
[ModuleInterface] Support loading an aliased module with an underlying module
2 parents 5fa31c6 + 0e40dac commit b526205

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static void ParseModuleInterfaceArgs(ModuleInterfaceOptions &Opts,
371371
Opts.AliasModuleNames |=
372372
Args.hasFlag(OPT_alias_module_names_in_module_interface,
373373
OPT_disable_alias_module_names_in_module_interface,
374-
false);
374+
::getenv("SWIFT_ALIAS_MODULE_NAMES_IN_INTERFACES"));
375375
Opts.PrintFullConvention |=
376376
Args.hasArg(OPT_experimental_print_full_convention);
377377
Opts.ExperimentalSPIImports |=

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ class ModuleInterfaceLoaderImpl {
614614
StringRef inParentDirName =
615615
path::filename(path::parent_path(interfacePath));
616616
if (path::extension(inParentDirName) == ".swiftmodule") {
617-
assert(path::stem(inParentDirName) == moduleName);
617+
assert(path::stem(inParentDirName) ==
618+
ctx.getRealModuleName(ctx.getIdentifier(moduleName)).str());
618619
path::append(scratch, inParentDirName);
619620
}
620621
path::append(scratch, path::filename(modulePath));

lib/Serialization/Deserialization.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2360,8 +2360,9 @@ ModuleDecl *ModuleFile::getModule(ImportPath::Module name,
23602360
return getContext().TheBuiltinModule;
23612361

23622362
// FIXME: duplicated from ImportResolver::getModule
2363+
Identifier parentName = FileContext->getParentModule()->getName();
23632364
if (name.size() == 1 &&
2364-
name.front().Item == FileContext->getParentModule()->getName()) {
2365+
name.front().Item == getContext().getRealModuleName(parentName)) {
23652366
if (!UnderlyingModule && allowLoading) {
23662367
auto importer = getContext().getClangModuleLoader();
23672368
assert(importer && "no way to import shadowed module");

test/ModuleInterface/ambiguous-aliases-workaround.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
// RUN: -alias-module-names-in-module-interface
1919
// RUN: %target-swift-typecheck-module-from-interface(%t/AmbiguousClientName.swiftinterface) -I%t
2020

21+
// RUN: %target-swift-frontend -emit-module -module-name OverlayClient \
22+
// RUN: -swift-version 5 -enable-library-evolution \
23+
// RUN: -o %t/OverlayClient.swiftmodule \
24+
// RUN: -emit-module-interface-path %t/OverlayClient.swiftinterface \
25+
// RUN: %t/OverlayClient.swift -I%t \
26+
// RUN: -alias-module-names-in-module-interface
27+
// RUN: %target-swift-typecheck-module-from-interface(%t/OverlayClient.swiftinterface) -I%t
28+
2129
//--- module.modulemap
2230
module AmbiguousClientName {
2331
header "AmbiguousClientName.h"
@@ -64,3 +72,10 @@ public func refToNestedInLib(_ a: AmbiguousLib.Nested) {}
6472
public func refToStdlib(_ a: Swift.Int) {}
6573
public func refToUnderlying(_ a: UnderlyingType) {}
6674
public func refToC(_ a: CType) {}
75+
76+
//--- OverlayClient.swift
77+
78+
import AmbiguousClientName
79+
80+
public func refToImportedType(_ a: SomeType) {}
81+
public func refToImportedUnderlying(_ a: UnderlyingType) {}

0 commit comments

Comments
 (0)