Conversation
|
The breaking change also has the effect of calling the C++ Is the problem that we have both a Type and a HeapType called "none", but JS puts them all in the same namespace? Then I wonder if we can use a separate namespace for Types and HeapTypes. |
|
@kripken I do like that idea, because with all the different types and heap types at the same Would they be better organized into enums? We could build off the names Something like: Module['Type'] = {};
[
['none', 'None'],
['i32', 'Int32'],
...
].forEach(entry => {
Module['Type'][entry[0]] = Module['_BinaryenType' + entry[1]]();
});
Module['HeapType'] = {};
[
['none', 'None'],
['func', 'Func'],
['extern', 'Ext'],
...
].forEach(entry => {
Module['HeapType'][entry[0]] = Module['_BinaryenHeapType' + entry[1]]();
});
Module['PackedType'] = {};
[
['notPacked', 'NotPacked'],
['i8', 'Int8'],
['i16', 'Int16']
].forEach(entry => {
Module['PackedType'][entry[0]] = Module['_BinaryenPackedType' + entry[1]]();
});and then in the TypeScript typings: // all exported under the `binaryen.*` namespace
export type Type = number;
export type HeapType = number;
export type PackedType = number;
export const Type: {
none: number,
i32: number,
...
};
export const HeapType: {
none: number,
func: number,
extern: number,
...
};
export const PackedType: {
notPacked: number,
i8: number,
i16: number,
};As far as I know, TypeScript lets you export both a Of course this would still a breaking change as users would need to update all references to types, but probably for the better. Or we could go in a different direction, so would want to hear from the other JS devs before committing to a decision. |
|
Yes, some kind of enums make sense to me too. This does require a breaking change as you say, but it seems worth it to me. cc @brendandahl for TypeScript and general design thoughts here |
Alternative to #9085, which renamed `binaryen.none` to `binaryen.void` and added a new `binaryen.none` referring to the heap type. There were concerns that `binaryen.void` mapping to the C API `BinaryenTypeNone()` might be confusing. This PR moves all types from the top-level `binaryen.*` namespace into respective enums called `Type`, `HeapType`, and `PackedType`. This change plays nicely with AssemblyScript’s established [TypeScript typings](https://github.com/AssemblyScript/binaryen.js/blob/main/index.d.ts#L3) because now types are scoped in an enum space. This is not a breaking change for the TS typings file — e.g., a function that accepts a `Type` (previously just `number`) now accepts a member of the new `Type` enum. This change also follows well-established patterns of existing enums such as `ExpressionIds` and `Features`. `binaryen.Type.none` now uses `BinaryenTypeNone()` and `binaryen.HeapType.none` uses `BinaryenHeapTypeNone()`, so there’s no conflict across enums. This *is* a breaking change for JS/TS users: they will now have to reference types from the enum space instead of at the top level. E.g. `binaryen.i32` becomes `binaryen.Type.i32`, `binaryen.any` becomes `binaryen.HeapType.any`, `binaryen.i8` becomes `binaryen.PackedType.i8`, etc.
|
closing in favor of #9098 |
BinaryenTypeNonerefers to the typewith stack effect
[] -> [](e.g. the(nop)instruction).BinaryenHeapTypeNoneis the new GC heap typenone, which is“the common subtype of all forms of aggregate types.”
(https://webassembly.github.io/spec/core/syntax/types.html#heap-types)
The former had been named
'none'in the JS API, predating the GC proposal.However, this can be confusing with GC heap type support now finalized in Binaryen.
This PR renames the old type
'none'to'void',and adds support for the heap type and gives it the name
'none'.This is a breaking change. Users who write
binaryen.none,when referring to the empty type, must rename it to
binaryen.void.The type
binaryen.nonemay still be used but now refers to the GC heap type.