Skip to content
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

[js-api] Update basic and identity tests for exnref #316

Merged
merged 3 commits into from
Jul 4, 2024

Conversation

aheejin
Copy link
Member

@aheejin aheejin commented Jun 27, 2024

This updates basic.tentative.any.js and identity.tentative.any.js tests to use the new instructions (try_table and throw_ref). In addition to converting existing tests to use the new instruction while maintaining the semantics, I added a new test in
basic.tentative.any.js that makes use of all four catch clause variants to show all catch clauses works well in JS API tests.

These new tests reauire --js-flags=--experimental-wasm-exnref argument to chrome, which is not currently supported in WPT out of the box. I've instead confirmed these run with chrome web tests infrastructure (https://chromium.googlesource.com/chromium/src/+/HEAD/docs/testing/web_tests.md#Running-Web-Tests).

This updates `basic.tentative.any.js` and `identity.tentative.any.js`
tests to use the new instructions (`try_table` and `throw_ref`). In
addition to converting existing tests to use the new instruction while
maintaining the semantics, I added a new test in
`basic.tentative.any.js` that makes use of all four `catch` clause
variants to show all catch clauses works well in JS API tests.

These new tests reauire `--js-flags=--experimental-wasm-exnref` argument
to chrome, which is not currently supported in WPT out of the box. I've
instead confirmed these run with chrome web tests infrastructure
(https://chromium.googlesource.com/chromium/src/+/HEAD/docs/testing/web_tests.md#Running-Web-Tests).
@aheejin aheejin requested review from Ms2ger and dschuff June 27, 2024 22:31
Copy link
Member Author

@aheejin aheejin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added wasm instruction-equivalent of the programs for readability.

@@ -73,7 +73,7 @@ promise_test(async () => {
promise_test(async () => {
const builder = new WasmModuleBuilder();
const fnIndex = builder.addImport("module", "fn", kSig_v_v);
const tagIndex= builder.addTag(kSig_v_r);
const tagIndex = builder.addTag(kSig_v_r);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by fix

Comment on lines +80 to 90
kExprBlock, kWasmVoid,
kExprBlock, kExternRefCode,
kExprTryTable, kWasmVoid, 1,
kCatchNoRef, tagIndexExternref, 0,
kExprCallFunction, fnIndex,
kExprEnd,
kExprBr, 1,
kExprEnd,
kExprReturn,
kExprEnd,
kExprRefNull, kExternRefCode,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to

block $outer
  block $catch_dest (result externref)
    try_table (catch $tag-externref $catch_dest)
      call $fn
    end
    br $outer
  end
  return
end
ref.null extern

Comment on lines +109 to 119
kExprBlock, kWasmVoid,
kExprBlock, kExnRefCode,
kExprTryTable, kWasmVoid, 1,
kCatchAllRef, 0,
kExprCallFunction, fnIndex,
kExprEnd,
kExprBr, 1,
kExprEnd,
kExprThrowRef,
kExprEnd,
kExprRefNull, kExternRefCode,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to

block $outer
  block $catch_all_ref_dest (result exnref)
    try_table (catch_all_ref $catch_all_ref_dest)
      call $fn
    end
    br $outer
  end
  throw_ref
end
ref.null extern

Comment on lines +144 to +168
kExprBlock, kWasmVoid,
kExprBlock, kExnRefCode,
kExprBlock, sig_ie_v,
kExprBlock, kWasmVoid,
kExprBlock, kWasmI32,
kExprTryTable, kWasmVoid, 4,
kCatchNoRef, tagIndexI32, 0,
kCatchAllNoRef, 1,
kCatchRef, tagIndexI32, 2,
kCatchAllRef, 3,
kExprCallFunction, fnIndex,
kExprEnd,
kExprBr, 4,
kExprEnd,
kExprReturn,
kExprEnd,
kExprBr, 2,
kExprEnd,
kExprDrop,
kExprDrop,
kExprBr, 1,
kExprEnd,
kExprDrop,
kExprEnd,
kExprI32Const, 0,
Copy link
Member Author

@aheejin aheejin Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to

block $outer
  block $catch_all_ref_dest (result exnref)
    block $catch_ref_dest (result i32 exnref)
      block $catch_all_dest
        block $catch_dest (result i32)
          try_table (catch $tag-i32 $catch_dest) (catch_all $catch_all_dest) (catch_ref $tag-i32 $catch_ref_dest) (catch_all_ref $catch_all_ref_dest)
            call $fn
          end
          br $outer
        end
        return
      end
      br $outer
    end
    drop
    drop
    br $outer
  end
  drop
end
i32.const 0

Comment on lines +41 to 50
kExprBlock, kWasmVoid,
kExprBlock, sig_ie_v,
kExprTryTable, kWasmVoid, 1,
kCatchRef, jsTagIndex, 0,
kExprCallFunction, throwJSTagExnIndex,
kExprEnd,
kExprBr, 1,
kExprEnd,
kExprThrowRef,
kExprEnd
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to

block $outer
  block $catch_ref_dest (result i32 exnref)
    try_table (catch_ref $js_tag $catch_ref_dest)
      call $throw_js_tag_exn
    end
    br $outer
  end
  throw_ref
end

Comment on lines +59 to 68
kExprBlock, kWasmVoid,
kExprBlock, sig_ie_v,
kExprTryTable, kWasmVoid, 1,
kCatchRef, wasmTagIndex, 0,
kExprCallFunction, throwWasmTagExnIndex,
kExprEnd,
kExprBr, 1,
kExprEnd,
kExprThrowRef,
kExprEnd
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to

block $outer
  block $catch_ref_dest (result i32 exnref)
    try_table (catch_ref $wasm_tag $catch_ref_dest)
      call $throw_wasm_tag_exn
    end
    br $outer
  end
  throw_ref
end

Comment on lines +77 to 86
kExprBlock, kWasmVoid,
kExprBlock, kExnRefCode,
kExprTryTable, kWasmVoid, 1,
kCatchAllRef, 0,
kExprCallFunction, throwJSTagExnIndex,
kExprEnd,
kExprBr, 1,
kExprEnd,
kExprThrowRef,
kExprEnd
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to

block $outer
  block $catch_all_ref_dest (result exnref)
    try_table (catch_all_ref $js_tag $catch_all_ref_dest)
      call $throw_js_tag_exn
    end
    br $outer
  end
  throw_ref
end

Comment on lines +95 to 104
kExprBlock, kWasmVoid,
kExprBlock, kExnRefCode,
kExprTryTable, kWasmVoid, 1,
kCatchAllRef, 0,
kExprCallFunction, throwWasmTagExnIndex,
kExprEnd,
kExprBr, 1,
kExprEnd,
kExprThrowRef,
kExprEnd
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to

block $outer
  block $catch_all_ref_dest (result exnref)
    try_table (catch_all_ref $wasm_tag $catch_all_ref_dest)
      call $throw_wasm_tag_exn
    end
    br $outer
  end
  throw_ref
end

Comment on lines +113 to +123
kExprBlock, kWasmVoid,
kExprBlock, kWasmI32,
kExprTryTable, kWasmVoid, 1,
kCatchNoRef, jsTagIndex, 0,
kExprCallFunction, throwJSTagExnIndex,
kExprEnd,
kExprBr, 1,
kExprEnd,
kExprReturn,
kExprEnd
kExprEnd,
kExprI32Const, 0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to

block $outer
  block $catch_dest (result i32)
    try_table (catch $js_tag $catch_dest)
      call $throw_js_tag_exn
    end
    br $outer
  end
  return
end
i32.const 0

Comment on lines +132 to 141
kExprBlock, kWasmVoid,
kExprBlock, kWasmI32,
kExprTryTable, kWasmVoid, 1,
kCatchNoRef, jsTagIndex, 0,
kExprCallFunction, throwJSTagExnIndex,
kExprEnd,
kExprBr, 1,
kExprEnd,
kExprThrow, jsTagIndex,
kExprEnd
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to

block $outer
  block $catch_dest (result i32)
    try_table (catch $js_tag $catch_dest)
      call $throw_js_tag_exn
    end
    br $outer
  end
  throw $js_tag
end

Copy link
Contributor

@Ms2ger Ms2ger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I have not reviewed the changed wasm code.

test/js-api/exception/basic.tentative.any.js Outdated Show resolved Hide resolved
@aheejin aheejin merged commit c5b968f into WebAssembly:main Jul 4, 2024
1 check passed
@aheejin aheejin deleted the js_api_tests_exnref branch July 4, 2024 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants