tobogganSe connecter

louise

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

Types: associated types, with eager reduction (issue #234)

ADR 0047, first part: declarations, definitions and projections.
Unification is eager here: a projection whose arguments are still
unknown where two types must be compared is reported (E0403). The
next PR defers those equalities instead.

- **Syntax:**
  - `type Elem` / `type Mapped<x>` in a trait, `type Elem = a` in an
    impl (an `ASSOC_TYPE` node);
  - grammar.md;
  - tree-sitter (`associated_type`, a highlight and a corpus case).
- **HIR:**
  - `DefKind::AssocType`. A trait's associated types are in its
    module's type namespace and exported with it; an impl's definitions
    are in no scope.
  - Defining in the trait (no defaults), or declaring without `= type`
    in an impl, is E0120.
- **Types:**
  - `Ty::Proj(assoc, args)`, with the trait's arguments, then the
    associated type's own;
  - the impls' definitions go in an `AssocTable` that `InferCtx`
    shares, so `shallow` reduces a projection an impl defines, and
    `normalize` reduces all the way down for later phases and schemes;
  - a variable is bound to a projection as written, so an arm's
    equalities never leak through one;
  - a projection no impl reduces equals only itself (projections are
    not injective).
- **Impls:**
  - each declared associated type is defined exactly once (E0406,
    E0407 now say "item");
  - a definition uses the impl's variables and its own parameters
    (E0211);
  - a projection inside a definition takes the impl's own variables as
    its trait's arguments, so reduction ends (E0415).
- **Signatures:**
  - `Elem<c>` needs `where Container<c>` unless `c` is a named type
    (E0402);
  - a variable only inside projections is not determined (E0403);
  - projections are refused as GADT indices (E0214) and in
    `@derivable` traits (E0412).
- **Solver and `Send`:**
  - normalization reduces projections;
  - a stuck projection is unknown with inference variables, rigid
    otherwise;
  - `Send` of one needs a given.
- **IDE:** semantic tokens, hover, outline and navigation know
  associated types.
- **Docs:** the language reference's "Associated types"; diagnostics
  E0120, E0415, and widened E0402, E0403, E0406 and E0407.

Tests:
- `tests/run/assoc_types.lse` on both backends: a nested definition
  `type Elem = Elem<c>`, a generic associated type, and a message whose
  type is a projection.
- `tests/ui/assoc_types.lse` covers every rule above.

The generated C of every existing program is byte-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

olivier · il y a 1 mois · f0017488818331b80cdd5fbcbb189962784c3431

Parents a132845

28 fichiers modifiés, 10424 ajouts, 9088 suppressions

Mcrates/louise_db/src/ide/hover.rs+18−0
Mcrates/louise_db/src/ide/tokens.rs+1−1
Mcrates/louise_hir/src/lower/mod.rs+27−1
Mcrates/louise_syntax/src/grammar/mod.rs+22−2
Mcrates/louise_syntax/src/syntax_kind.rs+2−0
Mcrates/louise_types/src/derive.rs+5−0
Mcrates/louise_types/src/env/impls.rs+159−0
Mcrates/louise_types/src/env/mod.rs+172−3
Mcrates/louise_types/src/infer/mod.rs+11−0
Mcrates/louise_types/src/traits.rs+30−3
Meditors/tree-sitter-louise/grammar.js+11−2
Meditors/tree-sitter-louise/queries/helix/highlights.scm+2−0
Meditors/tree-sitter-louise/queries/highlights.scm+2−0
Meditors/tree-sitter-louise/src/grammar.json+76−4
Meditors/tree-sitter-louise/src/node-types.json+52−0
Meditors/tree-sitter-louise/src/parser.c+9258−9051
Meditors/tree-sitter-louise/test/corpus/items.txt+69−0