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: describe evaluation strategies of Tact #311

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

novusnota
Copy link
Member

@novusnota novusnota commented Jul 11, 2024

WIP: Need to move/refine examples of assignments and function calls from the playground contracts

Closes #251
Towards #105 (in some sense)


### Binding strategy [#runtime-binding]

Tact uses the [call by value (CBV)](https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_value) parameter-passing and binding strategy. That is, the evaluated value of any variable passed in a function call (except for [receivers](/book/contracts#receiver-functions) and [getters](/book/contracts#getter-functions)) or assigned in the [`let{:tact}`](/book/statements#let) or [assignment](/book/statements#assignment) statement is copied. This prevents mutations of the original values in different scopes, but increases the gas usage.
Copy link
Member

Choose a reason for hiding this comment

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

Let's also clarify that copying happens for structs and maps as well

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure!

@anton-trunov
Copy link
Member

The draft looks good!


### Binding strategy [#runtime-binding]

Tact uses the [call by value (CBV)](https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_value) parameter-passing and binding strategy. That is, the evaluated value of any variable passed in a function call (except for [receivers](/book/contracts#receiver-functions) and [getters](/book/contracts#getter-functions)) or assigned in the [`let{:tact}`](/book/statements#let) or [assignment](/book/statements#assignment) statement is copied. This prevents mutations of the original values in different scopes, but increases the gas usage.
Copy link
Member

Choose a reason for hiding this comment

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

There is one missing piece though: mutating methods! Those cannot not copy their self argument

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but those aren't part of the binding strategy, just as assignments to struct/message fields, map.set()/del(), or any other re-assignments to local or state/storage variables. Like, the only things actively preventing re-assignments are constants :)

I can create a list of "allowed mutations" or say something about constants, not sure

Copy link
Member

Choose a reason for hiding this comment

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

what about things like "small byte arrays"? tact-lang/tact#163 (comment)

@tact-lang tact-lang deleted a comment from TolyaTTT Jul 13, 2024
@tact-lang tact-lang deleted a comment from TolyaTTT Jul 13, 2024
@novusnota novusnota added this to the v1.4.0 milestone Jul 16, 2024
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.

Clarify assignment semantics
2 participants