cairo-vm icon indicating copy to clipboard operation
cairo-vm copied to clipboard

fix: remove static lifetime for name str parameter requirement for constant getter

Open Eikix opened this issue 1 year ago • 2 comments

remove static lifetime for name str parameter requirement for constant getter

Description

Hey! I noticed get_constant_from_var_name has a different signature from other hint_utils helper functions, namely that it has a bound of static lifetime on the name parameter. I noticed it mainly comes from the error signature HintError::MissingConstant.

I changed the signature of MissingConstant to match other errors: from Box<'static &str> to Box using the same util you use around the hint error codebase: var_name.to_string().into_boxed_str().

In doing this, one no longer needs to have 'static strings for constant getting -> this will allow me in next PRs to have dynamic constant name getting, i.e., in garaga there are constant limbs of Prime P of the BN Curve. And depending on N_LIMBS, we'll get P_i.

Let me know if this works!

Resolves: #1522

Description of the pull request changes and motivation.

Checklist

  • [x] Linked to Github Issue
  • [ ] Unit tests added
  • [ ] Integration tests added.
  • [ ] This change requires new documentation.
    • [ ] Documentation has been added/updated.
    • [ ] CHANGELOG has been updated.

Eikix avatar Dec 21 '23 16:12 Eikix

Codecov Report

Attention: Patch coverage is 79.31034% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 97.11%. Comparing base (f47f760) to head (6b22b68).

:exclamation: Current head 6b22b68 differs from pull request most recent head 97bb7df. Consider uploading reports for the commit 97bb7df to get more accurate results

Files Patch % Lines
...uiltin_hint_processor/cairo_keccak/keccak_hints.rs 71.42% 4 Missing :warning:
...int_processor/builtin_hint_processor/math_utils.rs 77.77% 2 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1523      +/-   ##
==========================================
+ Coverage   94.76%   97.11%   +2.34%     
==========================================
  Files         101       91      -10     
  Lines       38826    37248    -1578     
==========================================
- Hits        36795    36172     -623     
+ Misses       2031     1076     -955     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Dec 21 '23 16:12 codecov[bot]

Applying this patch should fix the linter:

diff --git a/vm/src/hint_processor/builtin_hint_processor/math_utils.rs b/vm/src/hint_processor/builtin_hint_processor/math_utils.rs
index 68cb30fc1..bbe18b5d7 100644
--- a/vm/src/hint_processor/builtin_hint_processor/math_utils.rs
+++ b/vm/src/hint_processor/builtin_hint_processor/math_utils.rs
@@ -2085,7 +2085,7 @@ mod tests {
         //Execute the hint
         assert_matches!(
             run_hint!(vm, ids_data, hint_code),
-            Err(HintError::MissingConstant(bx)) if *bx == ADDR_BOUND.to_string()
+            Err(HintError::MissingConstant(bx)) if &*bx == ADDR_BOUND
         );
     }
 
@@ -2309,7 +2309,7 @@ mod tests {
         //Execute the hint
         assert_matches!(
             run_hint!(vm, ids_data, hint_code),
-            Err(HintError::MissingConstant(x)) if (*x) == "MAX_HIGH".to_string()
+            Err(HintError::MissingConstant(x)) if &*x == "MAX_HIGH"
         );
     }
 
diff --git a/vm/src/hint_processor/builtin_hint_processor/uint384.rs b/vm/src/hint_processor/builtin_hint_processor/uint384.rs
index 4e2bb4412..9f6646dd3 100644
--- a/vm/src/hint_processor/builtin_hint_processor/uint384.rs
+++ b/vm/src/hint_processor/builtin_hint_processor/uint384.rs
@@ -535,7 +535,7 @@ mod tests {
         //Execute the hint
         assert_matches!(
             run_hint!(vm, ids_data, hint_code::ADD_NO_UINT384_CHECK),
-            Err(HintError::MissingConstant(bx)) if *bx == "SHIFT".to_string()
+            Err(HintError::MissingConstant(bx)) if &*bx == "SHIFT"
         );
     }

Oppen avatar Jan 22 '24 18:01 Oppen