-
Notifications
You must be signed in to change notification settings - Fork 1
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
ITF serialization of Value
s
#36
Conversation
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.
A first set of comments.
The ITF-serialization of state looks good.
I've not had time to look at all the code for supporting nonhomogenous collections.
solarkraft/src/io/itf.ts
Outdated
case 'arr': | ||
// array of 0/1 s, must be wrapped | ||
return v.val.map(numWrap) |
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.
afaict, for a byte[] = 101 this would give
[{
"#bigint": "1"
}, {
"#bigint": "0"
}, {
"#bigint": "1"
}]
?
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.
Yes, I did it for consistency, but for Bytes
specifically, we could deviate from ITF and just use the JS numbers, since it's only 0s and 1s, b/c I do agree that it's a bit clunky.
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.
If it's an array of zeroes and ones, why would not we just wrap it as a string, e.g., by introducing a new kinds of a field { "#bytes": "101" }
, or by just using an array of numbers, as you are suggesting. Actually, ITF does not prohibit JS numbers from being used for the small ranges.
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.
IIRC we had a discussion about standardizing this in Apalache where every value was #bigint
. But yeah, we don't have to 100% copy ITF here
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.
Why do we encode a bytes[]
as bits in the first place?
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.
because I'm illiterate apparently
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.
Is this question resolved? I am not sure I understand the last comment.
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.
Yes, I fixed it. bytes = number
now, and the validations check for 2^8
solarkraft/src/state/value.ts
Outdated
case 'arr': | ||
return 'Bytes' |
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.
How is 'arr' different from the other basic types?
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'll add a comment about this inline, but I wanted to convey that Bytes
, while it is a collection, is basically atomic as a type, since it's always an array of exactly 0s or 1s. I felt like using the word array
/arr
might give the impression that this is an array in the traditional sense, i.e. a fixed-sized ordered collection of arbitrary values, which is very much not supported (but there is Vec
).
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 added a comment on that. I think it would improve our understanding of the issue if you added a link to the original description of this datatypes in Stellar or Soroban SDK?
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.
Left a few comments
solarkraft/src/io/itf.ts
Outdated
case 'arr': | ||
// array of 0/1 s, must be wrapped | ||
return v.val.map(numWrap) |
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.
If it's an array of zeroes and ones, why would not we just wrap it as a string, e.g., by introducing a new kinds of a field { "#bytes": "101" }
, or by just using an array of numbers, as you are suggesting. Actually, ITF does not prohibit JS numbers from being used for the small ranges.
solarkraft/src/io/itf.ts
Outdated
timeStyle: 'long', | ||
}) | ||
|
||
// const desc = `Created by Solarkraft on ${formatter.format(new Date().getTime())}` |
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.
// const desc = `Created by Solarkraft on ${formatter.format(new Date().getTime())}` |
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.
Oh, actually, considering the other response I made, it should be this line that stays uncommented and the line below removed. Either way, do you have a preference for one of the two approaches to dates?
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.
Idk. Perhaps, using the UTC date would be more consistent. I don't have any strong preference.
} | ||
|
||
// Returns the full type annotation of the provided (possibly complex) Value `v`. | ||
// It uses Apalache-style type notation, with Soroban type primitives. |
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 is Apalache-style type notation? What we see below looks like Soroban to me.
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.
Well, our "maps" are A -> B
@Kukovec your last commit deleted ~2kLOC from the npm lockfile. |
I have not touched it beyond what |
Oh, that's indeed strange. It looks like all of |
I just took the |
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 left a few comments on the unresolved issues. I think we should resolve as much as we can asap and merge this PR.
solarkraft/src/state/value.ts
Outdated
// As a type, `Bytes` is atomic, even though it is an array. We avoid `arr`, as it could imply | ||
// a generic array type, which does not exist. | ||
return 'Bytes' |
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 do not understand what it means for a type to be atomic. Atomicity means that a value is updated in a single machine instruction, or it is updated in a way such that another thread/process cannot interfere with an update. Do you mean that a value of type Bytes
is opaque in the sense that it cannot be decomposed into smaller pieces? I am still not sure about the second sentence. What is a generic array type that does not exist?
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.
Atomic as in the smallest type-term (or in this context, not a generic collection). E.g. Array[T]
would be a generic array, which Bytes
is not. There is Vec
, which is a dynamic, non-fixed sized collection, but there are no arrays in the Rust sense.
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'll rewrite this a bit.
solarkraft/src/state/value.ts
Outdated
case 'arr': | ||
return 'Bytes' |
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 added a comment on that. I think it would improve our understanding of the issue if you added a link to the original description of this datatypes in Stellar or Soroban SDK?
solarkraft/src/io/itf.ts
Outdated
timeStyle: 'long', | ||
}) | ||
|
||
// const desc = `Created by Solarkraft on ${formatter.format(new Date().getTime())}` |
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.
Idk. Perhaps, using the UTC date would be more consistent. I don't have any strong preference.
closes #35
Introduces the following:
State
typeu32
,symb
, etc.)