Skip to content

Commit 9e5744b

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 ebe1769 commit 9e5744b

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,8 +2068,6 @@ StringRef InterfaceSubContextDelegateImpl::computeCachedOutputPath(
20682068
std::string
20692069
InterfaceSubContextDelegateImpl::getCacheHash(StringRef useInterfacePath,
20702070
StringRef sdkPath) {
2071-
auto normalizedTargetTriple =
2072-
getTargetSpecificModuleTriple(genericSubInvocation.getLangOptions().Target);
20732071
std::string sdkBuildVersion = getSDKBuildVersion(sdkPath);
20742072
const auto ExtraArgs = genericSubInvocation.getClangImporterOptions()
20752073
.getReducedExtraArgsForSwiftModuleDependency();
@@ -2086,13 +2084,12 @@ InterfaceSubContextDelegateImpl::getCacheHash(StringRef useInterfacePath,
20862084
// anyways.
20872085
useInterfacePath,
20882086

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

20972094
// The SDK path is going to affect how this module is imported, so
20982095
// include it.
@@ -2118,12 +2115,15 @@ InterfaceSubContextDelegateImpl::getCacheHash(StringRef useInterfacePath,
21182115
// module.
21192116
llvm::hash_combine_range(ExtraArgs.begin(), ExtraArgs.end()),
21202117

2118+
/// Application extension.
2119+
unsigned(
2120+
genericSubInvocation.getLangOptions().EnableAppExtensionRestrictions),
2121+
21212122
// Whether or not OSSA modules are enabled.
21222123
//
21232124
// If OSSA modules are enabled, we use a separate namespace of modules to
21242125
// ensure that we compile all swift interface files with the option set.
2125-
unsigned(genericSubInvocation.getSILOptions().EnableOSSAModules)
2126-
);
2126+
unsigned(genericSubInvocation.getSILOptions().EnableOSSAModules));
21272127

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

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)