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

add method to encode tuple element #624

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

barnjamin
Copy link
Contributor

@barnjamin barnjamin commented Dec 23, 2022

I just want bytes, no need for other scratch vars or lambdas

diff from a program where i switched to this:

image

pyteal/ast/abi/tuple.py Outdated Show resolved Hide resolved
@ahangsu ahangsu self-requested a review December 28, 2022 18:26
pyteal/ast/abi/tuple.py Outdated Show resolved Hide resolved
pyteal/ast/abi/tuple.py Outdated Show resolved Hide resolved
pyteal/ast/abi/tuple.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ahangsu ahangsu left a comment

Choose a reason for hiding this comment

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

overall looks good and correct in implementation, need changelog entry and resolve discussion thread on encode method.

Copy link
Contributor

@jasonpaulos jasonpaulos left a comment

Choose a reason for hiding this comment

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

Generally makes sense, but I'd like to see sufficient test coverage too. (Check out test_indexTuple in pyteal/ast/abi/tuple_test.py for coverage of _index_tuple for inspiration)

pyteal/ast/abi/tuple.py Outdated Show resolved Hide resolved
pyteal/ast/abi/tuple.py Outdated Show resolved Hide resolved
pyteal/ast/abi/tuple.py Outdated Show resolved Hide resolved
@ahangsu
Copy link
Contributor

ahangsu commented Jan 4, 2023

I am still opinionated on this one tho, after some more thoughts. Maybe I am wrong.

This encode method applies to all ComputedType, so it also applies to ReturnedType which wraps up a computation returning something on stack. What if the encode called twice for a ReturnedType instance with a computation that has side effect? That would not be ideal.

@barnjamin barnjamin marked this pull request as ready for review January 12, 2023 12:53
@barnjamin barnjamin requested review from bbroder-algo and jasonpaulos and removed request for michaeldiamant January 12, 2023 12:54
@bbroder-algo
Copy link
Contributor

barnjamin can you please speak with Hang to elaborate his concerns regarding multiple instance requests of ReturnedType

pyteal/ast/abi/array_base.py Outdated Show resolved Hide resolved
pyteal/ast/abi/util.py Show resolved Hide resolved
pyteal/ast/abi/array_base_test.py Show resolved Hide resolved
@barnjamin
Copy link
Contributor Author

@ahangsu correctly notes that if someone were to call something like encode multiple times on a ReturnedValue the computation Expr would be run again.

However, this behavior is already present in the current release. While it isn't ideal I think it shouldn't be a show stopped for this pr. Perhaps another pr that improves how a ReturnedValue caches its computation (via scratch var or otherwise?) is warranted.

@ahangsu ahangsu force-pushed the tuple-element-encode branch 2 times, most recently from 2852bef to abe8203 Compare February 1, 2023 16:50
@barnjamin
Copy link
Contributor Author

I forgot about this one, assuming the conflict is resolved is it good to merge?

cc @ahangsu @bbroder-algo

Copy link
Contributor

@bbroder-algo bbroder-algo left a comment

Choose a reason for hiding this comment

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

lgtm

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.

5 participants