-
-
Notifications
You must be signed in to change notification settings - Fork 115
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(stdlib): Marshal #1352
feat(stdlib): Marshal #1352
Conversation
ba032c7
to
8223491
Compare
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 like this approach and a good implementation too
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.
This is sweet! I didn't validate the low-level memory offsets and stuff but I trust they are working from the tests. Most of my comments center around Map.contains
followed by Map.get
which is doubling the cost of lookup. I also wondered why we don't use Set data types where they would work.
stdlib/marshal.gr
Outdated
if (isHeapPtr(value)) { | ||
let asInt32 = toGrain(newInt32(value)): Int32 | ||
if (Map.contains(asInt32, valuesSeen)) { | ||
// We've detected a cycle, and we'll refer the existing instance |
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.
// We've detected a cycle, and we'll refer the existing instance | |
// We've detected a cycle, and we'll refer to the existing instance |
stdlib/marshal.gr
Outdated
// if (Map.contains(asInt32, valuesSeen)) { | ||
// // Mark that there's a cycle | ||
// store(buf, _CYCLE_MARKER, offset) | ||
// store( | ||
// buf, | ||
// load(fromGrain(Option.unwrap(Map.get(asInt32, valuesSeen))), 8n), | ||
// offset + 4n | ||
// ) | ||
// offset + 8n | ||
// } else { |
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.
Are you keeping this for something?
stdlib/marshal.gr
Outdated
// We've detected a cycle, and we'll refer the existing instance | ||
acc | ||
} else { | ||
Map.set(asInt32, void, valuesSeen) |
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 are you setting void
here? Should this be a Set
?
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.
Just to avoid depending on another library since we've already got maps imported. I was worried about having the unnecessary module size increase, but I checked and the difference is only 6k.
stdlib/marshal.gr
Outdated
let asInt32 = toGrain(newInt32(value)): Int32 | ||
if (Map.contains(asInt32, valuesSeen)) { | ||
let ptr = load( | ||
fromGrain(Option.unwrap(Map.get(asInt32, valuesSeen))), |
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 would be a lot cheaper to Map.get
then pattern match on the option, right?
stdlib/marshal.gr
Outdated
let asInt32 = toGrain(newInt32(value)): Int32 | ||
if (Map.contains(asInt32, valuesSeen)) { | ||
let ptr = load( | ||
fromGrain(Option.unwrap(Map.get(asInt32, valuesSeen))), |
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.
Same question about get
stdlib/marshal.gr
Outdated
let asInt32 = toGrain(newInt32(subvalue)): Int32 | ||
if (Map.contains(asInt32, valuesUnmarshaled)) { | ||
let ptr = load( | ||
fromGrain(Option.unwrap(Map.get(asInt32, valuesUnmarshaled))), |
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.
👀
stdlib/marshal.gr
Outdated
let asInt32 = toGrain(newInt32(subvalue)): Int32 | ||
if (Map.contains(asInt32, valuesUnmarshaled)) { | ||
let ptr = load( | ||
fromGrain(Option.unwrap(Map.get(asInt32, valuesUnmarshaled))), |
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.
👀
stdlib/marshal.gr
Outdated
let asInt32 = toGrain(newInt32(subvalue)): Int32 | ||
if (Map.contains(asInt32, valuesUnmarshaled)) { | ||
let ptr = load( | ||
fromGrain(Option.unwrap(Map.get(asInt32, valuesUnmarshaled))), |
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.
👀
stdlib/marshal.gr
Outdated
let asInt32 = toGrain(newInt32(subvalue)): Int32 | ||
if (Map.contains(asInt32, valuesUnmarshaled)) { | ||
let ptr = load( | ||
fromGrain(Option.unwrap(Map.get(asInt32, valuesUnmarshaled))), |
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.
👀
stdlib/marshal.gr
Outdated
let asInt32 = toGrain(newInt32(subvalue)): Int32 | ||
if (Map.contains(asInt32, valuesUnmarshaled)) { | ||
let ptr = load( | ||
fromGrain(Option.unwrap(Map.get(asInt32, valuesUnmarshaled))), |
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.
This PR implements serialization and deserialization of Grain values, useful for a variety of purposes like transmission across a network or storing values on disk to use later.