Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
639fb10
Give an elaboration-inserted cast an id derived from what it wraps
Negabinary Nov 20, 2026
ed2ba8b
Record each expression's syn type beside its elab syn type
Negabinary Nov 20, 2026
538eccd
Settle each expression's elab syn type against ana
Negabinary Nov 20, 2026
ac2c347
Show syn against ana in the inspector; mark only where an error arises
Negabinary Nov 20, 2026
6c75b5c
Test that errors are marked once and elaborations carry their types
Negabinary Nov 20, 2026
bf47c3e
Explain a tuple's shape when it does not fit the expected tuple type
Negabinary Nov 20, 2026
dda96ab
Elaborate a value lifted into a singleton labelled tuple
Negabinary Nov 20, 2026
f84180f
Rename fresh_ascription to ascribe
Negabinary Nov 20, 2026
8406cf6
Drop an expression's ty: once settled, its elab syn type is all that …
Negabinary Nov 25, 2026
7790bec
Mark mixed-type list literals in synthesis again
Negabinary Nov 25, 2026
af0c101
Where branches or elements disagree, their syn type is the one they w…
Negabinary Nov 25, 2026
0c0667e
Mark an unexpected tuple label only on its entry
Negabinary Nov 25, 2026
594bd6f
Show a mark where its syntax is seen: at the projector folding it, an…
Negabinary Nov 25, 2026
451af9d
Keep a mismatch beside a node's other marks, now that the node settle…
Negabinary Nov 25, 2026
ba95f71
The type projector reads the type of what is written
Negabinary Nov 25, 2026
a8e8069
A projector shows an error inside a projector it folds
Negabinary Nov 25, 2026
e08a5ee
Review nits: list the type forms with no labels; share info_where
Negabinary Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/CLI/Diagnostic.re
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ let format_diagnostic_with_location =
};
};

/* Syntax a projector folds away has no position of its own: report it at
the nearest enclosing term that has one. */
let located_id = (measured: Haz3lcore.Measured.t, info: Language.Info.t) =>
List.find(
[Language.Info.id_of(info), ...Language.Info.ancestors_of(info)], ~f=id =>
Option.is_some(Haz3lcore.Measured.find_opt_by_id(id, measured))
)
|> Option.value(~default=Language.Info.id_of(info));

let format_error_with_location =
(
~source: string,
Expand All @@ -132,7 +141,7 @@ let format_error_with_location =
~source,
~path,
measured,
Info.id_of(info),
located_id(measured, info),
),
);
}
Expand All @@ -159,7 +168,7 @@ let format_warning_with_location =
~source,
~path,
measured,
Info.id_of(info),
located_id(measured, info),
),
);
}
Expand Down
25 changes: 10 additions & 15 deletions src/haz3lcore/ProblemCollection.re
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,8 @@ type problem_context = {
nearest_measured_id: Id.t => option(Id.t),
};

/* Walk `id` and its ancestors (innermost-first via Statics.Map) and
return the first one present in `measured`. The ancestor lookup is
only forced if `id` itself is missing from `measured`. */
let nearest_measured_id =
(~info_map: Statics.Map.t, ~measured: Measured.t, id: Id.t): option(Id.t) =>
Stdlib.Seq.cons(id, () =>
Stdlib.List.to_seq(Statics.Map.ancestors_of(id, info_map), ())
)
|> Stdlib.Seq.find(anc =>
Option.is_some(Measured.find_by_id(anc, measured))
);
/* `id`, or its nearest ancestor present in `measured`. */
let nearest_measured_id = ErrorSites.located;

