WebAssembly / WebAssembly/component-model
`.wit`: default implementations
Nobody has claimed this yet.
- Dominant language
- WebAssembly
- Stars
- 1.4k
- Forks
- 130
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 15
Description
I'm proposing an addition to the current syntax to support default implementations for functions.
Sometimes a function isn't required to be implemented and its return could be substituted for a default value. This happens quite often and even more so with functions that don't have a return value. Imagine having to write dozens of functions that do absolutely nothing but are required exist.
In Rust, we extensively use default trait implementations to remove this type of boilerplate. For instance, the Iterator trait has 75 methods, 74 of which have default implementations. I'm not suggesting we allow behavior in wit definitions. Instead, we need a way to define default return values, like in size_hint that returns (0, None) by default.
Structured Annotations could be a good candidate for this syntax. We probably don't want to use curly brackets at the end of the function, as that would normally imply behavior.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the current WIT function syntax and the Structured Annotations proposal referenced in the issue. Determine whether default return values can be expressed without implying behavior, and document the accepted syntax and its treatment of functions with and without return values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- wasm
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100