<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>185337</bug_id>
          
          <creation_ts>2018-05-04 18:49:15 -0700</creation_ts>
          <short_desc>Support instantiating a String with a StaticStringImpl{&amp;, *}</short_desc>
          <delta_ts>2019-02-03 23:12:19 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Web Template Framework</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>ASSIGNED</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=194212</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Daniel Bates">dbates</reporter>
          <assigned_to name="Daniel Bates">dbates</assigned_to>
          <cc>benjamin</cc>
    
    <cc>cdumez</cc>
    
    <cc>cmarcelo</cc>
    
    <cc>ews-watchlist</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1420985</commentid>
    <comment_count>0</comment_count>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2018-05-04 18:49:15 -0700</bug_when>
    <thetext>We should support instantiating a String with a StaticStringImpl{&amp;, *} so that we can construct constexpr StaticStringImpls and pass them to functions the take a String without needing to cast it to non-const StaticStringImpl beforehand. It is safe for String to take a const StaticStringImpl and internally cast to a non-const StringImpl because StaticStringImpls are guaranteed to be immutable. This immutability is guaranteed both at runtime (by [1]) and by convention of only instantiating a StaticStringImpl in a constexpr expression.

[1] &lt;https://trac.webkit.org/browser/trunk/Source/WTF/wtf/text/StringImpl.h?rev=231268#L330&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1420988</commentid>
    <comment_count>1</comment_count>
      <attachid>339622</attachid>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2018-05-04 18:53:11 -0700</bug_when>
    <thetext>Created attachment 339622
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1420994</commentid>
    <comment_count>2</comment_count>
      <attachid>339622</attachid>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2018-05-04 19:13:01 -0700</bug_when>
    <thetext>Comment on attachment 339622
Patch

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

&gt; Source/WTF/ChangeLog:11
&gt; +        convention of only instantiating a StaticStringImpl in a constexpr expression.

