<?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>213278</bug_id>
          
          <creation_ts>2020-06-16 18:14:12 -0700</creation_ts>
          <short_desc>IPC/Decoder.h and IPC/Encoder.h need every WTF::EnumTraits&lt;&gt; specialization included before they are included</short_desc>
          <delta_ts>2020-06-23 12:00:11 -0700</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>Other</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=213224</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=213199</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="David Kilzer (:ddkilzer)">ddkilzer</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>achristensen</cc>
    
    <cc>darin</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1663334</commentid>
    <comment_count>0</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2020-06-16 18:14:12 -0700</bug_when>
    <thetext>IPC/Decoder.h and IPC/Encoder.h need every WTF::EnumTraits&lt;&gt; specialization #included before they are included.

See Bug 213224, Comment #12 for an example where &lt;WebCore/ContextMenuItem.h&gt; had to be included in IPC/Decoder.h and IPC/Encoder.h.

&lt;https://bugs.webkit.org/show_bug.cgi?id=213224#c12&gt;

I think this issue is exacerbated by unified sources since a prior source file (in the united source) may include IPC/Decoder.h and IPC/Encoder.h before a later WTF::EnumTraits&lt;&gt; is included.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1663336</commentid>
    <comment_count>1</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2020-06-16 18:15:24 -0700</bug_when>
    <thetext>I&apos;m having to do this for the patch for Bug 213199 as well.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1663384</commentid>
    <comment_count>2</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2020-06-16 23:38:33 -0700</bug_when>
    <thetext>It doesn’t really make logical sense that every specialization has to be included first. I think we have to more deeply understand why. Normally it’s when templates are expanded/used, not when they are included, that all the things they call have to be present. We probably have to get a more solid understanding of what creates this dependency.

We may change isValidEnum from a namespace-level function template to something different. Normally functions are specialized with overloading rather than specializing a template. That may be part of the problem here. Perhaps we can overload isValidEnum rather than specializing an isValidEnum function template. Another possibility is to use the traits pattern and have EnumValidityCheck be a class template with a static member function isValid. Not sure this solves the problem, but I think it might.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1663750</commentid>
    <comment_count>3</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2020-06-17 18:44:02 -0700</bug_when>
    <thetext>(In reply to David Kilzer (:ddkilzer) from comment #1)
&gt; I&apos;m having to do this for the patch for Bug 213199 as well.

I was wrong about this--ran into a different issue.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1665279</commentid>
    <comment_count>4</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2020-06-22 21:11:46 -0700</bug_when>
    <thetext>(In reply to Darin Adler from comment #2)
&gt; It doesn’t really make logical sense that every specialization has to be
&gt; included first. I think we have to more deeply understand why. Normally it’s
&gt; when templates are expanded/used, not when they are included, that all the
&gt; things they call have to be present. We probably have to get a more solid
&gt; understanding of what creates this dependency.
&gt; 
&gt; We may change isValidEnum from a namespace-level function template to
&gt; something different. Normally functions are specialized with overloading
&gt; rather than specializing a template. That may be part of the problem here.
&gt; Perhaps we can overload isValidEnum rather than specializing an isValidEnum
&gt; function template. Another possibility is to use the traits pattern and have
&gt; EnumValidityCheck be a class template with a static member function isValid.
&gt; Not sure this solves the problem, but I think it might.

Okay, using pre-processed source, I&apos;ve verified that if I don&apos;t #include &lt;WebCore/ContextMenuItem.h&gt; in Decoder.h/Encoder.h, then the specialized isValidEnum() function is included after it&apos;s needed in Decoder.h/Encoder.h when building Source/WebKit/Shared/WebContextMenuItemData.cpp.

I&apos;m not sure how to turn your suggestion into code, though. I tried a first pass, but it seems much more complex than it should be (I didn&apos;t even try to compile it), and I don&apos;t see how it solves the #include order issue.  I&apos;m probably doing it wrong, and figuring it out is going to take me much longer than it should to get it correct/working.  (I suspect my time could best be spent on other bugs, despite wanting to learn how to do this.)

This is what I wrote:


template&lt;&gt;
struct EnumValueChecker&lt;false&gt; {
    template&lt;typename E, typename T&gt;
    static constexpr bool isValid(T t)
    {
        static_assert(sizeof(T) &gt;= sizeof(std::underlying_type_t&lt;E&gt;), &quot;Integral type must be at least the size of the underlying enum type&quot;);

        return EnumValueChecker&lt;T, typename EnumTraits&lt;E&gt;::values&gt;::isValidEnum(t);
    }
};

template&lt;&gt;
struct EnumValueChecker&lt;false&gt; {
    template&lt;typename E, typename T = bool&gt;
    static constexpr bool isValid(T t)
    {
        return !t || t == 1;
    }
};

template&lt;typename E, typename T&gt;
constexpr bool isValidEnum(T t)
{
    return EnumValidityCheck&lt;HasCustomIsValidEnum&lt;E&gt;::value&gt;::isValid&lt;E&gt;(t);
}


I still think it requires an early #include, though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1665428</commentid>
    <comment_count>5</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2020-06-23 09:57:27 -0700</bug_when>
    <thetext>(In reply to David Kilzer (:ddkilzer) from comment #4)
&gt; Okay, using pre-processed source, I&apos;ve verified that if I don&apos;t #include
&gt; &lt;WebCore/ContextMenuItem.h&gt; in Decoder.h/Encoder.h, then the specialized
&gt; isValidEnum() function is included after it&apos;s needed in Decoder.h/Encoder.h
&gt; when building Source/WebKit/Shared/WebContextMenuItemData.cpp.

We need to look deeper into *this*. Typically you don’t need things that templates depend on until you instantiate the template, so it doesn’t make logical sense that the order of includes would matter if these things in Decoder.h and Encoder.h are templates. Before we make any changes, we need to figure out more precisely exactly what goes wrong when ContextMenuItem.h is included after the templates, but before the templates are instantiated because they are used.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1665485</commentid>
    <comment_count>6</comment_count>
      <attachid>402580</attachid>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2020-06-23 12:00:11 -0700</bug_when>
    <thetext>Created attachment 402580
Reproduce the build failure

This patch reproduces the build failure after removing #include &lt;WebCore/ContextMenuItem.h&gt; from Decoder.h/Encoder.h and adding it to Source/WebKit/Shared/WebContextMenuItemData.cpp.  (Adding it to WebContextMenuItemData.cpp doesn&apos;t actually make any difference, so this change could also be left out.  It&apos;s what I would expect to work, but doesn&apos;t.)

The call to WTF::isValidEnum&lt;E&gt;() when wants the template specialization defined is happening in Encoder.h (and Decoder.h), but both of those headers are included by an earlier *.cpp file in UnifiedSource24.cpp for WebKit.

So one solution might be to remove WebContextMenuItemData.cpp as supporting Unified Sources.  I have not tried that.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>402580</attachid>
            <date>2020-06-23 12:00:11 -0700</date>
            <delta_ts>2020-06-23 12:00:11 -0700</delta_ts>
            <desc>Reproduce the build failure</desc>
            <filename>bug-213278-reproduce-build-failure.diff</filename>
            <type>text/plain</type>
            <size>1267</size>
            <attacher name="David Kilzer (:ddkilzer)">ddkilzer</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdX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