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

feat(VM): propagate values from immutable variables #2801

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

petar-dambovaliev
Copy link
Contributor

@petar-dambovaliev petar-dambovaliev commented Sep 14, 2024

If variables have constant values of a primitive type and they are never mutated (or mutated by constant expressions),
just like values from constants are currently propagated, we can do the same for this set of variables.
This is an optimization to avoid computation like searching for the value through the name valuepath during runtime.

Conditions for propagation

  • There is no mutation
  • There are no references given out
  • The initial value during definition is a literal
  • The type of the value is primitive

This must be done in 2 passes.
First pass needs to establish which variables adhere to these conditions and mark them.
The second pass can do this propagation based on that metadata.

Here is an example.

func Foo(b int) {
   a := 5
   
   if a > 1 {
      println(a)
   } 
}

This code would turn into

func Foo(b int) {
   a := 5
   
   if 5 > 1 {
      println(5)
   } 
}

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Sep 14, 2024
Copy link

codecov bot commented Sep 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.84%. Comparing base (8a62a28) to head (c81683b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2801      +/-   ##
==========================================
- Coverage   60.95%   60.84%   -0.12%     
==========================================
  Files         564      563       -1     
  Lines       75273    75137     -136     
==========================================
- Hits        45884    45717     -167     
- Misses      26019    26055      +36     
+ Partials     3370     3365       -5     
Flag Coverage Δ
contribs/gnofaucet 14.46% <ø> (ø)
misc/genstd 80.54% <ø> (ø)
misc/logos 20.23% <ø> (+0.35%) ⬆️
tm2 62.10% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: No status
Status: In Progress
Development

Successfully merging this pull request may close these issues.

1 participant