Is this condition maintained for the refcount of StaticStringImpl? StaticStringImpl sets s_refCountFlagIsStaticString = 0x1.
Since our StringImpl increments/decrements the refcount by 2, setting 0x1 initial ensures that the refcount never becomes zero even if multiple threads ref/deref it.
Even though, the refcount itself is mutated.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1420997</commentid>
    <comment_count>3</comment_count>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2018-05-04 20:02:07 -0700</bug_when>
    <thetext>(In reply to Yusuke Suzuki from comment #2)
&gt; Comment on attachment 339622 [details]
&gt; Patch
&gt; 
&gt; View in context:
&gt; https://bugs.webkit.org/attachment.cgi?id=339622&amp;action=review
&gt; 
&gt; &gt; Source/WTF/ChangeLog:11
&gt; &gt; +        convention of only instantiating a StaticStringImpl in a constexpr expression.
&gt; 
&gt; Is this condition maintained for the refcount of StaticStringImpl?
&gt; StaticStringImpl sets s_refCountFlagIsStaticString = 0x1.
&gt; Since our StringImpl increments/decrements the refcount by 2, setting 0x1
&gt; initial ensures that the refcount never becomes zero even if multiple
&gt; threads ref/deref it.
&gt; Even though, the refcount itself is mutated.

:( This patch is wrong.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1421001</commentid>
    <comment_count>4</comment_count>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2018-05-04 20:08:19 -0700</bug_when>
    <thetext>(In reply to Yusuke Suzuki from comment #2)
&gt; Comment on attachment 339622 [details]
&gt; Patch
&gt; 
&gt; View in context:
&gt; https://bugs.webkit.org/attachment.cgi?id=339622&amp;action=review
&gt; 
&gt; &gt; Source/WTF/ChangeLog:11
&gt; &gt; +        convention of only instantiating a StaticStringImpl in a constexpr expression.
&gt; 
&gt; Is this condition maintained for the refcount of StaticStringImpl?
&gt; StaticStringImpl sets s_refCountFlagIsStaticString = 0x1.
&gt; Since our StringImpl increments/decrements the refcount by 2, setting 0x1
&gt; initial ensures that the refcount never becomes zero even if multiple
&gt; threads ref/deref it.

How is it thread-safe to increment and decrement the ref count for a StringImpl? I mean, its ref count is an unsigned and we do not use we do not use locks in StringImpl::ref/deref(). In particular, how is StringImpl::deref() thread-safe?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1421003</commentid>
    <comment_count>5</comment_count>
      <attachid>339622</attachid>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2018-05-04 20:17:52 -0700</bug_when>
    <thetext>Comment on attachment 339622
Patch

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

&gt;&gt;&gt;&gt; Source/WTF/ChangeLog:11
&gt;&gt;&gt;&gt; +        convention of only instantiating a StaticStringImpl in a constexpr expression.
&gt;&gt;&gt; 
&gt;&gt;&gt; Is this condition maintained for the refcount of StaticStringImpl? StaticStringImpl sets s_refCountFlagIsStaticString = 0x1.
&gt;&gt;&gt; Since our StringImpl increments/decrements the refcount by 2, setting 0x1 initial ensures that the refcount never becomes zero even if multiple threads ref/deref it.
&gt;&gt;&gt; Even though, the refcount itself is mutated.
&gt;&gt; 
&gt;&gt; :( This patch is wrong.
&gt; 
&gt; How is it thread-safe to increment and decrement the ref count for a StringImpl? I mean, its ref count is an unsigned and we do not use we do not use locks in StringImpl::ref/deref(). In particular, how is StringImpl::deref() thread-safe?

Basic StringImpl is not thread-safe. When moving it around threads, we call `isolateCopy()`.
The exception is *static* StringImpl (like, StaticStringImpl. The StringImpl with `isStatic()` flag). In this case, the ref count is set to 0x1.
Since there is not thread-safety in StringImpl, the effect of StringImpl::ref/deref() would be lost. But it is OK since Static StringImpl is never destroyed. Threads increment/decrement refcount by 2. (ref += 2 / ref -= 2).
But refcount&apos;s first bit is always 0x1 in static StringImpl. So while the value of refCount() of static StringImpl becomes bogus, the refcount never becomes zero, and static StringImpl is never destroyed.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>339622</attachid>
            <date>2018-05-04 18:53:11 -0700</date>
            <delta_ts>2018-05-04 20:02:16 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>Bug185337.patch</filename>
            <type>text/plain</type>
            <size>2202</size>
            <attacher name="Daniel Bates">dbates</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XVEYvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFNvdXJjZS9XVEYvQ2hh
bmdlTG9nCShyZXZpc2lvbiAyMzEzOTQpCisrKyBTb3VyY2UvV1RGL0NoYW5nZUxvZwkod29ya2lu
ZyBjb3B5KQpAQCAtMSwzICsxLDIwIEBACisyMDE4LTA1LTA0ICBEYW5pZWwgQmF0ZXMgIDxkYWJh
dGVzQGFwcGxlLmNvbT4KKworICAgICAgICBTdXBwb3J0IGluc3RhbnRpYXRpbmcgYSBTdHJpbmcg
d2l0aCBhIFN0YXRpY1N0cmluZ0ltcGx7JiwgKn0KKyAgICAgICAgaHR0cHM6Ly9idWdzLndlYmtp
dC5vcmcvc2hvd19idWcuY2dpP2lkPTE4NTMzNworCisgICAg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JbXBsKiBz
dHJpbmcpCi0gICAgOiBtX2ltcGwocmVpbnRlcnByZXRfY2FzdDxTdHJpbmdJbXBsKj4oc3RyaW5n
KSkKK2lubGluZSBTdHJpbmc6OlN0cmluZyhjb25zdCBTdGF0aWNTdHJpbmdJbXBsKiBzdHJpbmcp
CisgICAgOiBtX2ltcGwocmVpbnRlcnByZXRfY2FzdDxTdHJpbmdJbXBsKj4oY29uc3RfY2FzdDxT
dGF0aWNTdHJpbmdJbXBsKj4oc3RyaW5nKSkpCiB7CiB9CiAK
</data>
<flag name="review"
          id="357861"
          type_id="1"
          status="-"
          setter="dbates"
    />
          </attachment>
      

    </bug>

</bugzilla>