Skip to content

Commit 55085de

Browse files
authored
Use GetStructType when building object repr structs (#5923)
I was thinking about this for destruction, which I may not be able to use it for, but still think this may be a good change to keep features consistent.
1 parent 37d5046 commit 55085de

File tree

199 files changed

+794
-1428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+794
-1428
lines changed

toolchain/check/class.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,13 @@ static auto CheckCompleteClassType(
314314
.specific_id = self_specific_id});
315315
}
316316

317-
auto struct_type_inst_id = AddTypeInst<SemIR::StructType>(
318-
context, node_id,
319-
{.type_id = SemIR::TypeType::TypeId,
320-
.fields_id =
321-
AddStructTypeFields(context, struct_type_fields, field_decls)});
317+
auto struct_type_id = GetStructType(
318+
context, AddStructTypeFields(context, struct_type_fields, field_decls));
322319

323320
return AddInst<SemIR::CompleteTypeWitness>(
324321
context, node_id,
325322
{.type_id = GetSingletonType(context, SemIR::WitnessType::TypeInstId),
326-
.object_repr_type_inst_id = struct_type_inst_id});
323+
.object_repr_type_inst_id = context.types().GetInstId(struct_type_id)});
327324
}
328325

329326
auto ComputeClassObjectRepr(Context& context, Parse::ClassDefinitionId node_id,

toolchain/check/testdata/alias/export_name.carbon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ var d: D* = &c;
9191
// CHECK:STDOUT: }
9292
// CHECK:STDOUT:
9393
// CHECK:STDOUT: class @C {
94-
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
95-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
94+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
9695
// CHECK:STDOUT: complete_type_witness = %complete_type
9796
// CHECK:STDOUT:
9897
// CHECK:STDOUT: !members:

toolchain/check/testdata/alias/import.carbon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ var c: () = a_alias_alias;
9797
// CHECK:STDOUT: }
9898
// CHECK:STDOUT:
9999
// CHECK:STDOUT: class @C {
100-
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
101-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
100+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
102101
// CHECK:STDOUT: complete_type_witness = %complete_type
103102
// CHECK:STDOUT:
104103
// CHECK:STDOUT: !members:

toolchain/check/testdata/alias/import_access.carbon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ var inst: Test.A = {};
7575
// CHECK:STDOUT: }
7676
// CHECK:STDOUT:
7777
// CHECK:STDOUT: class @C {
78-
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
79-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
78+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
8079
// CHECK:STDOUT: complete_type_witness = %complete_type
8180
// CHECK:STDOUT:
8281
// CHECK:STDOUT: !members:

toolchain/check/testdata/alias/import_order.carbon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ var a_val: a = {.v = b_val.v};
6666
// CHECK:STDOUT: %.loc4_19.1: %empty_tuple.type = tuple_literal ()
6767
// CHECK:STDOUT: %.loc4_19.2: type = converted %.loc4_19.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
6868
// CHECK:STDOUT: %.loc4_16: %C.elem = field_decl v, element0 [concrete]
69-
// CHECK:STDOUT: %struct_type.v: type = struct_type {.v: %empty_tuple.type} [concrete = constants.%struct_type.v]
70-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.v [concrete = constants.%complete_type]
69+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.v [concrete = constants.%complete_type]
7170
// CHECK:STDOUT: complete_type_witness = %complete_type
7271
// CHECK:STDOUT:
7372
// CHECK:STDOUT: !members:

toolchain/check/testdata/class/access_modifers.carbon

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,7 @@ class A {
284284
// CHECK:STDOUT: impl_decl @Circle.as.Destroy.impl [concrete] {} {}
285285
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@Circle.as.Destroy.impl.%Circle.as.Destroy.impl.Op.decl), @Circle.as.Destroy.impl [concrete]
286286
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.2a8]
287-
// CHECK:STDOUT: %struct_type.radius: type = struct_type {.radius: %i32} [concrete = constants.%struct_type.radius.251]
288-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.radius [concrete = constants.%complete_type.5a5]
287+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.radius.251 [concrete = constants.%complete_type.5a5]
289288
// CHECK:STDOUT: complete_type_witness = %complete_type
290289
// CHECK:STDOUT:
291290
// CHECK:STDOUT: !members:
@@ -433,8 +432,7 @@ class A {
433432
// CHECK:STDOUT: impl_decl @A.as.Destroy.impl [concrete] {} {}
434433
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@A.as.Destroy.impl.%A.as.Destroy.impl.Op.decl), @A.as.Destroy.impl [concrete]
435434
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness]
436-
// CHECK:STDOUT: %struct_type.x: type = struct_type {.x: %i32} [concrete = constants.%struct_type.x]
437-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.x [concrete = constants.%complete_type.1ec]
435+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.x [concrete = constants.%complete_type.1ec]
438436
// CHECK:STDOUT: complete_type_witness = %complete_type
439437
// CHECK:STDOUT:
440438
// CHECK:STDOUT: !members:
@@ -588,8 +586,7 @@ class A {
588586
// CHECK:STDOUT: impl_decl @Circle.as.Destroy.impl [concrete] {} {}
589587
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@Circle.as.Destroy.impl.%Circle.as.Destroy.impl.Op.decl), @Circle.as.Destroy.impl [concrete]
590588
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.2a8]
591-
// CHECK:STDOUT: %struct_type.radius: type = struct_type {.radius: %i32} [concrete = constants.%struct_type.radius]
592-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.radius [concrete = constants.%complete_type.5a5]
589+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.radius [concrete = constants.%complete_type.5a5]
593590
// CHECK:STDOUT: complete_type_witness = %complete_type
594591
// CHECK:STDOUT:
595592
// CHECK:STDOUT: !members:
@@ -740,8 +737,7 @@ class A {
740737
// CHECK:STDOUT: impl_decl @A.as.Destroy.impl [concrete] {} {}
741738
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@A.as.Destroy.impl.%A.as.Destroy.impl.Op.decl), @A.as.Destroy.impl [concrete]
742739
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.b44]
743-
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
744-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
740+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type.357]
745741
// CHECK:STDOUT: complete_type_witness = %complete_type
746742
// CHECK:STDOUT:
747743
// CHECK:STDOUT: !members:
@@ -889,8 +885,7 @@ class A {
889885
// CHECK:STDOUT: impl_decl @A.as.Destroy.impl [concrete] {} {}
890886
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@A.as.Destroy.impl.%A.as.Destroy.impl.Op.decl), @A.as.Destroy.impl [concrete]
891887
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.b44]
892-
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
893-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
888+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type.357]
894889
// CHECK:STDOUT: complete_type_witness = %complete_type
895890
// CHECK:STDOUT:
896891
// CHECK:STDOUT: !members:
@@ -970,8 +965,7 @@ class A {
970965
// CHECK:STDOUT: impl_decl @A.as.Destroy.impl [concrete] {} {}
971966
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@A.as.Destroy.impl.%A.as.Destroy.impl.Op.decl), @A.as.Destroy.impl [concrete]
972967
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness]
973-
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
974-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
968+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
975969
// CHECK:STDOUT: complete_type_witness = %complete_type
976970
// CHECK:STDOUT:
977971
// CHECK:STDOUT: !members:

