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

Ownership model for streams is not clear. #7

Open
brendandburns opened this issue Mar 5, 2023 · 5 comments
Open

Ownership model for streams is not clear. #7

brendandburns opened this issue Mar 5, 2023 · 5 comments

Comments

@brendandburns
Copy link
Contributor

When reading from a stream, it seems that the list that is returned from a stream is owned by the caller, but that is not clearly spelled out in the documentation.

@lukewagner
Copy link
Member

The ownership of memory is not something specific to the wasi-http/wasi-io proposals, but rather defined by the Canonical ABI based purely on the types involved. For list<u8>, if you look at store_list in CanonicalABI.md, it describes how the core module's exported cabi_realloc function is called to allocate the memory, which is written into by the host, and then the pointer is returned to the core module. The C headers for the ownership semantics could be generated per-interface by wit-bindgen, though.

@brendandburns
Copy link
Contributor Author

I was suggesting that the streams wit definition should add clarity in the comments about how this is expected to work.

@lukewagner
Copy link
Member

Improving documentation is a good idea, but I don't know if the Wit document is the right place since this ends up being for many guest/host languages, a bindings-internal detail (e.g., JS will simply see a JS array pop out). But perhaps this could be usefully generated as part of the ABI documentation or, perhaps better, in the generated C header comments. @sunfishcode was thinking about this too recently, so that we're not having to send folks to read Canonical ABI all the time.

@brendandburns
Copy link
Contributor Author

In garbage collected languages, the ownership is clearly not as important, but in non-gc languages like C it is a question that someone asks whenever they see a pointer as a return value.

@lukewagner
Copy link
Member

Even for explicitly-managed languages like C++/Rust, the ownership transfer should be made explicit in the return types of the generated bindings (e.g., a std::vector return-by-value). Also, when wasm-gc is integrated by adding new canonopts, the core wasm signature won't even return an i32 pointer, but rather some sort of wasm-GC reference type. Thus, this does seem to be something most appropriate in a generated C header file or perhaps a generated ABI doc.

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

No branches or pull requests

2 participants