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

wgsl: Add short-circuiting validation tests #3567

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jrprice
Copy link
Contributor

@jrprice jrprice commented Mar 28, 2024

Test that the short-circuiting logical expressions are only accepted for scalar boolean types.

Also test that they guard invalid expressions on the right-hand-side when the left-hand-side is a const-expression.


Requirements for PR author:

  • All missing test coverage is tracked with "TODO" or .unimplemented().
  • New helpers are /** documented */ and new helper files are found in helper_index.txt.
  • Test behaves as expected in a WebGPU implementation. (If not passing, explain above.)
  • Test have be tested with compatibility mode validation enabled and behave as expected. (If not passing, explain above.)

Requirements for reviewer sign-off:

  • Tests are properly located in the test tree.
  • Test descriptions allow a reader to "read only the test plans and evaluate coverage completeness", and accurately reflect the test code.
  • Tests provide complete coverage (including validation control cases). Missing coverage MUST be covered by TODOs.
  • Helpers and types promote readability and maintainability.

When landing this PR, be sure to make any necessary issue status updates.

Test that the short-circuiting logical expressions are only accepted
for scalar boolean types.

Also test that they guard invalid expressions on the right-hand-side
when the left-hand-side is a const-expression.
@jrprice jrprice added the wgsl label Mar 28, 2024
@jrprice jrprice requested a review from dneto0 March 28, 2024 13:53
overflow: 'i32(1<<31) < 0',
binary: '(1.0 / 0) == 0',
builtin: 'sqrt(-1) == 0',
array_size: 'array<bool, 3 - 4>()[0]',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the contentious case that we've been discussing internally, and likely needs clarification in the spec as to whether this is valid or not on the RHS of a short-circuited expression.

FYI @alan-baker too.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree it makes sense for this to be a shader-creation error. I'd be in favour of updating the spec to reflect that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've opened gpuweb/gpuweb#4551 to get clarification on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should land this test before the spec update is reviewed (if needed)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pulled out the array-element-count tests to their own suite(?) and made them expected-to-fail (with a control case), in anticipation of the spec clarification falling in that direction. No need to rush to land this though.

Copy link
Contributor

@dneto0 dneto0 left a comment

Choose a reason for hiding this comment

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

Thanks!

overflow: 'i32(1<<31) < 0',
binary: '(1.0 / 0) == 0',
builtin: 'sqrt(-1) == 0',
array_size: 'array<bool, 3 - 4>()[0]',
Copy link
Contributor

Choose a reason for hiding this comment

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

We should land this test before the spec update is reviewed (if needed)

)
.fn(t => {
const lhs =
t.params.op === '&&'
Copy link
Contributor

Choose a reason for hiding this comment

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

It took a while to read this but yes, this is correct.

An alternative:

const lookup =  { '&&': { true: false, false: true}, '||': { true: true, false: false}};
const lhs = lookup[t.params.op][t.params.skip_rhs];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did this a slightly different way because TypeScript was being picky.

Copy link
Contributor Author

@jrprice jrprice left a comment

Choose a reason for hiding this comment

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

Also added override tests.

)
.fn(t => {
const lhs =
t.params.op === '&&'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did this a slightly different way because TypeScript was being picky.

overflow: 'i32(1<<31) < 0',
binary: '(1.0 / 0) == 0',
builtin: 'sqrt(-1) == 0',
array_size: 'array<bool, 3 - 4>()[0]',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pulled out the array-element-count tests to their own suite(?) and made them expected-to-fail (with a control case), in anticipation of the spec clarification falling in that direction. No need to rush to land this though.

Copy link
Contributor

@dneto0 dneto0 left a comment

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants