pub fn reachable_modules<'a>(
modules: &'a [(&'a AIRModule, &'a Path)],
) -> Vec<(&'a AIRModule, &'a Path)>Expand description
Restrict modules to those reachable from the entry module via real
use edges, returned in a deterministic dependency-before-dependent order
(a post-order DFS of the use graph with use targets visited in declared
module-path order). The result is independent of the input slice’s order, so
the emitted per-module tree is byte-stable across the per-process topo-sort
shuffling described below.
bock build prepends the entire embedded core.* stdlib and makes every
user module implicitly depend on all of it (the §18.2 prelude, so core
symbols resolve without an explicit use). That implicit dependency is
correct for name resolution but wrong for output: emitting a core
module a program never references both bloats the output and — until the
stdlib is codegen-clean on every target — drags its latent codegen defects
into the build. The emitted tree must therefore include only modules the
entry program actually reaches through a real use.
Reachability is the transitive closure of each module’s ImportDecl paths
(the explicit uses) matched against other modules’ declared module
path — never the synthetic prelude edges, which are not represented as
ImportDecls in the AIR. A program with no use (e.g. hello_world) thus
emits its entry module alone.
The entry module is the one declaring main; absent that (a library), the
last module in dependency order. The returned vec borrows from modules.