[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

@@ -0,0 +1,115 @@
/// Test the logic printing the export_as name in public swiftinterfaces
/// and the real source module name in the private swiftinterfaces.
// RUN: %empty-directory(%t)
// RUN: split-file %s %t
/// Build lib with an export_as.
// RUN: %target-swift-frontend -emit-module %t/Exported.swift \
// RUN: -module-name Exported -swift-version 5 -I %t \
// RUN: -enable-library-evolution \
// RUN: -emit-module-path %t/Exported.swiftmodule \
// RUN: -emit-module-interface-path %t/Exported.swiftinterface \
// RUN: -emit-private-module-interface-path %t/Exported.private.swiftinterface \
// RUN: -enable-experimental-feature ModuleInterfaceExportAs
// RUN: %target-swift-typecheck-module-from-interface(%t/Exported.private.swiftinterface) -module-name Exported -I %t
// RUN: cat %t/Exported.swiftinterface | %FileCheck -check-prefix=CHECK-USE-EXPORTER %s
// RUN: cat %t/Exported.private.swiftinterface | %FileCheck -check-prefix=CHECK-USE-EXPORTED %s
/// The public swiftinterface only builds under the name of Exporter.
// RUN: sed -e "s/module-name Exported/module-name Exporter/" -ibk %t/Exported.swiftinterface
// RUN: %target-swift-typecheck-module-from-interface(%t/Exported.swiftinterface) -I %t -module-name Exporter
/// Build lib with an @exported import of the exported one.
/// Default/old behavior.
// RUN: %target-swift-frontend -emit-module %t/Exporter.swift \
// RUN: -module-name Exporter -swift-version 5 -I %t \
// RUN: -enable-library-evolution \
// RUN: -emit-module-path %t/Exporter.swiftmodule \
// RUN: -emit-module-interface-path %t/Exporter.swiftinterface \
// RUN: -emit-private-module-interface-path %t/Exporter.private.swiftinterface
// RUN: %target-swift-typecheck-module-from-interface(%t/Exporter.swiftinterface) -I %t
// RUN: %target-swift-typecheck-module-from-interface(%t/Exporter.private.swiftinterface) -module-name Exporter -I %t
// RUN: cat %t/Exporter.swiftinterface | %FileCheck -check-prefix=CHECK-USE-EXPORTER %s
// RUN: cat %t/Exporter.private.swiftinterface | %FileCheck -check-prefix=CHECK-USE-EXPORTER %s
/// Build lib with an @exported import of the exported one.
/// New behavior via flag.
// RUN: %target-swift-frontend -emit-module %t/Exporter.swift \
// RUN: -module-name Exporter -swift-version 5 -I %t \
// RUN: -enable-library-evolution \
// RUN: -emit-module-path %t/Exporter.swiftmodule \
// RUN: -emit-module-interface-path %t/Exporter.swiftinterface \
// RUN: -emit-private-module-interface-path %t/Exporter.private.swiftinterface \
// RUN: -enable-experimental-feature ModuleInterfaceExportAs
// RUN: %target-swift-typecheck-module-from-interface(%t/Exporter.swiftinterface) -I %t
// RUN: %target-swift-typecheck-module-from-interface(%t/Exporter.private.swiftinterface) -module-name Exporter -I %t
// RUN: cat %t/Exporter.swiftinterface | %FileCheck -check-prefix=CHECK-USE-EXPORTER %s
// RUN: cat %t/Exporter.private.swiftinterface | %FileCheck -check-prefix=CHECK-USE-EXPORTED %s
/// Build lib with an @exported import of the exported one.
/// New behavior via env var.
// RUN: env SWIFT_DEBUG_USE_EXPORTED_MODULE_NAME_IN_PUBLIC_ONLY=1 \
// RUN: %target-swift-frontend -emit-module %t/Exporter.swift \
// RUN: -module-name Exporter -swift-version 5 -I %t \
// RUN: -enable-library-evolution \
// RUN: -emit-module-path %t/Exporter.swiftmodule \
// RUN: -emit-module-interface-path %t/Exporter.swiftinterface \
// RUN: -emit-private-module-interface-path %t/Exporter.private.swiftinterface
// RUN: %target-swift-typecheck-module-from-interface(%t/Exporter.swiftinterface) -I %t
// RUN: %target-swift-typecheck-module-from-interface(%t/Exporter.private.swiftinterface) -module-name Exporter -I %t
// RUN: cat %t/Exporter.swiftinterface | %FileCheck -check-prefix=CHECK-USE-EXPORTER %s
// RUN: cat %t/Exporter.private.swiftinterface | %FileCheck -check-prefix=CHECK-USE-EXPORTED %s
/// Build a client of the exporter lib.
// RUN: %target-swift-frontend -emit-module %t/Client.swift \
// RUN: -module-name Client -swift-version 5 -I %t \
// RUN: -enable-library-evolution \
// RUN: -emit-module-path %t/Client.swiftmodule \
// RUN: -emit-module-interface-path %t/Client.swiftinterface \
// RUN: -emit-private-module-interface-path %t/Client.private.swiftinterface \
// RUN: -enable-experimental-feature ModuleInterfaceExportAs
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.swiftinterface) -I %t
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.private.swiftinterface) -module-name Client -I %t
// RUN: cat %t/Client.swiftinterface | %FileCheck -check-prefix=CHECK-USE-EXPORTER %s
// RUN: cat %t/Client.private.swiftinterface | %FileCheck -check-prefix=CHECK-USE-EXPORTED %s
/// Build a client of the exporter lib.
// RUN: rm %t/Exporter.private.swiftinterface %t/Exporter.swiftmodule
// RUN: %target-swift-frontend -emit-module %t/Client.swift \
// RUN: -module-name Client -swift-version 5 -I %t \
// RUN: -enable-library-evolution \
// RUN: -emit-module-path %t/Client.swiftmodule \
// RUN: -emit-module-interface-path %t/Client.swiftinterface \
// RUN: -emit-private-module-interface-path %t/Client.private.swiftinterface \
// RUN: -enable-experimental-feature ModuleInterfaceExportAs
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.swiftinterface) -I %t
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.private.swiftinterface) -module-name Client -I %t
// RUN: cat %t/Client.swiftinterface | %FileCheck -check-prefix=CHECK-USE-EXPORTER %s
// RUN: cat %t/Client.private.swiftinterface | %FileCheck -check-prefix=CHECK-USE-EXPORTED %s
//--- module.modulemap
module Exported {
export_as Exporter
header "Exported.h"
}
//--- Exported.h
struct exportedClangType {};
//--- Exported.swift
@_exported import Exported
public func foo(a: exportedClangType) {}
// CHECK-USE-EXPORTED: Exported.exportedClangType
// CHECK-USE-EXPORTER: Exporter.exportedClangType
//--- Exporter.swift
@_exported import Exported
public func foo(a: exportedClangType) {}
//--- Client.swift
import Exporter
public func foo(a: exportedClangType) {}