WebAssembly / WASI

WebAssembly System Interface
Other
4.81k stars 249 forks source link

Add an `option` shorthand to witx. #420

Closed sunfishcode closed 3 years ago

sunfishcode commented 3 years ago

I was mocking up a witx description for #322 and had a use for an option type. Of course, I could also just emit a variant manually, or reuse expected by omitting the error type, but option better conveys the sense that the none case doesn't necessarily represent an error.

jedisct1 commented 3 years ago

That would be a nice addition!

In wasi-crypto, a custom Option type is also used everywhere, which leads to non-idiomatic generated code in languages supporting optional types.

alexcrichton commented 3 years ago

The code here looks fine to me, but I would hesitate because I'm not sure whether we want to continue to enhance the current ABI of WASI since it makes it more complicated to support in a future with support for a new ABI. I've been working on an abi-next branch locally which also has support for option, and I definitely agree it would be nice to support!

Do you think it would be better for me to try to land by "abi next" work and get option supported only there? Or do you think that it would be best to stick with this extension to the current ABI?

sunfishcode commented 3 years ago

Ah, cool. I'm ok waiting for the new ABI; this was just for some prototyping I was doing.

alexcrichton commented 3 years ago

Ok! I'll work on cleaning that up for a PR this week.

alexcrichton commented 3 years ago

Ok I posted https://github.com/WebAssembly/WASI/pull/422 which has option in it as well