Skip to main content

Crate cove_ir

Crate cove_ir 

Source
Expand description

The executable IR Cove is lowered to: one linear memory, one word stack, one slot numbering.

ADR 0034 decides what this is, and docs/LINEAR_VM.md writes the design out at the level an implementer needs. The short version:

  • There is one linear memory, addressed in eight-byte words. The stack region is reserved at [0, STACK_WORDS); the heap region begins at STACK_WORDS. An address is a word index into that one space, so nothing changes value when the two regions are later placed in one block.
  • There is one stack region. A frame is a run of words, named by a frame_base, and a slot is memory[frame_base + slot]. Parameters, locals, temporaries and captures share the numbering.
  • A word is untagged. What it means comes from Repr, and the only question the collector asks the static side is which slots are Repr::Ref.
  • The IR is a register machine. Every instruction names its operands and destination by slot; there is no operand stack.
  • A place is a one-word address. There is no place object, no place stack and no table of places.
  • The public Value is a boundary, not a store. It is materialised at Host calls, entry results and trace captures, and nowhere else.

§This is not a continuation of anything

It is a clean-room replacement. No instruction, storage region, admission predicate or naming convention is carried over from the IR it replaces, and nothing here exists to be compatible with it. In particular there is no Unsupported: a lowering that met something it had not been taught would be a bug in the lowering, not a program the backend declines. The predecessor’s per-refusal extension mechanism is exactly what ADR 0034 forbids reconstructing.

§This is a lowering, not a second source of truth

cove-sema has already answered what every reference denotes and what every expression’s type is. Nothing here re-derives that; it records the answers in a shape the machine can act on without asking again. Where the two could disagree, the checker is right by construction, because the lowering reads its answers rather than recomputing them.

Re-exports§

pub use bytecode::EncodedInst;
pub use bytecode::MAX_FRAME_WORDS;
pub use inst::ArithOp;
pub use inst::CmpOp;
pub use inst::Compare;
pub use inst::Convert;
pub use inst::Inst;
pub use inst::Len;
pub use inst::Num;
pub use inst::Pc;
pub use inst::Slot;
pub use layout::enum_layout;
pub use layout::struct_layout;
pub use layout::Case;
pub use layout::Field;
pub use layout::Layout;
pub use layout::LayoutId;
pub use layout::Part;
pub use layout::Shape;
pub use layout::SHARED_STATE;
pub use layout::SHARED_VALUE;
pub use lower::lower;
pub use lower::lower_entry;
pub use lower::lower_roots;
pub use program::Arg;
pub use program::ArgsId;
pub use program::Builtin;
pub use program::BuiltinId;
pub use program::Capture;
pub use program::CaseId;
pub use program::Function;
pub use program::FunctionId;
pub use program::HostOp;
pub use program::HostOpId;
pub use program::Local;
pub use program::Program;
pub use program::StrId;
pub use program::Table;
pub use program::TableId;
pub use repr::RefMap;
pub use repr::Repr;
pub use verify::verify;
pub use verify::Invalid;

Modules§

bytecode
The fixed-width encoded form of the instructions.
inst
The instructions.
layout
What a value is made of.
lower
Turning a checked package into the executable IR.
print
A disassembly, for reading a lowering and for a test to assert on.
program
A lowered program, and the tables an instruction indexes into.
repr
What one eight-byte word means.
verify
A static check that a lowered program is well formed.