Get the currently accessible paths (Load_path.get_path_list) from a toplevel plugin

Hi,

I’m trying to write a patch for down and i need the list of currently accessible paths (i.e. the list of directories which the compiler uses to discover identifiers, added using #directory and the like).

However Load_path.get_path_list seems to be inaccessible through a toplevel plugin (simply using the module raises Symtable.Error at runtime) and Toploop.get_directive "show_dirs" is unhelpful given it only gives a function that prints what i need but doesn’t return it.

Does anyone know how one is meant to get this information? Or is that simply missing from the toplevel API and i need to open a feature request?

You can’t. This is a long standing issue. But the upsteam issue reporting this was closed, see point 2. here.

Out of curiosity, could you provide more detail about exactly what you’re trying to accomplish? Are you trying to dynamically compile/link modules from the toplevel or implement some sort of plugin system? I ask because I’ve been curious about how “plugins” could/should be implemented in OCaml without using WASM or similar.

(I assume you’re aware of Omod and are trying to do something not possible with that, but I also want to link that for other readers that might not be aware.)

Note that omod has the same problem. It’s maintaining its own data structures about included path and loaded objects.

Now of course if you #directory or #load, or use ocamlfind’s #require on your side omod will not be aware of these which could lead to all sorts of odd behaviours. My implementation of the library linking proposal upstream had patches to solve that e.g. here.

On the topic of omod what I’d like is to eventually provide the same functionality, that is load by module name – which is what matters to users – but by going back to use META files to lookup dependencies since it seems those are unlikely to go and nowadays have information that cannot be obtained via omod’s data driven strategy (exports).

After having done that I’d like to provide, opt-in, “autoload” functionality where basically stuff will be automatically loaded (as was once prototyped in another context) as you use it. If the result ends up being small enough and not too brittle I think I’ll add this directly to down and leave omod to rot. The day I get time on my hands…

1 Like