[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:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@247419 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 802d6c3..09e22ce 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -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.
diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReturn.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReturn.h
index a73b4b1..5794186 100644
--- a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReturn.h
+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReturn.h
@@ -56,12 +56,8 @@
 
     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
diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp
index c0c83ff..06997bf 100644
--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp
+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp
@@ -517,6 +517,7 @@
     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 @@
 
 void Checker::visit(AST::FunctionDefinition& functionDefinition)
 {
+    m_currentFunction = &functionDefinition;
     if (functionDefinition.entryPointType()) {
         if (!checkShaderType(functionDefinition)) {
             setError();
@@ -1144,12 +1146,12 @@
         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();
 }
 
diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp
index 6b83c64..3660439 100644
--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp
+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp
@@ -28,7 +28,6 @@
 
 #if ENABLE(WEBGPU)
 
-#include "WHLSLCallExpression.h"
 #include "WHLSLDoWhileLoop.h"
 #include "WHLSLDotExpression.h"
 #include "WHLSLEnumerationDefinition.h"
@@ -38,10 +37,8 @@
 #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 @@
     : m_nameContext(nameContext)
     , m_parentNameResolver(&parentResolver)
 {
-    setCurrentFunctionDefinition(parentResolver.m_currentFunction);
 }
 
 NameResolver::~NameResolver()
@@ -190,18 +186,6 @@
     }
 }
 
-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 @@
     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 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())
diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h
index 9237b37..3acdadf 100644
--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h
+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h
@@ -44,11 +44,6 @@
 
     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 @@
     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 };
 };