Map: core / ty

core/src/ty.rs and core/src/ty/ are the type language as data, below the IR and the checker: the IR’s schemes and sites name it, and nothing in it reads a unifier or a runtime value.

Types are interned handles: Ty, Row and CompTy each wrap one allocation of a one-layer node (TyNode, RowNode, CompTyNode) whose children are handles, made by ty/intern.rs. Equal structures are one allocation, so == is pointer equality, Hash a structural hash cached at construction, is_ground a flag cached per node, and height the syntactic nesting height cached per node (row and curried arrow spines counting as width). The table holds its entries weakly and sweeps the dead ones in amortized constant time per insertion. The sharing is the point: the checker answers “same type?”, “free of variables?” and “how deep?” in O(1), and the checker’s walks over Term visit each handle once, so shared DAGs stay linear in unique handles rather than unrolling into trees. OwnedTerm is a Term holding its handle, for a visited set that outlives the borrows it was reached through.

  • ty.rs: Ty, CompTy, Grade, Row, Label, the unification-variable newtypes, Var (a variable of any sort) and Term (a term of any sort); TAG_PREFIX, the sigil of a tag, written once.
  • ty/kind.rs: Kind, the chain number ⊂ comparable ⊂ scalar ⊂ data ⊂ any. Its meet is min; Head::least gives each head its least kind, and a kind admits the heads whose least kind lies at or below it.
  • ty/scheme.rs: Scheme { ty, tys, comps, rows, grades }, one map per sort from variable to Role<M, B>::{Forall(M), Weak(M), Mu(B)}. M is what minting a fresh variable of that sort needs (a type’s Kind, a row’s deep bit), B the sort’s μ-binding: Ty, CompTy, and the uninhabited NoMu for rows, since a cycle through a row is rooted at a type or computation. Grades are a set, only ever quantified. A role is thus of its variable’s sort by construction. Weak records a rank-zero residual for reseeding; ranks themselves live in the checker. Closed is a scheme writing no variable it gives no role, constructed only by settlement, Binders::close (a builtin’s own binder supply) or Closed::new, used by checked deserialisation and raw scheme admission. The child reader checks environment schemes and every recursively linked-module definition scheme, refusing a free variable with DecodeCause::OpenScheme at its JSON path (transport). Equality is structural. There are no partial schemes or cached environment free variables (schemes leave closed).
  • ty/exec_arg.rs: RefusedArg, the shapes execve(2) has no argument for, one match on a Head.
  • ty/typed.rs: Typed, a Datum whose encoding has a ral type derived from its own fields, and the record and variant types ral shows for a Rust type (transport).
  • ty/fmt.rs: Display for Ty and Scheme; one FmtCtx names a shared variable the same in every type a diagnostic prints. Producers print as Command, Returns A or Command[ν] A; a free grade paired with a type excluding unit prints Returns A, using quantified kinds where known. Scheme quantifiers list only visible grades. Local unit tests build schemes directly to check quantified computation variables and cyclic roots.
  • ty/site.rs: the data of a Site, a boundary’s checked type frozen as a graph of shared nodes (Arc<[Node]>, Shape, Fields, Tail) naming its unit by a UnitId — an OS nonce drawn once per process and a count, so unique in every process that meets it, a baked prelude unit’s included. Fixings is the session’s table of what each unit’s weak comparable variables were fixed to, keyed by (UnitId, var), which a session’s threads share and a new session snapshots (shell-state). The checker builds a Site (typecheck/site.rs), one fresh UnitId per unit, and the runtime walks it against the running session’s table (shell/runtime/admit.rs). Free type/computation nodes, open row tails and free grades retain canonical ids; the first three also retain rank-zero weakness, and Site::check certifies that every node reference in a decoded site lies within its slice.

Str, the shared immutable string a Value::String holds, lives in core/src/data/string.rs, exported as data::Str.