Skip to content

runtime: make arrays and struct field hashes order dependent - #5581

Merged
dgryski merged 1 commit into
tinygo-org:devfrom
dgryski:dgryski/array-struct-hash
Aug 12, 2026
Merged

runtime: make arrays and struct field hashes order dependent#5581
dgryski merged 1 commit into
tinygo-org:devfrom
dgryski:dgryski/array-struct-hash

Conversation

@dgryski

@dgryski dgryski commented Aug 11, 2026

Copy link
Copy Markdown
Member

Tweak the hash to ensure that [1, 2] has a different hash value from [2, 1]

@dgryski
dgryski requested a review from jakebailey August 12, 2026 18:29

@jakebailey jakebailey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was this motivated by something?

(Seems fine of course)

Comment thread src/runtime/hashmap.go
Comment on lines 775 to 777
if x.RawType().Size() <= unsafe.Sizeof(uintptr(0)) {
// Value fits in pointer, so it's directly stored in the pointer.
ptr = unsafe.Pointer(&value)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unrelated, but I didn't realize that tinygo still used this method and not staticuint64s etc; this has GC implications since I think this means that number values stored in interfaces are treated as pointers

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Motivated by me reading the hashmap code. I didn't have a particular bug.

Yeah, the interface values sometimes being ints and sometimes being pointers means we can pin stuff. But at long as we don't panic any garbage collector implementations we'll be fine, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It won't panic anything, no, since most everything can do conservative scanning, but I do think it'd be best to avoid that pinning

@dgryski
dgryski merged commit c421943 into tinygo-org:dev Aug 12, 2026
20 checks passed
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.

2 participants