winglang / winglang/wing

Introduce fp-bindgen to reduce WASM boilerplate

Open
#2,104 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🛠️ compiler refactor
Dominant language
TypeScript
Stars
5.4k
Forks
215
Avg merge
2h 9m
Merged PRs (30d)
27

Description

Currently, interactions between JS<->WASM have several non-critical issues:

  • They are handwritten boilerplate (allocating/reading/freeing memory mostly)
  • Each new export/import introduces a lot of code duplication
  • The ABI is slightly inconsistent. Sometimes functions don't return anything, sometimes they take multiple raw strings and sometimes they take a single string that is meant to be read as a JSON.

Normally, projects like this would use wasm-bindgen and/or wasm-pack. Unfortunately, we cannot use those due to our reliance on the wasm32-wasi target. https://github.com/fiberplane/fp-bindgen however, should work for us. We should likely use their beta releases, because they do not do releases very frequently at the moment.

With this, we can have a much stronger contract between wingc and any JS that attempts to consume it. It also uses MessagePack to get data between runtimes, which may even be faster than the current JSON method we use in several places.

Note: Technically, an alternative would be to use https://github.com/bytecodealliance/wit-bindgen and https://github.com/bytecodealliance/jco. It's very possible these will be the defacto method of doing this in the future, but it's likely too early to go all-in on WASM components.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing wingc's existing JavaScript↔WASM interactions and the handwritten memory-management and import/export code described in the issue. Then evaluate fp-bindgen's beta releases against the wasm32-wasi target, including its MessagePack-based data exchange. Done means the duplicated boilerplate is replaced and the ABI contract is made consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, wasm
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
24/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.