Skip to content

feat(runtime): Move Memory.compare from compiler to runtime#2376

Open
spotandjake wants to merge 1 commit intograin-lang:oscar/gc-rebasedfrom
spotandjake:spotandjake/memory_compare
Open

feat(runtime): Move Memory.compare from compiler to runtime#2376
spotandjake wants to merge 1 commit intograin-lang:oscar/gc-rebasedfrom
spotandjake:spotandjake/memory_compare

Conversation

@spotandjake
Copy link
Copy Markdown
Member

This pr removes our @wasm.memory_compare primitive in favour of implementing it in the runtime.

The reason I am making this change, is as we move away from linear memory and towards wasm gc it isn't as important that this function is in the compiler. Removing it from compcore lowers our maintance burden and moving it to grain makes it easier to manage. The bigger motivator is that our primitives tend to represent either low level things that aren't practical todo in the language itself or things with a direct wasm instruction and this fits neither of those, making the runtime a better home. Similar to how we handle all of the gc array comparisons once that pr lands.

I'm not sure if we actually want to go forward with this change or not so i'm really just putting this pr in the case we do.

Notes:

  • Instead of returning -1 or 1 we now return the magnitude of the difference, this fits the compare api however it is a slight change to the logic we had before.
  • I added tests for all the functions in memory.gr I can move those to a seperate pr but I figured if i'm testing one I might as well test the things it relies on.

Closes: #2375

@ospencer
Copy link
Copy Markdown
Member

ospencer commented May 3, 2026

Want to rebase this off of the GC branch?

This pr removes our `@wasm.memory_compare` primitive in favour of implementing it in the runtime.

The reason I am making this change, is as we move away from linear memory and towards wasm gc it isn't as important that this function is in the compiler. Removing it from compcore lowers our maintance burden and moving it to grain makes it easier to manage.  The bigger motivator is that our primitives tend to represent either low level things that aren't practical todo in the language itself or things with a direct wasm instruction and this fits neither of those, making the runtime a better home. Similar to how we handle all of the gc array comparisons once that pr lands.

I'm not sure if we actually want to go forward with this change or not so i'm really just putting this pr in the case we do.

Closes: grain-lang#2375
@spotandjake spotandjake force-pushed the spotandjake/memory_compare branch from e85eaec to a7d5ed4 Compare May 5, 2026 23:56
@spotandjake spotandjake changed the base branch from main to oscar/gc-rebased May 5, 2026 23:57
@spotandjake
Copy link
Copy Markdown
Member Author

Want to rebase this off of the GC branch?

Made that change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runtime: Consider moving Memory.compare primitive into the runtime.

2 participants