Skip to content

Commit ffefa77

Browse files
authored
Move the mapping from entity name to an imported C++ global variable declaration outside of EntityName (#6211)
This would save space for every `EntityName` that is not an imported C++ global variable. C++ global variables include static data members. Created `CppGlobalVarId`, `CppGlobalVarKey` and `CppGlobalVar` to allow having `CanonicalValueStore` that maps `EntityNameId` (which is in `CppGlobalVarKey` and `CppGlobalVar`) to `ClangDeclId` (which is also in `CppGlobalVar`). This is similar to `ClangDeclId`, `ClangDeclKey` and `ClangDecl` .
1 parent 3fa427b commit ffefa77

File tree

18 files changed

+354
-191
lines changed

18 files changed

+354
-191
lines changed

toolchain/check/context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ class Context {
255255
auto entity_names() -> SemIR::EntityNameStore& {
256256
return sem_ir().entity_names();
257257
}
258+
auto cpp_global_names() -> SemIR::CppGlobalVarStore& {
259+
return sem_ir().cpp_global_vars();
260+
}
258261
auto cpp_overload_sets() -> SemIR::CppOverloadSetStore& {
259262
return sem_ir().cpp_overload_sets();
260263
}

toolchain/check/cpp/import.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,9 @@ static auto ImportVarDecl(Context& context, SemIR::LocId loc_id,
18531853
SemIR::EntityNameId entity_name_id =
18541854
context.entity_names().AddSymbolicBindingName(
18551855
var_name_id, GetParentNameScopeId(context, var_decl),
1856-
SemIR::CompileTimeBindIndex::None, false, clang_decl_id);
1856+
SemIR::CompileTimeBindIndex::None, false);
1857+
context.cpp_global_names().Add({.key = {.entity_name_id = entity_name_id},
1858+
.clang_decl_id = clang_decl_id});
18571859

18581860
// Create `BindingPattern` and `VarPattern` in a `NameBindingDecl`.
18591861
context.pattern_block_stack().Push();

toolchain/check/testdata/basics/raw_sem_ir/builtins.carbon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// CHECK:STDOUT: name_scopes:
2323
// CHECK:STDOUT: name_scope0: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {}}
2424
// CHECK:STDOUT: entity_names: {}
25+
// CHECK:STDOUT: cpp_global_vars: {}
2526
// CHECK:STDOUT: functions: {}
2627
// CHECK:STDOUT: classes: {}
2728
// CHECK:STDOUT: generics: {}

toolchain/check/testdata/basics/raw_sem_ir/cpp_interop.carbon

Lines changed: 170 additions & 113 deletions
Large diffs are not rendered by default.

toolchain/check/testdata/basics/raw_sem_ir/multifile.carbon

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ fn B() {
3838
// CHECK:STDOUT: name_scopes:
3939
// CHECK:STDOUT: name_scope0: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {name0: inst6000000F}}
4040
// CHECK:STDOUT: entity_names: {}
41+
// CHECK:STDOUT: cpp_global_vars: {}
4142
// CHECK:STDOUT: functions:
4243
// CHECK:STDOUT: function60000000: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]}
4344
// CHECK:STDOUT: classes: {}
@@ -99,7 +100,8 @@ fn B() {
99100
// CHECK:STDOUT: name_scope0: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {name1: inst50000010, name0: inst50000011}}
100101
// CHECK:STDOUT: name_scope1: {inst: inst50000010, parent_scope: name_scope0, has_error: false, extended_scopes: [], names: {name1: inst50000016}}
101102
// CHECK:STDOUT: entity_names:
102-
// CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope1, index: -1, is_template: 0, clang_decl_id: clang_decl_id<none>}
103+
// CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope1, index: -1, is_template: 0}
104+
// CHECK:STDOUT: cpp_global_vars: {}
103105
// CHECK:STDOUT: functions:
104106
// CHECK:STDOUT: function50000000: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]}
105107
// CHECK:STDOUT: function50000001: {name: name1, parent_scope: name_scope1}

toolchain/check/testdata/basics/raw_sem_ir/multifile_with_textual_ir.carbon

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ fn B() {
3838
// CHECK:STDOUT: name_scopes:
3939
// CHECK:STDOUT: name_scope0: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {name0: inst6000000F}}
4040
// CHECK:STDOUT: entity_names: {}
41+
// CHECK:STDOUT: cpp_global_vars: {}
4142
// CHECK:STDOUT: functions:
4243
// CHECK:STDOUT: function60000000: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]}
4344
// CHECK:STDOUT: classes: {}
@@ -118,7 +119,8 @@ fn B() {
118119
// CHECK:STDOUT: name_scope0: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {name1: inst50000010, name0: inst50000011}}
119120
// CHECK:STDOUT: name_scope1: {inst: inst50000010, parent_scope: name_scope0, has_error: false, extended_scopes: [], names: {name1: inst50000016}}
120121
// CHECK:STDOUT: entity_names:
121-
// CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope1, index: -1, is_template: 0, clang_decl_id: clang_decl_id<none>}
122+
// CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope1, index: -1, is_template: 0}
123+
// CHECK:STDOUT: cpp_global_vars: {}
122124
// CHECK:STDOUT: functions:
123125
// CHECK:STDOUT: function50000000: {name: name0, parent_scope: name_scope0, call_params_id: inst_block_empty, body: [inst_block5]}
124126
// CHECK:STDOUT: function50000001: {name: name1, parent_scope: name_scope1}

toolchain/check/testdata/basics/raw_sem_ir/one_file.carbon

Lines changed: 63 additions & 62 deletions
Large diffs are not rendered by default.

toolchain/check/testdata/basics/raw_sem_ir/one_file_with_textual_ir.carbon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ fn Foo(n: ()) -> ((), ()) {
2828
// CHECK:STDOUT: name_scopes:
2929
// CHECK:STDOUT: name_scope0: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {name0: inst60000025}}
3030
// CHECK:STDOUT: entity_names:
31-
// CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope<none>, index: -1, is_template: 0, clang_decl_id: clang_decl_id<none>}
31+
// CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope<none>, index: -1, is_template: 0}
32+
// CHECK:STDOUT: cpp_global_vars: {}
3233
// CHECK:STDOUT: functions:
3334
// CHECK:STDOUT: function60000000: {name: name0, parent_scope: name_scope0, call_params_id: inst_block9, return_slot_pattern: inst60000020, body: [inst_block12]}
3435
// CHECK:STDOUT: classes: {}

toolchain/driver/testdata/stdin.carbon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
// CHECK:STDOUT: name_scopes:
3535
// CHECK:STDOUT: name_scope0: {inst: inst0000000E, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {}}
3636
// CHECK:STDOUT: entity_names: {}
37+
// CHECK:STDOUT: cpp_global_vars: {}
3738
// CHECK:STDOUT: functions: {}
3839
// CHECK:STDOUT: classes: {}
3940
// CHECK:STDOUT: generics: {}

toolchain/lower/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ cc_library(
6161
"//toolchain/base:kind_switch",
6262
"//toolchain/parse:tree",
6363
"//toolchain/sem_ir:absolute_node_id",
64+
"//toolchain/sem_ir:clang_decl",
6465
"//toolchain/sem_ir:diagnostic_loc_converter",
6566
"//toolchain/sem_ir:entry_point",
6667
"//toolchain/sem_ir:expr_info",

0 commit comments

Comments
 (0)