Skip to content

Commit eed21f6

Browse files
authored
Make applying const repeatedly to the same type have less additional effect. (#6287)
This is to avoid edge cases where there are multiple `ConstType` instructions, which code may not handle appropriately. I was thinking about this for #6279
1 parent 0811d99 commit eed21f6

File tree

5 files changed

+9
-11
lines changed

5 files changed

+9
-11
lines changed

toolchain/check/handle_operator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ auto HandleParseNode(Context& context, Parse::PrefixOperatorConstId node_id)
293293
"`const` applied repeatedly to the same type has no "
294294
"additional effect");
295295
context.emitter().Emit(node_id, RepeatedConst);
296+
context.node_stack().Push(node_id, value_id);
297+
return true;
296298
}
297299
auto inner_type = ExprAsType(context, node_id, value_id);
298300
AddInstAndPush<SemIR::ConstType>(

toolchain/check/testdata/class/syntactic_merge.carbon

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,11 +1081,10 @@ fn Base.F[addr self: Base*]() {
10811081
// CHECK:STDOUT: %Foo.decl.loc18: %Foo.type.39e446.2 = class_decl @Foo.loc18 [concrete = constants.%Foo.generic.80461b.2] {
10821082
// CHECK:STDOUT: %a.patt: %pattern_type = symbolic_binding_pattern a, 0 [concrete]
10831083
// CHECK:STDOUT: } {
1084-
// CHECK:STDOUT: %.loc18: type = splice_block %const.loc18_15 [concrete = constants.%const] {
1084+
// CHECK:STDOUT: %.loc18: type = splice_block %const [concrete = constants.%const] {
10851085
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
10861086
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
1087-
// CHECK:STDOUT: %const.loc18_22: type = const_type %C.ref [concrete = constants.%const]
1088-
// CHECK:STDOUT: %const.loc18_15: type = const_type %const.loc18_22 [concrete = constants.%const]
1087+
// CHECK:STDOUT: %const: type = const_type %C.ref [concrete = constants.%const]
10891088
// CHECK:STDOUT: }
10901089
// CHECK:STDOUT: %a.loc18_11.2: %const = symbolic_binding a, 0 [symbolic = %a.loc18_11.1 (constants.%a)]
10911090
// CHECK:STDOUT: }

toolchain/check/testdata/const/basics.carbon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ fn PassConstReferenceToReference(p: const X*) {
304304
// CHECK:STDOUT: } {
305305
// CHECK:STDOUT: %C.ref.loc11_36: type = name_ref C, file.%C.decl [concrete = constants.%C]
306306
// CHECK:STDOUT: %const.loc11_30: type = const_type %C.ref.loc11_36 [concrete = constants.%const.668]
307-
// CHECK:STDOUT: %const.loc11_23: type = const_type %const.loc11_30 [concrete = constants.%const.668]
308-
// CHECK:STDOUT: %ptr.loc11_38: type = ptr_type %const.loc11_23 [concrete = constants.%ptr.801]
307+
// CHECK:STDOUT: %ptr.loc11_38: type = ptr_type %const.loc11_30 [concrete = constants.%ptr.801]
309308
// CHECK:STDOUT: %ptr.loc11_39: type = ptr_type %ptr.loc11_38 [concrete = constants.%ptr.564]
310309
// CHECK:STDOUT: %p.param: %ptr.564 = value_param call_param0
311310
// CHECK:STDOUT: %.loc11: type = splice_block %ptr.loc11_17 [concrete = constants.%ptr.564] {

toolchain/check/testdata/function/definition/syntactic_merge.carbon

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,10 +940,9 @@ fn Foo(a: const (const C)) {}
940940
// CHECK:STDOUT: %a.param_patt: %pattern_type = value_param_pattern %a.patt, call_param0 [concrete]
941941
// CHECK:STDOUT: } {
942942
// CHECK:STDOUT: %a.param: %const = value_param call_param0
943-
// CHECK:STDOUT: %.loc18: type = splice_block %const.loc18_11 [concrete = constants.%const] {
943+
// CHECK:STDOUT: %.loc18: type = splice_block %const [concrete = constants.%const] {
944944
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
945-
// CHECK:STDOUT: %const.loc18_18: type = const_type %C.ref [concrete = constants.%const]
946-
// CHECK:STDOUT: %const.loc18_11: type = const_type %const.loc18_18 [concrete = constants.%const]
945+
// CHECK:STDOUT: %const: type = const_type %C.ref [concrete = constants.%const]
947946
// CHECK:STDOUT: }
948947
// CHECK:STDOUT: %a: %const = value_binding a, %a.param
949948
// CHECK:STDOUT: }

toolchain/check/testdata/interface/syntactic_merge.carbon

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,11 +1160,10 @@ interface Foo(a:! const (const C)) {}
11601160
// CHECK:STDOUT: %Foo.decl.loc18: %Foo.type.5380b8.2 = interface_decl @Foo.loc18 [concrete = constants.%Foo.generic.ec3175.2] {
11611161
// CHECK:STDOUT: %a.patt: %pattern_type = symbolic_binding_pattern a, 0 [concrete]
11621162
// CHECK:STDOUT: } {
1163-
// CHECK:STDOUT: %.loc18: type = splice_block %const.loc18_19 [concrete = constants.%const] {
1163+
// CHECK:STDOUT: %.loc18: type = splice_block %const [concrete = constants.%const] {
11641164
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
11651165
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
1166-
// CHECK:STDOUT: %const.loc18_26: type = const_type %C.ref [concrete = constants.%const]
1167-
// CHECK:STDOUT: %const.loc18_19: type = const_type %const.loc18_26 [concrete = constants.%const]
1166+
// CHECK:STDOUT: %const: type = const_type %C.ref [concrete = constants.%const]
11681167
// CHECK:STDOUT: }
11691168
// CHECK:STDOUT: %a.loc18_15.2: %const = symbolic_binding a, 0 [symbolic = %a.loc18_15.1 (constants.%a)]
11701169
// CHECK:STDOUT: }

0 commit comments

Comments
 (0)