Skip to content

Commit 82cb31d

Browse files
committed
[Frontend] Don't load modules from the prebuilt cache for private interfaces
rdar://73007024
1 parent 0f7f060 commit 82cb31d

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,11 @@ class ModuleInterfaceLoaderImpl {
521521
namespace path = llvm::sys::path;
522522
StringRef sdkPath = ctx.SearchPathOpts.SDKPath;
523523

524-
// Check if the interface file comes from the SDK
525-
if (sdkPath.empty() || !hasPrefix(path::begin(interfacePath),
526-
path::end(interfacePath),
527-
path::begin(sdkPath),
528-
path::end(sdkPath)))
524+
// Check if this is a public interface file from the SDK.
525+
if (sdkPath.empty() ||
526+
!hasPrefix(path::begin(interfacePath), path::end(interfacePath),
527+
path::begin(sdkPath), path::end(sdkPath)) ||
528+
StringRef(interfacePath).endswith(".private.swiftinterface"))
529529
return None;
530530

531531
// Assemble the expected path: $PREBUILT_CACHE/Foo.swiftmodule or
@@ -558,11 +558,11 @@ class ModuleInterfaceLoaderImpl {
558558
namespace path = llvm::sys::path;
559559
StringRef sdkPath = ctx.SearchPathOpts.SDKPath;
560560

561-
// Check if the interface file comes from the SDK
562-
if (sdkPath.empty() || !hasPrefix(path::begin(interfacePath),
563-
path::end(interfacePath),
564-
path::begin(sdkPath),
565-
path::end(sdkPath)))
561+
// Check if this is a public interface file from the SDK.
562+
if (sdkPath.empty() ||
563+
!hasPrefix(path::begin(interfacePath), path::end(interfacePath),
564+
path::begin(sdkPath), path::end(sdkPath)) ||
565+
StringRef(interfacePath).endswith(".private.swiftinterface"))
566566
return None;
567567

568568
// If the module isn't target-specific, there's no fallback path.

test/ModuleInterface/loading-order.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/// Test the loading order of module interfaces between the SDK and the
22
/// prebuilt cache. The order should be:
33
///
4-
/// 1. Local cache (not tested here)
5-
/// 2. Next to the swiftinterface file
6-
/// 3. Prebuilt-module cache
4+
/// 1. swiftmodule in the local cache (not tested here)
5+
/// 2. swiftmodule next to the swiftinterface file
6+
/// 3. If it's a private swiftinterface, rebuild the swiftmodule from the private swiftinterface
7+
/// 4. swiftmodule in the prebuilt-module cache
8+
/// 5. Rebuild the swiftmodule from the swiftinterface file and keep in the local cache
79

810
/// Create folders for a) our Swift module, b) the module cache, and c) a
911
/// fake resource dir with a default prebuilt module cache inside.
@@ -16,16 +18,20 @@
1618
// RUN: echo 'public func prebuiltModule() {}' > %t/PrebuiltModule.swift
1719

1820
/// Compile this into a module in the SDK.
19-
// RUN: %target-swift-frontend -emit-module %t/NextToSwiftinterface.swift -o %t/MyModule.swiftmodule/%target-swiftmodule-name -module-name MyModule -parse-stdlib -emit-module-interface-path %t/MyModule.swiftmodule/%target-swiftinterface-name
21+
// RUN: %target-swift-frontend -emit-module %t/NextToSwiftinterface.swift -o %t/MyModule.swiftmodule/%target-swiftmodule-name -module-name MyModule -parse-stdlib -emit-module-interface-path %t/MyModule.swiftmodule/%target-swiftinterface-name -emit-private-module-interface-path %t/MyModule.swiftmodule/%target-private-swiftinterface-name
2022

21-
/// Also put a module with a different API into the default prebuilt cache under the same name.
23+
/// Also put a module with a different API into the default prebuilt cache under the same name to detect when its picked.
2224
// RUN: %target-swift-frontend -emit-module %t/PrebuiltModule.swift -o %t/ResourceDir/%target-sdk-name/prebuilt-modules/MyModule.swiftmodule/%target-swiftmodule-name -module-name MyModule -parse-stdlib
2325

2426
/// Import this module and expect to use the swiftmodule next to the swiftinterface.
2527
// RUN: %target-swift-frontend -typecheck -resource-dir %t/ResourceDir -I %t %s -parse-stdlib -module-cache-path %t/ModuleCache -sdk %t -D FIRST_NEXT_TO_SWIFTINTERFACE
2628

27-
/// Remove the first swiftmodule and import again to use the prebuilt swiftmodule.
29+
/// Remove the swiftmodule next to the swiftinterface, the compiler should rebuild from the private swiftinterface.
2830
// RUN: rm %t/MyModule.swiftmodule/%target-swiftmodule-name
31+
// RUN: %target-swift-frontend -typecheck -resource-dir %t/ResourceDir -I %t %s -parse-stdlib -module-cache-path %t/ModuleCache -sdk %t -D FIRST_NEXT_TO_SWIFTINTERFACE
32+
33+
/// Remove the private swiftinterface and import again to use the prebuilt swiftmodule.
34+
// RUN: rm %t/MyModule.swiftmodule/%target-private-swiftinterface-name
2935
// RUN: %target-swift-frontend -typecheck -resource-dir %t/ResourceDir -I %t %s -parse-stdlib -module-cache-path %t/ModuleCache -sdk %t -D THEN_PREBUILT_MODULE
3036

3137
import MyModule

test/lit.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,7 @@ config.substitutions.append(('%target-swiftmodule-name', target_specific_module_
20232023
config.substitutions.append(('%target-swiftdoc-name', target_specific_module_triple + '.swiftdoc'))
20242024
config.substitutions.append(('%target-swiftsourceinfo-name', target_specific_module_triple + '.swiftsourceinfo'))
20252025
config.substitutions.append(('%target-swiftinterface-name', target_specific_module_triple + '.swiftinterface'))
2026+
config.substitutions.append(('%target-private-swiftinterface-name', target_specific_module_triple + '.private.swiftinterface'))
20262027

20272028
config.substitutions.append(('%target-object-format', config.target_object_format))
20282029
config.substitutions.append(('%{target-shared-library-prefix}', config.target_shared_library_prefix))

0 commit comments

Comments
 (0)