Skip to content

Commit 250d057

Browse files
[Module] Use stricter module hash
Use a stricter module hash for modules as moving towards more explicit modules. Previously, a normalized target triple without deployment target is used as part of the module hash, with the assumption that deployment target should not change binary module generated. In reality, the binary module compilation also needs to provide the typecheck for all interface to ensure the underlying C/ObjC module that built with the correct deployment target does provide the interfaces to pass typecheck. Using a stricter module hash can avoid the potentially confusing error when importing the module. This commit adds following to module hash to distinguish swiftmodules. * Deployment target * -application-extension rdar://134301179
1 parent db0b5db commit 250d057

File tree

5 files changed

+56
-69
lines changed

5 files changed

+56
-69
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,8 +2071,6 @@ StringRef InterfaceSubContextDelegateImpl::computeCachedOutputPath(
20712071
std::string
20722072
InterfaceSubContextDelegateImpl::getCacheHash(StringRef useInterfacePath,
20732073
StringRef sdkPath) {
2074-
auto normalizedTargetTriple =
2075-
getTargetSpecificModuleTriple(genericSubInvocation.getLangOptions().Target);
20762074
std::string sdkBuildVersion = getSDKBuildVersion(sdkPath);
20772075
const auto ExtraArgs = genericSubInvocation.getClangImporterOptions()
20782076
.getReducedExtraArgsForSwiftModuleDependency();
@@ -2089,13 +2087,12 @@ InterfaceSubContextDelegateImpl::getCacheHash(StringRef useInterfacePath,
20892087
// anyways.
20902088
useInterfacePath,
20912089

2092-
// Include the normalized target triple. In practice, .swiftinterface
2090+
// Include the target triple. In practice, .swiftinterface
20932091
// files will be in target-specific subdirectories and would have
20942092
// target-specific pieces #if'd out. However, it doesn't hurt to include
20952093
// it, and it guards against mistakenly reusing cached modules across
2096-
// targets. Note that this normalization explicitly doesn't include the
2097-
// minimum deployment target (e.g. the '12.0' in 'ios12.0').
2098-
normalizedTargetTriple.str(),
2094+
// targets.
2095+
genericSubInvocation.getLangOptions().Target.str(),
20992096

21002097
// The SDK path is going to affect how this module is imported, so
21012098
// include it.
@@ -2121,12 +2118,15 @@ InterfaceSubContextDelegateImpl::getCacheHash(StringRef useInterfacePath,
21212118
// module.
21222119
llvm::hash_combine_range(ExtraArgs.begin(), ExtraArgs.end()),
21232120

2121+
/// Application extension.
2122+
unsigned(
2123+
genericSubInvocation.getLangOptions().EnableAppExtensionRestrictions),
2124+
21242125
// Whether or not OSSA modules are enabled.
21252126
//
21262127
// If OSSA modules are enabled, we use a separate namespace of modules to
21272128
// ensure that we compile all swift interface files with the option set.
2128-
unsigned(genericSubInvocation.getSILOptions().EnableOSSAModules)
2129-
);
2129+
unsigned(genericSubInvocation.getSILOptions().EnableOSSAModules));
21302130

21312131
return llvm::toString(llvm::APInt(64, H), 36, /*Signed=*/false);
21322132
}

test/ModuleInterface/ModuleCache/module-cache-deployment-target-irrelevant.swift

Lines changed: 0 additions & 32 deletions
This file was deleted.

test/ModuleInterface/multiple-targets-same-interface.swift

Lines changed: 0 additions & 28 deletions
This file was deleted.

test/ScanDependencies/module_hash.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -O \
1515
// RUN: -o %t/deps-3.json -Xcc -fapplication-extension -I %t/include
1616

17-
/// Check module hash for the swiftmodule. 1 and 2 should match, but not 3.
17+
/// Check module hash for the swiftmodule. They should all not match.
1818
// RUN: %{python} %S/../CAS/Inputs/SwiftDepsExtractor.py %t/deps-1.json Library modulePath > %t/path-1
1919
// RUN: %{python} %S/../CAS/Inputs/SwiftDepsExtractor.py %t/deps-2.json Library modulePath > %t/path-2
2020
// RUN: %{python} %S/../CAS/Inputs/SwiftDepsExtractor.py %t/deps-3.json Library modulePath > %t/path-3
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// REQUIRES: OS=macosx, objc_interop
2+
// RUN: %empty-directory(%t)
3+
// RUN: split-file %s %t
4+
5+
/// Different version should not match.
6+
// RUN: %target-swift-frontend -target %module-target-triple -scan-dependencies -module-name Test %t/main.swift -module-cache-path %t/clang-module-cache \
7+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -O \
8+
// RUN: -o %t/deps-now.json -I %t/include
9+
// RUN: %target-swift-frontend -target %module-target-future -scan-dependencies -module-name Test %t/main.swift -module-cache-path %t/clang-module-cache \
10+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -O \
11+
// RUN: -o %t/deps-future.json -I %t/include
12+
// RUN: %{python} %S/../CAS/Inputs/SwiftDepsExtractor.py %t/deps-now.json Library modulePath > %t/path-now
13+
// RUN: %{python} %S/../CAS/Inputs/SwiftDepsExtractor.py %t/deps-future.json Library modulePath > %t/path-future
14+
// RUN: not diff %t/path-now %t/path-future
15+
16+
/// Application extension should not match.
17+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test %t/main.swift -module-cache-path %t/clang-module-cache \
18+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -O \
19+
// RUN: -o %t/deps.json -I %t/include
20+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test %t/main.swift -module-cache-path %t/clang-module-cache \
21+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -O \
22+
// RUN: -o %t/deps-ae.json -I %t/include -application-extension
23+
// RUN: %{python} %S/../CAS/Inputs/SwiftDepsExtractor.py %t/deps.json Library modulePath > %t/path
24+
// RUN: %{python} %S/../CAS/Inputs/SwiftDepsExtractor.py %t/deps-ae.json Library modulePath > %t/path-ae
25+
// RUN: not diff %t/path %t/path-ae
26+
27+
//--- main.swift
28+
import Library
29+
30+
//--- include/Library.swiftinterface
31+
// swift-interface-format-version: 1.0
32+
// swift-module-flags: -module-name Library -O -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -user-module-version 1.0
33+
import Swift
34+
@_exported import A
35+
@inlinable
36+
public func test() {
37+
foo()
38+
}
39+
40+
//--- include/a.h
41+
void foo(void);
42+
43+
//--- include/module.modulemap
44+
module A {
45+
header "a.h"
46+
export *
47+
}

0 commit comments

Comments
 (0)