Expand description
Decl, implemented natively in Rust: the parser binding, the static checker, the evaluator, modules and packages, the canonical formatter, and the language server — the same behavior as the TypeScript reference implementation, verified by tests/parity in the repository.
Re-exports§
pub use api::check;pub use api::evaluate;pub use api::evaluate_source;pub use api::format_source;pub use api::validate;pub use api::DeclError;pub use api::Diagnostic;pub use api::Document;pub use api::EvaluateOptions;pub use api::Report;
Modules§
- api
- The high-level API of the crate: the operations the
declcommand line offers, in the same vocabulary —evaluatebinds inputs and returns outputs,check,validate,evaluate_source,format_source— for programs that would otherwise assemble parser, checker, and engine by hand (those modules are public too). The npm package and the Python package offer the same functions with the same semantics. - ast
- AST of the runtime — the shape the tree-sitter CST lowers into (parse.rs), mirroring the reference implementation’s ast.ts.
- checker
- Static checks over the AST + resolved types — a port of the reference implementation’s checker.ts (chapters 3–4). Implemented: E3001 duplicate module name E3003 unknown type name E4010 mixed range endpoints E4011 empty range / array size E4012 structurally empty intersection E4013 non-discriminable record union arms E4014 more than one non-record object arm in a union E4015 map key not string-shaped E4030 inheritance widening E4032 illegal member-kind transition E4052 ?? mixed with &&/|| unparenthesized E4094 context variable without / with an invalid context declaration plus the expression pass of infer.rs (inference, assignability, absence).
- cli
decl check/decl evaluate/decl validate/decl fmt(cli.ts). Output is byte-identical to the reference implementation’s CLI so the three implementations can be diffed (tests/parity/differential.py).- conformance
- Conformance judging — a port of the reference implementation’s conformance.ts: judges fixtures by their declared phase. valid/* -> parse + checks clean + outputs evaluate clean invalid @expect-phase: parsing -> must fail to parse invalid @expect-phase: checking -> parses; static checks report @expect-error invalid @expect-phase: binding -> parses; the pipeline reports @expect-error
- engine
- Binding, evaluation, validation, and serialization — a port of the reference implementation’s engine.ts. Semantics are the spec’s: lazy slots with cycle detection, taint / root-cause diagnostics, $referrers universe ordering, canonical JSON output.
- fmt
- Canonical formatter — a port of the reference implementation’s fmt.ts (ROADMAP Phase 4; §2.1/D1): LF, 4-space indentation, no tabs, normalized intra-line spacing. The original line structure is preserved — §2.9 makes newlines separators, so where a construct breaks lines is the author’s statement — and the formatter re-derives indentation and token spacing deterministically, which makes it idempotent by construction.
- infer
- Expression-level static analysis — a port of the reference
implementation’s infer.ts: type inference, assignability (§3.18,
strict S ⊑ T), the absence discipline (§4.10) with its two narrowing
rules, and the
matchstatic checks (§4.7). Inference is conservative: a form whose type cannot be determined yieldsunknown(rt None) and suppresses downstream judgments rather than guessing. - lsp
- decl-lsp (docs/tooling/03_lsp.md): the language server over stdio — a port of the reference implementation’s lsp.ts. Every answer comes from the same checker, inference, and engine as the command line, driven through the session object (session.rs) with the open buffers overriding the disk; positions come from the source ranges every AST node carries, and the types and resolutions recorded while the checker runs (infer.rs hooks). Messages are handled strictly in order, and the server exits when its input closes.
- module
- Module loading, linking, and universe evaluation (module.ts, §8.1–8.5, §8.8): files are modules, the import graph is acyclic, exports are explicit; packages (§8.6–8.7) plug in through the resolver hook.
- package
- Packages, decl.toml, and decl.lock (§8.6–8.7) — a port of the
reference implementation’s package.ts: exact-pinned dependencies,
fail-closed manifests, content-hashed reproducibility. Conventions:
dependency packages live under
<root>/decl_modules/<name>/in a flat layout, and the lock file is line-basedname version sha256in name order. - parse
- CST -> AST lowering over the compiled tree-sitter grammar (parse.ts).
- pipeline
- The single-module pipeline — a port of the reference implementation’s pipeline.ts: bind and evaluate every output of one module’s declarations (the judgment the conformance runner applies), and the source-level report that front-ends and embedders consume.
- repl
- The REPL (docs/tooling/02_repl.md) — a port of the reference
implementation’s repl.ts: an interactive session over a universe —
expressions evaluated partially, session outputs and declarations,
documents bound and edited with exact undo, and the command-line verbs
root for root. Everything it prints goes to standard output; a scripted
session (
--script) prints the transcript the terminal would show, so the three implementations can be diffed. - semantics
- Value model, environment, and type resolution — a port of the reference implementation’s semantics.ts.
- session
- The session object (docs/tooling/02_repl.md §1) — a port of the
reference implementation’s session.ts: a universe — the modules loaded
from an entry file, their texts taken as a snapshot — plus an operation
log (bindings, document edits, session declarations, reloads). The
state is the universe with the log applied, recomputed deterministically
from the snapshot, which is what makes
:undoexact and a scripted session reproducible. The REPL (repl.rs) drives it; nothing here prints, and every answer is the same checker, inference, and engine the command line runs. - subsume
- The subsumption judgment ⊑ (§3.17) — the runtime needs it for
matcharm selection over bound records and generic value-argument checks.