WebAssembly / WebAssembly/component-model

flags: support flags that are just combinations of other flags, not taking a new bit.

Open
#660 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
1.4k
Forks
130
Avg merge
2d 1h
Merged PRs (30d)
15

Description

This came up in https://github.com/WebAssembly/wasi-gfx/pull/71#discussion_r3358530577

where WebGpu has a C definition:
https://github.com/webgpu-native/webgpu-headers/blob/bf8ddb91dc38ea11ec1b727dae1fa965c4207d22/webgpu.h#L1334

/**
 * `Red | Green | Blue | Alpha`.
 */
static const WGPUColorWriteMask WGPUColorWriteMask_All = 0x000000000000000F;

the generated WIT in https://github.com/WebAssembly/wasi-gfx/pull/71 as of writing is:

flags gpu-color-write {
    red,
    green,
    blue,
    alpha,
    all,
}

which is incorrect in that all shouldn't be a new flag, just a shorthand for a combination of all the other flags.

I think WIT should be changed to allow expressing named flag values that are just combinations of zero or more existing flags by allowing assigning flag values to either 0 or the bitwise or of one or more other named flags:

flags colors {
    black = 0,
    red,
    green,
    yellow = red | green,
    blue,
    magenta = red | blue,
    purple = magenta,
    cyan = green | blue,
    white = red | green | blue,
}

note: I'm not planning on implementing this myself, so whoever's interested feel free to implement it whenever ready.

Contributor guide

No contributing guide indexed for this repository

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

Review the linked wasi-gfx discussion and PR 71, then trace how WIT flag declarations are specified and generated. The work is done when named flag values can be zero or combinations of existing flags, including aliases such as all, without allocating new bits.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.