Skip to content

[WGSL] Type checker should exit after encountering the first error #47246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

tadeuzagallo
Copy link
Member

@tadeuzagallo tadeuzagallo commented Jun 26, 2025

ffb2fe1

[WGSL] Type checker should exit after encountering the first error
https://bugs.webkit.org/show_bug.cgi?id=295038
rdar://154408433

Reviewed by Mike Wyrzykowski.

In order to reduce the amount of code reachable from incorrect/malicious shaders,
the type checker should immediately return after encountering the first error
instead of trying to continue and report as many errors as possible at once.

NOTE: this breaks many wgslc tests, but those are already broken due to a recent
python upgrade and in the process of being migrated to TestWebKitAPI

* Source/WebGPU/WGSL/AST/AST.h:
* Source/WebGPU/WGSL/AST/ASTBitcastExpression.h: Removed.
* Source/WebGPU/WGSL/AST/ASTExpression.h:
(isType):
* Source/WebGPU/WGSL/AST/ASTForward.h:
* Source/WebGPU/WGSL/AST/ASTNode.h:
* Source/WebGPU/WGSL/AST/ASTStatement.h:
(isType):
* Source/WebGPU/WGSL/AST/ASTStaticAssertStatement.h: Removed.
* Source/WebGPU/WGSL/AST/ASTVisitor.cpp:
(WGSL::AST::Visitor::visit):
* Source/WebGPU/WGSL/AST/ASTVisitor.h:
* Source/WebGPU/WGSL/BoundsCheck.cpp:
(WGSL::BoundsCheckVisitor::visit):
* Source/WebGPU/WGSL/CMakeLists.txt:
* Source/WebGPU/WGSL/ConstantFunctions.h:
(WGSL::zeroValue):
* Source/WebGPU/WGSL/Constraints.cpp:
(WGSL::concretize):
* Source/WebGPU/WGSL/GlobalVariableRewriter.cpp:
(WGSL::RewriteGlobalVariables::pack):
(WGSL::bindingMemberForGlobal):
(WGSL::bindingTypeForType):
(WGSL::RewriteGlobalVariables::insertWorkgroupBarrier):
(WGSL::RewriteGlobalVariables::storeInitialValue):
* Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp:
(WGSL::Metal::FunctionDefinitionWriter::visit):
(WGSL::Metal::FunctionDefinitionWriter::serializeConstant):
* Source/WebGPU/WGSL/TypeCheck.cpp:
(WGSL::TypeChecker::TypeChecker):
(WGSL::TypeChecker::declareBuiltins):
(WGSL::TypeChecker::check):
(WGSL::TypeChecker::visit):
(WGSL::TypeChecker::visitStatements):
(WGSL::TypeChecker::binaryExpression):
(WGSL::TypeChecker::bitcast):
(WGSL::TypeChecker::validateF16Usage):
(WGSL::TypeChecker::visitAttributes):
(WGSL::TypeChecker::analyze):
(WGSL::TypeChecker::analyzeStatements):
(WGSL::TypeChecker::unify):
(WGSL::TypeChecker::introduceType):
(WGSL::TypeChecker::convertValue):
(WGSL::TypeChecker::convertValueImpl):
(WGSL::TypeChecker::introduceValue):
(WGSL::TypeChecker::introduceFunction):
(WGSL::TypeChecker::allocateSimpleConstructor):
(WGSL::TypeChecker::allocateTextureStorageConstructor):
(WGSL::TypeChecker::texelFormat):
(WGSL::TypeChecker::accessMode):
(WGSL::TypeChecker::addressSpace):
(WGSL::TypeChecker::setConstantValue):
(WGSL::TypeChecker::lookupType): Deleted.
(WGSL::TypeChecker::vectorFieldAccess): Deleted.
(WGSL::TypeChecker::chooseOverload): Deleted.
(WGSL::TypeChecker::infer): Deleted.
(WGSL::TypeChecker::resolve): Deleted.
(WGSL::TypeChecker::isBottom const): Deleted.
(WGSL::TypeChecker::typeError): Deleted.
* Source/WebGPU/WGSL/TypeStore.cpp:
(WGSL::TypeStore::TypeStore):
(WGSL::TypeStore::typeConstructorType):
* Source/WebGPU/WGSL/TypeStore.h:
(WGSL::TypeStore::bottomType const): Deleted.
* Source/WebGPU/WGSL/Types.cpp:
(WGSL::Type::dump const):
(WGSL::Type::maybeSize const):
(WGSL::Type::alignment const):
(WGSL::Type::isConstructible const):
(WGSL::Type::isStorable const):
(WGSL::Type::isHostShareable const):
(WGSL::Type::hasFixedFootprint const):
(WGSL::Type::hasCreationFixedFootprint const):
* Source/WebGPU/WGSL/Types.h:
* Source/WebGPU/WGSL/generator/main.rb:
* Source/WebGPU/WebGPU.xcodeproj/project.pbxproj:

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

ea1841a

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
❌ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🛠 wpe-cairo
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@tadeuzagallo tadeuzagallo self-assigned this Jun 26, 2025
@tadeuzagallo tadeuzagallo added the WebGPU For bugs in WebGPU label Jun 26, 2025
Copy link
Contributor

@mwyrzykowski mwyrzykowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ but does appear to have a failing WGSL test to fix

@tadeuzagallo tadeuzagallo force-pushed the eng/WGSL-Type-checker-should-exit-after-encountering-the-first-error branch from e14eaa1 to ea1841a Compare June 30, 2025 13:05
@tadeuzagallo tadeuzagallo added the merge-queue Applied to send a pull request to merge-queue label Jun 30, 2025
https://bugs.webkit.org/show_bug.cgi?id=295038
rdar://154408433

Reviewed by Mike Wyrzykowski.

In order to reduce the amount of code reachable from incorrect/malicious shaders,
the type checker should immediately return after encountering the first error
instead of trying to continue and report as many errors as possible at once.

NOTE: this breaks many wgslc tests, but those are already broken due to a recent
python upgrade and in the process of being migrated to TestWebKitAPI

* Source/WebGPU/WGSL/AST/AST.h:
* Source/WebGPU/WGSL/AST/ASTBitcastExpression.h: Removed.
* Source/WebGPU/WGSL/AST/ASTExpression.h:
(isType):
* Source/WebGPU/WGSL/AST/ASTForward.h:
* Source/WebGPU/WGSL/AST/ASTNode.h:
* Source/WebGPU/WGSL/AST/ASTStatement.h:
(isType):
* Source/WebGPU/WGSL/AST/ASTStaticAssertStatement.h: Removed.
* Source/WebGPU/WGSL/AST/ASTVisitor.cpp:
(WGSL::AST::Visitor::visit):
* Source/WebGPU/WGSL/AST/ASTVisitor.h:
* Source/WebGPU/WGSL/BoundsCheck.cpp:
(WGSL::BoundsCheckVisitor::visit):
* Source/WebGPU/WGSL/CMakeLists.txt:
* Source/WebGPU/WGSL/ConstantFunctions.h:
(WGSL::zeroValue):
* Source/WebGPU/WGSL/Constraints.cpp:
(WGSL::concretize):
* Source/WebGPU/WGSL/GlobalVariableRewriter.cpp:
(WGSL::RewriteGlobalVariables::pack):
(WGSL::bindingMemberForGlobal):
(WGSL::bindingTypeForType):
(WGSL::RewriteGlobalVariables::insertWorkgroupBarrier):
(WGSL::RewriteGlobalVariables::storeInitialValue):
* Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp:
(WGSL::Metal::FunctionDefinitionWriter::visit):
(WGSL::Metal::FunctionDefinitionWriter::serializeConstant):
* Source/WebGPU/WGSL/TypeCheck.cpp:
(WGSL::TypeChecker::TypeChecker):
(WGSL::TypeChecker::declareBuiltins):
(WGSL::TypeChecker::check):
(WGSL::TypeChecker::visit):
(WGSL::TypeChecker::visitStatements):
(WGSL::TypeChecker::binaryExpression):
(WGSL::TypeChecker::bitcast):
(WGSL::TypeChecker::validateF16Usage):
(WGSL::TypeChecker::visitAttributes):
(WGSL::TypeChecker::analyze):
(WGSL::TypeChecker::analyzeStatements):
(WGSL::TypeChecker::unify):
(WGSL::TypeChecker::introduceType):
(WGSL::TypeChecker::convertValue):
(WGSL::TypeChecker::convertValueImpl):
(WGSL::TypeChecker::introduceValue):
(WGSL::TypeChecker::introduceFunction):
(WGSL::TypeChecker::allocateSimpleConstructor):
(WGSL::TypeChecker::allocateTextureStorageConstructor):
(WGSL::TypeChecker::texelFormat):
(WGSL::TypeChecker::accessMode):
(WGSL::TypeChecker::addressSpace):
(WGSL::TypeChecker::setConstantValue):
(WGSL::TypeChecker::lookupType): Deleted.
(WGSL::TypeChecker::vectorFieldAccess): Deleted.
(WGSL::TypeChecker::chooseOverload): Deleted.
(WGSL::TypeChecker::infer): Deleted.
(WGSL::TypeChecker::resolve): Deleted.
(WGSL::TypeChecker::isBottom const): Deleted.
(WGSL::TypeChecker::typeError): Deleted.
* Source/WebGPU/WGSL/TypeStore.cpp:
(WGSL::TypeStore::TypeStore):
(WGSL::TypeStore::typeConstructorType):
* Source/WebGPU/WGSL/TypeStore.h:
(WGSL::TypeStore::bottomType const): Deleted.
* Source/WebGPU/WGSL/Types.cpp:
(WGSL::Type::dump const):
(WGSL::Type::maybeSize const):
(WGSL::Type::alignment const):
(WGSL::Type::isConstructible const):
(WGSL::Type::isStorable const):
(WGSL::Type::isHostShareable const):
(WGSL::Type::hasFixedFootprint const):
(WGSL::Type::hasCreationFixedFootprint const):
* Source/WebGPU/WGSL/Types.h:
* Source/WebGPU/WGSL/generator/main.rb:
* Source/WebGPU/WebGPU.xcodeproj/project.pbxproj:

Canonical link: https://commits.webkit.org/296795@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/WGSL-Type-checker-should-exit-after-encountering-the-first-error branch from ea1841a to ffb2fe1 Compare June 30, 2025 15:27
@webkit-commit-queue
Copy link
Collaborator

Committed 296795@main (ffb2fe1): https://commits.webkit.org/296795@main

Reviewed commits have been landed. Closing PR #47246 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit ffb2fe1 into WebKit:main Jun 30, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebGPU For bugs in WebGPU
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants