Skip to content

Commit

Permalink
Merge DHExp and UExp (#1197)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrus- authored Jul 31, 2024
2 parents 2bfaef4 + 73826ea commit 40d1896
Show file tree
Hide file tree
Showing 133 changed files with 7,016 additions and 7,665 deletions.
4 changes: 2 additions & 2 deletions src/haz3lcore/TermMap.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include Id.Map;
type t = Id.Map.t(Term.t);
type t = Id.Map.t(Any.t);

let add_all = (ids: list(Id.t), tm: Term.t, map: t) =>
let add_all = (ids: list(Id.t), tm: Any.t, map: t) =>
ids |> List.fold_left((map, id) => add(id, tm, map), map);
1 change: 1 addition & 0 deletions src/haz3lcore/Unicode.re
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let zwsp = "​";

let typeArrowSym = "→"; // U+2192 "Rightwards Arrow"
let castArrowSym = "⇨";
let castBackArrowSym = "⇦";

let ellipsis = "\xE2\x80\xA6";

Expand Down
24 changes: 14 additions & 10 deletions src/haz3lcore/assistant/AssistantCtx.re
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let bound_constructors =
let bound_aps = (ty_expect: Typ.t, ctx: Ctx.t): list(Suggestion.t) =>
List.filter_map(
fun
| Ctx.VarEntry({typ: Arrow(_, ty_out) as ty_arr, name, _})
| Ctx.VarEntry({typ: {term: Arrow(_, ty_out), _} as ty_arr, name, _})
when
Typ.is_consistent(ctx, ty_expect, ty_out)
&& !Typ.is_consistent(ctx, ty_expect, ty_arr) => {
Expand All @@ -66,7 +66,11 @@ let bound_aps = (ty_expect: Typ.t, ctx: Ctx.t): list(Suggestion.t) =>
let bound_constructor_aps = (wrap, ty: Typ.t, ctx: Ctx.t): list(Suggestion.t) =>
List.filter_map(
fun
| Ctx.ConstructorEntry({typ: Arrow(_, ty_out) as ty_arr, name, _})
| Ctx.ConstructorEntry({
typ: {term: Arrow(_, ty_out), _} as ty_arr,
name,
_,
})
when
Typ.is_consistent(ctx, ty, ty_out)
&& !Typ.is_consistent(ctx, ty, ty_arr) =>
Expand Down Expand Up @@ -141,7 +145,7 @@ let suggest_lookahead_variable = (ci: Info.t): list(Suggestion.t) => {
let exp_aps = ty =>
bound_aps(ty, ctx)
@ bound_constructor_aps(x => Exp(Common(x)), ty, ctx);
switch (Mode.ty_of(mode)) {
switch (Mode.ty_of(mode) |> Typ.term_of) {
| List(ty) =>
List.map(restrategize(" )::"), exp_aps(ty))
@ List.map(restrategize("::"), exp_refs(ty))
Expand All @@ -152,20 +156,20 @@ let suggest_lookahead_variable = (ci: Info.t): list(Suggestion.t) => {
@ List.map(restrategize(commas), exp_refs(ty));
| Bool =>
/* TODO: Find a UI to make these less confusing */
exp_refs(Int)
@ exp_refs(Float)
@ exp_refs(String)
@ exp_aps(Int)
@ exp_aps(Float)
@ exp_aps(String)
exp_refs(Int |> Typ.fresh)
@ exp_refs(Float |> Typ.fresh)
@ exp_refs(String |> Typ.fresh)
@ exp_aps(Int |> Typ.fresh)
@ exp_aps(Float |> Typ.fresh)
@ exp_aps(String |> Typ.fresh)
| _ => []
};
| InfoPat({mode, co_ctx, _}) =>
let pat_refs = ty =>
free_variables(ty, ctx, co_ctx)
@ bound_constructors(x => Pat(Common(x)), ty, ctx);
let pat_aps = ty => bound_constructor_aps(x => Pat(Common(x)), ty, ctx);
switch (Mode.ty_of(mode)) {
switch (Mode.ty_of(mode) |> Typ.term_of) {
| List(ty) =>
List.map(restrategize(" )::"), pat_aps(ty))
@ List.map(restrategize("::"), pat_refs(ty))
Expand Down
30 changes: 18 additions & 12 deletions src/haz3lcore/assistant/AssistantForms.re
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,36 @@ let leading_expander = " " ++ AssistantExpander.c;
* running Statics, but for now, new forms e.g. operators must be added
* below manually. */
module Typ = {
let unk: Typ.t = Unknown(Internal);
let unk: Typ.t = Unknown(Internal) |> Typ.fresh;

let of_const_mono_delim: list((Token.t, Typ.t)) = [
("true", Bool),
("false", Bool),
("true", Bool |> Typ.fresh),
("false", Bool |> Typ.fresh),
//("[]", List(unk)), / *NOTE: would need to refactor buffer for this to show up */
//("()", Prod([])), /* NOTE: would need to refactor buffer for this to show up */
("\"\"", String), /* NOTE: Irrelevent as second quote appears automatically */
("\"\"", String |> Typ.fresh), /* NOTE: Irrelevent as second quote appears automatically */
("_", unk),
];

let of_leading_delim: list((Token.t, Typ.t)) = [
("case" ++ leading_expander, unk),
("fun" ++ leading_expander, Arrow(unk, unk)),
("typfun" ++ leading_expander, Forall("", unk)),
("fun" ++ leading_expander, Arrow(unk, unk) |> Typ.fresh),
(
"typfun" ++ leading_expander,
Forall(Var("") |> TPat.fresh, unk) |> Typ.fresh,
),
("if" ++ leading_expander, unk),
("let" ++ leading_expander, unk),
("test" ++ leading_expander, Prod([])),
("test" ++ leading_expander, Prod([]) |> Typ.fresh),
("type" ++ leading_expander, unk),
];

let of_infix_delim: list((Token.t, Typ.t)) = [
("|>", unk), /* */
let of_infix_delim: list((Token.t, Typ.term)) = [
("|>", Unknown(Internal)), /* */
(",", Prod([unk, unk])), /* NOTE: Current approach doesn't work for this, but irrelevant as 1-char */
("::", List(unk)),
("@", List(unk)),
(";", unk),
(";", Unknown(Internal)),
("&&", Bool),
("\\/", Bool),
("||", Bool),
Expand Down Expand Up @@ -72,7 +75,7 @@ module Typ = {
fun
| InfoExp({mode, _})
| InfoPat({mode, _}) => Mode.ty_of(mode)
| _ => Unknown(Internal);
| _ => Unknown(Internal) |> Typ.fresh;

let filter_by =
(
Expand Down Expand Up @@ -194,7 +197,10 @@ let suggest_form = (ty_map, delims_of_sort, ci: Info.t): list(Suggestion.t) => {
};

let suggest_operator: Info.t => list(Suggestion.t) =
suggest_form(Typ.of_infix_delim, Delims.infix);
suggest_form(
List.map(((a, b)) => (a, IdTagged.fresh(b)), Typ.of_infix_delim),
Delims.infix,
);

let suggest_operand: Info.t => list(Suggestion.t) =
suggest_form(Typ.of_const_mono_delim, Delims.const_mono);
Expand Down
Loading

0 comments on commit 40d1896

Please sign in to comment.