-
Notifications
You must be signed in to change notification settings - Fork 111
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(docs): asm
functions
#1061
base: main
Are you sure you want to change the base?
Conversation
… make it more streamlined
Co-authored-by: Anton Trunov <[email protected]>
asm(-> 1 0) extends mutates fun asmLoadCoins(self: Slice): Int { LDVARUINT16 } | ||
// --- | ||
// Notice, that return values are best thought as tuples with indexed access into them | ||
// and not as bottom-up representation of stack values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably we need to clarify this in a more detailed example (tutorial-like), because the connection with the stack is very vague and confusing. I can do such detailed example in a separate page, and then I can add a link in here to such page. I can work on that example as a separate PR, since now I am working on writing docs. What do you think? Do you suggest I should use the same TVM instructions you were using in these examples or should I use another TVM instruction that produces at least 3 or more results to exemplify the use of structs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense. If that's a tutorial-like example (for the Cookbook, I presume), then I'd use some other instruction with 3+ results to exemplify the use of Structs, exactly :)
UPD: Well, since my original answer I discovered that unused values are discarded only when the primitive type is specified as the return type. And now the idea of a tutorial makes much less sense to me — it's better that we improve descriptions here and now. But I may be totally wrong
I agree that this is confusing, and I think that the cause is that we are mixing two mental models: a stack (low-level) and tuples (high-level). We should pick only one and stick with it the entire explanation. It seems that describing everything in terms of tuples is more intuitive, but then we should not mention the stack (or mention how tuples are pushed and popped from a stack in a separate subsection, and only in that section mention the stack). So, for example, I would start the examples saying something about the TVM instructions, something like this: " Then, explaining the meaning of a declaration like:
amounts to saying simply: " |
@jeshecdom interesting note. The cases with multiple instructions should be covered too. And tuples on TON are denoted with square brackets @anton-trunov wdyt about #1061 (comment)? |
this is incorrect in a very specific technical sense: a tuple is a TVM data structure that occupy precisely one TVM stack position but can contain multiple other TVM primitives, including tuples the term you probably intended to use is tensor |
I find it confusing |
@novusnota just adapt the corresponding calling convention description from tvm.pdf |
@novusnota you also need to check how structures that are returned from a function are actually encoded |
To fully finish this section, #910 needs to be resolved too |
I meant mathematical tuple, but now I see that this would introduce much more confusion because of the technical terms in TVM. So, the explanation should stick with the stack and use the technical terms in TVM. |
Yeah, we should stick with the stack explanation and use the technical terms in TVM, because I see everyone is confused now :). But the way, a question: In a function like this:
Does Tact know that after executing those instructions, there will be exactly 5 results in the stack? |
not in the current implementation
nope (the consequence of the previous answer) This should be documented, of course, but an even more important question is "are returned structs actually represented as tensors (multiple TVM values)?" |
and, of course, the symmetrical question for input function parameters (including passing structs) |
in any case, each such point should be accompanied by a concrete example of an |
Sure, the
Nope, at the moment it's all handled by FunC, which it turn just passes it to Fift, which does all the work. Neither Tact nor FunC check anything until it's too late and user hits exit code 5, 7, or whatever else. Also, there could be more things in the stack, only the topmost 5 are of interest if we know that after all the instructions we need 5 values.
👍 |
@jeshecdom when we have the grammar and AST for our embedded assembly language then we will be able to typecheck asm-functions and warn the user their stack discipline makes sense |
We could do the following with specific examples (previously, we should have explained how function arguments are pushed into the stack):
|
Eh, Structs are represented as tensors So I'm a bit hesitant on explaining things in tensors, and instead let's just properly describe stack and stack registers. |
Sounds good. |
sounds good to me too, since tvm.pdf does not even mention tensors, looks like it's a term coined by the FunC community |
And updated the version of Starlight used
|
Rewrote the method ID collisions section to remove all logical jumps and make it much more streamlined :)
Also adjusted the structure a little towards the upcoming PR revamping this page. I'll push the draft of it right after we deal with asm functions here.
P.S.: I actually call argument to return position mappings "arrangements" and not "shuffle" as in
grammar.ohm
, because the latter kinda implies randomness, while those are actually deterministic. Hence, "asm arrangments".Issue
asm
functions #1011.tact-docs
)Also, resolved two teeny tiny issues from
tact-docs
— virtually 3-5 lines of fixes for each, no need in a separate CHANGELOG entry:fromSlice
tact-docs#368Checklist