Skip to content

Allow specifying explicit values for flags #662

Closed as duplicate
Closed as duplicate

Description

@MendyBerger

Currently flags assigns each member an implicit bit position based on declaration order.
I'd like to be able to specify the bit pattern explicitly:

flags foo {
    a   = 0b00000001,
    b   = 0b00000010,
    c   = 0b00000100,
    all = 0b00000111,
}

Motivation: Many existing APIs define flags with fixed bit values that hosts must match. WebGPU is one example—e.g. GPUColorWrite and GPUBufferUsage. Without explicit bit patterns, the host has to translate between WIT's implicit layout and the API's expected layout on every call, which negates much of the performance benefit of flags.

It's worse when the guest already uses an existing WebGPU binding (webgpu.h in C/C++, wgpu in Rust, the WebGPU API in JS): the guest sets the bit pattern the spec expects, converts it to WIT's layout, and the host converts it right back. If WIT supported explicit bit patterns, that round-trip would collapse into passing a single integer.

Activity

  1. lukewagner commented on Jun 15, 2026

    @lukewagner
    Member

    Related discussion in #660. What do you think about the design question in this comment?

  2. MendyBerger commented on Jun 16, 2026

    @MendyBerger
    Author

    Good discussion there, and I saw you already brought up this feature request.

    Closing. Let's continue the discussion in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions