title: Who calls describeConstable(), and when?
body: <p>I have stumbled somewhat happily into <a href="https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/constant/package-summary.html" rel="nofollow noreferrer"><code>Constable</code> and the like in JDK 15</a>.  I mostly understand.</p>
  <p>After frolicking through all the compiler theory and even understanding a little bit of it, I find I still have this question: <strong>Who calls a <code>Constable</code>'s <code>describeConstable()</code> method, and when?</strong>  <a href="https://www.youtube.com/watch?v=iSEjlLFCS3E" rel="nofollow noreferrer">Brian's presentation</a> seemed to imply it is somehow accessed at compile time.  Being naïve about such things, I was expecting it to show up in <a href="https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/constant/class-use/Constable.html" rel="nofollow noreferrer">the usage page</a> under <code>jdk.compiler</code> or something.  Instead, <a href="https://docs.oracle.com/en/java/javase/15/docs/api/jdk.incubator.foreign/jdk/incubator/foreign/package-summary.html" rel="nofollow noreferrer">the only consumption seems to be in the <code>jdk.incubator.foreign</code> package</a>.  (Obviously I understand it may be used by some private machinery somewhere that isn't exposed by the usage page; hence my question.)</p>
  <p>I placed a <code>Thread.dumpStack()</code> in a <code>describeConstable()</code> implementation of a dumb class that implements <code>Constable</code> and that returns <code>Optional.ofNullable(null)</code> just to see what would happen and…nothing happened at compile- or runtime.</p>
  <p>(I do know that until JDK 12 if you wanted to write dynamic constants you had to use ASM or ByteBuddy or something similar.  To my naïve eyes it looks, though, like <code>Constable</code> is there to allow your user class to &quot;plug into&quot; the Java compiler and allow <em>it</em> to do the constant writing for you.  I am also aware that the classes and methods in <code>java.lang.constant</code> are primarily intended for compiler writers, but <code>Constable</code> seemed to me to be a bit of an exception.  Finally, I obviously understand that <em>I</em> can call this method any time I wish, but that's clearly not what it's intended for.)</p>
  <p><strong>EDIT</strong>: Thanks (very much) to some of the extremely helpful and patient answers and comments below, I think I'm starting to get it (I'm not a compiler guy which by this point should be quite obvious).  While I understand that <em>once an instance of <code>X implements Constable</code> exists</em> then the <code>ContantDesc</code> it returns from its <code>describeConstable()</code> must be made (itself) of other constant descriptors, and while I understand that &quot;constant factories&quot; (such as <code>ClassDesc#of()</code> and so on) may be called at compile time and obviously must accept only other constants as any arguments they might require, <strong>I'm still not clear on how an <em>arbitrary</em> <code>X implements Constable</code> is instantiated during compilation</strong> in the first place while…it is being compiled (!) such that <code>describeConstable()</code> can be called on it at compile time.</p>
  <p>Please kindly bear in mind the answer to this question may be something rudimentary that I'm missing about compilers in general, or the sorts of hijinks they get up to during static analysis.  I just see an instance method (<code>describeConstable()</code>) that needs to be invoked on an instance of an object (<code>X implements Constable</code>) and in order to have an instance of an object someone has to call its constructor.  It's unclear to me how the Java compiler could know how to construct my <code>X implements Constable</code> with its arbitrary, possibly multi-argument constructor so that it could then call <code>describeConstable()</code> on it.</p>