Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
docs: Added initial architecture decision records #1
docs: Added initial architecture decision records #1
Changes from 7 commits
4921462
ec5e69e
29c9a99
42661d0
1facddf
0ad42fe
4390ae2
23ef10c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
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 have a slightly more nuanced view of this.
There should be default typing options that meet this principle. Like how in Algorand Python if you use a
UInt64
orString
then Puya takes care of encoding/decoding for you.But, I think it's important to also have control over that stuff when you want/need it, or there isn't a direct translation between AVM primitives and the ABI type. The way this was achieved in Algorand Python was to have primitive types (e.g.
UInt64
,String
) that automatically get decoded and encoded on their way in/out and represented with the equivalent ABI type in ARC-32/4, but then to expose specific ABI encoded types in a separate (arc4) namespace, so when you want to work with the encoded data you can do that too (and those types all have a.native
property to easily decode to the relevant underlying AVM type. Reference: https://algorandfoundation.github.io/puya/lg-types.htmlRegardless, this is not relevant to these ADRs because they are talking about AVM primitive types. We plan on having a separate ADR to discuss how ABI types are handled.
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.
What are the scenarios where a developer wants to perform operations on the encoded bytes? Seems to be very rare. For edge cases TEALScript provides a
rawBytes
function that will give you the encodedbytes
of the value.Ah gotcha. I do think they are a bit linked though because compatibility between native types and ABI types is important. It's something develoeprs have tripped up on with Beaker and Algorand Python
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.
The main problem with having non-implemented functions is them still showing IDE, but we can solve this with plugins
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.
It's also name clashes. e.g. if we want a
length
method that returnsuint64
then you can't do it with extending string prototype.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.
But I thought we were after semantic compatibility with TypeScript, not EcmaScript?
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.
TypeScript being a superset of EcmaScript takes its
string
semantics from EcmaScript so it made more sense to me to reference the latter. This will probably apply in most cases. Maybe it's not valuable to distinguish between the two and we should just use 'TypeScript' everywhere.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 the distinction is semantic compatibility with the runtime vs semantic compatibility with the type system. We know we'll have a transformer to adjust runtime behavior, thus is still seems reasonable to me to use
string
to representutf-8
strings (much like how we can usenumber
to representuint64
).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.
Semantic compatibility means given some typescript code - it either runs the same in our execution environment (test execution and AVM execution), or doesn't run at all (if we don't support a given syntax).
AlgoTS will need to introduce several types that don't exist in any existing javascript execution environment so there is no expectation that you will be able to lift AlgoTS code and run it in a browser but the syntax and semantics should be the same.
For the reasons listed above I think it is impractical to have a string type on the avm behave the same as the typescript/ecmascript string so we would be better off introducing a new type that doesn't carry any semantic expectations.
As another example, given this function
When you pass in the string "a", you would get "a" back in any javascript execution environment - and the same in TealScript; however if you pass in the string "ā", you would get "ā" back in any javascript execution environment - but you'll get
0xC4
in TealScript (an invalid utf8 string)With regards to
number
we deliberately don't expose the type asnumber
and force implicit and explicit casts when dealing with literals and operations. In other words we pretend to introduce a new typeuint64
without semantic expectations but are forced (by limitations of typescript/ecmascript) to depend onnumber
underneath.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.
Ah ok thanks for the example. That makes sense.
Perhaps a viable option here is also a branded
string
with the upside being string literal supportThere 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.
A branded string is definitely an option - the major con is the crowded prototype which we can (probably??) clean up with a plugin, but that's additional complication (and development effort). It feels like a lot to pay to get plain literals
"hello"
over tagged literalsStr`hello`
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.
Yeah true, branded strings still would't address the incorrect intuition of
str[x]
accessing byte x rather than character x.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.
Minor detail, but I would propose we take inspiration from Python and use
b
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 did explore this but found (at least in contrived example code) the likelihood of a name clash with a local variable to be quite high. eg.
const [a, b, c] = someArray
. This resulted in an unfriendly error. We could useB
if we prefer to be terse at the expense of clarity.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.
Ah right yeah you did mention that. I don't feel strongly either way so we should just see what existing developers would prefer.