WebAssembly / WebAssembly/binaryen

Opportunity to further simplify internal cast representation

Open
#5,755 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 19h
Merged PRs (30d)
69

Description

Right now almost all casts are represented as RefCast expressions, but ref.as_non_null is instead represented as a RefAs expression. This is a little awkward because the other two operations represented by RefAs are actually not casts at all, but rather conversions to and from externref. Having casts spread across two expression classes and having both cast and conversion operations represented by RefAs are sources of unnecessary complexity.

We could instead represent ref.as_non_null as a RefCast where the cast target heap type is a subtype of the input heap type. Another way to say this is that we could remove the RefAs representation of ref.as_non_null and instead opportunistically emit ref.as_non_null instead of ref.cast when the types work out.

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 tracing how RefCast and RefAs expressions represent casts and conversions in Binaryen. Determine where ref.as_non_null is created, transformed, and emitted, then verify that the representation is unified without changing the intended ref.as_non_null versus ref.cast output behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, wasm
Domain
compilers
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.