<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 1, 2023 at 1:59 PM Brian Goetz <<a href="mailto:brian.goetz@oracle.com">brian.goetz@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

  
  <div>
    <font size="4"><font face="monospace">I think that there should be
        an explicit (and not synthetic) method_info for the implicit
        constructor, with the obvious Code attribute (`defaultvalue` /
        `areturn`.) </font></font></div></blockquote><div><br></div><div>I'm slightly concerned about having a Code attribute for the implicit constructor as it allows agents (ClassFile load hook & redefinition) to modify the bytecodes to be inconsistent with the VM's behaviour given the VM won't actually call the implicit constructor.</div><div><br></div><div>Telling users it's "as if" the VM called the implicit ctor and then having the reflective behaviour be different after retransformation is slightly uncomfortable.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><font size="4"><font face="monospace"> <br>
        <br>
        My rationale is: "the declaration said there's a no-arg
        constructor, I should be able to call it".  And that intuition
        is entirely reasonable.  Users should be able to say `new
        Complex()` and get a default complex value.  (Maybe they can
        also say `Complex.default`; maybe we won't need that.)  And the
        same for reflection. </font></font></div></blockquote><div><br></div><div>Agreed on this. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><font size="4"><font face="monospace"> <br>
        <br>
        Also, in case it is not obvious, the following class is illegal:<br>
        <br>
            value class X { <br>
                implicit X();<br>
                X() { ... }<br>
            }<br>
        <br>
        because it is trying to declare the same constructor twice.  An
        implicit constructor is a constructor, just one for which the
        compiler can deduce specific known semantics.<br></font></font></div></blockquote><div><br></div><div>And this sounds right to me as well.  I guess the only concern I have is whether there should be a Code attribute or not and I think I lean towards not... </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><font size="4"><font face="monospace">
      </font></font><br>
    <div>On 6/1/2023 10:47 AM, Dan Heidinga
      wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">Pulling on a couple of threads to make sure I have
        the translation strategy for the implicit constructors straight.
        <div><br>
        </div>
        <div>Given a class like Complex with an implicit constructor:</div>
        <div>```<br>
          value class Complex {<br>
              private int re;<br>
              private int im;<br>
          <br>
              public implicit Complex();<br>
              public Complex(int re, int im) { ... }<br>
          <br>
              ...<br>
          }<br>
          ```<br>
        </div>
        <div>and the JEP 401's ImplicitCreation attribute:</div>
        <div>```</div>
        <div>ImplicitCreation_attribute {<br>
              u2 attribute_name_index;<br>
              u4 attribute_length;<br>
              u2 implicit_creation_flags;<br>
          }</div>
        <div>```</div>
        <div>The "obvious" translation is to generate an
          ImplicitCreation attribute if there is an implicit
          constructor, which seems reasonable.</div>
        <div><br>
        </div>
        <div>The piece I'm looking for clarification on is whether there
          will also be a `method_info` in the classfile representing the
          implicit constructor.</div>
        <div><br>
        </div>
        <div>If the implicit constructor has a `method_info` then it
          will naturally be represented in the same way as the explicit
          `Complex(int, int)` constructor.  This means both will be
          found by reflective operations (ie by
          j.l.Class::getConstructor) without special casing.  Users that
          expect two constructors will find them in classfile and
          reflectively.</div>
        <div><br>
        </div>
        <div>Alas representing implicit constructors with a
          `method_info` is not without costs: primarily specing how the
          method_info exists and explaining why it doesn't have a code
          attribute.</div>
        <div><br>
        </div>
        <div>I know this has been mentioned on the EG calls, and I
          don't recall a final decision or see it in the spec drafts /
          documents so far.  Was a conclusion reached on how to do the
          translation?</div>
        <div><br>
        </div>
        <div>--Dan</div>
      </div>
    </blockquote>
    <br>
  </div>

</blockquote></div></div>