Skip to main content

resolve_program

Function resolve_program 

Source
pub fn resolve_program(
    modules: &[ModuleSource<'_>],
    std_files: &[FileId],
    extra_std: Option<((&str, &str), FileId)>,
) -> ProgramResolution
Expand description

Resolve a multi-module program: collect each module’s item namespace, enforce pub visibility across modules, wire up imports, and merge all items into one file for whole-program compilation downstream.

std_files are the FileIds the caller registered each of STD_MODULES’s sources under, one per entry, in the same order. Only the driver owns a FileDb, so the ids cannot be invented here; threading them through means a syntax error inside an embedded std module is reported against a real file instead of FileId::DUMMY. The single-module resolve wrapper passes FileId::DUMMY for each, since it has no FileDb to register into. Entries beyond std_files’s length are simply not compiled in (the driver always supplies one id per STD_MODULES entry, so this is not expected to happen).

extra_std is Some((STD_TEST_MODULE, file_id)) under nova test and None otherwise (the driver decides). When present it is treated as one more std module — glob-imported into every other module exactly like each STD_MODULES entry, and on the receiving end of their glob-imports too (so assert_eq’s bounds can name Eq/Debug with no import) — but it is threaded through this one parameter rather than folded into STD_MODULES itself, so that array’s length stays fixed regardless of compilation mode; every other consumer of STD_MODULES (and the driver’s one-FileId-per-entry allocation) is therefore unaffected by its existence.

item_indexes in the returned ProgramResolution::file are global (module items concatenated in modules order, plus the implicit std modules last, in STD_MODULES order, plus extra_std if present).