Bug 199289 - [WHLSL] 'uint y = x ? 1 : 2' fails to typecheck
Summary: [WHLSL] 'uint y = x ? 1 : 2' fails to typecheck
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGPU (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Saam Barati
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-27 14:47 PDT by Myles C. Maxfield
Modified: 2020-05-05 00:42 PDT (History)
1 user (show)

See Also:


Attachments
WIP (26.38 KB, patch)
2019-07-03 19:21 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
WIP (26.81 KB, patch)
2019-07-03 19:31 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
patch (38.41 KB, patch)
2019-07-04 01:32 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
patch (38.65 KB, patch)
2019-07-04 01:37 PDT, Saam Barati
sbarati: review?
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Myles C. Maxfield 2019-06-27 14:47:33 PDT
Right now we will unifyAndConmit both of the ResolvableTypes together, which IIRC will say “hey let’s just resolve these to their preferred type” which is int but the function needs to return uchar so fail!
Comment 1 Saam Barati 2019-06-27 14:59:36 PDT
```
float foo() {
    return true ? 1 : 2
}
```
Comment 2 Myles C. Maxfield 2019-07-03 15:43:42 PDT
This patch should add the following text into the "operator cast" section of the standard library:

operator uchar(bool x) {
    return x ? 1 : 0;
}
operator ushort(bool x) {
    return x ? 1 : 0;
}
operator uint(bool x) {
    return x ? 1 : 0;
}
operator char(bool x) {
    return x ? 1 : 0;
}
operator short(bool x) {
    return x ? 1 : 0;
}
operator half(bool x) {
    return x ? 1 : 0;
}
operator float(bool x) {
    return x ? 1 : 0;
}
Comment 3 Saam Barati 2019-07-03 19:21:06 PDT
Created attachment 373448 [details]
WIP

Trying to fix some final bugs
Comment 4 Saam Barati 2019-07-03 19:31:22 PDT
Created attachment 373449 [details]
WIP
Comment 5 Saam Barati 2019-07-04 01:32:39 PDT
Created attachment 373457 [details]
patch
Comment 6 Saam Barati 2019-07-04 01:33:31 PDT
(In reply to Myles C. Maxfield from comment #2)
> This patch should add the following text into the "operator cast" section of
> the standard library:
> 
> operator uchar(bool x) {
>     return x ? 1 : 0;
> }
> operator ushort(bool x) {
>     return x ? 1 : 0;
> }
> operator uint(bool x) {
>     return x ? 1 : 0;
> }
> operator char(bool x) {
>     return x ? 1 : 0;
> }
> operator short(bool x) {
>     return x ? 1 : 0;
> }
> operator half(bool x) {
>     return x ? 1 : 0;
> }
> operator float(bool x) {
>     return x ? 1 : 0;
> }

I need to rebase and do this, but the patch won't change. So it's still valuable to review in its current form.
Comment 7 Saam Barati 2019-07-04 01:37:09 PDT
Created attachment 373458 [details]
patch
Comment 8 Robin Morisset 2019-07-05 18:12:00 PDT
Comment on attachment 373458 [details]
patch

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

I don't currently understand this code well enough to give it an r+

> Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp:-368
> -    }

Why change this?

> Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp:63
> +static constexpr bool dumpASTAtEnd = true;

Please remove.
Comment 9 Saam Barati 2019-07-07 00:35:48 PDT
Comment on attachment 373458 [details]
patch

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

>> Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp:-368
>> -    }
> 
> Why change this?

This is not intentional. Will revert
Comment 10 Myles C. Maxfield 2020-05-05 00:42:38 PDT
WHLSL is no longer relevant.