-
Notifications
You must be signed in to change notification settings - Fork 14
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
Reference types, typed function references #20
Comments
If maintaining a simple textual/JSONifiable representation is what is desired, in the case of circular types, perhaps we should be exposing the types from a module. If we do this we could just use the numeric indexes in such a representation. i.e.: > console.log(WebAssembly.Module.types(someModule)); // FunctionType[]
[
{
parameters: [{
kind: "ref",
nullable: false,
typeIndex: 1, // points to index 1 in this type table
}],
results: ["i32", "externref"],
},
{ parameters: ["i32", "i32"], results: ["i32"] },
]
// Suppose we have some exported function, then it might point to WebAssembly.Module.types
// indexes as well
> module.exports.myFunc.type();
{
parameters: [{
kind: "ref",
nullable: false,
typeIndex: 1,
}],
results: ["i32"],
} This would also explain how const myWasmFunc = new WebAssembly.Function(
someModule,
{ parameters: ["i32", { kind: "ref", nullable: true, typeIndex: 0 }],
results: ["i32", "externref"]
},
(num, func) => {
const x = func(num, num);
return [x, new SomeObject()];
},
); Although the caveat here is we would need to pass a specific module to the If we don't care about textual representation, then it would be generally just simpler if we had a This would be a bit less convenient for people wanting to process these types, however it could simply be encouraged that rather than sending these textual representations, one just shares the binary |
Okay so it looks like typed function references actually recently banned recursion in type definitions. Although something like interface types could still produce them in future, presumably interface types would have a separate reflection API as in that proposal the "interface module" with it's "interface types" are actually a seperate construct from the "real module" and the "real types". In this regard a textual/tree representation should be viable if we're confident that types (excluding "interface types" for reasons mentioned in the previous paragraph) will never be allowed to be defined recursively. This might be a reasonable assumption, as the core module presumably will need types that are very quick to processs, although it would be awkward if recursive types were added later. |
Looking into it further, recursive types will happen but they will part of the gc proposal instead. So yeah my initial comment will still be relevant with that proposal. |
How will this evolve with (notably) the typed function references proposal? Unless I've misunderstood that proposal, it is possible for the new function types to be self-referential, leading to a non-tree structure being required in the js-types proposal; that's going to be a problem for any textual representation at least.
The text was updated successfully, but these errors were encountered: