Bug 218744

Summary: [WASM-References] Support imm for ref.null
Product: WebKit Reporter: Dmitry <dbezhetskov>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: chi187, ews-watchlist, fpizlo, keith_miller, mark.lam, msaboff, saam, tzagallo, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Description Dmitry 2020-11-10 03:23:22 PST
[WASM-References] Support imm for ref.null
Comment 1 Dmitry 2020-11-10 03:24:20 PST
Created attachment 413682 [details]
Patch
Comment 2 EWS Watchlist 2020-11-10 03:25:13 PST
This patch modifies one of the wasm.json files. Please ensure that any changes in one have been mirrored to the other. You can find the wasm.json files at "Source/JavaScriptCore/wasm/wasm.json" and "JSTests/wasm/wasm.json".
Comment 3 Dmitry 2020-11-10 21:56:36 PST
Created attachment 413779 [details]
Patch
Comment 4 Yusuke Suzuki 2020-11-11 14:40:16 PST
Comment on attachment 413779 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=413779&action=review

Nice, the design of the patch looks good!

> Source/JavaScriptCore/ChangeLog:6
> +        Reviewed by NOBODY (OOPS!).

Can you describe the explanation of changes in ChangeLog?
And can you also add a link to the spec of this change in the ChangeLog?

> Source/JavaScriptCore/wasm/WasmFunctionParser.h:497
> +        WASM_PARSER_FAIL_IF(!parseValueType(typeOfNull), "can't get ref.null's type");

This is checking whether the value is ValueType. I think we need to validate whether this is RefType.
Can you add a test to ensure that module validation fails if the input is not a retype?

> Source/JavaScriptCore/wasm/WasmSectionParser.cpp:478
> +        WASM_PARSER_FAIL_IF(!parseValueType(typeOfNull), "can't get ref.null's type");

Ditto.

> Source/JavaScriptCore/wasm/wasm.json:62
> +        "ref.null":            { "category": "special",    "value": 208, "return": ["externref", "funcref"],         "parameter": [],                             "immediate": [{"name": "reftype",        "type": "elem_type"}],                                             "description": "a constant null reference" },

Ditto.

> JSTests/wasm/Builder.js:311
> +            assert.truthy(WASM.isValidElemType(imms[idx]), `Invalid elem type on ${op}: "${imms[idx]}"`);

Let's rename ElemType to RefType.

> JSTests/wasm/LowLevelBinary.js:206
> +    elem_type(v) {
> +        if (!WASM.isValidElemType(v))

Ditto. ref_type and RefType.

> JSTests/wasm/WASM.js:45
> +const _elemTypeSet = new Set(description.elem_type);
> +export const isValidElemType = v => _elemTypeSet.has(v);

Ditto.

> JSTests/wasm/wasm.json:62
> +        "ref.null":            { "category": "special",    "value": 208, "return": ["externref", "funcref"],         "parameter": [],                             "immediate": [{"name": "reftype",        "type": "elem_type"}],                                             "description": "a constant null reference" },

Can you rename this "elem_type" to "ref_type"?
https://webassembly.github.io/reference-types/core/binary/instructions.html#reference-instructions
Comment 5 Dmitry 2020-11-11 23:54:08 PST
Created attachment 413917 [details]
Patch
Comment 6 Yusuke Suzuki 2020-11-12 00:16:55 PST
Comment on attachment 413917 [details]
Patch

Nice! r=me if EWS gets green.
Comment 7 EWS 2020-11-12 04:00:06 PST
Committed r269729: <https://trac.webkit.org/changeset/269729>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 413917 [details].
Comment 8 Radar WebKit Bug Importer 2020-11-12 04:01:56 PST
<rdar://problem/71321783>