[WHLSL] Return statements don't need to keep track of the function they're in
authorrmorisset@apple.com <rmorisset@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Jul 2019 17:43:41 +0000 (17:43 +0000)
committerrmorisset@apple.com <rmorisset@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Jul 2019 17:43:41 +0000 (17:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199763

Reviewed by Myles C. Maxfield.

Return::m_function is only used in the Checker, and it can easily enough keep track of the current function.
This means we no longer need to keep track of the current function in the NameResolver, and we can save 8 bytes per Return

Since I was touching the NameResolver I also removed a few pointless overrides of Visitor::visit().

No new tests as there is no intended functional change.

* Modules/webgpu/WHLSL/AST/WHLSLReturn.h:
* Modules/webgpu/WHLSL/WHLSLChecker.cpp:
(WebCore::WHLSL::Checker::visit):
* Modules/webgpu/WHLSL/WHLSLNameResolver.cpp:
(WebCore::WHLSL::NameResolver::NameResolver):
(WebCore::WHLSL::resolveTypeNamesInFunctions):
* Modules/webgpu/WHLSL/WHLSLNameResolver.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@247419 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReturn.h
Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h

index 802d6c3..09e22ce 100644 (file)
@@ -1,3 +1,25 @@
+2019-07-13  Robin Morisset  <rmorisset@apple.com>
+
+        [WHLSL] Return statements don't need to keep track of the function they're in
+        https://bugs.webkit.org/show_bug.cgi?id=199763
+
+        Reviewed by Myles C. Maxfield.
+
+        Return::m_function is only used in the Checker, and it can easily enough keep track of the current function.
+        This means we no longer need to keep track of the current function in the NameResolver, and we can save 8 bytes per Return
+
+        Since I was touching the NameResolver I also removed a few pointless overrides of Visitor::visit().
+
+        No new tests as there is no intended functional change.
+
+        * Modules/webgpu/WHLSL/AST/WHLSLReturn.h:
+        * Modules/webgpu/WHLSL/WHLSLChecker.cpp:
+        (WebCore::WHLSL::Checker::visit):
+        * Modules/webgpu/WHLSL/WHLSLNameResolver.cpp:
+        (WebCore::WHLSL::NameResolver::NameResolver):
+        (WebCore::WHLSL::resolveTypeNamesInFunctions):
+        * Modules/webgpu/WHLSL/WHLSLNameResolver.h:
+
 2019-07-13  Andres Gonzalez  <andresg_22@apple.com>
 
         Add accessibility support to WKDataListSuggestionsView.
index a73b4b1..5794186 100644 (file)
@@ -56,12 +56,8 @@ public:
 
     Expression* value() { return m_value.get(); }
 
-    FunctionDefinition* function() { return m_function; }
-    void setFunction(FunctionDefinition* functionDefinition) { m_function = functionDefinition; }
-
 private:
     std::unique_ptr<Expression> m_value;
-    FunctionDefinition* m_function { nullptr };
 };
 
 } // namespace AST
index c0c83ff..06997bf 100644 (file)
@@ -517,6 +517,7 @@ private:
     HashSet<String> m_computeEntryPoints;
     const Intrinsics& m_intrinsics;
     Program& m_program;
+    AST::FunctionDefinition* m_currentFunction { nullptr };
 };
 
 void Checker::visit(Program& program)
@@ -572,6 +573,7 @@ bool Checker::checkShaderType(const AST::FunctionDefinition& functionDefinition)
 
 void Checker::visit(AST::FunctionDefinition& functionDefinition)
 {
+    m_currentFunction = &functionDefinition;
     if (functionDefinition.entryPointType()) {
         if (!checkShaderType(functionDefinition)) {
             setError();
@@ -1144,12 +1146,12 @@ void Checker::visit(AST::Return& returnStatement)
         auto valueInfo = recurseAndGetInfo(*returnStatement.value());
         if (!valueInfo)
             return;
-        if (!matchAndCommit(valueInfo->resolvingType, returnStatement.function()->type()))
+        if (!matchAndCommit(valueInfo->resolvingType, m_currentFunction->type()))
             setError();
         return;
     }
 
-    if (!matches(returnStatement.function()->type(), m_intrinsics.voidType()))
+    if (!matches(m_currentFunction->type(), m_intrinsics.voidType()))
         setError();
 }
 
index 6b83c64..3660439 100644 (file)
@@ -28,7 +28,6 @@
 
 #if ENABLE(WEBGPU)
 
-#include "WHLSLCallExpression.h"
 #include "WHLSLDoWhileLoop.h"
 #include "WHLSLDotExpression.h"
 #include "WHLSLEnumerationDefinition.h"
 #include "WHLSLIfStatement.h"
 #include "WHLSLNameContext.h"
 #include "WHLSLProgram.h"
-#include "WHLSLPropertyAccessExpression.h"
 #include "WHLSLReplaceWith.h"
 #include "WHLSLResolveOverloadImpl.h"
-#include "WHLSLReturn.h"
 #include "WHLSLScopedSetAdder.h"
 #include "WHLSLTypeReference.h"
 #include "WHLSLVariableDeclaration.h"
@@ -61,7 +58,6 @@ NameResolver::NameResolver(NameResolver& parentResolver, NameContext& nameContex
     : m_nameContext(nameContext)
     , m_parentNameResolver(&parentResolver)
 {
-    setCurrentFunctionDefinition(parentResolver.m_currentFunction);
 }
 
 NameResolver::~NameResolver()
@@ -190,18 +186,6 @@ void NameResolver::visit(AST::VariableReference& variableReference)
     }
 }
 
-void NameResolver::visit(AST::Return& returnStatement)
-{
-    ASSERT(m_currentFunction);
-    returnStatement.setFunction(m_currentFunction);
-    Visitor::visit(returnStatement);
-}
-
-void NameResolver::visit(AST::PropertyAccessExpression& propertyAccessExpression)
-{
-    Visitor::visit(propertyAccessExpression);
-}
-
 void NameResolver::visit(AST::DotExpression& dotExpression)
 {
     if (is<AST::VariableReference>(dotExpression.base())) {
@@ -226,11 +210,6 @@ void NameResolver::visit(AST::DotExpression& dotExpression)
     Visitor::visit(dotExpression);
 }
 
-void NameResolver::visit(AST::CallExpression& callExpression)
-{
-    Visitor::visit(callExpression);
-}
-
 void NameResolver::visit(AST::EnumerationMemberLiteral& enumerationMemberLiteral)
 {
     if (enumerationMemberLiteral.enumerationMember())
@@ -288,12 +267,10 @@ bool resolveNamesInTypes(Program& program, NameResolver& nameResolver)
 bool resolveTypeNamesInFunctions(Program& program, NameResolver& nameResolver)
 {
     for (auto& functionDefinition : program.functionDefinitions()) {
-        nameResolver.setCurrentFunctionDefinition(&functionDefinition);
         nameResolver.checkErrorAndVisit(functionDefinition);
         if (nameResolver.error())
             return false;
     }
-    nameResolver.setCurrentFunctionDefinition(nullptr);
     for (auto& nativeFunctionDeclaration : program.nativeFunctionDeclarations()) {
         nameResolver.checkErrorAndVisit(nativeFunctionDeclaration);
         if (nameResolver.error())
index 9237b37..3acdadf 100644 (file)
@@ -44,11 +44,6 @@ public:
 
     virtual ~NameResolver();
 
-    void setCurrentFunctionDefinition(AST::FunctionDefinition* functionDefinition)
-    {
-        m_currentFunction = functionDefinition;
-    }
-
 private:
     void visit(AST::FunctionDefinition&) override;
     void visit(AST::NativeFunctionDeclaration&) override;
@@ -60,15 +55,11 @@ private:
     void visit(AST::ForLoop&) override;
     void visit(AST::VariableDeclaration&) override;
     void visit(AST::VariableReference&) override;
-    void visit(AST::Return&) override;
-    void visit(AST::PropertyAccessExpression&) override;
     void visit(AST::DotExpression&) override;
-    void visit(AST::CallExpression&) override;
     void visit(AST::EnumerationMemberLiteral&) override;
 
     NameContext& m_nameContext;
     HashSet<AST::TypeReference*> m_typeReferences;
-    AST::FunctionDefinition* m_currentFunction { nullptr };
     NameResolver* m_parentNameResolver { nullptr };
 };