Skip to content

Commit a6e5242

Browse files
committed
[Modules] Add merged Files to UsedModuleFiles
This is needed by no casacading chanegs feature. A BMI of a module interface needs to merge the hash value of all the module files that the users can touched actually.
1 parent ce8f160 commit a6e5242

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ class ASTWriter : public ASTDeserializationListener,
376376
/// Only meaningful for standard C++ named modules. See the comments in
377377
/// createSignatureForNamedModule() for details.
378378
llvm::SetVector<Module *> TouchedTopLevelModules;
379+
llvm::SetVector<serialization::ModuleFile *> TouchedModuleFiles;
379380

380381
/// An update to a Decl.
381382
class DeclUpdate {
@@ -913,6 +914,8 @@ class ASTWriter : public ASTDeserializationListener,
913914

914915
void handleVTable(CXXRecordDecl *RD);
915916

917+
void addTouchedModuleFile(serialization::ModuleFile *);
918+
916919
private:
917920
// ASTDeserializationListener implementation
918921
void ReaderInitialized(ASTReader *Reader) override;

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4062,6 +4062,10 @@ void ASTWriter::handleVTable(CXXRecordDecl *RD) {
40624062
PendingEmittingVTables.push_back(RD);
40634063
}
40644064

4065+
void ASTWriter::addTouchedModuleFile(serialization::ModuleFile *MF) {
4066+
TouchedModuleFiles.insert(MF);
4067+
}
4068+
40654069
//===----------------------------------------------------------------------===//
40664070
// DeclContext's Name Lookup Table Serialization
40674071
//===----------------------------------------------------------------------===//
@@ -4106,7 +4110,7 @@ class ASTDeclContextNameLookupTraitBase {
41064110
"have reference to loaded module file but no chain?");
41074111

41084112
using namespace llvm::support;
4109-
4113+
Writer.addTouchedModuleFile(F);
41104114
endian::write<uint32_t>(Out, Writer.getChain()->getModuleFileID(F),
41114115
llvm::endianness::little);
41124116
}
@@ -4473,6 +4477,7 @@ class LazySpecializationInfoLookupTrait {
44734477
"have reference to loaded module file but no chain?");
44744478

44754479
using namespace llvm::support;
4480+
Writer.addTouchedModuleFile(F);
44764481
endian::write<uint32_t>(Out, Writer.getChain()->getModuleFileID(F),
44774482
llvm::endianness::little);
44784483
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Test that adding a new unused decl within reduced BMI may not produce a transitive change.
2+
//
3+
// RUN: rm -rf %t
4+
// RUN: split-file %s %t
5+
//
6+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/T.cppm -o %t/T.pcm \
7+
// RUN: -fmodule-file=T=%t/T.pcm
8+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/T1.cppm -o %t/T1.pcm \
9+
// RUN: -fmodule-file=T=%t/T.pcm
10+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/T2.cppm -o %t/T2.pcm \
11+
// RUN: -fmodule-file=T=%t/T.pcm
12+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/T3.cppm -o %t/T3.pcm \
13+
// RUN: -fmodule-file=T=%t/T.pcm
14+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/T4.cppm -o %t/T4.pcm \
15+
// RUN: -fmodule-file=T=%t/T.pcm
16+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/A.cppm -o %t/A.pcm \
17+
// RUN: -fmodule-file=T=%t/T.pcm
18+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/AWrapper.cppm -o %t/AWrapper.pcm \
19+
// RUN: -fprebuilt-module-path=%t
20+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/B.cppm -o %t/B.pcm \
21+
// RUN: -fprebuilt-module-path=%t
22+
//
23+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/A.v1.cppm -o %t/A.v1.pcm \
24+
// RUN: -fmodule-file=T=%t/T.pcm
25+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/AWrapper.cppm -o %t/AWrapper.v1.pcm \
26+
// RUN: -fprebuilt-module-path=%t -fmodule-file=A=%t/A.v1.pcm
27+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/B.cppm -o %t/B.v1.pcm \
28+
// RUN: -fprebuilt-module-path=%t -fmodule-file=AWrapper=%t/AWrapper.v1.pcm -fmodule-file=A=%t/A.v1.pcm
29+
//
30+
// RUN: not diff %t/B.pcm %t/B.v1.pcm &> /dev/null
31+
32+
//--- T.cppm
33+
export module T;
34+
export template <class T>
35+
struct Templ {};
36+
37+
//--- T1.cppm
38+
export module T1;
39+
import T;
40+
export using Tunsigned = Templ<unsigned>;
41+
42+
//--- T2.cppm
43+
export module T2;
44+
import T;
45+
export using Tfloat = Templ<float>;
46+
47+
//--- T3.cppm
48+
export module T3;
49+
import T;
50+
export using Tlong = Templ<long long>;
51+
52+
//--- T4.cppm
53+
export module T4;
54+
import T;
55+
export using Tshort = Templ<short>;
56+
57+
//--- A.cppm
58+
export module A;
59+
import T;
60+
export using Tint = Templ<int>;
61+
62+
//--- A.v1.cppm
63+
export module A;
64+
import T;
65+
export using Tint = Templ<int>;
66+
void __unused__() {}
67+
68+
//--- AWrapper.cppm
69+
export module AWrapper;
70+
import A;
71+
72+
//--- B.cppm
73+
export module B;
74+
import AWrapper;
75+
import T;
76+
import T1;
77+
import T2;
78+
import T3;
79+
import T4;
80+
81+
export using Tdouble = Templ<double>;

0 commit comments

Comments
 (0)