[webkit-changes] [WebKit/WebKit] d042e6: [WGSL] Merge constant rewriting into the type checker

Tadeu Zagallo noreply at github.com
Mon Oct 2 06:44:15 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: d042e66eb2af2bdbaa7522173356c7a4013502a4
      https://github.com/WebKit/WebKit/commit/d042e66eb2af2bdbaa7522173356c7a4013502a4
  Author: Tadeu Zagallo <tzagallo at apple.com>
  Date:   2023-10-02 (Mon, 02 Oct 2023)

  Changed paths:
    M Source/WebGPU/WGSL/AST/ASTExpression.h
    M Source/WebGPU/WGSL/AST/ASTVisitor.cpp
    M Source/WebGPU/WGSL/AST/ASTVisitor.h
    M Source/WebGPU/WGSL/ConstantFunctions.h
    R Source/WebGPU/WGSL/ConstantRewriter.cpp
    R Source/WebGPU/WGSL/ConstantRewriter.h
    M Source/WebGPU/WGSL/ConstantValue.h
    M Source/WebGPU/WGSL/EntryPointRewriter.cpp
    M Source/WebGPU/WGSL/GlobalVariableRewriter.cpp
    M Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp
    M Source/WebGPU/WGSL/TypeCheck.cpp
    M Source/WebGPU/WGSL/WGSL.cpp
    M Source/WebGPU/WGSL/tests/valid/global-constant-vector.wgsl
    M Source/WebGPU/WGSL/tests/valid/global-used-by-callee.wgsl
    M Source/WebGPU/WGSL/tests/valid/local-constant-vector.wgsl
    M Source/WebGPU/WGSL/tests/valid/packing.wgsl
    M Source/WebGPU/WebGPU.xcodeproj/project.pbxproj

  Log Message:
  -----------
  [WGSL] Merge constant rewriting into the type checker
https://bugs.webkit.org/show_bug.cgi?id=262387
rdar://116247645

Reviewed by Mike Wyrzykowski.

Originally I was trying to keep type checking and constant rewriting as separate
passes, as I think it's nice to have small passes with a single responsibility,
but I don't think it's possible in this case. Constant rewriting depends on type
checking, in order to make sure that the expressions that are being evaluated are
valid, and type checking depends depends on constant evaluation, for things like
`array<T, constexpr>`. While merging the two phases, I also simplified a couple
of things:
- Remove the constant duplication/insertion, which was currently implement as part
  of the global rewriter (which wasn't a great design to begin with). Instead, we
  now just serialize all the constants inline. If that proves to be a problem, we
  can always fallback to the previous approach, but probably implemented in a more
  appropriate place anyway.
- Stopped replacing AST nodes: instead, we just save the constant value in all Expression
  nodes and check it during serialization. This greatly simplified the code.

* Source/WebGPU/WGSL/AST/ASTExpression.h:
(WGSL::AST::Expression::constantValue const):
(WGSL::AST::Expression::setConstantValue):
* Source/WebGPU/WGSL/AST/ASTVisitor.cpp:
(WGSL::AST::extractInteger): Deleted.
* Source/WebGPU/WGSL/AST/ASTVisitor.h:
* Source/WebGPU/WGSL/ConstantFunctions.h:
(WGSL::constantVector):
* Source/WebGPU/WGSL/ConstantRewriter.cpp: Removed.
* Source/WebGPU/WGSL/ConstantRewriter.h: Removed.
* Source/WebGPU/WGSL/ConstantValue.h:
(WGSL::ConstantValue::toInt const):
(WGSL::ConstantValue::toDouble const):
* Source/WebGPU/WGSL/EntryPointRewriter.cpp:
(WGSL::EntryPointRewriter::EntryPointRewriter):
* Source/WebGPU/WGSL/GlobalVariableRewriter.cpp:
(WGSL::RewriteGlobalVariables::collectGlobals):
(WGSL::RewriteGlobalVariables::insertStructs):
(WGSL::RewriteGlobalVariables::insertParameters):
(WGSL::RewriteGlobalVariables::readVariable):
* Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp:
(WGSL::Metal::FunctionDefinitionWriter::visit):
(WGSL::Metal::FunctionDefinitionWriter::serializeConstant):
* Source/WebGPU/WGSL/TypeCheck.cpp:
(WGSL::TypeChecker::TypeChecker):
(WGSL::TypeChecker::visitVariable):
(WGSL::TypeChecker::visit):
(WGSL::TypeChecker::introduceType):
(WGSL::TypeChecker::introduceValue):
(WGSL::TypeChecker::setConstantValue):
* Source/WebGPU/WGSL/WGSL.cpp:
(WGSL::staticCheck):
* Source/WebGPU/WGSL/tests/valid/global-constant-vector.wgsl:
* Source/WebGPU/WGSL/tests/valid/global-used-by-callee.wgsl:
* Source/WebGPU/WGSL/tests/valid/local-constant-vector.wgsl:
* Source/WebGPU/WGSL/tests/valid/packing.wgsl:
* Source/WebGPU/WebGPU.xcodeproj/project.pbxproj:

Canonical link: https://commits.webkit.org/268726@main




More information about the webkit-changes mailing list