algorand / pyteal

Algorand Smart Contracts in Python
https://pyteal.readthedocs.io
MIT License
288 stars 130 forks source link

Optimized local variable allocation scheme #684

Closed ahangsu closed 1 year ago

ahangsu commented 1 year ago

Squeeze out over allocated spaces, dry the sponge.

This PR serves as a fix (or optimization) for local variable allocation in frame pointer based compilation (avm-ver $\ge$ 8).

The problem is that, frame pointer based compilation leads to ABI value allocation "context sensitive":

This PR's contribution is following 2-folds:

  1. Fixed the subroutine evaluation process, that:
    • allocates arguments + output values under right proto
    • separation between frame based evaluation and scratch based evaluation
  2. Minor changed integration test - ABIRoundtrip test code generation logic, as stated above that ABI value new instance is "context sensitive", then we create needed instance inside subroutine of generated code. This removed previously unnoticed scratch slot usage in tuple related roundtrip test (which is tricky, for the assumption on newing instance changed subtly).
ahangsu commented 1 year ago

BTW, we can't merge in like this - there are experimental code in compilation (some option to activate/deactivate). We probably need to settle down about merge to where, how to merge.