Skip to content

Commit

Permalink
Avoid recursion in InstNamer::CollectNamesInBlock (#4706)
Browse files Browse the repository at this point in the history
Use a deque to maintain the set of instructions to be walked over. so
that the loop can append more instructions (with their related scope)
during iteration without requiring recursion.

---------

Co-authored-by: jonmeow <[email protected]>
  • Loading branch information
danakj and jonmeow authored Dec 20, 2024
1 parent aca862c commit 6cb660f
Show file tree
Hide file tree
Showing 92 changed files with 974 additions and 955 deletions.
12 changes: 6 additions & 6 deletions toolchain/check/testdata/array/array_in_place.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ fn G() {
// CHECK:STDOUT: %v.var: ref %array_type = var v
// CHECK:STDOUT: %v: ref %array_type = bind_name v, %v.var
// CHECK:STDOUT: %F.ref.loc14_34: %F.type = name_ref F, file.%F.decl [template = constants.%F]
// CHECK:STDOUT: %.loc14_42.2: ref %tuple.type.2 = splice_block %.loc14_42.1 {
// CHECK:STDOUT: %.loc14_42.1: ref %tuple.type.2 = splice_block %.loc14_42.2 {
// CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0]
// CHECK:STDOUT: %.loc14_42.1: ref %tuple.type.2 = array_index %v.var, %int_0
// CHECK:STDOUT: %.loc14_42.2: ref %tuple.type.2 = array_index %v.var, %int_0
// CHECK:STDOUT: }
// CHECK:STDOUT: %F.call.loc14_36: init %tuple.type.2 = call %F.ref.loc14_34() to %.loc14_42.2
// CHECK:STDOUT: %F.call.loc14_36: init %tuple.type.2 = call %F.ref.loc14_34() to %.loc14_42.1
// CHECK:STDOUT: %F.ref.loc14_39: %F.type = name_ref F, file.%F.decl [template = constants.%F]
// CHECK:STDOUT: %.loc14_42.4: ref %tuple.type.2 = splice_block %.loc14_42.3 {
// CHECK:STDOUT: %.loc14_42.3: ref %tuple.type.2 = splice_block %.loc14_42.4 {
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
// CHECK:STDOUT: %.loc14_42.3: ref %tuple.type.2 = array_index %v.var, %int_1
// CHECK:STDOUT: %.loc14_42.4: ref %tuple.type.2 = array_index %v.var, %int_1
// CHECK:STDOUT: }
// CHECK:STDOUT: %F.call.loc14_41: init %tuple.type.2 = call %F.ref.loc14_39() to %.loc14_42.4
// CHECK:STDOUT: %F.call.loc14_41: init %tuple.type.2 = call %F.ref.loc14_39() to %.loc14_42.3
// CHECK:STDOUT: %.loc14_42.5: %tuple.type.3 = tuple_literal (%F.call.loc14_36, %F.call.loc14_41)
// CHECK:STDOUT: %.loc14_42.6: init %array_type = array_init (%F.call.loc14_36, %F.call.loc14_41) to %v.var
// CHECK:STDOUT: %.loc14_43: init %array_type = converted %.loc14_42.5, %.loc14_42.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ fn Foo(n: ()) -> ((), ()) {
// CHECK:STDOUT: %.loc15_25.3: type = converted %.loc15_24, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc15_25.4: type = converted %.loc15_25.1, constants.%tuple.type [template = constants.%tuple.type]
// CHECK:STDOUT: %n.param: %empty_tuple.type = value_param runtime_param0
// CHECK:STDOUT: %.loc15_12.3: type = splice_block %.loc15_12.2 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc15_12.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc15_12.2: type = converted %.loc15_12.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc15_12.1: type = splice_block %.loc15_12.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc15_12.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc15_12.3: type = converted %.loc15_12.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %n: %empty_tuple.type = bind_name n, %n.param
// CHECK:STDOUT: %return.param: ref %tuple.type = out_param runtime_param1
Expand Down
18 changes: 9 additions & 9 deletions toolchain/check/testdata/basics/no_prelude/raw_identifier.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ fn C(r#if: ()) -> () {
// CHECK:STDOUT: %.loc15_17.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc15_17.2: type = converted %.loc15_17.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %n.param: %empty_tuple.type = value_param runtime_param0
// CHECK:STDOUT: %.loc15_10.3: type = splice_block %.loc15_10.2 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc15_10.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc15_10.2: type = converted %.loc15_10.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc15_10.1: type = splice_block %.loc15_10.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc15_10.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc15_10.3: type = converted %.loc15_10.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %n: %empty_tuple.type = bind_name n, %n.param
// CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param runtime_param1
Expand All @@ -68,9 +68,9 @@ fn C(r#if: ()) -> () {
// CHECK:STDOUT: %.loc19_19.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc19_19.2: type = converted %.loc19_19.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %n.param: %empty_tuple.type = value_param runtime_param0
// CHECK:STDOUT: %.loc19_12.3: type = splice_block %.loc19_12.2 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc19_12.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc19_12.2: type = converted %.loc19_12.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc19_12.1: type = splice_block %.loc19_12.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc19_12.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc19_12.3: type = converted %.loc19_12.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %n: %empty_tuple.type = bind_name n, %n.param
// CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param runtime_param1
Expand All @@ -85,9 +85,9 @@ fn C(r#if: ()) -> () {
// CHECK:STDOUT: %.loc23_20.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc23_20.2: type = converted %.loc23_20.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %if.param: %empty_tuple.type = value_param runtime_param0
// CHECK:STDOUT: %.loc23_13.3: type = splice_block %.loc23_13.2 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc23_13.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc23_13.2: type = converted %.loc23_13.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc23_13.1: type = splice_block %.loc23_13.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc23_13.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc23_13.3: type = converted %.loc23_13.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %if: %empty_tuple.type = bind_name r#if, %if.param
// CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param runtime_param1
Expand Down
6 changes: 3 additions & 3 deletions toolchain/check/testdata/basics/no_prelude/textual_ir.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ fn Foo(n: ()) -> ((), ()) {
// CHECK:STDOUT: %.loc15_25.3: type = converted %.loc15_24, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc15_25.4: type = converted %.loc15_25.1, constants.%tuple.type [template = constants.%tuple.type]
// CHECK:STDOUT: %n.param: %empty_tuple.type = value_param runtime_param0
// CHECK:STDOUT: %.loc15_12.3: type = splice_block %.loc15_12.2 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc15_12.1: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc15_12.2: type = converted %.loc15_12.1, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: %.loc15_12.1: type = splice_block %.loc15_12.3 [template = constants.%empty_tuple.type] {
// CHECK:STDOUT: %.loc15_12.2: %empty_tuple.type = tuple_literal ()
// CHECK:STDOUT: %.loc15_12.3: type = converted %.loc15_12.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %n: %empty_tuple.type = bind_name n, %n.param
// CHECK:STDOUT: %return.param: ref %tuple.type = out_param runtime_param1
Expand Down
24 changes: 12 additions & 12 deletions toolchain/check/testdata/builtins/bool/eq.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ var d: C(false == false) = True();
// CHECK:STDOUT: %.loc4_28.1: type = value_of_initializer %bool.make_type.loc4_28 [template = bool]
// CHECK:STDOUT: %.loc4_28.2: type = converted %bool.make_type.loc4_28, %.loc4_28.1 [template = bool]
// CHECK:STDOUT: %a.param: bool = value_param runtime_param0
// CHECK:STDOUT: %.loc4_10.3: type = splice_block %.loc4_10.2 [template = bool] {
// CHECK:STDOUT: %.loc4_10.1: type = splice_block %.loc4_10.3 [template = bool] {
// CHECK:STDOUT: %bool.make_type.loc4_10: init type = call constants.%Bool() [template = bool]
// CHECK:STDOUT: %.loc4_10.1: type = value_of_initializer %bool.make_type.loc4_10 [template = bool]
// CHECK:STDOUT: %.loc4_10.2: type = converted %bool.make_type.loc4_10, %.loc4_10.1 [template = bool]
// CHECK:STDOUT: %.loc4_10.2: type = value_of_initializer %bool.make_type.loc4_10 [template = bool]
// CHECK:STDOUT: %.loc4_10.3: type = converted %bool.make_type.loc4_10, %.loc4_10.2 [template = bool]
// CHECK:STDOUT: }
// CHECK:STDOUT: %a: bool = bind_name a, %a.param
// CHECK:STDOUT: %b.param: bool = value_param runtime_param1
// CHECK:STDOUT: %.loc4_19.3: type = splice_block %.loc4_19.2 [template = bool] {
// CHECK:STDOUT: %.loc4_19.1: type = splice_block %.loc4_19.3 [template = bool] {
// CHECK:STDOUT: %bool.make_type.loc4_19: init type = call constants.%Bool() [template = bool]
// CHECK:STDOUT: %.loc4_19.1: type = value_of_initializer %bool.make_type.loc4_19 [template = bool]
// CHECK:STDOUT: %.loc4_19.2: type = converted %bool.make_type.loc4_19, %.loc4_19.1 [template = bool]
// CHECK:STDOUT: %.loc4_19.2: type = value_of_initializer %bool.make_type.loc4_19 [template = bool]
// CHECK:STDOUT: %.loc4_19.3: type = converted %bool.make_type.loc4_19, %.loc4_19.2 [template = bool]
// CHECK:STDOUT: }
// CHECK:STDOUT: %b: bool = bind_name b, %b.param
// CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
Expand All @@ -116,10 +116,10 @@ var d: C(false == false) = True();
// CHECK:STDOUT: %B.param_patt: bool = value_param_pattern %B.patt.loc6_9.1, runtime_param<invalid> [symbolic = %B.patt.loc6_9.2 (constants.%B.patt)]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %B.param: bool = value_param runtime_param<invalid>
// CHECK:STDOUT: %.loc6_13.3: type = splice_block %.loc6_13.2 [template = bool] {
// CHECK:STDOUT: %.loc6_13.1: type = splice_block %.loc6_13.3 [template = bool] {
// CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
// CHECK:STDOUT: %.loc6_13.1: type = value_of_initializer %bool.make_type [template = bool]
// CHECK:STDOUT: %.loc6_13.2: type = converted %bool.make_type, %.loc6_13.1 [template = bool]
// CHECK:STDOUT: %.loc6_13.2: type = value_of_initializer %bool.make_type [template = bool]
// CHECK:STDOUT: %.loc6_13.3: type = converted %bool.make_type, %.loc6_13.2 [template = bool]
// CHECK:STDOUT: }
// CHECK:STDOUT: %B.loc6_9.1: bool = bind_symbolic_name B, 0, %B.param [symbolic = %B.loc6_9.2 (constants.%B)]
// CHECK:STDOUT: }
Expand Down Expand Up @@ -262,10 +262,10 @@ var d: C(false == false) = True();
// CHECK:STDOUT: %B.param_patt: bool = value_param_pattern %B.patt.loc4_9.1, runtime_param<invalid> [symbolic = %B.patt.loc4_9.2 (constants.%B.patt)]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %B.param: bool = value_param runtime_param<invalid>
// CHECK:STDOUT: %.loc4_13.3: type = splice_block %.loc4_13.2 [template = bool] {
// CHECK:STDOUT: %.loc4_13.1: type = splice_block %.loc4_13.3 [template = bool] {
// CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
// CHECK:STDOUT: %.loc4_13.1: type = value_of_initializer %bool.make_type [template = bool]
// CHECK:STDOUT: %.loc4_13.2: type = converted %bool.make_type, %.loc4_13.1 [template = bool]
// CHECK:STDOUT: %.loc4_13.2: type = value_of_initializer %bool.make_type [template = bool]
// CHECK:STDOUT: %.loc4_13.3: type = converted %bool.make_type, %.loc4_13.2 [template = bool]
// CHECK:STDOUT: }
// CHECK:STDOUT: %B.loc4_9.1: bool = bind_symbolic_name B, 0, %B.param [symbolic = %B.loc4_9.2 (constants.%B)]
// CHECK:STDOUT: }
Expand Down
24 changes: 12 additions & 12 deletions toolchain/check/testdata/builtins/bool/neq.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ var d: C(false != false) = False();
// CHECK:STDOUT: %.loc4_29.1: type = value_of_initializer %bool.make_type.loc4_29 [template = bool]
// CHECK:STDOUT: %.loc4_29.2: type = converted %bool.make_type.loc4_29, %.loc4_29.1 [template = bool]
// CHECK:STDOUT: %a.param: bool = value_param runtime_param0
// CHECK:STDOUT: %.loc4_11.3: type = splice_block %.loc4_11.2 [template = bool] {
// CHECK:STDOUT: %.loc4_11.1: type = splice_block %.loc4_11.3 [template = bool] {
// CHECK:STDOUT: %bool.make_type.loc4_11: init type = call constants.%Bool() [template = bool]
// CHECK:STDOUT: %.loc4_11.1: type = value_of_initializer %bool.make_type.loc4_11 [template = bool]
// CHECK:STDOUT: %.loc4_11.2: type = converted %bool.make_type.loc4_11, %.loc4_11.1 [template = bool]
// CHECK:STDOUT: %.loc4_11.2: type = value_of_initializer %bool.make_type.loc4_11 [template = bool]
// CHECK:STDOUT: %.loc4_11.3: type = converted %bool.make_type.loc4_11, %.loc4_11.2 [template = bool]
// CHECK:STDOUT: }
// CHECK:STDOUT: %a: bool = bind_name a, %a.param
// CHECK:STDOUT: %b.param: bool = value_param runtime_param1
// CHECK:STDOUT: %.loc4_20.3: type = splice_block %.loc4_20.2 [template = bool] {
// CHECK:STDOUT: %.loc4_20.1: type = splice_block %.loc4_20.3 [template = bool] {
// CHECK:STDOUT: %bool.make_type.loc4_20: init type = call constants.%Bool() [template = bool]
// CHECK:STDOUT: %.loc4_20.1: type = value_of_initializer %bool.make_type.loc4_20 [template = bool]
// CHECK:STDOUT: %.loc4_20.2: type = converted %bool.make_type.loc4_20, %.loc4_20.1 [template = bool]
// CHECK:STDOUT: %.loc4_20.2: type = value_of_initializer %bool.make_type.loc4_20 [template = bool]
// CHECK:STDOUT: %.loc4_20.3: type = converted %bool.make_type.loc4_20, %.loc4_20.2 [template = bool]
// CHECK:STDOUT: }
// CHECK:STDOUT: %b: bool = bind_name b, %b.param
// CHECK:STDOUT: %return.param: ref bool = out_param runtime_param2
Expand All @@ -116,10 +116,10 @@ var d: C(false != false) = False();
// CHECK:STDOUT: %B.param_patt: bool = value_param_pattern %B.patt.loc6_9.1, runtime_param<invalid> [symbolic = %B.patt.loc6_9.2 (constants.%B.patt)]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %B.param: bool = value_param runtime_param<invalid>
// CHECK:STDOUT: %.loc6_13.3: type = splice_block %.loc6_13.2 [template = bool] {
// CHECK:STDOUT: %.loc6_13.1: type = splice_block %.loc6_13.3 [template = bool] {
// CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
// CHECK:STDOUT: %.loc6_13.1: type = value_of_initializer %bool.make_type [template = bool]
// CHECK:STDOUT: %.loc6_13.2: type = converted %bool.make_type, %.loc6_13.1 [template = bool]
// CHECK:STDOUT: %.loc6_13.2: type = value_of_initializer %bool.make_type [template = bool]
// CHECK:STDOUT: %.loc6_13.3: type = converted %bool.make_type, %.loc6_13.2 [template = bool]
// CHECK:STDOUT: }
// CHECK:STDOUT: %B.loc6_9.1: bool = bind_symbolic_name B, 0, %B.param [symbolic = %B.loc6_9.2 (constants.%B)]
// CHECK:STDOUT: }
Expand Down Expand Up @@ -262,10 +262,10 @@ var d: C(false != false) = False();
// CHECK:STDOUT: %B.param_patt: bool = value_param_pattern %B.patt.loc4_9.1, runtime_param<invalid> [symbolic = %B.patt.loc4_9.2 (constants.%B.patt)]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %B.param: bool = value_param runtime_param<invalid>
// CHECK:STDOUT: %.loc4_13.3: type = splice_block %.loc4_13.2 [template = bool] {
// CHECK:STDOUT: %.loc4_13.1: type = splice_block %.loc4_13.3 [template = bool] {
// CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
// CHECK:STDOUT: %.loc4_13.1: type = value_of_initializer %bool.make_type [template = bool]
// CHECK:STDOUT: %.loc4_13.2: type = converted %bool.make_type, %.loc4_13.1 [template = bool]
// CHECK:STDOUT: %.loc4_13.2: type = value_of_initializer %bool.make_type [template = bool]
// CHECK:STDOUT: %.loc4_13.3: type = converted %bool.make_type, %.loc4_13.2 [template = bool]
// CHECK:STDOUT: }
// CHECK:STDOUT: %B.loc4_9.1: bool = bind_symbolic_name B, 0, %B.param [symbolic = %B.loc4_9.2 (constants.%B)]
// CHECK:STDOUT: }
Expand Down
Loading

0 comments on commit 6cb660f

Please sign in to comment.