Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler)!: Block off 1KiB of heap space as generic swap #935

Closed
wants to merge 2 commits into from

Conversation

peblair
Copy link
Member

@peblair peblair commented Sep 28, 2021

Currently, there is no way to allocate heap space in WASI polyfills (since they cannot import the dataStructures.gr module). To support cases in which some minimal heap use is desired (e.g. the NEAR SDK), this PR blocks off 1KiB of memory (0x400-0x800) which WASI polyfills can freely write to.

(Technically breaking, since the location of the runtime memory is moved)

@peblair peblair requested a review from a team September 28, 2021 19:24
@peblair peblair changed the title feat(compiler): Block off 1KiB of heap space for WASI polyfills feat!(compiler): Block off 1KiB of heap space for WASI polyfills Sep 28, 2021
@peblair peblair changed the title feat!(compiler): Block off 1KiB of heap space for WASI polyfills feat(compiler)!: Block off 1KiB of heap space for WASI polyfills Sep 28, 2021
@phated
Copy link
Member

phated commented Sep 28, 2021

This is a workaround for #841, right? Did @ospencer have any ideas on how to allow memory allocation in the polyfills to avoid this breaking change?

@peblair
Copy link
Member Author

peblair commented Sep 28, 2021

It does appear to be the same issue, but I had come up with this independently. This PR is a workaround for that issue. If @ospencer has a better idea, we can do that, but I need some sort of solution for the NEAR SDK.

@ospencer
Copy link
Member

Not sure how I feel about this yet, but in terms of something that'd work immediately, you can use a string or an array to block off some swap space.

@ospencer ospencer changed the title feat(compiler)!: Block off 1KiB of heap space for WASI polyfills feat(compiler)!: Block off 1KiB of heap space as generic swap Oct 30, 2021
@ospencer
Copy link
Member

ospencer commented Dec 2, 2021

@peblair I was chatting with Blaine about primitives and I had an idea about this:

Right now all of our primitives are functions, but I think we could have some values as well! I was thinking through that wasm4 issue and philip's PR for reserving a chunk of heap space for something that needs it—I think it's a good use case for a @heap.base primitive that you can populate with like a --memory-base to scoot up where we start the heap. Then you can reserve whatever amount of space you need for whatever your use case is, would set us up to support something like AssemblyScript's memory.data (which would be so nice) etc.

He liked that idea. If you think that sounds reasonable too, I can make an issue for it!

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.

3 participants