Skip to content
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

Merged
merged 2 commits into from
Aug 5, 2022
Merged

feat(stdlib): Marshal #1352

merged 2 commits into from
Aug 5, 2022

Conversation

ospencer
Copy link
Member

@ospencer ospencer commented Jul 2, 2022

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.

@ospencer ospencer self-assigned this Jul 2, 2022
@ospencer ospencer force-pushed the oscar/marshall branch 3 times, most recently from ba032c7 to 8223491 Compare July 8, 2022 16:32
@ospencer ospencer changed the title feat(stdlib): Marshall feat(stdlib): Marshal Jul 11, 2022
@ospencer ospencer marked this pull request as ready for review July 11, 2022 04:48
@ospencer ospencer requested a review from a team July 11, 2022 04:48
Copy link
Member

@marcusroberts marcusroberts left a 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

Copy link
Member

@phated phated left a 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.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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

Comment on lines 188 to 197
// 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 {
Copy link
Member

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?

// We've detected a cycle, and we'll refer the existing instance
acc
} else {
Map.set(asInt32, void, valuesSeen)
Copy link
Member

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?

Copy link
Member Author

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.

let asInt32 = toGrain(newInt32(value)): Int32
if (Map.contains(asInt32, valuesSeen)) {
let ptr = load(
fromGrain(Option.unwrap(Map.get(asInt32, valuesSeen))),
Copy link
Member

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?

let asInt32 = toGrain(newInt32(value)): Int32
if (Map.contains(asInt32, valuesSeen)) {
let ptr = load(
fromGrain(Option.unwrap(Map.get(asInt32, valuesSeen))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question about get

let asInt32 = toGrain(newInt32(subvalue)): Int32
if (Map.contains(asInt32, valuesUnmarshaled)) {
let ptr = load(
fromGrain(Option.unwrap(Map.get(asInt32, valuesUnmarshaled))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

let asInt32 = toGrain(newInt32(subvalue)): Int32
if (Map.contains(asInt32, valuesUnmarshaled)) {
let ptr = load(
fromGrain(Option.unwrap(Map.get(asInt32, valuesUnmarshaled))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

let asInt32 = toGrain(newInt32(subvalue)): Int32
if (Map.contains(asInt32, valuesUnmarshaled)) {
let ptr = load(
fromGrain(Option.unwrap(Map.get(asInt32, valuesUnmarshaled))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

let asInt32 = toGrain(newInt32(subvalue)): Int32
if (Map.contains(asInt32, valuesUnmarshaled)) {
let ptr = load(
fromGrain(Option.unwrap(Map.get(asInt32, valuesUnmarshaled))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

let asInt32 = toGrain(newInt32(subvalue)): Int32
if (Map.contains(asInt32, valuesUnmarshaled)) {
let ptr = load(
fromGrain(Option.unwrap(Map.get(asInt32, valuesUnmarshaled))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@ospencer ospencer merged commit d659de2 into main Aug 5, 2022
@ospencer ospencer deleted the oscar/marshall branch August 5, 2022 03:33
@github-actions github-actions bot mentioned this pull request Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants