-
-
Notifications
You must be signed in to change notification settings - Fork 670
Update type definitions for memory.* intrinsics #971
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
Conversation
I see the full test suite is failing. Interesting. Looks like some tests rely on these, but it's not clear how that can be as they weren't available to me. Maybe I'm mistaken about them no longer being exposed, and my local build is just screwed up. I'll dig, but lmk if you already know the answer easily. |
There are two distinct definition files, one for compiling to Wasm with asc (that has all the Wasm features we support) and one for cross-compiling to JS with tsc (the one mistakenly? updated in this PR). The portable definitions appear to be somewhat outdated, but it is correct that these can't provide the full set of instructions, like there's no |
That makes more sense! However, it turns out If my understanding is correct (probably isn't?) it seems like memory.allocate/free are implemented for when you're compiling to JS but not for when you're compiling to Wasm, which means we'd need to either re-implement them for Wasm or remove them from portable and move the compiler internals to use the managed GC. FWIW I think it's useful to publicly support exposing a raw bytes alloc function in some form, e.g. |
That's correct, but the implementation there doesn't have much in common with actual Wasm memory. This is rather a hacky shim originating from the necessity to somehow access Binaryen's memory, for example when creating C-strings for it to use. See also this PR that removes the portable memory stuff completely (figured that this is more confusing than it should be) and instead calls Binaryen's exported
Plan is that the compiler itself does not need Wasm-specific instructions at all, but instead relies exclusively on the runtime to do the heavy lifting. Like, the portable subset it is written in can be imagined as the intersection of functionality that is available in both TS and Wasm. Note that the compiler does not yet compile to Wasm due to some remaining missing features.
That's exactly the plan, yeah.
Would recommend the following to do this, resorting to unsafe code: function malloc(size: usize): usize {
return __retain(changetype<usize>(new ArrayBuffer(<i32>size)));
}
function free(ptr: usize): void {
__release(ptr);
} Doesn't necessarily have to be these exact functions, but this way one essentially gets a managed ArrayBuffer that is interoperable with anything C-like. |
Thanks for clarifying! Sounds like this PR is superseded by #971 so will close 🕺 |
I think that #592 removed these intrinsics and added the ones that are currently available.
__alloc
is technically available, but not included in the type definition. I assume that's expected and not intended as a "public" stable API, similar to how__heap_base
etc aren't included in the type def either.