Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information