Expand description
§typeck_lang
Profile-driven type checking over HIR: one checker, configured by a
type-system Profile instead of written per language.
use hir_lang::{Builder, Name, OpKind};
use intern_lang::Interner;
use typeck_lang::{check, Profile};
let mut names = Interner::new();
let mut b = Builder::new();
// fn main() { 1 + true; }
let one = b.int(1);
let yes = b.lit(hir_lang::Lit::Bool(true));
let sum = b.op(OpKind::Add, &[one, yes]);
let stmt = b.expr_stmt(sum);
let body = b.block(&[stmt], None);
let main = b.func(Name::new(names.intern("main")), &[], body);
let root = b.module(None, &[main]);
let hir = b.finish(root)?;
// Statically: one diagnostic, at `true`.
let typed = check(&hir, &Profile::static_explicit()).unwrap();
let d = typed.diagnostics()[0];
assert_eq!(d.node, hir_lang::NodeRef::Expr(yes));
assert_eq!(typed.message(&d, &names), "`add` is not defined for `bool`");
// Dynamically: nothing to report; every value is `any`.
assert!(check(&hir, &Profile::dynamic()).unwrap().is_ok());§What it does
- Profiles as data (
Profile,Discipline):dynamic,gradual,static-explicit,static-inferred, andhm, with toggles for subtyping, nominal or structural records, numeric widening, null safety, exhaustive matches, traits versus interfaces, implicit receiver borrowing, the monomorphization policy,let x = null, and?. This version implementsdynamic,static-explicit, andstatic-inferred;gradualandhmreturnCheckError::NotImplemented(seedev/ROADMAP.md). - Generics and interfaces: generic functions and types with bounds and
where clauses, constant parameters, defaults; interfaces (traits) with
methods, default methods, constants, associated types, and supertraits;
implblocks, generic ones indexed like any other; interface method resolution through bounds,dyntypes, and implementations;impl Traitparameters and results; coherence (overlapping implementations) and conformance (missing, extra, or mistyped members). - Bidirectional checking: expected types flow into arguments of
generic calls, record literals, and closures (whose signatures
static-inferredinfers). - Exhaustiveness through match-lang: missing values as witnesses, unreachable arms and redundant alternatives as warnings.
- Output (
Typed): dense side tables of types keyed by HIR expression, pattern, and binder ids; typed diagnostics with origins; the implicit conversions lowering must materialise; how each operation resolved (integer, IEEE, string); the definitions of partial paths’ unresolved tails (Shape::Circle,T::new); what each use of a generic item instantiates; and the monomorphization plan (MonoPlan). - One root cause, one diagnostic: anything reported has type
TypeId::ERROR, which every later check accepts silently. - Termination: union-find over hash-consed type terms (no exponential
blow-up on shared structure), iterative traversals everywhere, and a
Budget(steps, type-store size, trait-resolution depth) that turns pathological input intoCheckError::BudgetExceededinstead of a hang.
The checker does not resolve names (resolve-lang does) and does not compile patterns into decision trees (match-lang decides exhaustiveness for it; lowering compiles them).
Structs§
- Budget
- Limits on the work one check may do.
- Checker
- The configured path: declare host types, set a budget, then check.
- Diagnostic
- One finding about the checked program.
- Field
- A named field of a structural record type.
- Instance
- One instance in a
MonoPlan. - Instantiation
- The generic item an expression uses and its arguments: a path to a generic function, a method call, a constructor of a generic type.
- Mono
Plan - The instances a program needs.
- Profile
- A type-system profile.
- Stats
- Work counters of a finished check.
- Type
Display - A type rendered for display; see
Types::display. - TypeId
- A type in a
Typesstore. - Typed
- The result of checking one HIR unit.
- Types
- The store of interned type terms.
Enums§
- Check
Error - Why a check did not produce a
Typed. - Coercion
- An implicit conversion the checker accepted where a value meets a context of another type. Lowering must materialise it.
- Diagnostic
Kind - What a diagnostic says. Types are ids into the
Typed’s store, resolved (no inference variables). - Discipline
- How much a language checks statically, and how much it infers.
- Dispatch
- How a call reaches its callee.
- Feature
- A language feature the checker recognises but this version does not
check. Each is recorded in
dev/ROADMAP.md. - Limit
- Which budget ran out.
- Mono
Policy - Which generic items a profile copies and which it shares.
- NullLet
- What
let x = null(no annotation) givesx(ISSUES P17). - OpClass
- How an OPS operation was resolved by its operand types (HIR leaves this
open: the same
addis integer, IEEE, or string concatenation). - Polymorphism
- How a language attaches behaviour to types.
- Record
Typing - Whether record types are identified by declaration or by shape.
- Severity
- How serious a diagnostic is.
- Strategy
- How a generic item is compiled.
- TryHook
- How
?-style error propagation reaches the checker. - Type
- A read-only view of one type node.
Functions§
- check
- Checks
hirunderprofile, with no host declarations and a budget scaled to the HIR (Budget::for_hir).