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:
Burak Emir
2026-02-19 23:33:36 +00:00
committed by GitHub
co-authored by Burak Emir jonmeow
parent bea24a8bee
commit fdb188ccfd
366 changed files with 8453 additions and 7996 deletions
+8 -8
View File
@@ -26,9 +26,9 @@ package InsideFn;
var x: i32 = 0;
fn Main() {
var x: i32 = 1;
var unused x: i32 = 1;
var y: i32 = package.x;
var unused y: i32 = package.x;
}
// --- namespace.carbon
@@ -253,7 +253,7 @@ fn Main() {
// CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call: init %i32 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.5d2]
// CHECK:STDOUT: %.loc7_3: init %i32 = converted %int_1, %Core.IntLiteral.as.ImplicitAs.impl.Convert.call [concrete = constants.%int_1.5d2]
// CHECK:STDOUT: assign %x.var, %.loc7_3
// CHECK:STDOUT: %.loc7_10: type = splice_block %i32.loc7 [concrete = constants.%i32] {
// CHECK:STDOUT: %.loc7_17: type = splice_block %i32.loc7 [concrete = constants.%i32] {
// CHECK:STDOUT: %int_32.loc7: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
// CHECK:STDOUT: %i32.loc7: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
// CHECK:STDOUT: }
@@ -265,14 +265,14 @@ fn Main() {
// CHECK:STDOUT: %y.var: ref %i32 = var %y.var_patt
// CHECK:STDOUT: %package.ref: <namespace> = name_ref package, package [concrete = package]
// CHECK:STDOUT: %x.ref: ref %i32 = name_ref x, file.%x [concrete = file.%x.var]
// CHECK:STDOUT: %.loc9_23: %i32 = acquire_value %x.ref
// CHECK:STDOUT: %.loc9_30: %i32 = acquire_value %x.ref
// CHECK:STDOUT: %impl.elem0.loc9: %.8e2 = impl_witness_access constants.%Copy.impl_witness.f17, element0 [concrete = constants.%Int.as.Copy.impl.Op.664]
// CHECK:STDOUT: %bound_method.loc9_23.1: <bound method> = bound_method %.loc9_23, %impl.elem0.loc9
// CHECK:STDOUT: %bound_method.loc9_30.1: <bound method> = bound_method %.loc9_30, %impl.elem0.loc9
// CHECK:STDOUT: %specific_fn.loc9: <specific function> = specific_function %impl.elem0.loc9, @Int.as.Copy.impl.Op(constants.%int_32) [concrete = constants.%Int.as.Copy.impl.Op.specific_fn]
// CHECK:STDOUT: %bound_method.loc9_23.2: <bound method> = bound_method %.loc9_23, %specific_fn.loc9
// CHECK:STDOUT: %Int.as.Copy.impl.Op.call: init %i32 = call %bound_method.loc9_23.2(%.loc9_23)
// CHECK:STDOUT: %bound_method.loc9_30.2: <bound method> = bound_method %.loc9_30, %specific_fn.loc9
// CHECK:STDOUT: %Int.as.Copy.impl.Op.call: init %i32 = call %bound_method.loc9_30.2(%.loc9_30)
// CHECK:STDOUT: assign %y.var, %Int.as.Copy.impl.Op.call
// CHECK:STDOUT: %.loc9_10: type = splice_block %i32.loc9 [concrete = constants.%i32] {
// CHECK:STDOUT: %.loc9_17: type = splice_block %i32.loc9 [concrete = constants.%i32] {
// CHECK:STDOUT: %int_32.loc9: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
// CHECK:STDOUT: %i32.loc9: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
// CHECK:STDOUT: }