From c425a16bf1144e5233372685d839f0d906e8b86a Mon Sep 17 00:00:00 2001 From: Timothy Hoffman <4001421+tim-hoffman@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:11:35 -0500 Subject: [PATCH] Remove unused function and add more test case output (#123) --- .../controlflow/early_return_loop_1.circom | 32 +++++++++++++++++++ .../src/bucket_interpreter/observer.rs | 1 - .../src/bucket_interpreter/write_collector.rs | 3 -- .../src/passes/conditional_flattening.rs | 4 --- .../deterministic_subcomponent_invocation.rs | 4 --- .../passes/loop_unroll/loop_env_recorder.rs | 4 --- circuit_passes/src/passes/loop_unroll/mod.rs | 4 --- .../src/passes/mapped_to_indexed.rs | 4 --- circuit_passes/src/passes/simplification.rs | 4 --- .../src/passes/unknown_index_sanitization.rs | 4 --- .../src/passes/unreachable_code_removal.rs | 4 --- .../src/passes/unused_func_removal.rs | 4 --- 12 files changed, 32 insertions(+), 40 deletions(-) diff --git a/circom/tests/controlflow/early_return_loop_1.circom b/circom/tests/controlflow/early_return_loop_1.circom index 34c68f921..cdc3b8a9f 100644 --- a/circom/tests/controlflow/early_return_loop_1.circom +++ b/circom/tests/controlflow/early_return_loop_1.circom @@ -38,6 +38,38 @@ component main = EarlyReturn(); //CHECK-NEXT: br label %branch1 //CHECK-EMPTY: //CHECK-NEXT: branch1: +//CHECK-NEXT: %0 = getelementptr [0 x i256], [0 x i256]* %lvars, i32 0, i32 1 +//CHECK-NEXT: %1 = load i256, i256* %0, align 4 +//CHECK-NEXT: %call.fr_eq = call i1 @fr_eq(i256 %1, i256 99) +//CHECK-NEXT: br i1 %call.fr_eq, label %if.then, label %if.else +//CHECK-EMPTY: +//CHECK-NEXT: if.then: +//CHECK-NEXT: br label %if.merge +//CHECK-EMPTY: +//CHECK-NEXT: if.else: +//CHECK-NEXT: br label %if.merge +//CHECK-EMPTY: +//CHECK-NEXT: if.merge: +//CHECK-NEXT: br label %assert5 +//CHECK-EMPTY: +//CHECK-NEXT: assert5: +//CHECK-NEXT: %2 = getelementptr [0 x i256], [0 x i256]* %lvars, i32 0, i32 0 +//CHECK-NEXT: %3 = load i256, i256* %2, align 4 +//CHECK-NEXT: %call.fr_eq1 = call i1 @fr_eq(i256 %3, i256 0) +//CHECK-NEXT: call void @__assert(i1 %call.fr_eq1) +//CHECK-NEXT: br label %store6 +//CHECK-EMPTY: +//CHECK-NEXT: store6: +//CHECK-NEXT: %4 = getelementptr [0 x i256], [0 x i256]* %lvars, i32 0, i32 1 +//CHECK-NEXT: %5 = getelementptr [0 x i256], [0 x i256]* %lvars, i32 0, i32 1 +//CHECK-NEXT: %6 = load i256, i256* %5, align 4 +//CHECK-NEXT: %call.fr_add = call i256 @fr_add(i256 %6, i256 1) +//CHECK-NEXT: store i256 %call.fr_add, i256* %4, align 4 +//CHECK-NEXT: br label %return7 +//CHECK-EMPTY: +//CHECK-NEXT: return7: +//CHECK-NEXT: ret void +//CHECK-NEXT: } //CHECK-LABEL: define{{.*}} i256 @noEarlyReturnFn_{{[0-9]+}}(i256* %0){{.*}} { //CHECK-NEXT: noEarlyReturnFn_[[$F_ID_2:[0-9]+]]: diff --git a/circuit_passes/src/bucket_interpreter/observer.rs b/circuit_passes/src/bucket_interpreter/observer.rs index c18c52082..b7d714edc 100644 --- a/circuit_passes/src/bucket_interpreter/observer.rs +++ b/circuit_passes/src/bucket_interpreter/observer.rs @@ -124,7 +124,6 @@ pub trait Observer { } } - fn ignore_subcmp_calls(&self) -> bool; fn ignore_function_calls(&self) -> bool; fn ignore_extracted_function_calls(&self) -> bool; } diff --git a/circuit_passes/src/bucket_interpreter/write_collector.rs b/circuit_passes/src/bucket_interpreter/write_collector.rs index 8e067a1a1..90b7d3817 100644 --- a/circuit_passes/src/bucket_interpreter/write_collector.rs +++ b/circuit_passes/src/bucket_interpreter/write_collector.rs @@ -318,9 +318,6 @@ mod tests { fn ignore_function_calls(&self) -> bool { false } - fn ignore_subcmp_calls(&self) -> bool { - false - } fn ignore_extracted_function_calls(&self) -> bool { false } diff --git a/circuit_passes/src/passes/conditional_flattening.rs b/circuit_passes/src/passes/conditional_flattening.rs index e91e3e0cc..3629a5d33 100644 --- a/circuit_passes/src/passes/conditional_flattening.rs +++ b/circuit_passes/src/passes/conditional_flattening.rs @@ -94,10 +94,6 @@ impl Observer> for ConditionalFlatteningPass<'_> { true } - fn ignore_subcmp_calls(&self) -> bool { - true - } - fn ignore_extracted_function_calls(&self) -> bool { false } diff --git a/circuit_passes/src/passes/deterministic_subcomponent_invocation.rs b/circuit_passes/src/passes/deterministic_subcomponent_invocation.rs index 1b2a4f2e3..63c331da1 100644 --- a/circuit_passes/src/passes/deterministic_subcomponent_invocation.rs +++ b/circuit_passes/src/passes/deterministic_subcomponent_invocation.rs @@ -73,10 +73,6 @@ impl Observer> for DeterministicSubCmpInvokePass<'_> { true } - fn ignore_subcmp_calls(&self) -> bool { - true - } - fn ignore_extracted_function_calls(&self) -> bool { false } diff --git a/circuit_passes/src/passes/loop_unroll/loop_env_recorder.rs b/circuit_passes/src/passes/loop_unroll/loop_env_recorder.rs index 2efcb0cbc..2c0cf8658 100644 --- a/circuit_passes/src/passes/loop_unroll/loop_env_recorder.rs +++ b/circuit_passes/src/passes/loop_unroll/loop_env_recorder.rs @@ -333,10 +333,6 @@ impl Observer> for EnvRecorder<'_, '_> { true } - fn ignore_subcmp_calls(&self) -> bool { - true - } - fn ignore_extracted_function_calls(&self) -> bool { true } diff --git a/circuit_passes/src/passes/loop_unroll/mod.rs b/circuit_passes/src/passes/loop_unroll/mod.rs index d41d1bbfb..06759dbb7 100644 --- a/circuit_passes/src/passes/loop_unroll/mod.rs +++ b/circuit_passes/src/passes/loop_unroll/mod.rs @@ -170,10 +170,6 @@ impl Observer> for LoopUnrollPass<'_> { false } - fn ignore_subcmp_calls(&self) -> bool { - true - } - fn ignore_extracted_function_calls(&self) -> bool { true } diff --git a/circuit_passes/src/passes/mapped_to_indexed.rs b/circuit_passes/src/passes/mapped_to_indexed.rs index f4945e494..ef198c4db 100644 --- a/circuit_passes/src/passes/mapped_to_indexed.rs +++ b/circuit_passes/src/passes/mapped_to_indexed.rs @@ -114,10 +114,6 @@ impl Observer> for MappedToIndexedPass<'_> { true } - fn ignore_subcmp_calls(&self) -> bool { - true - } - fn ignore_extracted_function_calls(&self) -> bool { false } diff --git a/circuit_passes/src/passes/simplification.rs b/circuit_passes/src/passes/simplification.rs index dd38fbc65..a2dca8472 100644 --- a/circuit_passes/src/passes/simplification.rs +++ b/circuit_passes/src/passes/simplification.rs @@ -161,10 +161,6 @@ impl Observer> for SimplificationPass<'_> { false } - fn ignore_subcmp_calls(&self) -> bool { - true - } - fn ignore_extracted_function_calls(&self) -> bool { true } diff --git a/circuit_passes/src/passes/unknown_index_sanitization.rs b/circuit_passes/src/passes/unknown_index_sanitization.rs index 0983d40ac..6a2645865 100644 --- a/circuit_passes/src/passes/unknown_index_sanitization.rs +++ b/circuit_passes/src/passes/unknown_index_sanitization.rs @@ -175,10 +175,6 @@ impl Observer> for UnknownIndexSanitizationPass<'_> { false } - fn ignore_subcmp_calls(&self) -> bool { - false - } - fn ignore_extracted_function_calls(&self) -> bool { true } diff --git a/circuit_passes/src/passes/unreachable_code_removal.rs b/circuit_passes/src/passes/unreachable_code_removal.rs index 66a9e3135..a54f4482e 100644 --- a/circuit_passes/src/passes/unreachable_code_removal.rs +++ b/circuit_passes/src/passes/unreachable_code_removal.rs @@ -90,10 +90,6 @@ impl Observer> for UnreachableRemovalPass<'_> { false // Observe within all functions } - fn ignore_subcmp_calls(&self) -> bool { - false // Observe within subcomponents - } - fn ignore_extracted_function_calls(&self) -> bool { false // Observe within all functions } diff --git a/circuit_passes/src/passes/unused_func_removal.rs b/circuit_passes/src/passes/unused_func_removal.rs index 672e9d02b..90074ce89 100644 --- a/circuit_passes/src/passes/unused_func_removal.rs +++ b/circuit_passes/src/passes/unused_func_removal.rs @@ -34,10 +34,6 @@ impl Observer<()> for UnusedFuncRemovalPass<'_> { false } - fn ignore_subcmp_calls(&self) -> bool { - false - } - fn ignore_extracted_function_calls(&self) -> bool { false }