mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 07:24:42 +01:00
Implement unused pattern bindings, continued (#6518)
Implementation of unused pattern bindings #2022, continued. Whereas previous PR #6460 took care of parsing, and PR #6479 prepared the stage by using _ in some test cases, this PR has the the actual implementation, using a simple dataflow analysis. --------- Co-authored-by: Burak Emir <bqe@google.com> Co-authored-by: jonmeow <jperkins@google.com>
This commit is contained in:
co-authored by
Burak Emir
jonmeow
parent
bea24a8bee
commit
fdb188ccfd
+51
-51
@@ -35,7 +35,7 @@ fn F() -> (C, C, C);
|
||||
|
||||
fn G() {
|
||||
//@dump-sem-ir-begin
|
||||
var v: array((C, C, C), 2) = (F(), F());
|
||||
var unused v: array((C, C, C), 2) = (F(), F());
|
||||
//@dump-sem-ir-end
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ library "[[@TEST_NAME]]";
|
||||
fn G() {
|
||||
// These should have two different constant values.
|
||||
//@dump-sem-ir-begin
|
||||
var a: array((), 3);
|
||||
var b: ((), (), ());
|
||||
var unused a: array((), 3);
|
||||
var unused b: ((), (), ());
|
||||
//@dump-sem-ir-end
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ fn F() -> ((),) { return ((),); }
|
||||
|
||||
fn Run() {
|
||||
//@dump-sem-ir-begin
|
||||
var t: array((), 1) = F();
|
||||
var unused t: array((), 1) = F();
|
||||
//@dump-sem-ir-end
|
||||
}
|
||||
|
||||
@@ -195,30 +195,30 @@ var a: array(1, 1);
|
||||
// CHECK:STDOUT: %v.var_patt: %pattern_type.709 = var_pattern %v.patt [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %v.var: ref %array_type = var %v.var_patt
|
||||
// CHECK:STDOUT: %F.ref.loc10_33: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
|
||||
// CHECK:STDOUT: %.loc10_41.1: ref %tuple.type.e56 = splice_block %.loc10_41.6 {
|
||||
// CHECK:STDOUT: %F.ref.loc10_40: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
|
||||
// CHECK:STDOUT: %.loc10_48.1: ref %tuple.type.e56 = splice_block %.loc10_48.6 {
|
||||
// CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
|
||||
// CHECK:STDOUT: %.loc10_41.6: ref %tuple.type.e56 = array_index %v.var, %int_0
|
||||
// CHECK:STDOUT: %.loc10_48.6: ref %tuple.type.e56 = array_index %v.var, %int_0
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %F.call.loc10_35: init %tuple.type.e56 to %.loc10_41.1 = call %F.ref.loc10_33()
|
||||
// CHECK:STDOUT: %F.ref.loc10_38: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
|
||||
// CHECK:STDOUT: %.loc10_41.2: ref %tuple.type.e56 = splice_block %.loc10_41.5 {
|
||||
// CHECK:STDOUT: %F.call.loc10_42: init %tuple.type.e56 to %.loc10_48.1 = call %F.ref.loc10_40()
|
||||
// CHECK:STDOUT: %F.ref.loc10_45: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
|
||||
// CHECK:STDOUT: %.loc10_48.2: ref %tuple.type.e56 = splice_block %.loc10_48.5 {
|
||||
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
|
||||
// CHECK:STDOUT: %.loc10_41.5: ref %tuple.type.e56 = array_index %v.var, %int_1
|
||||
// CHECK:STDOUT: %.loc10_48.5: ref %tuple.type.e56 = array_index %v.var, %int_1
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %F.call.loc10_40: init %tuple.type.e56 to %.loc10_41.2 = call %F.ref.loc10_38()
|
||||
// CHECK:STDOUT: %.loc10_41.3: %tuple.type.708 = tuple_literal (%F.call.loc10_35, %F.call.loc10_40)
|
||||
// CHECK:STDOUT: %.loc10_41.4: init %array_type to %v.var = array_init (%F.call.loc10_35, %F.call.loc10_40)
|
||||
// CHECK:STDOUT: %.loc10_3: init %array_type = converted %.loc10_41.3, %.loc10_41.4
|
||||
// CHECK:STDOUT: %F.call.loc10_47: init %tuple.type.e56 to %.loc10_48.2 = call %F.ref.loc10_45()
|
||||
// CHECK:STDOUT: %.loc10_48.3: %tuple.type.708 = tuple_literal (%F.call.loc10_42, %F.call.loc10_47)
|
||||
// CHECK:STDOUT: %.loc10_48.4: init %array_type to %v.var = array_init (%F.call.loc10_42, %F.call.loc10_47)
|
||||
// CHECK:STDOUT: %.loc10_3: init %array_type = converted %.loc10_48.3, %.loc10_48.4
|
||||
// CHECK:STDOUT: assign %v.var, %.loc10_3
|
||||
// CHECK:STDOUT: %.loc10_28: type = splice_block %array_type [concrete = constants.%array_type] {
|
||||
// CHECK:STDOUT: %C.ref.loc10_17: type = name_ref C, file.%C.decl [concrete = constants.%C]
|
||||
// CHECK:STDOUT: %C.ref.loc10_20: type = name_ref C, file.%C.decl [concrete = constants.%C]
|
||||
// CHECK:STDOUT: %C.ref.loc10_23: type = name_ref C, file.%C.decl [concrete = constants.%C]
|
||||
// CHECK:STDOUT: %.loc10_24.1: %tuple.type.ff9 = tuple_literal (%C.ref.loc10_17, %C.ref.loc10_20, %C.ref.loc10_23) [concrete = constants.%tuple]
|
||||
// CHECK:STDOUT: %.loc10_35: type = splice_block %array_type [concrete = constants.%array_type] {
|
||||
// CHECK:STDOUT: %C.ref.loc10_24: type = name_ref C, file.%C.decl [concrete = constants.%C]
|
||||
// CHECK:STDOUT: %C.ref.loc10_27: type = name_ref C, file.%C.decl [concrete = constants.%C]
|
||||
// CHECK:STDOUT: %C.ref.loc10_30: type = name_ref C, file.%C.decl [concrete = constants.%C]
|
||||
// CHECK:STDOUT: %.loc10_31.1: %tuple.type.ff9 = tuple_literal (%C.ref.loc10_24, %C.ref.loc10_27, %C.ref.loc10_30) [concrete = constants.%tuple]
|
||||
// CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [concrete = constants.%int_2]
|
||||
// CHECK:STDOUT: %.loc10_24.2: type = converted %.loc10_24.1, constants.%tuple.type.e56 [concrete = constants.%tuple.type.e56]
|
||||
// CHECK:STDOUT: %array_type: type = array_type %int_2, %.loc10_24.2 [concrete = constants.%array_type]
|
||||
// CHECK:STDOUT: %.loc10_31.2: type = converted %.loc10_31.1, constants.%tuple.type.e56 [concrete = constants.%tuple.type.e56]
|
||||
// CHECK:STDOUT: %array_type: type = array_type %int_2, %.loc10_31.2 [concrete = constants.%array_type]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %v: ref %array_type = ref_binding v, %v.var
|
||||
// CHECK:STDOUT: %DestroyOp.bound: <bound method> = bound_method %v.var, constants.%DestroyOp
|
||||
@@ -255,11 +255,11 @@ var a: array(1, 1);
|
||||
// CHECK:STDOUT: %a.var_patt: %pattern_type.035 = var_pattern %a.patt [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %a.var: ref %array_type = var %a.var_patt
|
||||
// CHECK:STDOUT: %.loc7_21: type = splice_block %array_type [concrete = constants.%array_type] {
|
||||
// CHECK:STDOUT: %.loc7_17.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc7_28: type = splice_block %array_type [concrete = constants.%array_type] {
|
||||
// CHECK:STDOUT: %.loc7_24.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete = constants.%int_3]
|
||||
// CHECK:STDOUT: %.loc7_17.2: type = converted %.loc7_17.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
|
||||
// CHECK:STDOUT: %array_type: type = array_type %int_3, %.loc7_17.2 [concrete = constants.%array_type]
|
||||
// CHECK:STDOUT: %.loc7_24.2: type = converted %.loc7_24.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
|
||||
// CHECK:STDOUT: %array_type: type = array_type %int_3, %.loc7_24.2 [concrete = constants.%array_type]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %a: ref %array_type = ref_binding a, %a.var
|
||||
// CHECK:STDOUT: name_binding_decl {
|
||||
@@ -267,15 +267,15 @@ var a: array(1, 1);
|
||||
// CHECK:STDOUT: %b.var_patt: %pattern_type.8c1 = var_pattern %b.patt [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %b.var: ref %tuple.type = var %b.var_patt
|
||||
// CHECK:STDOUT: %.loc8_21.1: type = splice_block %.loc8_21.6 [concrete = constants.%tuple.type] {
|
||||
// CHECK:STDOUT: %.loc8_12: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc8_16: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc8_20: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc8_21.2: %tuple.type = tuple_literal (%.loc8_12, %.loc8_16, %.loc8_20) [concrete = constants.%tuple]
|
||||
// CHECK:STDOUT: %.loc8_21.3: type = converted constants.%empty_tuple, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
|
||||
// CHECK:STDOUT: %.loc8_21.4: type = converted constants.%empty_tuple, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
|
||||
// CHECK:STDOUT: %.loc8_21.5: type = converted constants.%empty_tuple, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
|
||||
// CHECK:STDOUT: %.loc8_21.6: type = converted %.loc8_21.2, constants.%tuple.type [concrete = constants.%tuple.type]
|
||||
// CHECK:STDOUT: %.loc8_28.1: type = splice_block %.loc8_28.6 [concrete = constants.%tuple.type] {
|
||||
// CHECK:STDOUT: %.loc8_19: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc8_23: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc8_27: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc8_28.2: %tuple.type = tuple_literal (%.loc8_19, %.loc8_23, %.loc8_27) [concrete = constants.%tuple]
|
||||
// CHECK:STDOUT: %.loc8_28.3: type = converted constants.%empty_tuple, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
|
||||
// CHECK:STDOUT: %.loc8_28.4: type = converted constants.%empty_tuple, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
|
||||
// CHECK:STDOUT: %.loc8_28.5: type = converted constants.%empty_tuple, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
|
||||
// CHECK:STDOUT: %.loc8_28.6: type = converted %.loc8_28.2, constants.%tuple.type [concrete = constants.%tuple.type]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %b: ref %tuple.type = ref_binding b, %b.var
|
||||
// CHECK:STDOUT: %DestroyOp.bound.loc8: <bound method> = bound_method %b.var, constants.%DestroyOp.b0ebf8.1
|
||||
@@ -302,7 +302,7 @@ var a: array(1, 1);
|
||||
// CHECK:STDOUT: %pattern_type.fe8: type = pattern_type %array_type [concrete]
|
||||
// CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete]
|
||||
// CHECK:STDOUT: %array: %array_type = tuple_value (%empty_tuple) [concrete]
|
||||
// CHECK:STDOUT: %DestroyOp.type.3e79c2.1: type = fn_type @DestroyOp.loc8_27 [concrete]
|
||||
// CHECK:STDOUT: %DestroyOp.type.3e79c2.1: type = fn_type @DestroyOp.loc8_34 [concrete]
|
||||
// CHECK:STDOUT: %DestroyOp.b0ebf8.1: %DestroyOp.type.3e79c2.1 = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %DestroyOp.type.3e79c2.2: type = fn_type @DestroyOp.loc8_3 [concrete]
|
||||
// CHECK:STDOUT: %DestroyOp.b0ebf8.2: %DestroyOp.type.3e79c2.2 = struct_value () [concrete]
|
||||
@@ -320,31 +320,31 @@ var a: array(1, 1);
|
||||
// CHECK:STDOUT: %t.var: ref %array_type = var %t.var_patt
|
||||
// CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
|
||||
// CHECK:STDOUT: %F.call: init %tuple.type = call %F.ref()
|
||||
// CHECK:STDOUT: %.loc8_27.1: ref %tuple.type = temporary_storage
|
||||
// CHECK:STDOUT: %.loc8_27.2: ref %tuple.type = temporary %.loc8_27.1, %F.call
|
||||
// CHECK:STDOUT: %tuple.elem0: ref %empty_tuple.type = tuple_access %.loc8_27.2, element0
|
||||
// CHECK:STDOUT: %.loc8_34.1: ref %tuple.type = temporary_storage
|
||||
// CHECK:STDOUT: %.loc8_34.2: ref %tuple.type = temporary %.loc8_34.1, %F.call
|
||||
// CHECK:STDOUT: %tuple.elem0: ref %empty_tuple.type = tuple_access %.loc8_34.2, element0
|
||||
// CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
|
||||
// CHECK:STDOUT: %.loc8_27.3: ref %empty_tuple.type = array_index %t.var, %int_0
|
||||
// CHECK:STDOUT: %.loc8_27.4: init %empty_tuple.type = tuple_init () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc8_27.5: init %empty_tuple.type = converted %tuple.elem0, %.loc8_27.4 [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc8_27.6: init %array_type to %t.var = array_init (%.loc8_27.5) [concrete = constants.%array]
|
||||
// CHECK:STDOUT: %.loc8_3: init %array_type = converted %F.call, %.loc8_27.6 [concrete = constants.%array]
|
||||
// CHECK:STDOUT: %.loc8_34.3: ref %empty_tuple.type = array_index %t.var, %int_0
|
||||
// CHECK:STDOUT: %.loc8_34.4: init %empty_tuple.type = tuple_init () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc8_34.5: init %empty_tuple.type = converted %tuple.elem0, %.loc8_34.4 [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc8_34.6: init %array_type to %t.var = array_init (%.loc8_34.5) [concrete = constants.%array]
|
||||
// CHECK:STDOUT: %.loc8_3: init %array_type = converted %F.call, %.loc8_34.6 [concrete = constants.%array]
|
||||
// CHECK:STDOUT: assign %t.var, %.loc8_3
|
||||
// CHECK:STDOUT: %.loc8_21: type = splice_block %array_type [concrete = constants.%array_type] {
|
||||
// CHECK:STDOUT: %.loc8_17.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %.loc8_28: type = splice_block %array_type [concrete = constants.%array_type] {
|
||||
// CHECK:STDOUT: %.loc8_24.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
||||
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
|
||||
// CHECK:STDOUT: %.loc8_17.2: type = converted %.loc8_17.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
|
||||
// CHECK:STDOUT: %array_type: type = array_type %int_1, %.loc8_17.2 [concrete = constants.%array_type]
|
||||
// CHECK:STDOUT: %.loc8_24.2: type = converted %.loc8_24.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
|
||||
// CHECK:STDOUT: %array_type: type = array_type %int_1, %.loc8_24.2 [concrete = constants.%array_type]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %t: ref %array_type = ref_binding t, %t.var
|
||||
// CHECK:STDOUT: %DestroyOp.bound.loc8_27: <bound method> = bound_method %.loc8_27.2, constants.%DestroyOp.b0ebf8.1
|
||||
// CHECK:STDOUT: %DestroyOp.call.loc8_27: init %empty_tuple.type = call %DestroyOp.bound.loc8_27(%.loc8_27.2)
|
||||
// CHECK:STDOUT: %DestroyOp.bound.loc8_34: <bound method> = bound_method %.loc8_34.2, constants.%DestroyOp.b0ebf8.1
|
||||
// CHECK:STDOUT: %DestroyOp.call.loc8_34: init %empty_tuple.type = call %DestroyOp.bound.loc8_34(%.loc8_34.2)
|
||||
// CHECK:STDOUT: %DestroyOp.bound.loc8_3: <bound method> = bound_method %t.var, constants.%DestroyOp.b0ebf8.2
|
||||
// CHECK:STDOUT: %DestroyOp.call.loc8_3: init %empty_tuple.type = call %DestroyOp.bound.loc8_3(%t.var)
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @DestroyOp.loc8_27(%self.param: ref %tuple.type) = "no_op";
|
||||
// CHECK:STDOUT: fn @DestroyOp.loc8_34(%self.param: ref %tuple.type) = "no_op";
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @DestroyOp.loc8_3(%self.param: ref %array_type) = "no_op";
|
||||
// CHECK:STDOUT:
|
||||
|
||||
Reference in New Issue
Block a user