<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Jonathan,<div><br></div><div><div>In the context of a static compiler, I would recommend that you implement your own “on the side” symbol table in order to track this state and perform on-demand instantiation as required. It is worthwhile to consider the LLVM module to be a passive output sink, not an active object.</div><div><br></div></div><div><div>The JIT compiler, by contrast, is an active object, cooperating with its environment via the <font class="Apple-style-span" face="Courier">ModuleProvider</font> interface. Overriding <font class="Apple-style-span" face="Courier">materializeFunction</font> should be useful for on-demand instantiation.</div><div><div><br></div><div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">— Gordon</div><div><br></div><div><html>On Mar 26, 2008, at 17:07, Jonathan S. Shapiro wrote:</html><br class="Apple-interchange-newline"><blockquote type="cite">Okay, we're starting to dig in, and I've hit a question that will no doubt seem strange.<br><br>Context: BitC is a polymorphic language. Since it has unboxed value types, our approach to compiling a polymorphic function is to polyinstantate it -- once for each signature.<br><br>The name mangling scheme is both stable and reversible. At the site of the use occurrence, we can fully determine the mangled name of the desired instantiation. Given the mangled name of an instantiation that has not yet been synthesized, we can determine which procedure must be synthesized.<br><br>At present, our front end implements a demand-driven instantiator that proceeds from main() until all calls are statically resolved.<br><br>It seems to me, however, that this duplicates (nearly) functionality that is probably already present in the LLVM JIT layer.<br><br>Here is what I am wondering:<br><br>Is there some way we can "hook" the global symbol resolver so that we can run the polyinstantiator on demand? I *think* this could be done by running the resolver normally, noticing failure on a symbol that we know ought to exist, code generating the instance definition corresponding to the needed symbol, and then re-performing the lookup at global scope.<br><br>What I'm not sure about here is several issues:<br><br> 1. Does this make sense?<br><br> 2. If so, where is the right place to hook the resolver?<br><br> 3. Are we going to run into trouble arising from the fact that we<br> are likely to end up using the module compiler in a recursive<br> way? That is: the referencing module's compile will (in effect) be<br> paused in its symbol resolution phase while we introduce a new<br> module and compile that. I can imagine implementations where this<br> would wreak serious havoc on the implementation of environments<br> within the LLVM infrastructure.<br><br> 4. Is there a better/cleaner approach? What other options should I<br> consider?<br><br>We can, thankfully, ensure that this recursive instantiation exercise terminates. :-)<br></blockquote></div><div apple-content-edited="true"><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div><br></div></span></span></span></span></span></div></span></div></div></div></div></body></html>