Skip to content

Spotandjake/gc stdlib#2364

Open
spotandjake wants to merge 12 commits intooscar/gc-rebasedfrom
spotandjake/gc-stdlib
Open

Spotandjake/gc stdlib#2364
spotandjake wants to merge 12 commits intooscar/gc-rebasedfrom
spotandjake/gc-stdlib

Conversation

@spotandjake
Copy link
Member

No description provided.

@spotandjake spotandjake force-pushed the spotandjake/gc-stdlib branch from 030212b to bac0d78 Compare March 1, 2026 01:09
Copy link
Member Author

Choose a reason for hiding this comment

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

I added a few more tests here, because I noticed we were never really validating the encoding itself just the operation. These tests validate things like endianness.

let buf = Buffer.make(0)
Buffer.addBytes(bytes, buf)
assert Buffer.toBytes(buf) == bytes
let buffer = Buffer.make(0)
Copy link
Member Author

Choose a reason for hiding this comment

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

I ran into a bug elsewhere for this in the stdlib and figured it should have a dedicated test.

Copy link
Member Author

Choose a reason for hiding this comment

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

There still seems to be a bug in atof somewhere causing overreads and slightly invalid numbers which is causing the Number and Json modules to fail their test.

I was having trouble tracking down the source though. I noticed that there are some cases where we were a bit laxed on our boundary checks before here, which may be part of the problem.

i += 1n
} else {
break
if (i < len) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is one such case where we were being a bit laxed before, the loop could go all the way to len and then when this tries to read it fails. I tried to correct the cases I could find, but I couldn't track them all down.


let simple = tagSimpleNumber(n)

if (untagSimpleNumber(simple) is n) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The is check here was causing an invalid module error.

provide let _GRAIN_NUMBER_TAG_TYPE = 0b0001n
provide let _GRAIN_SHORTVAL_TAG_TYPE = 0b0010n
provide let _GRAIN_CONST_TAG_TYPE = 0b0110n
provide let _GRAIN_GENERIC_HEAP_TAG_TYPE = 0b0000n
Copy link
Member Author

Choose a reason for hiding this comment

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

This is no longer a concept


// Handle lists separately to avoid stack overflow
if (DataStructures.loadVariantTypeId(xptr) is _LIST_ID) {
if (xVariantTag >> 1n == 1n) return true // End of list
Copy link
Member Author

Choose a reason for hiding this comment

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

I think you introduced this bug in one of your prior commits, but we already untagged it. So this was causing equality issues.

@@ -63,6 +62,7 @@ primitive typeMetadata = "@heap.type_metadata"
let findTypeMetadata = typeHash => {
let typeMetadata = typeMetadata()
Copy link
Member Author

Choose a reason for hiding this comment

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

I think we may want to make typeMetadata() return -1 or 0 if type metadata is elided. I need the eqz check on the number of buckets or we get a divide by zero error.

8n
)
ignore(array)
arr[i] = (key, value)
Copy link
Member Author

Choose a reason for hiding this comment

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

We may want to consider doing this in more of the places we are doing Array.setAnyValue

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.

1 participant