[ModuleInterface] Ignore export_as in private swiftinterface

Introduce a new behavior when printing references to modules with an
`export_as` definition. Use the `export_as` name in the public swiftinterface
and the real module name in the private swiftinterface.

This has some limits but should still be an improvement over the current
behavior. First, the we use the `export_as` names only for references to clang
decls, not Swift decls with an underlying module defining an `export_as`.
Second, we always print the `export_as` name in the public swiftinterface,
even in the original swiftinterface file when the `export_as` target is likely
not know, so that generated swiftinterface is still broken.

This behavior is enabled by the flags `-enable-experimental-feature ModuleInterfaceExportAs`
or the `SWIFT_DEBUG_USE_EXPORTED_MODULE_NAME_IN_PUBLIC_ONLY` env var. We may
consider turning it on by default in the future.

rdar://98532918
This commit is contained in:
Alexis Laferrière
2022-12-08 14:55:12 -08:00
parent 010973c276
commit ab38752d33
5 changed files with 132 additions and 1 deletions

View File

@@ -788,9 +788,18 @@ bool swift::emitSwiftInterface(raw_ostream &out,
printImports(out, Opts, M);
static bool forceUseExportedModuleNameInPublicOnly =
getenv("SWIFT_DEBUG_USE_EXPORTED_MODULE_NAME_IN_PUBLIC_ONLY");
bool useExportedModuleNameInPublicOnly =
M->getASTContext().LangOpts.hasFeature(Feature::ModuleInterfaceExportAs) ||
forceUseExportedModuleNameInPublicOnly;
bool useExportedModuleNames = !(useExportedModuleNameInPublicOnly &&
Opts.PrintPrivateInterfaceContent);
const PrintOptions printOptions = PrintOptions::printSwiftInterfaceFile(
M, Opts.PreserveTypesAsWritten, Opts.PrintFullConvention,
Opts.PrintPrivateInterfaceContent,
useExportedModuleNames,
Opts.AliasModuleNames, &aliasModuleNamesTargets);
InheritedProtocolCollector::PerTypeMap inheritedProtocolMap;