lang::typecheck::view_rules

lang/src/typecheck/view_rules.mo

The view-types soundness rules (plans/type-system/view-types.md, Phase 1).

These are ERRORS on every path, regardless of a mote's [affine] mode (lang/mote.toml is warn): a safety rule that a warn mote could downgrade is not a rule. module.mo's check_module_with_scope_classified appends them to errors in both modes.

The rules, in the order they appear below:

  1. Forced linearity lives in affine.mo's effective_mult_with_kinds: a #[proof] type is linear, a #[linear] type is linear unless ?x relaxes it to affine. ?/% on a proof is rejected there (proof_erased_binder).
  2. No Copy/Clone: a declared instance for one is rejected (check_instance_kinds). The affine rule consults is_linear_type/is_proof_type BEFORE is_copy, so no implicit ω-route reaches a linear type; an explicit Copy.copy would need the instance this rule rejects.
  3. No capture (P10): a linear or proof value used under a nested lambda. The closure body counts it once but may run many times, and eager fibers run closures on other threads.
  4. No re-readable container (P11): a linear/proof value passed to Shared.of (counted as BinderUse.borrowed), or a signature/field typed Shared/Ref/Array over one.
  5. Proofs are phantom in v1: a user def may not bind or return a proof type, because nothing erases it yet.

Deliberately NOT a rule in v1: passing a linear value to an arbitrary polymorphic function whose parameter type is a bare type variable. That needs the callee's instantiated signature at the call site (the same interprocedural information gap as Shared.get's owning-argument case, QTT Known Gap 12) and is documented as a residual.

defcheck_module_view_errors#
pub def check_module_view_errors (scope : Scope) (decl_list : List Decl) : List TypeError

Every view/proof diagnostic a module earns. Built once per module: the kind sets and the two name sets are scope scans, not per-binder lookups.

defcheck_module_view_diags#
pub def check_module_view_diags (path : Option String) (scope : Scope) (decl_list : List Decl) : List String

The same errors, rendered with the owning declaration's name as the diagnostic context. Always error: — a warn mote must not downgrade a safety rule.