Changeset 245706 in webkit
- Timestamp:
- May 23, 2019 12:54:53 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r245701 r245706 1 2019-05-23 Saam barati <sbarati@apple.com> 2 3 [WHLSL] Add a helper for in-place AST mutation 4 https://bugs.webkit.org/show_bug.cgi?id=198175 5 6 Reviewed by Myles Maxfield. 7 8 This makes WHLSL AST mutation code a bit easier to read and write. 9 10 Code that looked like: 11 ``` 12 static_assert(sizeof(AST::DereferenceExpression) <= sizeof(AST::DotExpression), "Dot expressions need to be able to become dereference expressions without updating backreferences"); 13 void* location = &dotExpression; 14 dotExpression.~DotExpression(); 15 auto* dereferenceExpression = new (location) AST::DereferenceExpression(WTFMove(origin), WTFMove(callExpression)); 16 ``` 17 18 Can now be: 19 ``` 20 auto* dereferenceExpression = AST::replaceWith<AST::DereferenceExpression>(dotExpression, WTFMove(origin), WTFMove(callExpression)); 21 ``` 22 23 * Modules/webgpu/WHLSL/AST/WHLSLNode.h: 24 (WebCore::WHLSL::AST::replaceWith): 25 * Modules/webgpu/WHLSL/WHLSLNameResolver.cpp: 26 (WebCore::WHLSL::NameResolver::visit): 27 * Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp: 28 (WebCore::WHLSL::PropertyResolver::visit): 29 (WebCore::WHLSL::PropertyResolver::simplifyRightValue): 30 (WebCore::WHLSL::LeftValueSimplifier::visit): 31 1 32 2019-05-23 Eric Carlson <eric.carlson@apple.com> 2 33 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNode.h
r239844 r245706 49 49 }; 50 50 51 template <typename New, typename Old, typename ...Args> 52 ALWAYS_INLINE New* replaceWith(Old& old, Args&&... args) 53 { 54 static_assert(sizeof(New) <= sizeof(Old), "This is needed for the placement new below to not overwrite unowned memory."); 55 void* location = &old; 56 old.~Old(); 57 return new (location) New(std::forward<Args>(args)...); 58 } 59 51 60 } // namespace AST 52 61 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp
r245680 r245706 195 195 auto memberName = dotExpression.fieldName(); 196 196 if (auto* member = enumerationDefinition.memberByName(memberName)) { 197 static_assert(sizeof(AST::EnumerationMemberLiteral) <= sizeof(AST::DotExpression), "Dot expressions need to be able to become EnumerationMemberLiterals without updating backreferences");198 197 Lexer::Token origin = dotExpression.origin(); 199 void* location = &dotExpression;200 dotExpression.~DotExpression();201 198 auto enumerationMemberLiteral = AST::EnumerationMemberLiteral::wrap(WTFMove(origin), WTFMove(baseName), WTFMove(memberName), enumerationDefinition, *member); 202 new (location) AST::EnumerationMemberLiteral(WTFMove(enumerationMemberLiteral));199 AST::replaceWith<AST::EnumerationMemberLiteral>(dotExpression, WTFMove(enumerationMemberLiteral)); 203 200 return; 204 201 } -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp
r245680 r245706 405 405 simplifyLeftValue(modifyResult->innerLeftValue); 406 406 407 static_assert(sizeof(AST::CommaExpression) <= sizeof(AST::AssignmentExpression), "Assignment expressions need to be able to become comma expressions without updating backreferences");408 407 Lexer::Token origin = assignmentExpression.origin(); 409 void* location = &assignmentExpression; 410 assignmentExpression.~AssignmentExpression(); 411 auto* commaExpression = new (location) AST::CommaExpression(WTFMove(origin), WTFMove(modifyResult->expressions)); 408 auto* commaExpression = AST::replaceWith<AST::CommaExpression>(assignmentExpression, WTFMove(origin), WTFMove(modifyResult->expressions)); 412 409 commaExpression->setType(WTFMove(type)); 413 410 commaExpression->setTypeAnnotation(AST::RightValue()); … … 514 511 UniqueRef<AST::VariableDeclaration> newVariableDeclaration = readModifyWriteExpression.takeNewValue(); 515 512 516 static_assert(sizeof(AST::CommaExpression) <= sizeof(AST::ReadModifyWriteExpression), "ReadModifyWrite expressions need to be able to become comma expressions without updating backreferences");517 513 Lexer::Token origin = readModifyWriteExpression.origin(); 518 void* location = &readModifyWriteExpression; 519 readModifyWriteExpression.~ReadModifyWriteExpression(); 520 auto* commaExpression = new (location) AST::CommaExpression(WTFMove(origin), WTFMove(expressions)); 514 auto* commaExpression = AST::replaceWith<AST::CommaExpression>(readModifyWriteExpression, WTFMove(origin), WTFMove(expressions)); 521 515 commaExpression->setType(WTFMove(type)); 522 516 commaExpression->setTypeAnnotation(AST::RightValue()); … … 581 575 UniqueRef<AST::VariableDeclaration> newVariableDeclaration = readModifyWriteExpression.takeNewValue(); 582 576 583 static_assert(sizeof(AST::CommaExpression) <= sizeof(AST::ReadModifyWriteExpression), "ReadModifyWrite expressions need to be able to become comma expressions without updating backreferences");584 577 Lexer::Token origin = readModifyWriteExpression.origin(); 585 void* location = &readModifyWriteExpression; 586 readModifyWriteExpression.~ReadModifyWriteExpression(); 587 auto* commaExpression = new (location) AST::CommaExpression(WTFMove(origin), WTFMove(modifyResult->expressions)); 578 auto* commaExpression = AST::replaceWith<AST::CommaExpression>(readModifyWriteExpression, WTFMove(origin), WTFMove(modifyResult->expressions)); 588 579 commaExpression->setType(WTFMove(type)); 589 580 commaExpression->setTypeAnnotation(AST::RightValue()); … … 613 604 callExpression->setFunction(*anderFunction); 614 605 615 static_assert(sizeof(AST::DereferenceExpression) <= sizeof(AST::DotExpression), "Dot expressions need to be able to become dereference expressions without updating backreferences"); 616 void* location = &dotExpression; 617 dotExpression.~DotExpression(); 618 auto* dereferenceExpression = new (location) AST::DereferenceExpression(WTFMove(origin), WTFMove(callExpression)); 606 auto* dereferenceExpression = AST::replaceWith<AST::DereferenceExpression>(dotExpression, WTFMove(origin), WTFMove(callExpression)); 619 607 dereferenceExpression->setType(downcast<AST::PointerType>(anderFunction->type()).elementType().clone()); 620 608 dereferenceExpression->setTypeAnnotation(AST::LeftValue { downcast<AST::PointerType>(anderFunction->type()).addressSpace() }); … … 656 644 dereferenceExpression->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); 657 645 658 static_assert(sizeof(AST::CommaExpression) <= sizeof(AST::DotExpression), "Dot expressions need to be able to become comma expressions without updating backreferences");659 void* location = &dotExpression;660 dotExpression.~DotExpression();661 646 Vector<UniqueRef<AST::Expression>> expressions; 662 647 expressions.append(WTFMove(assignmentExpression)); 663 648 expressions.append(WTFMove(dereferenceExpression)); 664 auto* commaExpression = new (location) AST::CommaExpression(WTFMove(origin), WTFMove(expressions));649 auto* commaExpression = AST::replaceWith<AST::CommaExpression>(dotExpression, WTFMove(origin), WTFMove(expressions)); 665 650 commaExpression->setType(downcast<AST::PointerType>(anderFunction->type()).elementType().clone()); 666 651 commaExpression->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); … … 670 655 } 671 656 672 static_assert(sizeof(AST::CallExpression) <= sizeof(AST::DotExpression), "Dot expressions need to be able to become call expressions without updating backreferences");673 657 ASSERT(dotExpression.getterFunction()); 674 658 auto& getterFunction = *dotExpression.getterFunction(); 675 659 Vector<UniqueRef<AST::Expression>> arguments; 676 660 arguments.append(dotExpression.takeBase()); 677 void* location = &dotExpression; 678 dotExpression.~DotExpression(); 679 auto* callExpression = new (location) AST::CallExpression(WTFMove(origin), String(getterFunction.name()), WTFMove(arguments)); 661 auto* callExpression = AST::replaceWith<AST::CallExpression>(dotExpression, WTFMove(origin), String(getterFunction.name()), WTFMove(arguments)); 680 662 callExpression->setFunction(getterFunction); 681 663 callExpression->setType(getterFunction.type().clone()); … … 713 695 callExpression->setFunction(*anderFunction); 714 696 715 static_assert(sizeof(AST::DereferenceExpression) <= sizeof(AST::DotExpression), "Dot expressions need to be able to become dereference expressions without updating backreferences"); 716 void* location = &dotExpression; 717 dotExpression.~DotExpression(); 718 auto* dereferenceExpression = new (location) AST::DereferenceExpression(WTFMove(origin), WTFMove(callExpression)); 697 auto* dereferenceExpression = AST::replaceWith<AST::DereferenceExpression>(dotExpression, WTFMove(origin), WTFMove(callExpression)); 719 698 dereferenceExpression->setType(downcast<AST::PointerType>(anderFunction->type()).elementType().clone()); 720 699 dereferenceExpression->setTypeAnnotation(AST::LeftValue { downcast<AST::PointerType>(anderFunction->type()).addressSpace() });
Note: See TracChangeset
for help on using the changeset viewer.