Skip to content

Add flagship bindings with per-monomorphization generics - #1053

Open
logan-gatlin wants to merge 17 commits into
mainfrom
flagship-per-mono-generics
Open

Add flagship bindings with per-monomorphization generics#1053
logan-gatlin wants to merge 17 commits into
mainfrom
flagship-per-mono-generics

Conversation

@logan-gatlin

@logan-gatlin logan-gatlin commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Amends the existing flagship work to use per-monomorphization generics. Eliminates the into_value() conversions. Also adds impl (De)Serialize for the types.

Thanks to @connyay for doing most of the work on this

connyay and others added 15 commits May 25, 2026 11:53
Adds first-class support for the Flagship feature-flag binding announced
on 2026-04-17. Users can now evaluate flags via `env.flagship("FLAGS")`
with a fluent `EvaluationContext` builder and typed `EvaluationDetails<T>`
responses.

- worker-sys: raw wasm_bindgen externs for all 9 Flagship JS methods
- worker: Flagship wrapper, EvaluationContext builder, EvaluationDetails<T>
- test: mini-flagship miniflare mock + 10 handlers + 16 vitest specs
- examples/flagship: runnable worker demoing value/details/context usage
need wasm-bindgen/wasm-bindgen#5180
for better ergonomics on generated bindings
inline closures were odd and didnt match the other
examples

@guybedford guybedford left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an excellent proof of concept proving real generics solves the issue we were having!

Let's integrate ts-gen generation into this PR, by adding support for generic-mono in ts-gen under an option, which when set outputs similar output to what you had here, but automatically.

- Enable experimental generic mono code generation
- Update Flagship values and details to convert wrapper types
@logan-gatlin

Copy link
Copy Markdown
Collaborator Author

Regenerated bindings using this branch of ts-gen: wasm-bindgen/ts-gen#31

@logan-gatlin
logan-gatlin force-pushed the flagship-per-mono-generics branch 2 times, most recently from 4437aac to b5eefaa Compare September 8, 2026 20:23
- Use native Rust primitives for Flagship values and evaluation details
- Update examples and tests for generic string-compatible binding arguments
@logan-gatlin
logan-gatlin force-pushed the flagship-per-mono-generics branch from b5eefaa to 8be4ab2 Compare September 8, 2026 22:25
Comment thread worker/src/flagship.rs
Comment on lines +9 to +10
// not wasm-bindgen ABI types. `EvaluationContext` and `EnvBinding` also remain
// here because ts-gen does not synthesize them.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't ts-gen synthesize EvaluationContext. isn't that what FlagshipEvaluationContext is?

It seems like we could support this in ts-gen if we had something along the lines of:

  • first-class Record<K, V> lowering. Emit a #[wasm_bindgen(extends = Object)] newtype for the alias with new() plus setters derived from V — for a primitive union, per-variant set_string/set_number/set_bool (same machinery the dictionary builder already uses for fixed keys, just keyed by runtime &str). Then the generated methods take &FlagshipEvaluationContext and EvaluationContext in workers-rs is deleted. This is the direct fix for the "union erased to JsValue" warning too.
  • keep getObjectValue in the .d.ts and let per-mono generics emit it as get_object_value<T: IntoWasmAbi + FromWasmAbi> / FlagshipEvaluationDetails. T is a JS-side type (Object/JsValue), so the serde layer becomes a one-line serde_wasm_bindgen::from_value at the call site or a tiny generic helper — not four hand-rolled externs and a parallel EvaluationDetails struct. One details type, not two.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants