Skip to content

s2/types: type inference, all generic calls solved (T1) - #21

Merged
vic merged 1 commit into
mainfrom
s2-types-t1
Nov 9, 2026
Merged

vic merged 1 commit into
mainfrom
s2-types-t1

Conversation

@vic

@vic vic commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Self-host rung T1: type inference over the s2 Ast (s2/types.srs, module Ty), following s1's rules (vic/c/s2-typing-spec.md).

  • A type is a K.Term. A callee's [] binders open to fresh K.Vars at each call, then get bound in this order: written type args, then the expected type (check mode first, as s1), then the args left to right through K.unify. In a generic body the binders are rigid.
  • Constructors, match arms (fields typed with the enum's args) and methods (protocol ops, or trait methods with the trait args taken from the evidence type) follow the same scheme.
  • Every error is a Ty.Clash (data). Every generic call or constructor records Ty.Inst(line, callee, type args) for mono and emit; an instance left unsolved is CannotInfer.

Oracle: the prelude and every s2 source (all accepted by s1) type with no clash, and over 1000 instances are solved. Extra cases: a trait method whose binder names differ from the trait's, and one program per clash kind.

Five mutants (type args dropped, no check mode, arm fields unbound, < typed I64, trait args unbound) each change the output; the last one first survived and led to the trait-args case. Local tests/run.sh: 186 ok, 0 FAIL.

…f-host rung T1)

A type is a K.Term (K.Con(name, args)). A callee's [] binders open to fresh K.Vars at each call; the
written type args bind them, then the expected type (check mode first, as s1 vic-m5r.18), then the args
left to right through K.unify. In a generic body the binders are rigid cons. Constructors open their
enum's binders the same way; a match binds each arm's fields with the enum's args; a method is an op
of a capability's protocol or a trait method of {} evidence, with the trait's args from the evidence
type. Every error is a Ty.Clash (Mismatch, Unknown, Arity, NotEnum, NoOp, CannotInfer); every generic
call and constructor records Ty.Inst(line, callee, type args), the input of mono and emit; an instance
with a var left after the whole program is CannotInfer.

tests/s2/types: the prelude and every s2 source (all accepted by s1) type with no clash and over 1000
instances solved; a trait method with binder names unlike the trait's; one program per clash kind.
Mutants: type args dropped, no check mode, arm fields unbound, < typed I64, trait args unbound: each
changes the output.
@vic
vic merged commit 2a27ce2 into main Nov 9, 2026
3 checks passed
@vic
vic deleted the s2-types-t1 branch November 9, 2026 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant