Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

feat: describe evaluation strategies of Tact #311

Closed
wants to merge 1 commit into 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 tact-lang/tact#1163
Towards tact-lang/tact#1097 (in some sense)

@novusnota novusnota requested a review from anton-trunov July 11, 2024 10:04

### 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
@novusnota novusnota modified the milestones: v1.4.0, v1.6.0 Sep 30, 2024
@anton-trunov
Copy link
Member

Closing this in favor of re-opening in the tact-lang/tact repo where the docs migrated a while ago

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clarify assignment semantics
2 participants