WebKit Bugzilla
Attachment 370512 Details for
Bug 198175
: [WHLSL] Add a helper for in-place AST mutation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch for landing
b-backup.diff (text/plain), 10.98 KB, created by
Saam Barati
on 2019-05-23 11:40:04 PDT
(
hide
)
Description:
patch for landing
Filename:
MIME Type:
Creator:
Saam Barati
Created:
2019-05-23 11:40:04 PDT
Size:
10.98 KB
patch
obsolete
>Index: Source/WebCore/ChangeLog >=================================================================== >--- Source/WebCore/ChangeLog (revision 245699) >+++ Source/WebCore/ChangeLog (working copy) >@@ -1,3 +1,34 @@ >+2019-05-23 Saam barati <sbarati@apple.com> >+ >+ [WHLSL] Add a helper for in-place AST mutation >+ https://bugs.webkit.org/show_bug.cgi?id=198175 >+ >+ Reviewed by Myles Maxfield. >+ >+ This makes WHLSL AST mutation code a bit easier to read and write. >+ >+ Code that looked like: >+ ``` >+ static_assert(sizeof(AST::DereferenceExpression) <= sizeof(AST::DotExpression), "Dot expressions need to be able to become dereference expressions without updating backreferences"); >+ void* location = &dotExpression; >+ dotExpression.~DotExpression(); >+ auto* dereferenceExpression = new (location) AST::DereferenceExpression(WTFMove(origin), WTFMove(callExpression)); >+ ``` >+ >+ Can now be: >+ ``` >+ auto* dereferenceExpression = AST::replaceWith<AST::DereferenceExpression>(dotExpression, WTFMove(origin), WTFMove(callExpression)); >+ ``` >+ >+ * Modules/webgpu/WHLSL/AST/WHLSLNode.h: >+ (WebCore::WHLSL::AST::replaceWith): >+ * Modules/webgpu/WHLSL/WHLSLNameResolver.cpp: >+ (WebCore::WHLSL::NameResolver::visit): >+ * Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp: >+ (WebCore::WHLSL::PropertyResolver::visit): >+ (WebCore::WHLSL::PropertyResolver::simplifyRightValue): >+ (WebCore::WHLSL::LeftValueSimplifier::visit): >+ > 2019-05-23 Antoine Quint <graouts@apple.com> > > [Pointer Events] Compatibility mouse events can only be prevented while the pointer is pressed >Index: Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp (revision 245692) >+++ Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp (working copy) >@@ -194,12 +194,9 @@ void NameResolver::visit(AST::DotExpress > AST::EnumerationDefinition& enumerationDefinition = downcast<AST::EnumerationDefinition>(type); > auto memberName = dotExpression.fieldName(); > if (auto* member = enumerationDefinition.memberByName(memberName)) { >- static_assert(sizeof(AST::EnumerationMemberLiteral) <= sizeof(AST::DotExpression), "Dot expressions need to be able to become EnumerationMemberLiterals without updating backreferences"); > Lexer::Token origin = dotExpression.origin(); >- void* location = &dotExpression; >- dotExpression.~DotExpression(); > auto enumerationMemberLiteral = AST::EnumerationMemberLiteral::wrap(WTFMove(origin), WTFMove(baseName), WTFMove(memberName), enumerationDefinition, *member); >- new (location) AST::EnumerationMemberLiteral(WTFMove(enumerationMemberLiteral)); >+ AST::replaceWith<AST::EnumerationMemberLiteral>(dotExpression, WTFMove(enumerationMemberLiteral)); > return; > } > setError(); >Index: Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp (revision 245692) >+++ Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp (working copy) >@@ -404,11 +404,8 @@ void PropertyResolver::visit(AST::Assign > } > simplifyLeftValue(modifyResult->innerLeftValue); > >- static_assert(sizeof(AST::CommaExpression) <= sizeof(AST::AssignmentExpression), "Assignment expressions need to be able to become comma expressions without updating backreferences"); > Lexer::Token origin = assignmentExpression.origin(); >- void* location = &assignmentExpression; >- assignmentExpression.~AssignmentExpression(); >- auto* commaExpression = new (location) AST::CommaExpression(WTFMove(origin), WTFMove(modifyResult->expressions)); >+ auto* commaExpression = AST::replaceWith<AST::CommaExpression>(assignmentExpression, WTFMove(origin), WTFMove(modifyResult->expressions)); > commaExpression->setType(WTFMove(type)); > commaExpression->setTypeAnnotation(AST::RightValue()); > >@@ -513,11 +510,8 @@ void PropertyResolver::visit(AST::ReadMo > UniqueRef<AST::VariableDeclaration> oldVariableDeclaration = readModifyWriteExpression.takeOldValue(); > UniqueRef<AST::VariableDeclaration> newVariableDeclaration = readModifyWriteExpression.takeNewValue(); > >- static_assert(sizeof(AST::CommaExpression) <= sizeof(AST::ReadModifyWriteExpression), "ReadModifyWrite expressions need to be able to become comma expressions without updating backreferences"); > Lexer::Token origin = readModifyWriteExpression.origin(); >- void* location = &readModifyWriteExpression; >- readModifyWriteExpression.~ReadModifyWriteExpression(); >- auto* commaExpression = new (location) AST::CommaExpression(WTFMove(origin), WTFMove(expressions)); >+ auto* commaExpression = AST::replaceWith<AST::CommaExpression>(readModifyWriteExpression, WTFMove(origin), WTFMove(expressions)); > commaExpression->setType(WTFMove(type)); > commaExpression->setTypeAnnotation(AST::RightValue()); > >@@ -580,11 +574,8 @@ void PropertyResolver::visit(AST::ReadMo > UniqueRef<AST::VariableDeclaration> oldVariableDeclaration = readModifyWriteExpression.takeOldValue(); > UniqueRef<AST::VariableDeclaration> newVariableDeclaration = readModifyWriteExpression.takeNewValue(); > >- static_assert(sizeof(AST::CommaExpression) <= sizeof(AST::ReadModifyWriteExpression), "ReadModifyWrite expressions need to be able to become comma expressions without updating backreferences"); > Lexer::Token origin = readModifyWriteExpression.origin(); >- void* location = &readModifyWriteExpression; >- readModifyWriteExpression.~ReadModifyWriteExpression(); >- auto* commaExpression = new (location) AST::CommaExpression(WTFMove(origin), WTFMove(modifyResult->expressions)); >+ auto* commaExpression = AST::replaceWith<AST::CommaExpression>(readModifyWriteExpression, WTFMove(origin), WTFMove(modifyResult->expressions)); > commaExpression->setType(WTFMove(type)); > commaExpression->setTypeAnnotation(AST::RightValue()); > >@@ -612,10 +603,7 @@ bool PropertyResolver::simplifyRightValu > callExpression->setTypeAnnotation(AST::RightValue()); > callExpression->setFunction(*anderFunction); > >- static_assert(sizeof(AST::DereferenceExpression) <= sizeof(AST::DotExpression), "Dot expressions need to be able to become dereference expressions without updating backreferences"); >- void* location = &dotExpression; >- dotExpression.~DotExpression(); >- auto* dereferenceExpression = new (location) AST::DereferenceExpression(WTFMove(origin), WTFMove(callExpression)); >+ auto* dereferenceExpression = AST::replaceWith<AST::DereferenceExpression>(dotExpression, WTFMove(origin), WTFMove(callExpression)); > dereferenceExpression->setType(downcast<AST::PointerType>(anderFunction->type()).elementType().clone()); > dereferenceExpression->setTypeAnnotation(AST::LeftValue { downcast<AST::PointerType>(anderFunction->type()).addressSpace() }); > return true; >@@ -655,13 +643,10 @@ bool PropertyResolver::simplifyRightValu > dereferenceExpression->setType(downcast<AST::PointerType>(anderFunction->type()).elementType().clone()); > dereferenceExpression->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); > >- static_assert(sizeof(AST::CommaExpression) <= sizeof(AST::DotExpression), "Dot expressions need to be able to become comma expressions without updating backreferences"); >- void* location = &dotExpression; >- dotExpression.~DotExpression(); > Vector<UniqueRef<AST::Expression>> expressions; > expressions.append(WTFMove(assignmentExpression)); > expressions.append(WTFMove(dereferenceExpression)); >- auto* commaExpression = new (location) AST::CommaExpression(WTFMove(origin), WTFMove(expressions)); >+ auto* commaExpression = AST::replaceWith<AST::CommaExpression>(dotExpression, WTFMove(origin), WTFMove(expressions)); > commaExpression->setType(downcast<AST::PointerType>(anderFunction->type()).elementType().clone()); > commaExpression->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); > >@@ -669,14 +654,11 @@ bool PropertyResolver::simplifyRightValu > return true; > } > >- static_assert(sizeof(AST::CallExpression) <= sizeof(AST::DotExpression), "Dot expressions need to be able to become call expressions without updating backreferences"); > ASSERT(dotExpression.getterFunction()); > auto& getterFunction = *dotExpression.getterFunction(); > Vector<UniqueRef<AST::Expression>> arguments; > arguments.append(dotExpression.takeBase()); >- void* location = &dotExpression; >- dotExpression.~DotExpression(); >- auto* callExpression = new (location) AST::CallExpression(WTFMove(origin), String(getterFunction.name()), WTFMove(arguments)); >+ auto* callExpression = AST::replaceWith<AST::CallExpression>(dotExpression, WTFMove(origin), String(getterFunction.name()), WTFMove(arguments)); > callExpression->setFunction(getterFunction); > callExpression->setType(getterFunction.type().clone()); > callExpression->setTypeAnnotation(AST::RightValue()); >@@ -712,10 +694,7 @@ void LeftValueSimplifier::visit(AST::Dot > callExpression->setTypeAnnotation(AST::RightValue()); > callExpression->setFunction(*anderFunction); > >- static_assert(sizeof(AST::DereferenceExpression) <= sizeof(AST::DotExpression), "Dot expressions need to be able to become dereference expressions without updating backreferences"); >- void* location = &dotExpression; >- dotExpression.~DotExpression(); >- auto* dereferenceExpression = new (location) AST::DereferenceExpression(WTFMove(origin), WTFMove(callExpression)); >+ auto* dereferenceExpression = AST::replaceWith<AST::DereferenceExpression>(dotExpression, WTFMove(origin), WTFMove(callExpression)); > dereferenceExpression->setType(downcast<AST::PointerType>(anderFunction->type()).elementType().clone()); > dereferenceExpression->setTypeAnnotation(AST::LeftValue { downcast<AST::PointerType>(anderFunction->type()).addressSpace() }); > } >Index: Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNode.h >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNode.h (revision 245692) >+++ Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNode.h (working copy) >@@ -48,6 +48,15 @@ public: > private: > }; > >+template <typename New, typename Old, typename ...Args> >+ALWAYS_INLINE New* replaceWith(Old& old, Args&&... args) >+{ >+ static_assert(sizeof(New) <= sizeof(Old), "This is needed for the placement new below to not overwrite unowned memory."); >+ void* location = &old; >+ old.~Old(); >+ return new (location) New(std::forward<Args>(args)...); >+} >+ > } // namespace AST > > }
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 198175
:
370510
| 370512