WebKit Bugzilla
Attachment 359126 Details for
Bug 193430
: [WHLSL] Add the literal type checker
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-193430-20190114204728.patch (text/plain), 12.67 KB, created by
Myles C. Maxfield
on 2019-01-14 20:47:29 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Myles C. Maxfield
Created:
2019-01-14 20:47:29 PST
Size:
12.67 KB
patch
obsolete
>Subversion Revision: 239973 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index d270af322118c720bc47256425e78e33f6f3af6c..41543b8f0777a9e5886ce54d206664638a35b7ab 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,29 @@ >+2019-01-14 Myles C. Maxfield <mmaxfield@apple.com> >+ >+ [WHLSL] Add the literal type checker >+ https://bugs.webkit.org/show_bug.cgi?id=193430 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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-14 Simon Fraser <simon.fraser@apple.com> > > Only run the node comparison code in FrameSelection::respondToNodeModification() for range selections >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h >index bc9f037099de0d810bed89ab12a451e5b3b08366..64743c4aef449e93aba0100e89c4bdd16e2459e9 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h >@@ -53,6 +53,8 @@ public: > > bool isFloatLiteralType() const override { return true; } > >+ float value() const { return m_value; } >+ > TypeReference& preferredType() { return m_preferredType; } > > bool canResolve(const Type&) const override; >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h >index 55617b6ba9eafbe185cdfe1ecf0eb3145dcaebcd..3d06b1df5f8d988fad87ac92564f8cf1f008bb96 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h >@@ -53,6 +53,8 @@ public: > > bool isIntegerLiteralType() const override { return true; } > >+ int value() const { return m_value; } >+ > TypeReference& preferredType() { return m_preferredType; } > > bool canResolve(const Type&) const override; >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h >index 95fbff6b9029f05ab524f730f9543f4d1e702707..ebc3106bcabf270e1108b89e4da9d487e3ce99ea 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h >@@ -53,6 +53,8 @@ public: > > bool isUnsignedIntegerLiteralType() const override { return true; } > >+ unsigned value() const { return m_value; } >+ > TypeReference& preferredType() { return m_preferredType; } > > bool canResolve(const Type&) const override; >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..ad16eff999ff809f051bae5325fc2fbb14568cd8 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp >@@ -0,0 +1,120 @@ >+/* >+ * 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 { >+ >+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: >+ LiteralTypeChecker() = default; >+ >+ virtual ~LiteralTypeChecker() = default; >+ >+ virtual void visit(AST::FloatLiteralType& floatLiteralType) >+ { >+ auto* nativeTypeDeclaration = getNativeTypeDeclaration(floatLiteralType); >+ if (!nativeTypeDeclaration) { >+ setError(); >+ return; >+ } >+ if (!nativeTypeDeclaration->canRepresentInteger()(floatLiteralType.value())) { >+ setError(); >+ return; >+ } >+ } >+ >+ virtual void visit(AST::IntegerLiteralType& integerLiteralType) >+ { >+ auto* nativeTypeDeclaration = getNativeTypeDeclaration(integerLiteralType); >+ if (!nativeTypeDeclaration) { >+ setError(); >+ return; >+ } >+ if (!nativeTypeDeclaration->canRepresentInteger()(integerLiteralType.value())) { >+ setError(); >+ return; >+ } >+ } >+ >+ virtual void visit(AST::UnsignedIntegerLiteralType& unsignedIntegerLiteralType) >+ { >+ auto* nativeTypeDeclaration = getNativeTypeDeclaration(unsignedIntegerLiteralType); >+ if (!nativeTypeDeclaration) { >+ setError(); >+ return; >+ } >+ if (!nativeTypeDeclaration->canRepresentInteger()(unsignedIntegerLiteralType.value())) { >+ setError(); >+ return; >+ } >+ } >+ >+ virtual void visit(AST::NullLiteralType& nullLiteralType) >+ { >+ if (!nullLiteralType.resolvedType()) >+ setError(); >+ } >+ >+private: >+}; >+ >+bool checkLiteralTypes(Program& program) >+{ >+ LiteralTypeChecker literalTypeChecker; >+ literalTypeChecker.Visitor::visit(program); >+ return !literalTypeChecker.error(); >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.h >new file mode 100644 >index 0000000000000000000000000000000000000000..b1095bac84d4e4f467902553748fae79e3f69e4b >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.h >@@ -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 checkLiteralTypes(Program&); >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt >index 0d256353d74abd62663024bd8054c950e0738103..e120e21782a6b4e2e40f533cb1b13804c8bd9101 100644 >--- a/Source/WebCore/Sources.txt >+++ b/Source/WebCore/Sources.txt >@@ -320,6 +320,7 @@ Modules/webgpu/WHLSL/WHLSLNameContext.cpp > Modules/webgpu/WHLSL/WHLSLNameResolver.cpp > Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.cpp > Modules/webgpu/WHLSL/WHLSLVisitor.cpp >+Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp > Modules/webgpu/WHLSL/AST/WHLSLTypeArgument.cpp > Modules/webgpu/WHLSL/AST/WHLSLBuiltInSemantic.cpp > Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index f2f515a4e43e519f4f349474e71492539bf848fc..e5bb2cfff7791cf76184cf13df6598bdc001c00c 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -6417,6 +6417,8 @@ > 1C840B7D21EBE0B800D0500D /* WHLSLEntryPointType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLEntryPointType.h; sourceTree = "<group>"; }; > 1C840B9021EC30F900D0500D /* WHLSLAddressSpace.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLAddressSpace.h; sourceTree = "<group>"; }; > 1C904DF90BA9D2C80081E9D0 /* Version.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Version.xcconfig; sourceTree = "<group>"; }; >+ 1C9AE5C421ED98AC0069D5F2 /* WHLSLLiteralTypeChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLLiteralTypeChecker.cpp; sourceTree = "<group>"; }; >+ 1C9AE5C521ED98AC0069D5F2 /* WHLSLLiteralTypeChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLLiteralTypeChecker.h; sourceTree = "<group>"; }; > 1CA19E030DC255950065A994 /* EventLoopMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = EventLoopMac.mm; sourceTree = "<group>"; }; > 1CA19E150DC255CA0065A994 /* EventLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventLoop.h; sourceTree = "<group>"; }; > 1CAF347E0A6C405200ABE06E /* WebScriptObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptObject.h; sourceTree = "<group>"; }; >@@ -25422,6 +25424,8 @@ > C234A9B621E92CC0003C984D /* WHLSLIntrinsics.h */, > C210E91121B4BD1000B7F83D /* WHLSLLexer.cpp */, > C210E91221B4BD1000B7F83D /* WHLSLLexer.h */, >+ 1C9AE5C421ED98AC0069D5F2 /* WHLSLLiteralTypeChecker.cpp */, >+ 1C9AE5C521ED98AC0069D5F2 /* WHLSLLiteralTypeChecker.h */, > C234A98D21E88884003C984D /* WHLSLNameContext.cpp */, > C234A98E21E88885003C984D /* WHLSLNameContext.h */, > C234A98A21E8883E003C984D /* WHLSLNameResolver.cpp */,
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 193430
:
359126
|
359216
|
359245