[webkit-changes] [WebKit/WebKit] 5186c2: [WGSL] Overload resolution shouldn't eagerly promo...
Tadeu Zagallo
noreply at github.com
Tue Apr 25 01:35:34 PDT 2023
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 5186c242378cb9c03f6f0699cfd8029e5b618a07
https://github.com/WebKit/WebKit/commit/5186c242378cb9c03f6f0699cfd8029e5b618a07
Author: Tadeu Zagallo <tzagallo at apple.com>
Date: 2023-04-25 (Tue, 25 Apr 2023)
Changed paths:
M Source/WebGPU/WGSL/Overload.cpp
M Source/WebGPU/WGSL/tests/valid/overload.wgsl
Log Message:
-----------
[WGSL] Overload resolution shouldn't eagerly promote variables
https://bugs.webkit.org/show_bug.cgi?id=255771
rdar://108361197
Reviewed by Mike Wyrzykowski.
During overload resolution, when trying to assign a type to a variable we check
whether it satisifies the variable's constraints. In order to satisfy a constraint
we might need to promote the type being assigned to the variable. The example
from the tests is when the variable requires a concrete type but we are assigning
an abstract type to it. Originally, we would promote the type as soon as we assigned
it to the variable, but that is not always correct. The promotion algorithm will
pick the cheapest conversion, in this case it would promote an AbstractInt to an
i32, which is a valid conversion. However, later we observe that the same variable
is also being unified with an u32, which was also a valid conversion for the original
type (AbstractInt), but since we already promoted the variable to i32, we can no
longer unify the variable with u32, since we can't unify i32 and u32. The solution
is faily straightforward though: we still reject types that don't satisfy the constraints,
but hold off on promoting the type until we materialize the variable after determining
that a given overload is a viable candidate. This guarantees that there will be a
suitable promotion that will satisfy the constraints, but we delay choosing which
type we'll promote to until we have looked at all arguments.
* Source/WebGPU/WGSL/Overload.cpp:
(WGSL::OverloadResolver::materialize const):
(WGSL::OverloadResolver::assign):
* Source/WebGPU/WGSL/tests/valid/overload.wgsl:
Canonical link: https://commits.webkit.org/263355@main
More information about the webkit-changes
mailing list