Add flagship bindings with per-monomorphization generics - #1053
Open
logan-gatlin wants to merge 17 commits into
Open
Add flagship bindings with per-monomorphization generics#1053logan-gatlin wants to merge 17 commits into
logan-gatlin wants to merge 17 commits into
Conversation
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
requested changes
Sep 3, 2026
guybedford
left a comment
Collaborator
There was a problem hiding this comment.
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
Collaborator
Author
|
Regenerated bindings using this branch of ts-gen: wasm-bindgen/ts-gen#31 |
logan-gatlin
force-pushed
the
flagship-per-mono-generics
branch
2 times, most recently
from
September 8, 2026 20:23
4437aac to
b5eefaa
Compare
- Use native Rust primitives for Flagship values and evaluation details - Update examples and tests for generic string-compatible binding arguments
logan-gatlin
force-pushed
the
flagship-per-mono-generics
branch
from
September 8, 2026 22:25
b5eefaa to
8be4ab2
Compare
guybedford
reviewed
Sep 9, 2026
Comment on lines
+9
to
+10
| // not wasm-bindgen ABI types. `EvaluationContext` and `EnvBinding` also remain | ||
| // here because ts-gen does not synthesize them. |
Collaborator
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Amends the existing flagship work to use per-monomorphization generics. Eliminates the
into_value()conversions. Also addsimpl (De)Serializefor the types.Thanks to @connyay for doing most of the work on this