toolchain/check/testdata/class/adapter/adapt.carbon

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ interface I {
182182
// CHECK:STDOUT: impl_decl @SomeClass.as.Destroy.impl [concrete] {} {}
183183
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@SomeClass.as.Destroy.impl.%SomeClass.as.Destroy.impl.Op.decl), @SomeClass.as.Destroy.impl [concrete]
184184
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.ab1]
185-
// CHECK:STDOUT: %struct_type.a.b: type = struct_type {.a: %i32, .b: %i32} [concrete = constants.%struct_type.a.b]
186-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a.b [concrete = constants.%complete_type.705]
185+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.a.b [concrete = constants.%complete_type.705]
187186
// CHECK:STDOUT: complete_type_witness = %complete_type
188187
// CHECK:STDOUT:
189188
// CHECK:STDOUT: !members:
@@ -321,8 +320,7 @@ interface I {
321320
// CHECK:STDOUT: impl_decl @Adapted.as.Destroy.impl [concrete] {} {}
322321
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@Adapted.as.Destroy.impl.%Adapted.as.Destroy.impl.Op.decl), @Adapted.as.Destroy.impl [concrete]
323322
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.d23]
324-
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
325-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
323+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
326324
// CHECK:STDOUT: complete_type_witness = %complete_type
327325
// CHECK:STDOUT:
328326
// CHECK:STDOUT: !members:

toolchain/check/testdata/class/adapter/adapt_copy.carbon

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,7 @@ fn InTuple(c: (AdaptStruct, u32)) -> (AdaptStruct, u32) {
647647
// CHECK:STDOUT: impl_decl @Noncopyable.as.Destroy.impl [concrete] {} {}
648648
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@Noncopyable.as.Destroy.impl.%Noncopyable.as.Destroy.impl.Op.decl), @Noncopyable.as.Destroy.impl [concrete]
649649
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.004]
650-
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
651-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
650+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
652651
// CHECK:STDOUT: complete_type_witness = %complete_type
653652
// CHECK:STDOUT:
654653
// CHECK:STDOUT: !members:
@@ -796,8 +795,7 @@ fn InTuple(c: (AdaptStruct, u32)) -> (AdaptStruct, u32) {
796795
// CHECK:STDOUT: impl_decl @Noncopyable.as.Destroy.impl [concrete] {} {}
797796
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@Noncopyable.as.Destroy.impl.%Noncopyable.as.Destroy.impl.Op.decl), @Noncopyable.as.Destroy.impl [concrete]
798797
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.004]
799-
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
800-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
798+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type.357]
801799
// CHECK:STDOUT: complete_type_witness = %complete_type
802800
// CHECK:STDOUT:
803801
// CHECK:STDOUT: !members:

toolchain/check/testdata/class/adapter/extend_adapt.carbon

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ fn F(a: IntAdapter) -> i32 {
287287
// CHECK:STDOUT: impl_decl @SomeClass.as.Destroy.impl [concrete] {} {}
288288
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@SomeClass.as.Destroy.impl.%SomeClass.as.Destroy.impl.Op.decl), @SomeClass.as.Destroy.impl [concrete]
289289
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.ab1]
290-
// CHECK:STDOUT: %struct_type.a.b: type = struct_type {.a: %i32, .b: %i32} [concrete = constants.%struct_type.a.b]
291-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a.b [concrete = constants.%complete_type.705]
290+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.a.b [concrete = constants.%complete_type.705]
292291
// CHECK:STDOUT: complete_type_witness = %complete_type
293292
// CHECK:STDOUT:
294293
// CHECK:STDOUT: !members:
@@ -430,8 +429,7 @@ fn F(a: IntAdapter) -> i32 {
430429
// CHECK:STDOUT: impl_decl @SomeClass.as.Destroy.impl [concrete] {} {}
431430
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@SomeClass.as.Destroy.impl.%SomeClass.as.Destroy.impl.Op.decl), @SomeClass.as.Destroy.impl [concrete]
432431
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.ab1]
433-
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
434-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
432+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
435433
// CHECK:STDOUT: complete_type_witness = %complete_type
436434
// CHECK:STDOUT:
437435
// CHECK:STDOUT: !members:
@@ -584,8 +582,7 @@ fn F(a: IntAdapter) -> i32 {
584582
// CHECK:STDOUT: impl_decl @SomeClass.as.Destroy.impl [concrete] {} {}
585583
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@SomeClass.as.Destroy.impl.%SomeClass.as.Destroy.impl.Op.decl), @SomeClass.as.Destroy.impl [concrete]
586584
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.ab1]
587-
// CHECK:STDOUT: %struct_type.a.b: type = struct_type {.a: %i32, .b: %i32} [concrete = constants.%struct_type.a.b]
588-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a.b [concrete = constants.%complete_type.705]
585+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.a.b [concrete = constants.%complete_type.705]
589586
// CHECK:STDOUT: complete_type_witness = %complete_type
590587
// CHECK:STDOUT:
591588
// CHECK:STDOUT: !members:

toolchain/check/testdata/class/adapter/fail_adapt_with_subobjects.carbon

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ class AdaptWithBaseAndFields {
163163
// CHECK:STDOUT: impl_decl @Base.as.Destroy.impl [concrete] {} {}
164164
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@Base.as.Destroy.impl.%Base.as.Destroy.impl.Op.decl), @Base.as.Destroy.impl [concrete]
165165
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.ae4]
166-
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
167-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
166+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type.357]
168167
// CHECK:STDOUT: complete_type_witness = %complete_type
169168
// CHECK:STDOUT:
170169
// CHECK:STDOUT: !members:
@@ -403,8 +402,7 @@ class AdaptWithBaseAndFields {
403402
// CHECK:STDOUT: impl_decl @Base.as.Destroy.impl [concrete] {} {}
404403
// CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@Base.as.Destroy.impl.%Base.as.Destroy.impl.Op.decl), @Base.as.Destroy.impl [concrete]
405404
// CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness.ae4]
406-
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
407-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
405+
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type.357]
408406
// CHECK:STDOUT: complete_type_witness = %complete_type
409407
// CHECK:STDOUT:
410408
// CHECK:STDOUT: !members:

0 commit comments

Comments
 (0)