<div dir="ltr">|preload-module| builtin dependency handling logics can work out real well.<div><br></div><div>I'm asking myself if that logic needs to be there though - </div><div><br></div><div>I understand that Gambit's builtin modules require a particular order of introduction into the GVM, however that order is hardcoded today isn't it, so can't that just remain so;</div>

<div><br></div><div>Would the additional complexity of |preload-modules| really be worth it, considering that it works well for Gambit's built-in modules to have a hardcoded load order -could that be 15 lines of code- , and as soon as Gambit is running fully, it delivers well anyhow that the user does dependency loading programmatically instead of having that done by additional logics in Gambit and a new special form?</div>

<div><br></div><div><br></div><div class="gmail_extra"><div class="gmail_quote">2013/11/6 Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>></span><br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im"><br>
On Nov 6, 2013, at 1:30 PM, Mikael <<a href="mailto:mikael.rcv@gmail.com">mikael.rcv@gmail.com</a>> wrote:<br></div></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div class="im"></div><div><div class="h5">
> Problem<br>
> So the conversation topic now is, that now that C linking/loading means a concurrent loading to the C level of all Gambit VM:s at the same time, then how should injection and execution of the loaded Scheme code be done into the VM:s, now that the user wants differentiated behavior between VM:s.<br>


><br>
> So problems that come with this are that for C code [modules] loaded, on the one hand<br>
>  * you need a way to define what code [modules] is actually executed in the primordial VM&processor as code not intended to be executed there on load can be linked in too, and, on the other hand<br>
>  * you need a way to specify what code [modules] should be executed in other VM:s.<br>
><br>
> This is the same problem as Unix and other OS:es face on boot: where to start execution, what's the first process and how to commence operations from there. The difference is just cosmetic in that a Unix system has the modules (the "init" program etc. and library files) in a filesystem while Gambit has them also on the heap already (the prelinked modules that this conversation are about).<br>


<br>
</div></div>Yes, it is a bootstraping problem.  A large part of the Gambit runtime is written in Scheme, and the rest is in C.  The C part has to be initialized first to provide support for running Scheme.  The runtime written in Scheme must be initialized in a methodical way to create the infrastructure on which more complex Scheme features are implemented.  For example, the _kernel module must be initialized first because it defines very basic stuff like interrupt handlers and memory allocation procedures (make-vector, make-string, etc) that other modules need.  After that that _num module, which implements bignums and other numerical types, is initialized.  Sometime later the interpreter is initialized (_eval module), the I/O system is initialized (_io module), the thread system is initialized (_thread module), and finally the REPL (_repl module).  These modules build on top of previous modules.<br>

</blockquote><div><br></div><div>Yep am completely with you.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<div class="im">><br>
> Indeed, in Unix each module (executable & library) has a dependencies definition, and the OS loader is tasked to loads those deps.<br>
><br>
> Possible solution (A): Gambit bundles dependency loading logic. |preload-module| + hook<br>
> Gambit can reuse this as |preload-module| (as you suggested) and due to its higher level of abstraction have such dep definitions not just per module but per lambda in a module (as you suggested).<br>
><br>
> For this to be fully satisfactory, (as you said) the user needs to be able to inject modules both in form of interpreted and compiled code on runtime.<br>
<br>
</div>I'm not sure what you mean by "inject modules"...<br></blockquote><div><br></div><div>Ah, by "inject" i just wanted to find a word to complement "execution" - say there's a module containing the code</div>

<div><br></div><div>     (define x (+ y z))</div><div><br></div><div>(+ y z) is obviously "executed" in a VM, and i thought of injecting as a way to point out the introduction of the globals defined by a module (x here) into a VM. Anyhow same thing.</div>

<div><br></div><div>This injection/execution as a contrast to a module being linked in to a Gambit executable, which means it's only reachable for that but unlike now, not automatically does that in a GVM.</div><div>
<br>
</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">><br>
> This probably also means there needs to be some runtime hook for a module system to perform the actual dependency loading, at the most basic level meaning resolving what already-linked-in module is actually meant by a particular module name specified to |preload-module|.<br>


