Diff
Modified: trunk/Source/WebCore/ChangeLog (240094 => 240095)
--- trunk/Source/WebCore/ChangeLog 2019-01-17 00:20:11 UTC (rev 240094)
+++ trunk/Source/WebCore/ChangeLog 2019-01-17 00:31:20 UTC (rev 240095)
@@ -1,3 +1,29 @@
+2019-01-16 Myles C. Maxfield <[email protected]>
+
+ [WHLSL] Add the literal type checker
+ https://bugs.webkit.org/show_bug.cgi?id=193430
+
+ Reviewed by Dean Jackson.
+
+ This is a translation of https://github.com/gpuweb/WHLSL/blob/master/Source/LiteralTypeChecker.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/WHLSLFloatLiteralType.h:
+ (WebCore::WHLSL::AST::FloatLiteralType::value const):
+ * Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h:
+ (WebCore::WHLSL::AST::IntegerLiteralType::value const):
+ * Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h:
+ (WebCore::WHLSL::AST::UnsignedIntegerLiteralType::value const):
+ * Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp: Added.
+ (WebCore::WHLSL::getNativeTypeDeclaration):
+ (WebCore::WHLSL::LiteralTypeChecker::visit):
+ (WebCore::WHLSL::checkLiteralTypes):
+ * Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.h: Copied from Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h.
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+
2019-01-16 Zalan Bujtas <[email protected]>
[LFC][BFC] Inflow non-replaced used width should not be negative.
Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h (240094 => 240095)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h 2019-01-17 00:20:11 UTC (rev 240094)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h 2019-01-17 00:31:20 UTC (rev 240095)
@@ -53,6 +53,8 @@
bool isFloatLiteralType() const override { return true; }
+ float value() const { return m_value; }
+
TypeReference& preferredType() { return m_preferredType; }
bool canResolve(const Type&) const override;
Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h (240094 => 240095)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h 2019-01-17 00:20:11 UTC (rev 240094)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h 2019-01-17 00:31:20 UTC (rev 240095)
@@ -53,6 +53,8 @@
bool isIntegerLiteralType() const override { return true; }
+ int value() const { return m_value; }
+
TypeReference& preferredType() { return m_preferredType; }
bool canResolve(const Type&) const override;
Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h (240094 => 240095)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h 2019-01-17 00:20:11 UTC (rev 240094)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h 2019-01-17 00:31:20 UTC (rev 240095)
@@ -53,6 +53,8 @@
bool isUnsignedIntegerLiteralType() const override { return true; }
+ unsigned value() const { return m_value; }
+
TypeReference& preferredType() { return m_preferredType; }
bool canResolve(const Type&) const override;
Added: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp (0 => 240095)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp 2019-01-17 00:31:20 UTC (rev 240095)
@@ -0,0 +1,100 @@
+/*
+ * 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 "WHLSLLiteralTypeChecker.h"
+
+#if ENABLE(WEBGPU)
+
+#include "WHLSLIntegerLiteralType.h"
+#include "WHLSLNativeTypeDeclaration.h"
+#include "WHLSLNullLiteralType.h"
+#include "WHLSLProgram.h"
+#include "WHLSLTypeReference.h"
+#include "WHLSLVisitor.h"
+
+namespace WebCore {
+
+namespace WHLSL {
+
+#if !ASSERT_DISABLED
+static AST::NativeTypeDeclaration* getNativeTypeDeclaration(AST::ResolvableType& resolvableType)
+{
+ if (!resolvableType.resolvedType())
+ return nullptr;
+ if (!is<AST::TypeReference>(*resolvableType.resolvedType()))
+ return nullptr;
+ auto& typeReference = downcast<AST::TypeReference>(*resolvableType.resolvedType());
+ ASSERT(typeReference.resolvedType());
+ if (!is<AST::NativeTypeDeclaration>(*typeReference.resolvedType()))
+ return nullptr;
+ return &downcast<AST::NativeTypeDeclaration>(*typeReference.resolvedType());
+}
+
+class LiteralTypeChecker : public Visitor {
+public:
+private:
+ void visit(AST::FloatLiteralType& floatLiteralType) override
+ {
+ auto* nativeTypeDeclaration = getNativeTypeDeclaration(floatLiteralType);
+ ASSERT(nativeTypeDeclaration);
+ ASSERT(nativeTypeDeclaration->canRepresentFloat()(floatLiteralType.value()));
+ }
+
+ void visit(AST::IntegerLiteralType& integerLiteralType) override
+ {
+ auto* nativeTypeDeclaration = getNativeTypeDeclaration(integerLiteralType);
+ ASSERT(nativeTypeDeclaration);
+ ASSERT(nativeTypeDeclaration->canRepresentInteger()(integerLiteralType.value()));
+ }
+
+ void visit(AST::UnsignedIntegerLiteralType& unsignedIntegerLiteralType) override
+ {
+ auto* nativeTypeDeclaration = getNativeTypeDeclaration(unsignedIntegerLiteralType);
+ ASSERT(nativeTypeDeclaration);
+ ASSERT(nativeTypeDeclaration->canRepresentUnsignedInteger()(unsignedIntegerLiteralType.value()));
+ }
+
+ void visit(AST::NullLiteralType& nullLiteralType) override
+ {
+ ASSERT(nullLiteralType.resolvedType());
+ }
+};
+#endif
+
+void checkLiteralTypes(Program& program)
+{
+#if ASSERT_DISABLED
+ UNUSED_PARAM(program);
+#else
+ LiteralTypeChecker().Visitor::visit(program);
+#endif
+}
+
+} // namespace WHLSL
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
Copied: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.h (from rev 240094, trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h) (0 => 240095)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.h (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.h 2019-01-17 00:31:20 UTC (rev 240095)
@@ -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;
+
+void checkLiteralTypes(Program&);
+
+}
+
+}
+
+#endif
Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp (240094 => 240095)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp 2019-01-17 00:20:11 UTC (rev 240094)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp 2019-01-17 00:31:20 UTC (rev 240095)
@@ -2586,8 +2586,8 @@
}
}
-}
+} // namespace WHLSL
-}
+} // namespace WebCore
-#endif
+#endif // ENABLE(WEBGPU)
Modified: trunk/Source/WebCore/Sources.txt (240094 => 240095)
--- trunk/Source/WebCore/Sources.txt 2019-01-17 00:20:11 UTC (rev 240094)
+++ trunk/Source/WebCore/Sources.txt 2019-01-17 00:31:20 UTC (rev 240095)
@@ -322,6 +322,7 @@
Modules/webgpu/WHLSL/WHLSLNameResolver.cpp
Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.cpp
Modules/webgpu/WHLSL/WHLSLVisitor.cpp
+Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp
Modules/webgpu/WHLSL/WHLSLHighZombieFinder.cpp
Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp
Modules/webgpu/WHLSL/AST/WHLSLTypeArgument.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (240094 => 240095)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-01-17 00:20:11 UTC (rev 240094)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-01-17 00:31:20 UTC (rev 240095)
@@ -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>"; };
+ 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>"; };
1C9AE5CB21ED9DF50069D5F2 /* WHLSLHighZombieFinder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLHighZombieFinder.h; sourceTree = "<group>"; };
1CA0C2F421EEDAD000A11860 /* WHLSLLoopChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLLoopChecker.cpp; sourceTree = "<group>"; };
@@ -25452,7 +25454,6 @@
C210E90D21B4BCA400B7F83D /* WHLSL */ = {
isa = PBXGroup;
children = (
- C21BF6F121CD898D00227979 /* AST */,
1CA0C2F621EEDAD200A11860 /* AST */,
C234A9B221E92C1F003C984D /* WHLSLCheckDuplicateFunctions.cpp */,
C234A9AE21E92C1A003C984D /* WHLSLCheckDuplicateFunctions.h */,
@@ -25468,6 +25469,8 @@
C234A9B621E92CC0003C984D /* WHLSLIntrinsics.h */,
C210E91121B4BD1000B7F83D /* WHLSLLexer.cpp */,
C210E91221B4BD1000B7F83D /* WHLSLLexer.h */,
+ 1CA0C2EC21EED6F600A11860 /* WHLSLLiteralTypeChecker.cpp */,
+ 1CA0C2EA21EED6F500A11860 /* WHLSLLiteralTypeChecker.h */,
1CA0C2F421EEDAD000A11860 /* WHLSLLoopChecker.cpp */,
1CA0C2F521EEDAD100A11860 /* WHLSLLoopChecker.h */,
C234A98D21E88884003C984D /* WHLSLNameContext.cpp */,
@@ -25497,7 +25500,7 @@
path = WHLSL;
sourceTree = "<group>";
};
- C21BF6F121CD898D00227979 /* AST */ = {
+ 1CA0C2F621EEDAD200A11860 /* AST */ = {
isa = PBXGroup;
children = (
1C840B9021EC30F900D0500D /* WHLSLAddressSpace.h */,