Bug 189502 - [WHLSL] Improve test suite type safety
Summary: [WHLSL] Improve test suite type safety
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Thomas Denney
URL:
Keywords: InRadar
Depends on:
Blocks: 187735
  Show dependency treegraph
 
Reported: 2018-09-11 09:17 PDT by Thomas Denney
Modified: 2018-09-19 13:09 PDT (History)
4 users (show)

See Also:


Attachments
Patch (5.13 KB, patch)
2018-09-11 09:30 PDT, Thomas Denney
no flags Details | Formatted Diff | Diff
Patch (59.91 KB, patch)
2018-09-11 13:06 PDT, Thomas Denney
no flags Details | Formatted Diff | Diff
Patch (55.86 KB, patch)
2018-09-11 14:30 PDT, Thomas Denney
no flags Details | Formatted Diff | Diff
Patch (56.71 KB, patch)
2018-09-19 09:49 PDT, Thomas Denney
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Denney 2018-09-11 09:17:21 PDT
[WHLSL] Improve test suite type safety
Comment 1 Thomas Denney 2018-09-11 09:30:09 PDT
Created attachment 349399 [details]
Patch
Comment 2 Myles C. Maxfield 2018-09-11 10:06:05 PDT
Comment on attachment 349399 [details]
Patch

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

> Tools/WebGPUShadingLanguageRI/Casts.js:45
> +function castToBool(value)
> +{
> +    return !!value;
> +}

Can we put this with the rest of the casts?

