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: deferred equalities for associated types, decided per arm (issue #234)

ADR 0047, second part. A projection whose arguments are unknown where
two types must be compared no longer stops inference with E0403. The
equality is set aside and decided once its arguments are known.

- **Unification:**
  - `InferCtx::unify_deferring` unifies everything it can and sets aside
    each innermost pair of a stuck projection and the type it must
    equal;
  - `unify` stays strict for every other caller, so tests such as
    `is_ok()` in pattern checking and derive cannot be fooled;
  - a debug assertion catches a set-aside pair that is never taken.
- **Bookkeeping:** `FnInfer::unify_at` keeps each pair with its `match`
  arm and place (`Deferred`).
- **Arms:** equalities are retried (`progress`) only under the arm
  scopes in force, at each arm's end before its equalities are
  retracted, and at field access. One arm may refine a type differently
  from another, so an equality is never decided under another arm's
  assumptions.
- **Functionality:** two equalities of one projection in the same arm
  chain must agree.
- **`settle`:** decides the rest, each under its own arm's equalities,
  assumed again. For an inferred function, a variable left equal to a
  projection is then bound to it as written.
- **Leftovers:**
  - an equality over an inferred function's generalized variables
    becomes part of its scheme (`Scheme::equalities`), printed inside
    its trait's constraint: `fn(a) -> Option<Int> where Container<a,
    Elem = Int>`; each use unifies it again;
  - anything else is E0403 ("cannot tell what `Elem<_>` is here"),
    including an equality on a projection with its own arguments, which
    a quantified binding cannot express;
  - an inferred scheme in which a variable appears only inside
    projections is rejected, as declared ones are.
- **Binding:** a binding that fails its occurs or escape check only
  because of a projection an impl defines is retried with the
  projection reduced (impls only, never an arm's equalities).

Tests:
- `tests/ui/assoc_types.lse`:
  - an inferred equality and a call that breaks it;
  - an undecidable annotated case;
  - **two arms where one projection must be `Int` in one and `String` in
    the other**, accepted, and its variant with a mistake in one arm,
    rejected there only. Deciding equalities without their arm, or
    merging them across arms, gets these wrong.
- `tests/run/assoc_types.lse`: `Boxed(41)` checked against an
  `Elem<Pair>` field, and an inferred equality, on both backends.

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 · dfe93ec1cd7c57d42fdd505549b76b0ecfbda1d1

Parents f001748

9 fichiers modifiés, 481 ajouts, 28 suppressions