Skip to content

[ModuleInterface] Support loading an aliased module with an underlying module #62044

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 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static void ParseModuleInterfaceArgs(ModuleInterfaceOptions &Opts,
Opts.AliasModuleNames |=
Args.hasFlag(OPT_alias_module_names_in_module_interface,
OPT_disable_alias_module_names_in_module_interface,
false);
::getenv("SWIFT_ALIAS_MODULE_NAMES_IN_INTERFACES"));
Opts.PrintFullConvention |=
Args.hasArg(OPT_experimental_print_full_convention);
Opts.ExperimentalSPIImports |=
Expand Down
3 changes: 2 additions & 1 deletion lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,8 @@ class ModuleInterfaceLoaderImpl {
StringRef inParentDirName =
path::filename(path::parent_path(interfacePath));
if (path::extension(inParentDirName) == ".swiftmodule") {
assert(path::stem(inParentDirName) == moduleName);
assert(path::stem(inParentDirName) ==
ctx.getRealModuleName(ctx.getIdentifier(moduleName)).str());
path::append(scratch, inParentDirName);
}
path::append(scratch, path::filename(modulePath));
Expand Down
3 changes: 2 additions & 1 deletion lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2359,8 +2359,9 @@ ModuleDecl *ModuleFile::getModule(ImportPath::Module name,
return getContext().TheBuiltinModule;

// FIXME: duplicated from ImportResolver::getModule
Identifier parentName = FileContext->getParentModule()->getName();
if (name.size() == 1 &&
name.front().Item == FileContext->getParentModule()->getName()) {
name.front().Item == getContext().getRealModuleName(parentName)) {
if (!UnderlyingModule && allowLoading) {
auto importer = getContext().getClangModuleLoader();
assert(importer && "no way to import shadowed module");
Expand Down
15 changes: 15 additions & 0 deletions test/ModuleInterface/ambiguous-aliases-workaround.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
// RUN: -alias-module-names-in-module-interface
// RUN: %target-swift-typecheck-module-from-interface(%t/AmbiguousClientName.swiftinterface) -I%t

// RUN: %target-swift-frontend -emit-module -module-name OverlayClient \
// RUN: -swift-version 5 -enable-library-evolution \
// RUN: -o %t/OverlayClient.swiftmodule \
// RUN: -emit-module-interface-path %t/OverlayClient.swiftinterface \
// RUN: %t/OverlayClient.swift -I%t \
// RUN: -alias-module-names-in-module-interface
// RUN: %target-swift-typecheck-module-from-interface(%t/OverlayClient.swiftinterface) -I%t

//--- module.modulemap
module AmbiguousClientName {
header "AmbiguousClientName.h"
Expand Down Expand Up @@ -64,3 +72,10 @@ public func refToNestedInLib(_ a: AmbiguousLib.Nested) {}
public func refToStdlib(_ a: Swift.Int) {}
public func refToUnderlying(_ a: UnderlyingType) {}
public func refToC(_ a: CType) {}

//--- OverlayClient.swift

import AmbiguousClientName

public func refToImportedType(_ a: SomeType) {}
public func refToImportedUnderlying(_ a: UnderlyingType) {}