-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IDL sequence should be Iterable, not Array #6
Comments
The WebIDL spec defines a Unfortunately An alternative would be declaring an iterable object as defined in the WebIDL spec. |
Ah, there's an effective difference between input WebGPU doesn't actually use any output |
Unfortunately I can't think of an easy way to be 100% correct about input vs output types. Many types can be used in both input and output (any that are sequence or dictionary, at least). IIRC these are only recommended to be used in input situations but they're allowed to be used in output situations as well. |
yeah, this one is a difficult one. for function arguments or return types a simple input/output heuristic could be used: undefined setSequence(sequence<any> value);
sequence<any> getSequence(); would translate to: setSequence(Iterable<any> value): void;
getSequence(): Array<any>; Properties are more difficult since they can either be The closest solution that I can think of is to follow the heuristic above and create setters and getters to be verbose: dictionary GPUBindGroupLayoutDescriptor : GPUObjectDescriptorBase {
required sequence<GPUBindGroupLayoutEntry> entries;
}; would translate to: interface GPUBindGroupLayoutDescriptor extends GPUObjectDescriptorBase {
set entries(value: Iterable<GPUBindGroupLayoutEntry>);
get entries(): Array<GPUBindGroupLayoutEntry>;
} but that feels off |
Yeah, that wouldn't work if the type were used as a local variable: const x: GPUBindGroupLayoutDescriptor = { entries: new Set(...) };
const y = x.entries[0]; Unfortunately the only thing I can think of is to generate both input and output versions of every type (perhaps differentiated by a type parameter??), then optionally prune any input or output variants that go unused... |
We can not worry about this for now for WebGPU though. The diff that we have to deal with manually is very small. |
In principle all the descriptors need to be I did a little experimentation with the idea I had above and it could work: |
WebIDL
sequence
s are (I think) equivalent to TypeScriptIterable
s - the WebIDL conversion rules from JS will iterate the value to produce an array. For example:generates:
but should generate:
The text was updated successfully, but these errors were encountered: