Skip to main content

Module

Struct Module 

Source
pub struct Module {
    pub name: ModuleName,
    pub foreign: bool,
    pub unions: Vec<Union>,
    pub declarations: Vec<Declaration>,
    pub unchecked: Vec<Unchecked>,
    pub instances: Vec<Instance>,
    pub initialisation_order: Vec<Name>,
    pub specialisations: Vec<Specialisation>,
}
Expand description

One checked module’s emittable shape: what a backend reads that no earlier phase carried.

Not everything emission needs — exports and marked_unsafe stay on the canonical::Module this was built from, and a backend is handed both halves as a CheckedModule. See this module’s doc comment.

Fields§

§name: ModuleName§foreign: bool

True when this module is a module foreign facade: every one of its declarations is a signature with no body, and the code behind them is in the companion beside it (Foreign interoperability).

§unions: Vec<Union>

The unions this module declares, sorted by name.

§declarations: Vec<Declaration>

The declarations this module can emit, sorted by name.

Sorted so that two runs of the compiler over one unchanged module produce the same order — canonical::Module::values is a HashMap and yields none. It is not an evaluation order: initialisation_order is what works out which parameterless declaration has to be initialised before which.

A declaration here may hold a hole, with an error standing behind it, and a backend refuses it.

§unchecked: Vec<Unchecked>

The declarations that have no IR, and therefore cannot be emitted.

A backend handed only declarations could not tell a module it may emit whole from one that quietly lost a declaration on the way here, which is the mistake DEC-18 decision 1 is about. Every value of the canonical module, in values or in broken, is in exactly one of the two lists.

Sorted by name, the same as declarations.

§instances: Vec<Instance>

The instances this module declares, in the order they were written, each with the body it was checked with. An instance of another module that this one can use is that module’s, and is not repeated here.

An instance that failed canonicalization is in no list: it never became a canonical::Instance, and the error behind it is canonicalization’s.

§initialisation_order: Vec<Name>

The names of declarations that take no parameter, in the order they must be initialised: each only after every parameterless declaration it depends on, whether its own body mentions that declaration or reaches it through a function it mentions (docs/spec/evaluation-semantics.md#a-binding-with-no-parameters-is-evaluated-once). Empty for a module whose declarations all take parameters, and for a module foreign facade, whose constants are evaluated on whatever schedule the target gives them (docs/spec/interop.md#facade-constants).

Sorted so that two runs of the compiler over one unchanged module produce the same order, same as declarations above — including among bindings with no path between them, where dependencies alone leave the order unconstrained.

canonical::initialisation_order computes it, from the same dependency graph canonical::canonicalize reads to reject a cycle (LANG-35) rather than a second one built from the same rule; see that function’s doc comment for what it does with a module whose cycle was rejected. zelkova_js::emit is what emits declarations in this order — this only computes it.

§specialisations: Vec<Specialisation>

The copies of constrained declarations and of instance members with a context that this module needs, each at one assignment of ground types to its constrained variables, in the order specialise found them.

Empty until specialise has run over the build: build knows one module and a specialisation is a fact about the whole of them. A reference to one is ReferenceKind::Specialised, and its number is a place in this list.

Trait Implementations§

Source§

impl Debug for Module

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.