WebKit Bugzilla
Attachment 370539 Details for
Bug 195794
: [WHLSL] Enforce variable lifetimes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP
b-backup.diff (text/plain), 15.56 KB, created by
Saam Barati
on 2019-05-23 18:20:38 PDT
(
hide
)
Description:
WIP
Filename:
MIME Type:
Creator:
Saam Barati
Created:
2019-05-23 18:20:38 PDT
Size:
15.56 KB
patch
obsolete
>Index: Source/WebCore/ChangeLog >=================================================================== >--- Source/WebCore/ChangeLog (revision 245728) >+++ Source/WebCore/ChangeLog (working copy) >@@ -1,3 +1,26 @@ >+2019-05-23 Saam barati <sbarati@apple.com> >+ >+ [WHLSL] ReadModifyWriteExpression always has a result and new value expression >+ https://bugs.webkit.org/show_bug.cgi?id=198079 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Let's not pretend it might not. >+ >+ * Modules/webgpu/WHLSL/AST/WHLSLReadModifyWriteExpression.h: >+ (WebCore::WHLSL::AST::ReadModifyWriteExpression::newValueExpression): >+ (WebCore::WHLSL::AST::ReadModifyWriteExpression::resultExpression): >+ (WebCore::WHLSL::AST::ReadModifyWriteExpression::takeNewValueExpression): >+ (WebCore::WHLSL::AST::ReadModifyWriteExpression::takeResultExpression): >+ * Modules/webgpu/WHLSL/WHLSLASTDumper.cpp: >+ (WebCore::WHLSL::ASTDumper::visit): >+ * Modules/webgpu/WHLSL/WHLSLChecker.cpp: >+ (WebCore::WHLSL::Checker::visit): >+ * Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp: >+ (WebCore::WHLSL::PropertyResolver::visit): >+ * Modules/webgpu/WHLSL/WHLSLVisitor.cpp: >+ (WebCore::WHLSL::Visitor::visit): >+ > 2019-05-23 Devin Rousso <drousso@apple.com> > > Web Inspector: Overlay: rulers should switch sides if they intersect the highlighted node(s) so they don't obstruct any content >Index: Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.cpp >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.cpp (revision 245727) >+++ Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.cpp (working copy) >@@ -625,7 +625,7 @@ void ASTDumper::visit(AST::ReadModifyWri > > visit(newVariable.get()); > m_out.print(" = "); >- visit(*readModifyWriteExpression.newValueExpression()); >+ visit(readModifyWriteExpression.newValueExpression()); > m_out.print(", "); > > visit(readModifyWriteExpression.leftValue()); >@@ -633,7 +633,7 @@ void ASTDumper::visit(AST::ReadModifyWri > visit(newVariable.get()); > m_out.print(", "); > >- visit(*readModifyWriteExpression.resultExpression()); >+ visit(readModifyWriteExpression.resultExpression()); > m_out.print(")"); > } > >Index: Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp (revision 245727) >+++ Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp (working copy) >@@ -847,7 +847,7 @@ void Checker::visit(AST::ReadModifyWrite > > // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198166 Figure out what to do with the ReadModifyWriteExpression's AnonymousVariables. > >- auto newValueInfo = recurseAndGetInfo(*readModifyWriteExpression.newValueExpression()); >+ auto newValueInfo = recurseAndGetInfo(readModifyWriteExpression.newValueExpression()); > if (!newValueInfo) > return; > >@@ -856,7 +856,7 @@ void Checker::visit(AST::ReadModifyWrite > return; > } > >- auto resultInfo = recurseAndGetInfo(*readModifyWriteExpression.resultExpression()); >+ auto resultInfo = recurseAndGetInfo(readModifyWriteExpression.resultExpression()); > if (!resultInfo) > return; > >Index: Source/WebCore/Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp (nonexistent) >+++ Source/WebCore/Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp (working copy) >@@ -0,0 +1,92 @@ >+/* >+ * 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 "WHLSLPreserveVariableLifetimes.h" >+ >+#if ENABLE(WEBGPU) >+ >+#include "WHLSLAST.h" >+#include "WHLSLVisitor.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+ >+class EscapedVariableCollector : Visitor { >+ using Base = Visitor; >+public: >+ void visit(AST::MakePointerExpression& makePointerExpression) override >+ { >+ // OOPS: figure out "(&(*foo))" >+ // OOPS: If we solve &*foo, I think this can be an assert? Because we should >+ // have transformed &foo.bar to ander calls already. But maybe I'm missing something >+ // obvious. >+ if (!is<AST::VariableReference>(makePointerExpression.leftValue())) { >+ visit(makePointerExpression.leftValue()); >+ return; >+ } >+ >+ auto& variableReference = downcast<AST::VariableReference>(makePointerExpression.leftValue()); >+ auto* variable = variableReference.variable(); >+ // If variable is unnamed, it means it's internal. We don't allow internal variables to escape. >+ // OOPS: verify this is correct. >+ if (variable->name().isEmpty()) >+ return; >+ m_escapedVariables.add(variable, makeString(variable->name(), m_count++)); >+ } >+ >+ HashMap<AST::VariableDeclaration*, String> takeEscapedVariables() { return WTFMove(m_escapedVariables); } >+ >+private: >+ size_t m_count { 1 }; >+ HashMap<AST::VariableDeclaration*, String> m_escapedVariables; >+}; >+ >+void preserveVariableLifetimes(Program& program) >+{ >+ >+ EscapedVariableCollector collector; >+ collector.visit(program); >+ HashMap<AST::VariableDeclaration*, String> escapedVariables = collector.takeEscapedVariables(); >+ >+ >+ StructureElements elements; >+ for (auto& pair : escapedVariables) { >+ auto* variable = pair.key; >+ String name = pair.value; >+ // OOPS: qualifiers? >+ // OOPS: Do I need to clone the type? Does ptr value itself matter? >+ elements.append(StructureElement { AST::Lexer::Token(), { }, variable->type()->clone(), WTFMove(name), WTF::nullopt }); >+ } >+ auto* wrapperStruct = makeUniqueRef<AST::StructureDefinition>(AST::Lexer::Token(), "OOPS_make_this_a_real_unique_name", WTFMove(elements)); >+} >+ >+} // namespace WHLSL >+ >+} // namespace WebCore >+ >+#endif // ENABLE(WEBGPU) >Index: Source/WebCore/Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.h >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.h (nonexistent) >+++ Source/WebCore/Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.h (working copy) >@@ -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 preserveVariableLifetimes(Program&); >+ >+} >+ >+} >+ >+#endif >Index: Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp (revision 245727) >+++ Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp (working copy) >@@ -474,8 +474,7 @@ void PropertyResolver::visit(AST::ReadMo > variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right? > > auto newValueExpression = readModifyWriteExpression.takeNewValueExpression(); >- ASSERT(newValueExpression); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198170 Relax this constraint. >- auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(readModifyWriteExpression.origin()), WTFMove(variableReference), WTFMove(*newValueExpression)); >+ auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(readModifyWriteExpression.origin()), WTFMove(variableReference), WTFMove(newValueExpression)); > assignmentExpression->setType(baseType->clone()); > assignmentExpression->setTypeAnnotation(AST::RightValue()); > >@@ -503,9 +502,8 @@ void PropertyResolver::visit(AST::ReadMo > } > > auto resultExpression = readModifyWriteExpression.takeResultExpression(); >- ASSERT(resultExpression); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198170 Be resilient to this being null. >- auto type = (*resultExpression)->resolvedType().clone(); >- expressions.append(WTFMove(*resultExpression)); >+ auto type = resultExpression->resolvedType().clone(); >+ expressions.append(WTFMove(resultExpression)); > > UniqueRef<AST::VariableDeclaration> oldVariableDeclaration = readModifyWriteExpression.takeOldValue(); > UniqueRef<AST::VariableDeclaration> newVariableDeclaration = readModifyWriteExpression.takeNewValue(); >@@ -549,8 +547,7 @@ void PropertyResolver::visit(AST::ReadMo > variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right? > > auto newValueExpression = readModifyWriteExpression.takeNewValueExpression(); >- ASSERT(newValueExpression); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198170 Relax this constraint >- auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(readModifyWriteExpression.leftValue().origin()), WTFMove(variableReference), WTFMove(*newValueExpression)); >+ auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(readModifyWriteExpression.leftValue().origin()), WTFMove(variableReference), WTFMove(newValueExpression)); > assignmentExpression->setType(readModifyWriteExpression.leftValue().resolvedType().clone()); > assignmentExpression->setTypeAnnotation(AST::RightValue()); > >@@ -567,9 +564,8 @@ void PropertyResolver::visit(AST::ReadMo > simplifyLeftValue(modifyResult->innerLeftValue); > > auto resultExpression = readModifyWriteExpression.takeResultExpression(); >- ASSERT(resultExpression); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198170 Be resilient to this being null. >- auto type = (*resultExpression)->resolvedType().clone(); >- modifyResult->expressions.append(WTFMove(*resultExpression)); >+ auto type = resultExpression->resolvedType().clone(); >+ modifyResult->expressions.append(WTFMove(resultExpression)); > > UniqueRef<AST::VariableDeclaration> oldVariableDeclaration = readModifyWriteExpression.takeOldValue(); > UniqueRef<AST::VariableDeclaration> newVariableDeclaration = readModifyWriteExpression.takeNewValue(); >Index: Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.cpp >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.cpp (revision 245727) >+++ Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.cpp (working copy) >@@ -536,10 +536,8 @@ void Visitor::visit(AST::ReadModifyWrite > checkErrorAndVisit(readModifyWriteExpression.leftValue()); > checkErrorAndVisit(readModifyWriteExpression.oldValue()); > checkErrorAndVisit(readModifyWriteExpression.newValue()); >- if (readModifyWriteExpression.newValueExpression()) >- checkErrorAndVisit(*readModifyWriteExpression.newValueExpression()); >- if (readModifyWriteExpression.resultExpression()) >- checkErrorAndVisit(*readModifyWriteExpression.resultExpression()); >+ checkErrorAndVisit(readModifyWriteExpression.newValueExpression()); >+ checkErrorAndVisit(readModifyWriteExpression.resultExpression()); > } > > void Visitor::visit(AST::TernaryExpression& ternaryExpression) >Index: Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReadModifyWriteExpression.h >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReadModifyWriteExpression.h (revision 245727) >+++ Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReadModifyWriteExpression.h (working copy) >@@ -86,13 +86,23 @@ public: > Expression& leftValue() { return m_leftValue; } > VariableDeclaration& oldValue() { return m_oldValue; } > VariableDeclaration& newValue() { return m_newValue; } >- Expression* newValueExpression() { return m_newValueExpression ? &*m_newValueExpression : nullptr; } >- Expression* resultExpression() { return m_resultExpression ? &*m_resultExpression : nullptr; } >+ Expression& newValueExpression() { ASSERT(m_newValueExpression); return *m_newValueExpression; } >+ Expression& resultExpression() { ASSERT(m_resultExpression); return *m_resultExpression; } > UniqueRef<Expression> takeLeftValue() { return WTFMove(m_leftValue); } > UniqueRef<VariableDeclaration> takeOldValue() { return WTFMove(m_oldValue); } > UniqueRef<VariableDeclaration> takeNewValue() { return WTFMove(m_newValue); } >- Optional<UniqueRef<Expression>> takeNewValueExpression() { return WTFMove(m_newValueExpression); } >- Optional<UniqueRef<Expression>> takeResultExpression() { return WTFMove(m_resultExpression); } >+ UniqueRef<Expression> takeNewValueExpression() >+ { >+ auto result = WTFMove(m_newValueExpression.value()); >+ m_newValueExpression.reset(); >+ return result; >+ } >+ UniqueRef<Expression> takeResultExpression() >+ { >+ auto result = WTFMove(m_resultExpression.value()); >+ m_resultExpression.reset(); >+ return result; >+ } > > private: > template<class U, class... Args> friend UniqueRef<U> WTF::makeUniqueRef(Args&&...);
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 195794
:
370539
|
370620
|
370786
|
370795
|
370802
|
370821
|
370827
|
370915
|
370916
|
370959
|
370999
|
371004
|
371027