Skip to content

driver: Use ModuleGraph for oneshot and --make mode

Matthew Pickering requested to merge wip/shared-module-graph into master

This patch uses the hsc_mod_graph field for both oneshot and --make mode. Therefore, if part of the compiler requires usage of the module graph, you do so in a uniform way for the two different modes.

The ModuleGraph describes the relationship between the modules in the home package and units in external packages. The ModuleGraph can be queried when information about the transitive closure of a package is needed. For example, the primary use of the ModuleGraph from within the compiler is in the loader, which needs to know the transitive closure of a module so it can load all the relevant objects for evaluation.

In --make mode, downsweep computes the ModuleGraph before any compilation starts.

In oneshot mode, a thunk is created at the start of compilation, which when forced will compute the module graph beneath the current module. The thunk is only forced at the moment when the user uses Template Haskell.

Finally, there are some situations where we need to discover what dependencies to load but haven't loaded a module graph at all. In this case, there is a fallback which computes the transitive closure on the fly and doesn't cache the result. Presumably if you are going to call getLinkDeps a lot, you would compute the right ModuleGraph before you started.

Importantly, this removes the ExternalModuleGraph abstraction. This was quite awkward to work with since it stored information about the home package inside the EPS.

This patch will also be very useful when implementing explicit level imports, which requires more significant use of the module graph in order to determine which level instances are available at.

Towards #25795

Merge request reports

Loading