Bug 198175

Summary: [WHLSL] Add a helper for in-place AST mutation
Product: WebKit Reporter: Myles C. Maxfield <mmaxfield>
Component: WebGPUAssignee: Saam Barati <saam>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, jfbastien, saam, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
patch
mmaxfield: review+
patch for landing none

Description Myles C. Maxfield 2019-05-23 00:30:13 PDT
Something like

template <typename Old, typename New, typename ...Args>
New* replace(Old& old, Args&&... args)
{
    static_assert(sizeof(New) <= sizeof(Old));
    return new (&old) New(std::forward<Args>(args)...);
}
Comment 1 Saam Barati 2019-05-23 10:54:20 PDT
patch forthcoming
Comment 2 Saam Barati 2019-05-23 11:26:03 PDT
Created attachment 370510 [details]
patch
Comment 3 Myles C. Maxfield 2019-05-23 11:32:05 PDT
Comment on attachment 370510 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=370510&action=review

> Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNode.h:56
> +    return new (&old) New(std::forward<Args>(args)...);

Don’t you have to save the address of “old” before you call its destructor?
Comment 4 Saam Barati 2019-05-23 11:38:47 PDT
(In reply to Myles C. Maxfield from comment #3)
> Comment on attachment 370510 [details]
> patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=370510&action=review
> 
> > Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNode.h:56
> > +    return new (&old) New(std::forward<Args>(args)...);
> 
> Don’t you have to save the address of “old” before you call its destructor?

Spoke with Myles offline. This code is probably fine (since dtor is just a method call), but we're just going to be explicit and do it before.
Comment 5 Saam Barati 2019-05-23 11:40:04 PDT
Created attachment 370512 [details]
patch for landing
Comment 6 WebKit Commit Bot 2019-05-23 12:55:00 PDT
Comment on attachment 370512 [details]
patch for landing

Clearing flags on attachment: 370512

Committed r245706: <https://trac.webkit.org/changeset/245706>
Comment 7 WebKit Commit Bot 2019-05-23 12:55:01 PDT
All reviewed patches have been landed.  Closing bug.
Comment 8 Radar WebKit Bug Importer 2019-05-23 12:55:17 PDT
<rdar://problem/51079016>