><br>
<br>
> Possible solution (B): Gambit does not bundle dependency loading logic. (declare (not execute-on-load)) / (load module #!optional (execute-on-load? #t)) , |create-vm!|, |inject-module!|<br>
<br>
</div>The preload-module I was proposing is a *special form*.  The extension to "load" you suggest can't work because "load" is a procedure that is only executed at run time.  A compile time annotation is required.  Perhaps I don't understand what you mean.<br>

</blockquote><div><br></div><div>Exactly - I'm with you. Indeed load is for loading on runtime only and does not apply to the injection into/execution in the VM of any linked-in modules, be they Gambit-internal or of the user.</div>

<div><br></div><div>For linked-in modules, a form (declare ([not] execute-on-load)) could be provided, to tell if they should automatically be injected/executed into the primordial VM & processor or not.</div><div><br>

</div><div>All modules remain loadable programmatically using (load) or alike for later, for any VM.</div><div><br></div><div>I suggested this (declare ([not] execute-on-load)) as an alternative to preload-module only because it would mean an introduction of a lower amount of new complexity/features, that was all.</div>

<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">> <span style="font-size:13px;color:rgb(34,34,34);font-family:arial,sans-serif">This probably also means there needs to be some runtime hook for a module system to perform the actual dependency loading, at the most basic level meaning resolving what already-linked-in module is actually meant by a particular module name specified to |</span><span style="font-size:13px;color:rgb(34,34,34);font-family:arial,sans-serif">preload-module|.</span></div>

</blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im"><span style="color:rgb(34,34,34)">I'm all in favor of implementing the dependency loading logic in Scheme code, with hooks to change how it is done if needed.</span><br>

</div></blockquote><div><br></div><div>Ok</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

However, it would be problematic to implement an API where one VM can force another VM to load a module of code.  A synchronization of the two VMs would be needed, and it is unclear what type of synchronization is needed (is the target VM interrupted?  at any time or must we wait for the target VM to be "idle"?  what is "idle"?).  This is problematic given that VMs are supposed to be independent.  It is also problematic in a system like Gambit where there are no blocking operations (at the lowest level).  Currently, when an operation would block at the lowest level, the Gambit thread scheduler hands the CPU to a thread that is not blocked. Introducing a low-level synchronization would void the guarantees of liveness of the system.<br>

</blockquote><div><br></div><div>Agreed.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

That's why I prefer a model where the VM is in charge of its own initialization.  When one VM creates a new VM, the source VM indicates the name of the main module of the new VM.  A new "processor" is created for the new VM and it goes about initializing the modules it requires.  The source VM is completely decoupled from the new VM.  This is a simpler higher-level API and covers the use cases I can think of.<br>

</blockquote><div><br></div><div>Super; yes!</div><div><br></div><div>So in this picture, starting a new VM would mean that it automatically injects/executes Gambit's built-in modules, and then a main module chosen by the user for that particular VM, that takes charge of all of its initialization.</div>

<div><br></div><div>And question is just what degree of dependency loading logics Gambit puts in place here - only something like a |load| used programmatically by the user as is now but upgraded with the ability to also load specified linked-in modules, or, a dependency loading mechanism.</div>

<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Another incentive for tracking module dependencies is that it simplifies linking of executable applications.  Instead of having to provide the list of all the modules an application needs, it would be possible to only provide the name of the main module.  The linker would figure out all the required modules automatically.</blockquote>

<div><br></div><div>Right - so this is a design choice and either way would work.</div><div><br></div><div>Gambit without dependency loading/handling logics gives something more resembling GCC & C linker.</div><div><br>

Gambit with dependency loading/handling logics would be something slightly more high-level than has been typical for Gambit until now?</div><div><br></div><div><br></div><div>For contrast, funny to see how Unix & C does this:</div>

<div><br></div><div>The OS loader indeed loads dependencies non-programmatically;</div><div><br></div><div>And the C linker and compiler have limited or no dependency tracking depending on how you define dependency tracking.</div>

<div><br></div><div><br></div><div><br></div><div>I wonder if Gambit's linker having built-in logics for tracking dependencies would be a non-leaky abstraction, in the sense that</div><div><br></div><div>there's all kinds of cases with user modules being available in different forms (compiled binary/interpreted sourcecode file, different source and input method e.g. disk, heap or network, and all kinds of sourcecode preprocessing by the user implying for instance that the module names that Gambit routines get will be mangled already) -</div>

<div><br></div><div>all of that would probably require many users to implement their own dependency handling logics, also with regard to the linking, from scratch, so why implement a special dependency handling logic that turns out to be used only for the initialization of Gambit's built-in modules anyhow?</div>

<div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Other modules could be specified, but these would only be loaded by an explicit request at run time (i.e. it would be for bundling multiple modules in a standalone executable).<br>

</blockquote><div><br></div><div>Sure!</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span class=""><font color="#888888"><br>
Marc<br>
<br>
</font></span></blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">Best regards,</div><div class="gmail_extra">Mikael</div><div class="gmail_extra"><br></div></div>