Skip to content

Commit 36b4a5b

Browse files
ChuanqiXu9AlexisPerry
authored andcommitted
[Serialization] Register Speical types before register decls
We will only regsiter top level types and decls in ASTWriter and we will register the sub types and decls during the process of writing types and decls. So that the ID for the types in the sub level can be different if the writing decl process changes the order of the to-be- emitted type queues. This is not ideal since it causes unnecessary changes especially in no transitive changes model. This patch migrates the issue by regsitering special types before regsitering decls. This make sure that the special types in the 2nd top level can be registered early than the decls. But it might still be problematic if there are more levels in the special types. Luckily we just don't have such special types.
1 parent 8961301 commit 36b4a5b

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5387,6 +5387,17 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
53875387
}
53885388
}
53895389

5390+
// Form the record of special types.
5391+
RecordData SpecialTypes;
5392+
AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes);
5393+
AddTypeRef(Context.getFILEType(), SpecialTypes);
5394+
AddTypeRef(Context.getjmp_bufType(), SpecialTypes);
5395+
AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes);
5396+
AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes);
5397+
AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes);
5398+
AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes);
5399+
AddTypeRef(Context.getucontext_tType(), SpecialTypes);
5400+
53905401
PrepareWritingSpecialDecls(SemaRef);
53915402

53925403
// Write the control block
@@ -5418,17 +5429,6 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
54185429
for (auto &Selector : AllSelectors)
54195430
SemaRef.ObjC().updateOutOfDateSelector(Selector);
54205431

5421-
// Form the record of special types.
5422-
RecordData SpecialTypes;
5423-
AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes);
5424-
AddTypeRef(Context.getFILEType(), SpecialTypes);
5425-
AddTypeRef(Context.getjmp_bufType(), SpecialTypes);
5426-
AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes);
5427-
AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes);
5428-
AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes);
5429-
AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes);
5430-
AddTypeRef(Context.getucontext_tType(), SpecialTypes);
5431-
54325432
if (Chain) {
54335433
// Write the mapping information describing our module dependencies and how
54345434
// each of those modules were mapped into our own offset/ID space, so that

clang/test/Modules/no-implicit-declarations.cppm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ export int a = 43;
1616

1717
// CHECK: <DECLTYPES_BLOCK
1818
// CHECK-NOT: <DECL_TYPEDEF
19+
// CHECK: <TYPE_TYPEDEF
1920
// CHECK: <DECL_CONTEXT_LEXICAL
2021
// CHECK: <DECL_EXPORT
21-
// CHECK: <TYPE_TYPEDEF
22+
// CHECK: <TYPE_RECORD
2223
// CHECK: <DECL_VAR
2324
// CHECK: <EXPR_INTEGER_LITERAL
2425
// CHECK: <STMT_STOP
25-
// CHECK: <TYPE_RECORD
2626
// CHECK: </DECLTYPES_BLOCK>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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/A.cppm -o %t/A.pcm
7+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/B.cppm -o %t/B.pcm \
8+
// RUN: -fmodule-file=A=%t/A.pcm
9+
//
10+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/A.v1.cppm -o %t/A.v1.pcm
11+
// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/B.cppm -o %t/B.v1.pcm \
12+
// RUN: -fmodule-file=A=%t/A.v1.pcm
13+
//
14+
// RUN: diff %t/B.pcm %t/B.v1.pcm &> /dev/null
15+
16+
//--- A.cppm
17+
export module A;
18+
export int a() { return 44; }
19+
20+
//--- A.v1.cppm
21+
export module A;
22+
int a_impl() { return 48; }
23+
export int a() { return a_impl(); }
24+
25+
//--- B.cppm
26+
export module B;
27+
import A;
28+
export int b() { return a(); }

0 commit comments

Comments
 (0)