Make SwiftRuntime.memory constant property#375
Merged
kateinoigakukun merged 2 commits intomainfrom Jun 16, 2025
Merged
Conversation
SwiftRuntime.memory constant property
81b6672 to
9a6c4c1
Compare
9a6c4c1 to
d5909d5
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request refactors the memory management layer and updates APIs to use a constant “SwiftRuntime.memory” property by replacing older Memory implementations with a new JSObjectSpace and caching mechanisms. Key changes include:
- Renaming and refactoring of memory‐related classes and methods (e.g. SwiftRuntimeHeap → JSObjectSpace).
- Upgrading function signatures to use DataView and JSObjectSpace instead of the old Memory instance.
- Removing the obsolete Memory implementation from Runtime/src/memory.ts.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Tests/prelude.mjs | Adds an extra parameter to assert.equal for improved error output |
| Runtime/src/object-heap.ts | Renames and refactors memory access methods (referenceHeap → getObject) |
| Runtime/src/memory.ts | Entire file removed in favor of the new JSObjectSpace-based approach |
| Runtime/src/js-value.ts | Updates function signatures to accept DataView and JSObjectSpace |
| Runtime/src/itc.ts | Updates constructor dependency from Memory to JSObjectSpace |
| Runtime/src/index.ts | Refactors multiple WASM memory accesses to utilize cached DataView and JSObjectSpace |
| Plugins/PackageToJS/Templates/runtime.mjs | Reflects similar API changes and refactor as in Runtime/src/index.ts |
Comments suppressed due to low confidence (1)
Runtime/src/index.ts:389
- Ensure that all instances converting the Memory API calls to use DataView and JSObjectSpace are consistent; consider reviewing similar calls throughout the file to verify correct behavior when WASM memory grows.
return JSValue.writeAndReturnKindBits(result, payload1_ptr, payload2_ptr, true, this.getDataView(), this.memory);
| @@ -110,7 +110,7 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { | |||
| exports.throwsSwiftError(); | |||
| assert.fail("Expected error"); | |||
| } catch (error) { | |||
There was a problem hiding this comment.
[nitpick] Consider clarifying why the additional 'error' argument is passed to assert.equal to aid debugging; a short inline comment could help future maintainers understand its purpose.
Suggested change
| } catch (error) { | |
| } catch (error) { | |
| // Include the 'error' object to provide additional debugging information if the assertion fails. |
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.
Also cache DataView instance as much as possible (until the underlying memory is grown)