Skip to main content

canonicalize_recovering

Function canonicalize_recovering 

Source
pub fn canonicalize_recovering(
    package: &PackageName,
    interfaces: &HashMap<Name, Interface>,
    source: &Module,
) -> Canonicalized
Expand description

Transform a given parser::Module into a canonical::Module, and hand it back beside every error found on the way.

There is always a module. An import that does not resolve is reported as one Error::EnvironmentErrors and costs the module that import and nothing else. A declaration that does not canonicalize costs the module that declaration and nothing else. A value declaration is recorded in Module::broken, with its annotation when that canonicalized; a type, infix, class or instance declaration is left out of Module::types, Module::infixes, Module::classes or Module::instances. An exposing entry that does not resolve is left out of Module::exports.

§Declarations that failed to parse

source may be a module that parsed only in part ([parser::Module::failed]), and each declaration chunk that failed has already been reported as a syntax error. A chunk that names a value puts that name in scope, so a reference to it resolves, and the value is recorded in Module::broken with no error of its own: its annotation, when one parsed, is read and checked as any other’s, and nothing else of it is. A chunk that names nothing makes the scope incomplete before the first sub-pass runs (DEC-23 decision 4).

§Incomplete scopes

A scope is incomplete when a name could be missing from it for a reason already reported, and a not-found error raised in one is dropped (DEC-23 decision 3). Each sub-pass’s errors are filtered by the flag as it stood before that sub-pass ran: a declaration’s own failure is reported, and what it makes incomplete is everything after it. A failed infix declaration makes the scope incomplete for everything after the infixes, a failed type declaration for everything after the types, a failed class declaration for the values, the bindings of the classes and the instances, and the exposing list, a derivation that failed its checks for the instances, and the exposing list, and a failed instance declaration for the exposing list. Dropping an error does not make its declaration sound. A declaration the dropped error broke is left out all the same; one whose only error was a name that did not resolve stays in Module::values holding a hole (ExpressionKind::Hole, PatternKind::Hole) for it, which no backend emits and Value::holds_hole finds.

Whether this module is exempt from the default imports is not this function’s question to answer: new_environment derives it from package itself (PackageName::is_core) once name is built.