Skip to content

Commit f8d6bed

Browse files
committed
Serialization: Consider the C++ interop use in module cache hash
It is expected to rebuild modules from swiftinterface when the C++ interop is enabled in clients. The swiftmodule produced is different. Make sure the rebuilt module is kept under a distinct cache key to avoid reusing previously compiled modules in an incompatible mode.
1 parent d8cfe92 commit f8d6bed

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2880,7 +2880,11 @@ static std::string getContextHash(const CompilerInvocation &CI,
28802880
//
28812881
// If OSSA modules are enabled, we use a separate namespace of modules to
28822882
// ensure that we compile all swift interface files with the option set.
2883-
unsigned(CI.getSILOptions().EnableOSSAModules));
2883+
unsigned(CI.getSILOptions().EnableOSSAModules),
2884+
2885+
// Is the C++ interop enabled?
2886+
unsigned(CI.getLangOptions().EnableCXXInterop)
2887+
);
28842888

28852889
return llvm::toString(llvm::APInt(64, H), 36, /*Signed=*/false);
28862890
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t --leading-lines
3+
4+
/// Build one library module
5+
// RUN: %target-swift-frontend -parse-stdlib -emit-module \
6+
// RUN: -o %t/Lib.swiftmodule %t/Lib.swift \
7+
// RUN: -emit-module-interface-path %t/Lib.swiftinterface \
8+
// RUN: -swift-version 5 -enable-library-evolution -module-name Lib
9+
10+
/// Distributed scenario with only the swiftinterface
11+
// RUN: rm %t/Lib.swiftmodule
12+
// RUN: %empty-directory(%t/ModuleCache)
13+
14+
/// Rebuild from the swiftinterface just once for non-C++ users
15+
// RUN: %target-swift-frontend -parse-stdlib -typecheck %t/Rebuild.swift -I %t \
16+
// RUN: -module-cache-path %t/ModuleCache -Rmodule-interface-rebuild -verify
17+
// RUN: %target-swift-frontend -parse-stdlib -typecheck %t/UseExisting.swift -I %t \
18+
// RUN: -module-cache-path %t/ModuleCache -Rmodule-interface-rebuild -verify
19+
20+
/// Rebuild from the swiftinterface just once for C++ users
21+
// RUN: %target-swift-frontend -parse-stdlib -typecheck %t/Rebuild.swift -I %t \
22+
// RUN: -module-cache-path %t/ModuleCache -Rmodule-interface-rebuild -verify \
23+
// RUN: -cxx-interoperability-mode=default
24+
// RUN: %target-swift-frontend -parse-stdlib -typecheck %t/UseExisting.swift -I %t \
25+
// RUN: -module-cache-path %t/ModuleCache -Rmodule-interface-rebuild -verify \
26+
// RUN: -cxx-interoperability-mode=default
27+
28+
//--- Lib.swift
29+
public func publicFunction() {}
30+
31+
//--- UseExisting.swift
32+
import Lib
33+
34+
//--- Rebuild.swift
35+
import Lib // expected-remark {{rebuilding module 'Lib' from interface}}

0 commit comments

Comments
 (0)