feat(compiler): Correct purity analysis of memory primitives#2387
Open
spotandjake wants to merge 1 commit intograin-lang:oscar/gc-rebasedfrom
Open
feat(compiler): Correct purity analysis of memory primitives#2387spotandjake wants to merge 1 commit intograin-lang:oscar/gc-rebasedfrom
spotandjake wants to merge 1 commit intograin-lang:oscar/gc-rebasedfrom
Conversation
This pr corrects the purity analysis of a few of our memory related primitives. While looking at this I also did an audit for grain-lang#1170, at the time the issue was opened we were using linear memory which meant that malloc was being called and allocations were impure, this isn't true anymore as we are using wasm gc all allocates can safely be considered pure. There are some additional changes I plan to make a future pr, for instance: * `break` & `consider` are impure as they impact control flow of a loop, however this the way we analyze purity of loops doesn't consider this, meaning any loop with a `break` or `continue` is considered impure. * Function calls are always considered impure however this isn't really the case, we should probably make a look up table of functions and analyze if the function being called is considered pure itself. * This gets complicated though as changing a local in a function is impure but when you look at it from the callers perspective its pure similar to the issues with `break` and `continue` on loops. * Closes: grain-lang#1170 Work towards: grain-lang#2029 This pr is based on: grain-lang#2378
ospencer
approved these changes
May 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pr corrects the purity analysis of a few of our memory related primitives.
While looking at this I also did an audit for #1170, at the time the issue was opened we were using linear memory which meant that malloc was being called and allocations were impure, this isn't true anymore as we are using wasm gc all allocates can safely be considered pure.
There are some additional changes I plan to make a future pr, for instance:
break&considerare impure as they impact control flow of a loop, however this the way we analyze purity of loops doesn't consider this, meaning any loop with abreakorcontinueis considered impure.breakandcontinueon loops.Closes: #1170
Work towards: #2029
This pr is based on: #2378