> Tools/WebGPUShadingLanguageRI/Test.js:83
> -    return TypedValue.box(program.intrinsics.int, value);
> +    return TypedValue.box(program.intrinsics.int, castToInt(value));
>  }
>  
>  function makeUint(program, value)
>  {
> -    return TypedValue.box(program.intrinsics.uint, value);
> +    return TypedValue.box(program.intrinsics.uint, castToUint(value));
>  }
>  
>  function makeUchar(program, value)
>  {
> -    return TypedValue.box(program.intrinsics.uchar, value);
> +    return TypedValue.box(program.intrinsics.uchar, castToUchar(value));
>  }
>  
>  function makeBool(program, value)
>  {
> -    return TypedValue.box(program.intrinsics.bool, value);
> +    return TypedValue.box(program.intrinsics.bool, castToBool(value));
>  }
>  
>  function makeFloat(program, value)
>  {
> -    return TypedValue.box(program.intrinsics.float, value);
> +    return TypedValue.box(program.intrinsics.float, castToFloat(value));
>  }
>  
>  function makeHalf(program, value)
>  {
> -    return TypedValue.box(program.intrinsics.half, value);
> +    return TypedValue.box(program.intrinsics.half, castToHalf(value));

perhaps instead of silently casting, we should throw if the input thing isn't already the right type. The caller should know if the only reason the test is passing is that the type system is interfering

> Tools/WebGPUShadingLanguageRI/Test.js:2702
> -    checkUchar(program, callFunction(program, "foo", [makeUchar(program, 65535), makeUint(program, 2)]), 255);
> -    checkUchar(program, callFunction(program, "foo", [makeUchar(program, -1), makeUint(program, 5)]), 255);
> +    checkUchar(program, callFunction(program, "foo", [makeUchar(program, 65535), makeUint(program, 2)]), 63);
> +    checkUchar(program, callFunction(program, "foo", [makeUchar(program, -1), makeUint(program, 5)]), 7);

What? Why is this necessary?
Comment 3 Thomas Denney 2018-09-11 10:10:25 PDT
(In reply to Myles C. Maxfield from comment #2)
> Comment on attachment 349399 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=349399&action=review
> 
> > Tools/WebGPUShadingLanguageRI/Casts.js:45
> > +function castToBool(value)
> > +{
> > +    return !!value;
> > +}
> 
> Can we put this with the rest of the casts?

It is!

> 
> > Tools/WebGPUShadingLanguageRI/Test.js:83
> > -    return TypedValue.box(program.intrinsics.int, value);
> > +    return TypedValue.box(program.intrinsics.int, castToInt(value));
> >  }
> >  
> >  function makeUint(program, value)
> >  {
> > -    return TypedValue.box(program.intrinsics.uint, value);
> > +    return TypedValue.box(program.intrinsics.uint, castToUint(value));
> >  }
> >  
> >  function makeUchar(program, value)
> >  {
> > -    return TypedValue.box(program.intrinsics.uchar, value);
> > +    return TypedValue.box(program.intrinsics.uchar, castToUchar(value));
> >  }
> >  
> >  function makeBool(program, value)
> >  {
> > -    return TypedValue.box(program.intrinsics.bool, value);
> > +    return TypedValue.box(program.intrinsics.bool, castToBool(value));
> >  }
> >  
> >  function makeFloat(program, value)
> >  {
> > -    return TypedValue.box(program.intrinsics.float, value);
> > +    return TypedValue.box(program.intrinsics.float, castToFloat(value));
> >  }
> >  
> >  function makeHalf(program, value)
> >  {
> > -    return TypedValue.box(program.intrinsics.half, value);
> > +    return TypedValue.box(program.intrinsics.half, castToHalf(value));
> 
> perhaps instead of silently casting, we should throw if the input thing
> isn't already the right type. The caller should know if the only reason the
> test is passing is that the type system is interfering

OK, I’ll add this now.

> 
> > Tools/WebGPUShadingLanguageRI/Test.js:2702
> > -    checkUchar(program, callFunction(program, "foo", [makeUchar(program, 65535), makeUint(program, 2)]), 255);
> > -    checkUchar(program, callFunction(program, "foo", [makeUchar(program, -1), makeUint(program, 5)]), 255);
> > +    checkUchar(program, callFunction(program, "foo", [makeUchar(program, 65535), makeUint(program, 2)]), 63);
> > +    checkUchar(program, callFunction(program, "foo", [makeUchar(program, -1), makeUint(program, 5)]), 7);
> 
> What? Why is this necessary?

makeUchar of -1 yields the value 0xFF (likewise with 65535), so right shifting these values by 2 and 5 yields 63 and 7 respectively.
Comment 4 Myles C. Maxfield 2018-09-11 10:18:52 PDT
Comment on attachment 349399 [details]
Patch

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

>>> Tools/WebGPUShadingLanguageRI/Casts.js:45
>>> +}
>> 
>> Can we put this with the rest of the casts?
> 
> It is!

Nevermind, you're right.

>>> Tools/WebGPUShadingLanguageRI/Test.js:2702
>>> +    checkUchar(program, callFunction(program, "foo", [makeUchar(program, -1), makeUint(program, 5)]), 7);
>> 
>> What? Why is this necessary?
> 
> makeUchar of -1 yields the value 0xFF (likewise with 65535), so right shifting these values by 2 and 5 yields 63 and 7 respectively.

I see, the test was testing incorrect behavior before. Either way, the test shouldn't say makeUchar(program, -1). It should say makeUchar(program, 255). Same with 65535.
Comment 5 Thomas Denney 2018-09-11 13:06:18 PDT
Created attachment 349429 [details]
Patch
Comment 6 Myles C. Maxfield 2018-09-11 14:13:44 PDT
Comment on attachment 349429 [details]
Patch

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

> Tools/WebGPUShadingLanguageRI/All.js:105
> +load("IsBitwiseEquivalent.js");

Why not put this in Casts.js?

> Tools/WebGPUShadingLanguageRI/Casts.js:126
> +        throw new Error(`${value} was casted to ${castedValue}`);

This message is not particularly clear why it is an error condition.
Comment 7 Thomas Denney 2018-09-11 14:30:55 PDT
Created attachment 349456 [details]
Patch
Comment 8 Myles C. Maxfield 2018-09-19 00:13:55 PDT
Comment on attachment 349456 [details]
Patch

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

> Tools/WebGPUShadingLanguageRI/Test.js:-2625
> -    checkUint(program, callFunction(program, "foo", [makeUint(program, -1), makeUint(program, 5)]), 134217727);

Can we replace all of these tests with 2^32-1 instead?
Comment 9 Thomas Denney 2018-09-19 09:49:53 PDT
Created attachment 350126 [details]
Patch
Comment 10 WebKit Commit Bot 2018-09-19 13:08:59 PDT
Comment on attachment 350126 [details]
Patch

Clearing flags on attachment: 350126

Committed r236217: <https://trac.webkit.org/changeset/236217>
Comment 11 WebKit Commit Bot 2018-09-19 13:09:00 PDT
All reviewed patches have been landed.  Closing bug.
Comment 12 Radar WebKit Bug Importer 2018-09-19 13:09:34 PDT
<rdar://problem/44613690>