Skip to content

Deduplicate Marks between Syn/Ana - #2849

Open
Negabinary wants to merge 17 commits into
devfrom
settle-elab-syn-ty
Open

Negabinary wants to merge 17 commits into
devfrom
settle-elab-syn-ty

Conversation

@Negabinary

@Negabinary Negabinary commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #2733. Fixes #2507 and #1958. Followed by #2866 (patterns) and #2867 (ascribed types).

An error is marked once, on the term where it arises.

The types

Each expression has three types:

  • ana: what its parent expects. Passed down.
  • elab_syn_ty: the type its rule builds from its children's elab_syn_ty, or ana where that is inconsistent with ana. The inconsistency is marked there, and the elaboration is ascribed there, so every elaborated subterm synthesizes its elab_syn_ty on its own. Passed up, and it is what parents and every other reader use.
  • syn_ty: built by the same rules from the children's syn_ty, never settled. It is the type of what is written, errors included. Only the inspector and the type projector read it.

Because a failure is settled where it is marked, nothing above it fails again. An expression's old ty, elab_syn_ty refined by ana, now differs from elab_syn_ty only where ana agrees but says more (a hole expected to be an Int), so it is gone. Patterns are in #2866.

Examples (dev on top)

The if has the type its branches were settled to. A function whose body is wrong still shows Int -> Int against Int -> Bool.

On dev, "s" was not checked, and c was marked three times. An unexpected label is now marked on its entry, with the expected labels. The other entries are checked against their own types.

#2213 had dropped this mark by accident. An if in the same position was still marked.

