<?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>181050</bug_id>
          
          <creation_ts>2017-12-20 11:34:51 -0800</creation_ts>
          <short_desc>Cleanup: Dereference value of optional directly instead of using checked value in WebCore::subdivide()</short_desc>
          <delta_ts>2018-01-08 09:18:43 -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>WebCore Misc.</component>
          <version>WebKit Local Build</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</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>darin</cc>
    
    <cc>jfbastien</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1383766</commentid>
    <comment_count>0</comment_count>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2017-12-20 11:34:51 -0800</bug_when>
    <thetext>Cleanup: Deference value of optional directly instead of using checked value in WebCore::subdivide().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1383768</commentid>
    <comment_count>1</comment_count>
      <attachid>329940</attachid>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2017-12-20 11:41:25 -0800</bug_when>
    <thetext>Created attachment 329940
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1383776</commentid>
    <comment_count>2</comment_count>
      <attachid>329940</attachid>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2017-12-20 12:00:50 -0800</bug_when>
    <thetext>Comment on attachment 329940
Patch

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

&gt; Source/WebCore/ChangeLog:3
&gt; +        Cleanup: Deference value of optional directly instead of using checked value in WebCore::subdivide()

Dereference</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1383777</commentid>
    <comment_count>3</comment_count>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2017-12-20 12:05:03 -0800</bug_when>
    <thetext>Committed r226195: &lt;https://trac.webkit.org/changeset/226195&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1383779</commentid>
    <comment_count>4</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2017-12-20 12:06:14 -0800</bug_when>
    <thetext>&lt;rdar://problem/36161451&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1386600</commentid>
    <comment_count>5</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2018-01-07 22:20:57 -0800</bug_when>
    <thetext>This does not seem right. Not harmful, but not helpful either.

I thought that std::optional::operator* and std::optional::value are supposed to have identical semantics. The choice of which one to use should be about clarity, not runtime checking cost.

Looking at our Optional.h header, in fact it seems that currently operator* has the assertion and value does not. Which seems quite peculiar. Not sure why.

JF?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1386757</commentid>
    <comment_count>6</comment_count>
    <who name="JF Bastien">jfbastien</who>
    <bug_when>2018-01-08 09:18:43 -0800</bug_when>
    <thetext>(In reply to Darin Adler from comment #5)
&gt; This does not seem right. Not harmful, but not helpful either.
&gt; 
&gt; I thought that std::optional::operator* and std::optional::value are
&gt; supposed to have identical semantics. The choice of which one to use should
&gt; be about clarity, not runtime checking cost.
&gt; 
&gt; Looking at our Optional.h header, in fact it seems that currently operator*
&gt; has the assertion and value does not. Which seems quite peculiar. Not sure
&gt; why.
&gt; 
&gt; JF?

They don&apos;t have the same semantics when the optional doesn&apos;t contain a value.

operator*() says:
  Requires: *this contains a value.

Therefore using it when the optional contains no value is UB. A valid implementation could throw or abort in these cases, or just return whatever random thing the memory contained.

Whereas value() has no requires clause, and instead says:
  Effects: Equivalent to:
    return bool(*this) ? *val : throw bad_optional_access();

Without exception support, the right thing to do in value() is to abort.


So I agree with Dan that it&apos;s sufficient to use operator* when you&apos;ve proven that a value is indeed contained. I&apos;m not sure it&apos;s more efficient: if we&apos;ve proven it then presumably the compiler can eliminate the value check: since it&apos;s the same thing, that check should just go away, I&apos;d look at the assembly. If the compiler doesn&apos;t do it I&apos;d say it&apos;s a bug, or it hasn&apos;t been proven sufficiently :-)

Maybe our implementation of optional should be changed to abort always on bad usage?

Another pattern that&apos;s nice is unwrapping the value and then just using that. Not sure that works here? Maybe value_or() would be appropriate (though seems not either...).</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>329940</attachid>
            <date>2017-12-20 11:41:25 -0800</date>
            <delta_ts>2017-12-20 12:00:50 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>bug-181050-20171220114125.patch</filename>
            <type>text/plain</type>
            <size>2830</size>
            <attacher name="Daniel Bates">dbates</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjI2MTkzCmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXggZjE2Yjc1YzNmMjExNmM1
ZjQzZTU4NDBkMGEwNzFhMDdhMDA3NDQwMy4uNzRiNjAzZTkwNWY5MmEwMmVmZjdlOTZjMzdjMTll
NGUzOTQ5YTg2ZCAxMDA2NDQKLS0tIGEvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCisrK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ZmZzZXRzW2ldLnZhbHVlLCBvZmZzZXRzWypmcm9udG1vc3Rd
LnN1YnJhbmdlLT50eXBlLCBvZmZzZXRzWypmcm9udG1vc3RdLnN1YnJhbmdlLT5tYXJrZXIgfSk7
CiAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAg
ICBmb3IgKHVuc2lnbmVkIGogPSAwOyBqIDwgaTsgKytqKSB7Cg==
</data>
<flag name="review"
          id="348974"
          type_id="1"
          status="+"
          setter="simon.fraser"
    />
          </attachment>
      

    </bug>

</bugzilla>