Diff
Modified: trunk/Source/WebCore/ChangeLog (240095 => 240096)
--- trunk/Source/WebCore/ChangeLog 2019-01-17 00:31:20 UTC (rev 240095)
+++ trunk/Source/WebCore/ChangeLog 2019-01-17 00:53:40 UTC (rev 240096)
@@ -1,5 +1,26 @@
2019-01-16 Myles C. Maxfield <[email protected]>
+ [WHLSL] Implement the recursion checker
+ https://bugs.webkit.org/show_bug.cgi?id=193436
+
+ Reviewed by Saam Barati.
+
+ This is a translation of https://github.com/gpuweb/WHLSL/blob/master/Source/RecursionChecker.mjs into C++.
+
+ No new tests because it isn't hooked up yet. Not enough of the compiler exists to have any meaningful sort
+ of test. When enough of the compiler is present, I'll port the reference implementation's test suite.
+
+ * Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h:
+ (WebCore::WHLSL::AST::CallExpression::function):
+ * Modules/webgpu/WHLSL/WHLSLRecursionChecker.cpp: Copied from Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp.
+ (WebCore::WHLSL::checkRecursion):
+ * Modules/webgpu/WHLSL/WHLSLRecursionChecker.h: Added.
+ * Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp:
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+
+2019-01-16 Myles C. Maxfield <[email protected]>
+
[WHLSL] Add the literal type checker
https://bugs.webkit.org/show_bug.cgi?id=193430
Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h (240095 => 240096)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h 2019-01-17 00:31:20 UTC (rev 240095)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h 2019-01-17 00:53:40 UTC (rev 240096)
@@ -75,6 +75,8 @@
m_overloads = overloads;
}
+ FunctionDeclaration* function() { return m_function; }
+
void setFunction(FunctionDeclaration& functionDeclaration)
{
assert(!m_function);
Added: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursionChecker.cpp (0 => 240096)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursionChecker.cpp (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursionChecker.cpp 2019-01-17 00:53:40 UTC (rev 240096)
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WHLSLRecursionChecker.h"
+
+#if ENABLE(WEBGPU)
+
+#include "WHLSLCallExpression.h"
+#include "WHLSLFunctionDefinition.h"
+#include "WHLSLVisitor.h"
+#include <wtf/HashSet.h>
+
+namespace WebCore {
+
+namespace WHLSL {
+
+// Makes sure there is no function recursion.
+class RecursionChecker : public Visitor {
+private:
+ void visit(AST::FunctionDefinition& functionDefinition) override
+ {
+ auto addResult = m_visitingSet.add(&functionDefinition);
+ if (!addResult.isNewEntry) {
+ setError();
+ return;
+ }
+
+ Visitor::visit(functionDefinition);
+
+ auto success = m_visitingSet.remove(&functionDefinition);
+ ASSERT_UNUSED(success, success);
+ }
+
+ void visit(AST::CallExpression& callExpression) override
+ {
+ ASSERT(callExpression.function());
+ Visitor::visit(*callExpression.function());
+ }
+
+ HashSet<AST::FunctionDefinition*> m_visitingSet;
+};
+
+bool checkRecursion(Program& program)
+{
+ RecursionChecker recursionChecker;
+ recursionChecker.Visitor::visit(program);
+ return !recursionChecker.error();
+}
+
+}
+
+}
+
+#endif
Added: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursionChecker.h (0 => 240096)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursionChecker.h (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursionChecker.h 2019-01-17 00:53:40 UTC (rev 240096)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGPU)
+
+namespace WebCore {
+
+namespace WHLSL {
+
+class Program;
+
+bool checkRecursion(Program&);
+
+}
+
+}
+
+#endif
Modified: trunk/Source/WebCore/Sources.txt (240095 => 240096)
--- trunk/Source/WebCore/Sources.txt 2019-01-17 00:31:20 UTC (rev 240095)
+++ trunk/Source/WebCore/Sources.txt 2019-01-17 00:53:40 UTC (rev 240096)
@@ -321,6 +321,7 @@
Modules/webgpu/WHLSL/WHLSLNameContext.cpp
Modules/webgpu/WHLSL/WHLSLNameResolver.cpp
Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.cpp
+Modules/webgpu/WHLSL/WHLSLRecursionChecker.cpp
Modules/webgpu/WHLSL/WHLSLVisitor.cpp
Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp
Modules/webgpu/WHLSL/WHLSLHighZombieFinder.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (240095 => 240096)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-01-17 00:31:20 UTC (rev 240095)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-01-17 00:53:40 UTC (rev 240096)
@@ -6427,6 +6427,8 @@
1C840B9A21EC400900D0500D /* WHLSLGatherEntryPointItems.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLGatherEntryPointItems.h; sourceTree = "<group>"; };
1C840B9B21EC400900D0500D /* WHLSLChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLChecker.cpp; sourceTree = "<group>"; };
1C904DF90BA9D2C80081E9D0 /* Version.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Version.xcconfig; sourceTree = "<group>"; };
+ 1CA0C2DE21EEB5F400A11860 /* WHLSLRecursionChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLRecursionChecker.h; sourceTree = "<group>"; };
+ 1CA0C2E021EEB5F500A11860 /* WHLSLRecursionChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLRecursionChecker.cpp; sourceTree = "<group>"; };
1CA0C2EA21EED6F500A11860 /* WHLSLLiteralTypeChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLLiteralTypeChecker.h; sourceTree = "<group>"; };
1CA0C2EC21EED6F600A11860 /* WHLSLLiteralTypeChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLLiteralTypeChecker.cpp; sourceTree = "<group>"; };
1C9AE5CA21ED9DF50069D5F2 /* WHLSLHighZombieFinder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLHighZombieFinder.cpp; sourceTree = "<group>"; };
@@ -25480,6 +25482,8 @@
C21BF73721CD8A0200227979 /* WHLSLParser.cpp */,
C21BF73821CD8A0300227979 /* WHLSLParser.h */,
C21BF73A21CD8D7000227979 /* WHLSLProgram.h */,
+ 1CA0C2E021EEB5F500A11860 /* WHLSLRecursionChecker.cpp */,
+ 1CA0C2DE21EEB5F400A11860 /* WHLSLRecursionChecker.h */,
C234A9AD21E92C19003C984D /* WHLSLRecursiveTypeChecker.cpp */,
C234A9AB21E92C18003C984D /* WHLSLRecursiveTypeChecker.h */,
C234A99921E90F29003C984D /* WHLSLResolveOverloadImpl.cpp */,