Also

  • The parentheses directly around a marked tuple are drawn with its mark (Inconsistent highlighting of parentheses in errors #1997). A mark on syntax a projector folds away is drawn, listed and reached by next/previous problem at the projector. A projector shows errors from inside projectors it folds.
  • A mismatch is kept beside a node's other marks ([fun 1 -> 2] : [Int]). A free constructor is the exception: its type is a placeholder.
  • The inspector compares syn_ty with ana. Above an error it shows a neutral status.
  • Tuple shape messages from Make matched-type handling explicit in statics #2733: sizes, and missing or unexpected labels.
  • if and match cast each branch to the type the branches meet at.
  • A value lifted into a singleton labelled tuple is elaborated. f((1, 2)) with f taking (a=(b=Int, c=Int)) used to get stuck.

Not done

  • The incremental evaluator can't reuse a definition wrapped in an inserted ascription. That will be a follow-up.
  • A value lifted into a singleton labelled tuple with an error still gets a second mark, on the lifted copy.
  • The property "Sub-expression synthesis agrees with a fresh run" stays disabled. It finds only failures dev already has.
  • Found on dev: let z : (y=Int) = { let y = 1 } in z.y evaluates to (y=1).

Testing

make test-quick: 4573 tests. New tests are in Statics.Settling, Statics.Tuples and ProblemCollection. The CLI gives the same results on hazel-programs/ as dev. The examples above were checked in a browser.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.85915% with 107 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.51%. Comparing base (f93930e) to head (e08a5ee).
⚠️ Report is 4 commits behind head on dev.

Files with missing lines Patch % Lines
src/web/app/inspector/CursorInspector.re 2.43% 40 Missing ⚠️
src/language/statics/LabeledTupleStaticsHelpers.re 71.21% 19 Missing ⚠️
src/haz3lcore/TyDi/ErrorPrint.re 64.00% 9 Missing ⚠️
src/haz3lcore/derived/ErrorSites.re 66.66% 7 Missing ⚠️
src/language/term/Cls.re 33.33% 4 Missing ⚠️
src/web/app/common/ProjectorView.re 0.00% 4 Missing ⚠️
src/haz3lcore/ProblemCollection.re 50.00% 3 Missing ⚠️
...core/projectors/implementations/TableTransforms.re 0.00% 3 Missing ⚠️
src/language/statics/Message.re 0.00% 3 Missing ⚠️
src/haz3lcore/zipper/action/Indicated.re 50.00% 2 Missing ⚠️
... and 9 more
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2849      +/-   ##
==========================================
+ Coverage   48.43%   48.51%   +0.08%     
==========================================
  Files         498      499       +1     
  Lines       57542    57723     +181     
==========================================
+ Hits        27871    28005     +134     
- Misses      29671    29718      +47     
Files with missing lines Coverage Δ
src/haz3lcore/TyDi/TyDiForms.re 86.48% <100.00%> (+0.12%) ⬆️
src/haz3lcore/derived/Measured.re 79.21% <100.00%> (ø)
src/haz3lcore/projectors/DynamicTypInfer.re 92.85% <100.00%> (ø)
src/language/statics/CustomStatics.re 92.55% <100.00%> (ø)
src/language/statics/FunctionSugar.re 97.14% <ø> (ø)
src/language/term/IdTagged.re 57.14% <100.00%> (+1.82%) ⬆️
src/web/app/Cursor.re 58.33% <ø> (ø)
...c/haz3lcore/projectors/implementations/TypeProj.re 7.79% <50.00%> (+2.59%) ⬆️
src/haz3lcore/tiles/Segment.re 79.16% <87.50%> (+0.08%) ⬆️
src/haz3lcore/zipper/action/Perform.re 76.31% <80.00%> (-0.09%) ⬇️
... and 16 more

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Negabinary
Negabinary marked this pull request as draft November 20, 2026 19:33
Negabinary and others added 8 commits November 20, 2026 14:55
fresh_ascription built the casts elaboration inserts with a fresh id on
every statics run, so a cons whose tail is not a list (`?:: ?`, `1:: 2`)
elaborated with an id the incremental cache can never hit. The cast's id
now derives from the expression it wraps, through IdTagged.derived.

Taken from the full-pbt stack (its "Give an elaboration-inserted cast an
id derived from what it wraps" and the IdTagged.derived helper from "Keep
elaboration ids stable through label inference"), without the property
infrastructure those commits extend.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each Info gets syn_ty: the type of the term as the user wrote it, with any
errors in it. Rules that pass a child through (parens, let and sequence
bodies, filters, aliases) take the child's; rules that build a type from
their children (tuples, labels, lists, functions, branches) build it from
the children's syn types, with unknown where branches or elements have no
meet. A function's parameter contributes the type it binds, whose own
errors are marked on the pattern. Everything else takes the type its rule
builds.

A tuple's or label's TupleLabelError describes the entry as written, so it
takes the syn types.

Nothing reads syn_ty yet: this prepares for elab_syn_ty to become the
type settled against ana.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
elab_syn_ty is the type a node passes to its parent. It is the type the
rule built from its children's elab syn types, unless that fails ana: then
the mismatch is marked there and the node passes ana instead, so the
failure goes no further up. A function whose body is marked, or a tuple
whose element is marked, is no longer marked again (#2507). A synthetic ana
(a function position) leaves the rule's type alone. Holes and free
variables keep their unknown type.

Wherever a type is settled, the elaboration is ascribed with it, so an
elaborated term synthesizes its elab_syn_ty with no ana: `let x : String =
4 in x` elaborates its definition as `4 : String`. An annotation already
carries the type, so it does not repeat the ascription its body's rule
added. Inserted ascriptions are canonical, as the evaluator expects.

If and Match cast each branch to the type the branches meet at, so the
value has that type whichever branch runs; the cast no longer folds in
ana, which the branches have already settled against.

An expression's ty is, as before, its elab syn type refined by ana. A
capitalised name that resolves to a variable keeps the ascription its
settling added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An expression's inspector message compares its syn_ty with ana. Where they
are inconsistent but the expression is unmarked (its error is marked
further down), the inspector says so in a neutral status rather than
falling back to the synthesized type alone, which hid the expectation.
The neutral status shares the inspector's status layout.

Parentheses and projectors around an expression no longer repeat its
marks, so an error is marked once however deeply it is parenthesized. At
the parentheses of a tuple, which are part of its syntax, the inspector
shows the tuple. A projector hides its syntax, so its widget shows an
error anywhere in that syntax, not only on the term it replaces, and the
CLI reports an error there at the nearest enclosing term with a position.
Pattern parentheses still repeat their content's marks: a pattern's
elab_syn_ty is not settled, so they would mark it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each program has one error and it is marked once, with the types the
expression actually has. The syn type keeps an error the elab syn type has
settled on ana. Every sub-expression's elaboration synthesizes the type
recorded for it, and the syntax elaboration inserts has the same ids on
every run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A tuple that does not fit the expected tuple type is described by its size
and labels and, if it has labels, the labels it is missing or should not
have, in the CLI and the inspector: both for a type mismatch and for a
tuple whose labels are not the expected ones. A recursive tuple type is
unrolled to count its elements; labels are quoted as they would be
written. Against the empty tuple the type mismatch is clearer, so it is
kept. Adapted from #2502 by way of #2733. (#1958)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A value written where a singleton labelled tuple is expected is lifted
into one, but its elaboration was the lifted source syntax rather than the
lifted tuple's elaboration. So the labels the value's own elaboration
infers, a module's lowering, and the ascriptions settling adds were all
missing at run time: `f((1, 2))` with `f` taking `(a=(b=Int, c=Int))` got
stuck projecting `b`. The lifted tuple's elaboration is now used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its ascriptions' ids derive from what they wrap, so they are not fresh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Negabinary
Negabinary marked this pull request as ready for review November 20, 2026 20:34
@Negabinary Negabinary changed the title Mark each type error once by settling elab syn types against ana Deduplicate Marks between Syn/Ana Nov 20, 2026
Comment thread src/language/statics/Statics.re Resolved
Comment thread src/language/statics/Statics.re Resolved
Comment thread src/language/statics/Statics.re Resolved
Comment thread src/web/app/common/ProjectorView.re Resolved
Comment thread test/statics/Test_Statics_Tuples.re Resolved
Negabinary and others added 9 commits November 25, 2026 13:36
…flows

With settling, an expression's ty differed from its elab syn type only where
ana agrees with it and says more (a hole expected to be an Int). Every reader
of an expression's ty sits where ana is synthetic, or gets the same results
from the elab syn type: the quick tests and the CLI on 85 programs are
unchanged. The few readers that want the expected type folded in (a custom
builtin's argument, a table projector, the inspector's lifted singleton)
compute the meet themselves. Patterns keep ty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
should_emit_nomeet_mark, added in #2213, dropped the NoMeet mark on a list
whose elements do not meet whenever List(?) met ana, and it always meets
SynSwitch, so [1, "s", 3] had no error. Before that a list's NoMeet in
synthesis was an error, as an if's still is. The CLI message names the parts
(elements, operands, branches) from the form, as the inspector does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ere settled to

An if, match or list whose parts have no common syn type now reports the type
they were settled to, not unknown: their disagreement is marked on the part
that failed. let r : Int = if true then 1 else "s" shows Int at the if, while
a function whose body is wrong still shows its own type against ana.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In (a=1, b=2, c=3) against (a=Int, b=Int), the label c, its entry and the
tuple were all marked. Now only the entry is, with the labels expected. Its
other entries are matched with the expected ones without it, so each is still
checked against its own type (b="s" was not), and the tuple settles on ana
without a mark of its own when it fits once the unexpected entries are left
out. A tuple also missing a label keeps its shape message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d over a tuple's parentheses

ErrorSites says where the editor shows a mark. A mark on syntax a projector
folds away is shown, listed and reached by next/previous problem at the
projector, as the CLI already did; without a mark of its own on the
projector, navigation skipped it. The parentheses directly around a marked
tuple are drawn with its mark (#1997) without being marked themselves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s on ana

A node with another mark used to drop its mismatch. Since it settles on ana
either way, that mismatch was then reported nowhere: [fun 1 -> 2] : [Int]
had no type error. A free constructor's type is a placeholder, so it settles
without a mismatch beside FreeConstructor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its self type was the elab syn type, which is settled on the expected type
exactly where they disagree, so it read the expected type and reported a
match. A known constructor records its own type as its syn type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Segment.ids stops at a nested projector, whose own Info no longer carries the
marks of what it folds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shape_mismatch_message lists every non-tuple type form instead of a catch-all,
and info_where moves to Test_Statics_Prelude for the tuple shape tests.

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

This branch has not been deployed

No deployments
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.

A function whose body mismatches its expected return type is marked twice

2 participants