Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Eikix
Copy link
Contributor

@Eikix Eikix commented Dec 21, 2023

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

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

fmoletta
fmoletta previously approved these changes Dec 21, 2023
Copy link
Member

@fmoletta fmoletta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 🚀 Please update the CHANGELOG file

Copy link

codecov bot commented Dec 21, 2023

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).

❗ 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 ⚠️
...int_processor/builtin_hint_processor/math_utils.rs 77.77% 2 Missing ⚠️
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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Oppen
Oppen previously approved these changes Dec 21, 2023
@Eikix Eikix dismissed stale reviews from Oppen and fmoletta via a2a932e December 21, 2023 17:25
@Eikix Eikix force-pushed the fix/get_constant_from_var_name branch from 5789f5e to a2a932e Compare December 21, 2023 17:25
@Eikix Eikix force-pushed the fix/get_constant_from_var_name branch from a272b73 to 42db06f Compare December 22, 2023 10:19
Oppen
Oppen previously approved these changes Dec 22, 2023
fmoletta
fmoletta previously approved these changes Dec 22, 2023
@Oppen Oppen dismissed stale reviews from fmoletta and themself via 0fb5a76 December 22, 2023 17:02
Oppen
Oppen previously approved these changes Jan 22, 2024
fmoletta
fmoletta previously approved these changes Jan 22, 2024
@Oppen Oppen enabled auto-merge January 22, 2024 18:17
@Oppen Oppen disabled auto-merge January 22, 2024 18:17
@Oppen
Copy link
Member

Oppen commented Jan 22, 2024

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"
         );
     }

@Eikix Eikix dismissed stale reviews from fmoletta and Oppen via 97a582b January 23, 2024 08:00
@Oppen Oppen enabled auto-merge May 9, 2024 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor: change lifetime for parameter var_name of get_constant_from_var_name from 'static to 'a
3 participants