pub fn lower(
checked: &Program,
sources: &SourceMap,
schemas: &HostSchemas,
) -> Result<Program, Vec<Diagnostic>>Expand description
Lowers a checked package: every declaration it has, whether or not anything reaches it.
The result either runs or names what stopped it. Nothing in between: a
lowered Program has been through crate::verify(), so a caller that
holds one holds a program whose locations, jumps and calls are all in
range and whose reference map is the one its reprs imply.
sources is the package’s own text, and it is here for one reason:
assert and assertEqual quote the code that failed, so the lowering
has to read the bytes an argument’s span covers. See this module’s
assertions submodule for why they are lowered rather than performed.
schemas is the set of host modules this compilation was given, and it
must be the set the checker was given. A type a host module declares has
a layout — a files.Reader is one Repr::Host word and an
http.Response is its fields inline — and the schema is the only thing
that says which of the two a name is. Reading cove_schema::hosts here
instead would describe the shipped modules and no others, so a program
that names a type an embedding registered would lower for fewer types than
it checked against: a backend refusing a program the language admits,
rather than a gap somebody can build. HostApi is a trait, and an
embedder’s module is not a lesser kind of host.
lower_roots is the same lowering over what a named set of roots
reaches, and it is what a command that runs a program should use — a
command names the roots it is about to run and this crate works out the
slice. This one is what a whole-package listing means — everything the
package declares is part of it — and it is what the lowering’s own tests
and the corpus survey ask for.