<html>
    <head>
      <base href="https://bugs.webkit.org/">
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - WebAssembly: several tests added in r214504 crash when building with GCC"
   href="https://bugs.webkit.org/show_bug.cgi?id=170390#c15">Comment # 15</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - WebAssembly: several tests added in r214504 crash when building with GCC"
   href="https://bugs.webkit.org/show_bug.cgi?id=170390">bug 170390</a>
              from <span class="vcard"><a class="email" href="mailto:cgarcia&#64;igalia.com" title="Carlos Garcia Campos &lt;cgarcia&#64;igalia.com&gt;"> <span class="fn">Carlos Garcia Campos</span></a>
</span></b>
        <pre>(In reply to Saam Barati from <a href="show_bug.cgi?id=170390#c14">comment #14</a>)
<span class="quote">&gt; (In reply to Carlos Garcia Campos from <a href="show_bug.cgi?id=170390#c12">comment #12</a>)
&gt; &gt; (In reply to Saam Barati from <a href="show_bug.cgi?id=170390#c9">comment #9</a>)
&gt; &gt; &gt; Comment on <span class=""><a href="attachment.cgi?id=306063&amp;action=diff" name="attach_306063" title="Updated patch">attachment 306063</a> <a href="attachment.cgi?id=306063&amp;action=edit" title="Updated patch">[details]</a></span>
&gt; &gt; &gt; Updated patch
&gt; &gt; &gt; 
&gt; &gt; &gt; View in context:
&gt; &gt; &gt; <a href="https://bugs.webkit.org/attachment.cgi?id=306063&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=306063&amp;action=review</a>
&gt; &gt; &gt; 
&gt; &gt; &gt; &gt;&gt;&gt;&gt; Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp:94
&gt; &gt; &gt; &gt;&gt;&gt;&gt; +        p.vm().promiseDeferredTimer-&gt;scheduleWorkSoon(promise, [source, promise, globalObject, plan = makeRefPtr(p)] () mutable {
&gt; &gt; &gt; &gt;&gt;&gt; 
&gt; &gt; &gt; &gt;&gt;&gt; Why not plan=WTFMove(plan)?
&gt; &gt; &gt; &gt;&gt; 
&gt; &gt; &gt; &gt;&gt; Because I've removed the line that created the plan to simplify it. 
&gt; &gt; &gt; &gt;&gt; 
&gt; &gt; &gt; &gt;&gt; RefPtr&lt;Plan&gt; plan = makeRef(p);
&gt; &gt; &gt; &gt;&gt; [plan = WTFMove(plan)]
&gt; &gt; &gt; &gt;&gt; 
&gt; &gt; &gt; &gt;&gt; is equivalent to 
&gt; &gt; &gt; &gt;&gt; 
&gt; &gt; &gt; &gt;&gt; [plan = makeRefPtr(p)]
&gt; &gt; &gt; &gt;&gt; 
&gt; &gt; &gt; &gt;&gt; I think this way is simpler, since we were only creating the plan to transfer it to the lambda capture (and to get the vm, but that is what caused the crash).
&gt; &gt; &gt; &gt; 
&gt; &gt; &gt; &gt; Gotcha. I see what's going on.
&gt; &gt; &gt; &gt; I still think you need a local variable for the plan, otherwise, won't the lambda capture the outermost plan? I think that'll lead to a reference cycle.
&gt; &gt; &gt; &gt; Even if that assignment doesn't cause this to happen, I think it's harder to reason about than just having a local variable.
&gt; &gt; &gt; 
&gt; &gt; &gt; Seems like you could also keep the code as is, and just use p.vm() instead
&gt; &gt; &gt; of plan-&gt;vm().
&gt; &gt; 
&gt; &gt; Yes, that's my first patch see <a href="show_bug.cgi?id=170390#c1">comment #1</a>
&gt; I like your first patch. I'm not sure what the semantics are here of your
&gt; capture of plan, since you don't define another variable named &quot;plan&quot;.
&gt; Anyways, I'm worried about a reference cycle, which is why I like an
&gt; explicit local variable. See the comment in WasmPlan.h.</span >

But this lambda is not the completion task one. That one is kept as a member of Plan, that's why it can cause a cycle. In this case we are keeping a ref in the lambda even if we use a local variable, because create the ref and then move to the lambda is the same as creating the ref in the lambda capture directly.

<span class="quote">&gt; &gt; 
&gt; &gt; &gt; Also, I'm not sure why we make a RefPtr instead of a Ref here.
&gt; &gt; 
&gt; &gt; I think it's because then we end up doing Ref&lt;&gt; foo = Ref(); and Ref(const
&gt; &gt; Ref&amp; other) is deleted.
&gt; Why not just do:
&gt; Ref&lt;Plan&gt; plan(p);
&gt; ?</span >

JSWebAssemblyModule::createStub() expects a RefPtr&lt;&gt;&amp;&amp; anyway, so it's simpler this way.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>