let make_problem_context =
(
Expand Down Expand Up @@ -107,8 +98,11 @@ let make_problem_context =
List.fold_right(
~f=
(id, (syn, stat)) =>
switch (Statics.Map.lookup(id, info_map)) {
| Some(ci) when Info.is_error(ci) && id_in_this_editor(id) =>
/* A problem in syntax a projector folds away is listed at the
projector, where the editor can go to it. */
switch (Statics.Map.lookup(id, info_map), resolve_nearest(id)) {
| (Some(ci), Some(id))
when Info.is_error(ci) && id_in_this_editor(id) =>
if (Info.is_syntax_error(ci)) {
([(id, ci), ...syn], stat);
} else {
Expand All @@ -125,8 +119,9 @@ let make_problem_context =
List.filter_map(
~f=
id =>
switch (Statics.Map.lookup(id, info_map)) {
| Some(ci) when Info.is_warning(ci) && id_in_this_editor(id) =>
switch (Statics.Map.lookup(id, info_map), resolve_nearest(id)) {
| (Some(ci), Some(id))
when Info.is_warning(ci) && id_in_this_editor(id) =>
Some((id, ci))
| _ => None
},
Expand Down
64 changes: 47 additions & 17 deletions src/haz3lcore/TyDi/ErrorPrint.re
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,42 @@ module Print = {

let prn = sprintf;

let core_mark_string = (ctx: Ctx.t, ana: Typ.t, m: Mark.t): string => {
let core_mark_string =
(~cls: option(Cls.t)=?, ctx: Ctx.t, ana: Typ.t, m: Mark.t): string => {
let ana = Statics.ana_skip_explicit_nonlabel(ana);
let expectation = (ana: Typ.t, syn: Typ.t) =>
prn(
"Expecting type %s but got inconsistent type %s",
Print.typ(ana),
Print.typ(syn),
);
switch (
LabeledTupleStaticsHelpers.shape_mismatch_message(ctx, ~ana, ~syn)
) {
| Some(message) => message
| None =>
prn(
"Expecting type %s but got inconsistent type %s",
Print.typ(ana),
Print.typ(syn),
)
};
switch (m) {
| BadLabel(_)
| InvalidLabel(_, _) => "Invalid label"
| BadLabel(_) => "Invalid label"
| InvalidLabel(name, []) =>
prn(
"Unexpected label %s; no labels were expected",
Token.quote_label_when_necessary(name),
)
| InvalidLabel(name, expected) =>
prn(
"Unexpected label %s; expecting labels %s",
Token.quote_label_when_necessary(name),
String.concat(
~sep=", ",
List.map(~f=Token.quote_label_when_necessary, expected),
),
)
| DuplicateLabel(_, _) => "Duplicate label"
| DuplicateVar(_, _) => "Duplicate variable"
| TupleLabelError({malformed_labels: [], duplicate_labels: [], typ, _}) =>
LabeledTupleStaticsHelpers.shape_mismatch_message(ctx, ~ana, ~syn=typ)
|> Option.value(~default="Invalid tuple label")
| TupleLabelError(_) => "Invalid tuple label"
| UnexpectedLabelSort(_) => "Unexpected label sort"
| BadToken(token) => prn("\"%s\" isn't a valid token", token)
Expand All @@ -53,7 +76,11 @@ let core_mark_string = (ctx: Ctx.t, ana: Typ.t, m: Mark.t): string => {
| NoMeet(PolyEq, tys)
| NoMeet(_, tys) when ana.term == Unknown(SynSwitch) =>
prn(
"Expecting branches to have consistent types but got types: %s",
"Expecting %s to have consistent types but got types: %s",
cls
|> Option.value_map(~default="branches", ~f=cls =>
String.lowercase(Cls.elements_noun(cls))
),
List.map(~f=Print.typ, Typ.of_source(tys)) |> String.concat(~sep=", "),
)
| NoMeet(wrap, _tys) =>
Expand Down Expand Up @@ -89,8 +116,9 @@ let drv_error: DrvInfo.error => string =
List.map(~f=DrvSort.to_string, actuals) |> String.concat(~sep=", "),
);

let exp_mark_to_string = (ctx: Ctx.t, ana: Typ.t, m: Mark.t): string => {
let common_from_core = () => core_mark_string(ctx, ana, m);
let exp_mark_to_string =
(~cls: option(Cls.t)=?, ctx: Ctx.t, ana: Typ.t, m: Mark.t): string => {
let common_from_core = () => core_mark_string(~cls?, ctx, ana, m);
switch (m) {
| Free(name) => "Variable " ++ name ++ " is not bound"
| InexhaustiveMatch(_) => "Match is not exhaustive"
Expand Down Expand Up @@ -168,18 +196,20 @@ let exp_mark_to_string = (ctx: Ctx.t, ana: Typ.t, m: Mark.t): string => {
};

let pat_marks_to_string =
(ctx: Ctx.t, ana: Typ.t, marks: list(Mark.t)): string =>
(~cls: option(Cls.t)=?, ctx: Ctx.t, ana: Typ.t, marks: list(Mark.t))
: string =>
switch (marks) {
| [Redundant, ...tl] =>
switch (Mark.highest(tl)) {
| None => "Redundant"
| Some(m) => core_mark_string(ctx, ana, m) ++ "; pattern is redundant"
| Some(m) =>
core_mark_string(~cls?, ctx, ana, m) ++ "; pattern is redundant"
}
| [ExpectedConstructor, ..._] => "Expected a constructor"
| _ =>
switch (Mark.highest(marks)) {
| None => "(static error)"
| Some(m) => core_mark_string(ctx, ana, m)
| Some(m) => core_mark_string(~cls?, ctx, ana, m)
}
};

Expand Down Expand Up @@ -225,12 +255,12 @@ let string_of_marks = (info: Info.t, marks: list(Mark.t)): string =>
| Some(err) => drv_error(err)
| None => "(static error)"
}
| InfoExp({ctx, ana, _}) =>
| InfoExp({ctx, ana, cls, _}) =>
switch (Mark.highest(marks)) {
| Some(m) => exp_mark_to_string(ctx, ana, m)
| Some(m) => exp_mark_to_string(~cls, ctx, ana, m)
| None => "(static error)"
}
| InfoPat({ctx, ana, _}) => pat_marks_to_string(ctx, ana, marks)
| InfoPat({ctx, ana, cls, _}) => pat_marks_to_string(~cls, ctx, ana, marks)
| InfoTyp(_) =>
switch (marks) {
| [] => "(static error)"
Expand Down
3 changes: 2 additions & 1 deletion src/haz3lcore/TyDi/TyDiForms.re
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ module Typ = {
| Some(term) =>
let (info_map, _) = Statics.mk(CoreSettings.on, Ctx.empty, term);
switch (Id.Map.find_opt(Exp.rep_id(term), info_map)) {
| Some(InfoExp({ty, _})) => Some(normalize_unknowns(ty))
| Some(InfoExp({elab_syn_ty, _})) =>
Some(normalize_unknowns(elab_syn_ty))
| _ => None
};
}
Expand Down
60 changes: 60 additions & 0 deletions src/haz3lcore/derived/ErrorSites.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
open Language;

/* ERRORSITES.re — where the editor shows what statics marked.

Statics marks the term where an error arises. The editor shows the mark
there, with two exceptions: syntax a projector folds away has no position
of its own, and the parentheses around a tuple are drawn as part of it. */

/* `id`, or failing that its nearest ancestor with a position: the projector
that folds it away. None if neither it nor any ancestor has one, as for a
term in another editor's part of a spliced statics map. */
let located =
(~info_map: Statics.Map.t, ~measured: Measured.t, id: Id.t): option(Id.t) =>
Stdlib.Seq.cons(id, () =>
Stdlib.List.to_seq(Statics.Map.ancestors_of(id, info_map), ())
)
|> Stdlib.Seq.find(id =>
Option.is_some(Measured.find_opt_by_id(id, measured))
);

/* The parentheses directly around the tuple `id`, which are part of its
syntax as the user sees it, so are drawn as part of its mark. */
let enclosing_parens = (~info_map: Statics.Map.t, id: Id.t): option(Id.t) =>
switch (Statics.Map.ancestors_of(id, info_map)) {
| [parent, ..._] =>
switch (Statics.Map.lookup(parent, info_map)) {
| Some(
InfoExp({
user_term: {term: Parens({term: Tuple(_), _} as tuple), _},
_,
}),
)
when Id.equal(Exp.rep_id(tuple), id) =>
Some(parent)
| Some(
InfoPat({
user_term: {term: Parens({term: Tuple(_), _} as tuple), _},
_,
}),
)
when Id.equal(Pat.rep_id(tuple), id) =>
Some(parent)
| _ => None
}
| [] => None
};

/* The terms whose syntax draws the marks on `ids`, each once. */
let drawn =
(~info_map: Statics.Map.t, ~measured: Measured.t, ids: list(Id.t))
: list(Id.t) =>
List.concat_map(ids, ~f=id =>
switch (located(~info_map, ~measured, id)) {
| Some(shown) when Id.equal(shown, id) =>
[shown] @ Option.to_list(enclosing_parens(~info_map, id))
| Some(shown) => [shown]
| None => []
}
)
|> List.dedup_and_sort(~compare=Id.compare);
18 changes: 10 additions & 8 deletions src/haz3lcore/derived/Measured.re
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ let find_p = (~msg="", p: Piece.t, map): measurement =>
| _ => failwith("find_p: " ++ msg ++ "id: " ++ Id.to_string(p |> Piece.id))
};

let find_by_id = (id: Id.t, map: t): option(measurement) => {
let find_opt_by_id = (id: Id.t, map: t): option(measurement) => {
switch (Id.Map.find_opt(id, map.secondary)) {
| Some(m) => Some(m)
| None =>
Expand All @@ -205,18 +205,20 @@ let find_by_id = (id: Id.t, map: t): option(measurement) => {
origin: first.origin,
last: last.last,
});
| None =>
switch (Id.Map.find_opt(id, map.projectors)) {
| Some(m) => Some(m)
| None =>
printf("Measured.WARNING: id %s not found", Id.to_string(id));
None;
}
| None => Id.Map.find_opt(id, map.projectors)
}
}
};
};

let find_by_id = (id: Id.t, map: t): option(measurement) => {
let m = find_opt_by_id(id, map);
if (Option.is_none(m)) {
printf("Measured.WARNING: id %s not found", Id.to_string(id));
};
m;
};

/* Content bounds of the row currently being measured */
type row_content_ = {
start_opt: option(int), /* column of first non-whitespace, None if none yet */
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/projectors/DynamicTypInfer.re
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let type_of_sample = (~ctx: Ctx.t, sample: Sample.t): option(Typ.t) => {
|> Option.bind(
~f=
fun
| Info.InfoExp(e) => Some(e.ty)
| Info.InfoExp(e) => Some(e.elab_syn_ty)
| _ => None,
);
};
Expand Down
9 changes: 4 additions & 5 deletions src/haz3lcore/projectors/implementations/TableTransforms.re
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ let strip_parens =

let get_type_from_info = (info: info): option(Typ.t) =>
switch (info.statics) {
| Some(InfoExp({ty, ctx, _})) =>
let ty = Typ.normalize(ctx, ty);
| Some(InfoExp({elab_syn_ty, ana, ctx, _})) =>
/* What the table's type is known to be, its expectation included. */
let ty = Typ.normalize(ctx, Statics.fixed_typ(ctx, ana, elab_syn_ty));
Typ.contains_unknown(ty) ? None : Some(ty);
| _ => None
};
Expand All @@ -73,9 +74,7 @@ let get_dynamic_type = (exp: Exp.t): option(Typ.t) => {
_,
~f=
fun
| InfoExp(e) => {
Some(e.ty);
}
| InfoExp(e) => Some(e.elab_syn_ty)
| _ => None,
);
};
Expand Down
6 changes: 4 additions & 2 deletions src/haz3lcore/projectors/implementations/TypeProj.re
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ let expected_ty = (info: Info.t): option(Typ.t) =>
| _ => None
};

/* The type of what is written: not its elab syn type, which is settled on
the expected type exactly where the two disagree. */
let self_ty = (info: Info.t): option(Typ.t) =>
switch (info) {
| InfoExp({elab_syn_ty, _})
| InfoPat({elab_syn_ty, _}) => Some(elab_syn_ty)
| InfoExp({syn_ty, _})
| InfoPat({syn_ty, _}) => Some(syn_ty)
| _ => None
};

Expand Down
15 changes: 15 additions & 0 deletions src/haz3lcore/tiles/Segment.re
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,21 @@ and ids_of_piece = (p: Piece.t): list(Id.t) =>
| Projector(_) => [Piece.id(p)]
};

/* Like ids, and also the ids of the syntax every projector in `s` folds
away. */
let rec ids_through_projectors = (s: t): list(Id.t) =>
List.concat_map(s, ~f=p =>
switch (p) {
| Tile(t) => [
Piece.id(p),
...ids_through_projectors(List.concat(t.children)),
]
| Projector(pr) => [Piece.id(p), ...ids_through_projectors([pr.syntax])]
| Grout(_)
| Secondary(_) => [Piece.id(p)]
}
);

let first_string =
fun
| [] => "EMPTY"
Expand Down
17 changes: 17 additions & 0 deletions src/haz3lcore/zipper/action/Indicated.re
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,23 @@ let ci_of =
});
};

/* The ci of what the indicated term presents: its own, except that the
parentheses around a tuple present the tuple, as they are part of its
syntax. */
let presented_ci =
(z: ZipperBase.t, info_map: Language.Statics.Map.t)
: option(Language.Statics.Info.t) =>
switch (ci_of(z, info_map)) {
| Some(
InfoExp({
user_term: {term: Parens({term: Tuple(_), _} as tuple), _},
_,
}),
) =>
Id.Map.find_opt(Language.Exp.rep_id(tuple), info_map)
| ci => ci
};

/* For type-directed completion (TyDi): returns the ci of the
* left neighbor tile, which is the token being completed.
* Falls back to ci_of when no suitable left neighbor exists. */
Expand Down
Loading
Loading