Skip to content

fix(stdlib): Ensure consistent marshal representation #2045

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

Merged
merged 4 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/test/stdlib/marshal.test.gr
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ let truncatedRecord = Bytes.slice(
)
)
assert Result.isErr(unmarshal(truncatedRecord))

assert Marshal.marshal("🌾") == Marshal.marshal("🌾")
3 changes: 3 additions & 0 deletions stdlib/marshal.gr
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Marshal
include "runtime/unsafe/wasmi32"
use WasmI32.{
(+),
(-),
(*),
(&),
(==),
Expand Down Expand Up @@ -196,6 +197,7 @@ let rec marshalHeap = (heapPtr, buf, offset, valuesSeen) => {
t when t == Tags._GRAIN_STRING_HEAP_TAG || t == Tags._GRAIN_BYTES_HEAP_TAG => {
let size = 8n + load(heapPtr, 4n)
Memory.copy(buf + offset, heapPtr, size)
Memory.fill(buf + offset + size, 0n, roundTo8(size) - size)
roundTo8(offset + size)
},
t when t == Tags._GRAIN_ADT_HEAP_TAG => {
Expand Down Expand Up @@ -426,6 +428,7 @@ provide let marshal = value => {
let valuePtr = fromGrain(value)
let buf = allocateBytes(size(valuePtr))
marshal(valuePtr, buf + 8n)
ignore(value)
toGrain(buf): Bytes
}

Expand Down