WSL needs a way to verify that structs are not cyclic
authorfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Sep 2017 17:41:11 +0000 (17:41 +0000)
committerfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Sep 2017 17:41:11 +0000 (17:41 +0000)
commitf584d086838593d823cafb9eead94651d5c9ef6c
treeb18be8b56daae73d91b4f4c4c9b97874410ec301
parent2cc32d1a9a0ac8edeca018731325e71dfc5debb9
WSL needs a way to verify that structs are not cyclic
https://bugs.webkit.org/show_bug.cgi?id=177044

Reviewed by Myles Maxfield.

This adds a recursive type checking phase. Even before adding this phase, the compiler would
successfully detect recursive types - but at the cost of also rejecting programs that had
recursive types indirectly through pointers. To make both things work, I had to change Visitor
to no longer visit TypeRef.type by default. This resulted in some other changes in a few other
parts of the code that previously relied on that behavior.

* WebGPUShadingLanguageRI/All.js:
* WebGPUShadingLanguageRI/CheckRecursiveTypes.js: Added.
(checkRecursiveTypes):
* WebGPUShadingLanguageRI/Checker.js:
(Checker.prototype._checkShaderType.NonNumericSearcher.prototype.visitArrayRefType):
(Checker.prototype._checkShaderType.NonNumericSearcher.prototype.visitPtrType):
(Checker.prototype._checkShaderType.NonNumericSearcher.prototype.visitTypeRef):
(Checker.prototype._checkShaderType.NonNumericSearcher):
(Checker.prototype._checkShaderType):
(Checker.prototype.visitTypeRef):
* WebGPUShadingLanguageRI/NameResolver.js:
(NameResolver.prototype.visitProtocolDecl):
* WebGPUShadingLanguageRI/Prepare.js:
(let.prepare):
* WebGPUShadingLanguageRI/RecursiveTypeChecker.js: Added.
(RecursiveTypeChecker):
(RecursiveTypeChecker.prototype.visitFuncDef):
(RecursiveTypeChecker.prototype.visitNativeFunc):
(RecursiveTypeChecker.prototype.visitStructType):
(RecursiveTypeChecker.prototype.visitReferenceType):
(RecursiveTypeChecker.prototype.visitTypeRef):
* WebGPUShadingLanguageRI/StructLayoutBuilder.js:
(StructLayoutBuilder.prototype.visitTypeRef):
(StructLayoutBuilder):
* WebGPUShadingLanguageRI/Test.html:
* WebGPUShadingLanguageRI/Test.js:
(TEST_simpleRecursiveStruct):
* WebGPUShadingLanguageRI/TypeDefResolver.js:
(TypeDefResolver.prototype.visitTypeRef):
(TypeDefResolver):
* WebGPUShadingLanguageRI/Visitor.js:
(Visitor.prototype.visitProtocolDecl):
* WebGPUShadingLanguageRI/index.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222328 268f45cc-cd09-0410-ab3c-d52691b4dbfc
16 files changed:
Tools/ChangeLog
Tools/WebGPUShadingLanguageRI/All.js
Tools/WebGPUShadingLanguageRI/CallFunction.js
Tools/WebGPUShadingLanguageRI/CheckRecursiveTypes.js [new file with mode: 0644]
Tools/WebGPUShadingLanguageRI/Checker.js
Tools/WebGPUShadingLanguageRI/EvaluationCommon.js
Tools/WebGPUShadingLanguageRI/Evaluator.js
Tools/WebGPUShadingLanguageRI/NameResolver.js
Tools/WebGPUShadingLanguageRI/Prepare.js
Tools/WebGPUShadingLanguageRI/RecursiveTypeChecker.js [new file with mode: 0644]
Tools/WebGPUShadingLanguageRI/StructLayoutBuilder.js
Tools/WebGPUShadingLanguageRI/Test.html
Tools/WebGPUShadingLanguageRI/Test.js
Tools/WebGPUShadingLanguageRI/TypeDefResolver.js
Tools/WebGPUShadingLanguageRI/Visitor.js
Tools/WebGPUShadingLanguageRI/index.html