Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Hole Inference (post merge) #1155

Draft
wants to merge 141 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
08ac8a8
update Typ.re to reflect new provenances and matched patterns with co…
RaefM Oct 30, 2022
a87c395
got new notion of matched functions and provenances compiling
RaefM Nov 1, 2022
ec96408
wip; ammend later
RaefM Dec 26, 2022
8c7a0d6
merge with recent changes from haz3l-tests and improved casts
RaefM Dec 26, 2022
e5b4b7a
fix remaining compiler errors after merge
RaefM Dec 26, 2022
09ddeea
adds constraints to Typ.re; doesn't compile yet
RaefM Dec 29, 2022
c4488cd
adds constraint generation to static type checking
RaefM Dec 31, 2022
5ad3ee9
adds all the inference modules; unlinked to UI or log in this commit
RaefM Dec 31, 2022
431c20f
links inference to UI. currently untested. changes existing code in M…
RaefM Jan 3, 2023
94669dd
makes annotation maps mutable. merges mk_map and mk_annotations
RaefM Jan 15, 2023
7dd160d
makes annotations be accumulated in a single source
RaefM Jan 15, 2023
be649cb
fix unsolved annotations bug. adds toggle for turning annotations on …
RaefM Jan 18, 2023
c48b065
adjusts coloring of annotations. removes empty hole svg when annotati…
RaefM Jan 18, 2023
d75fb75
fix bug with things solved as unknown retaining their annotations fro…
RaefM Jan 19, 2023
fece0e9
fix occurs stack overflowing. clear annotations on slide clear
RaefM Jan 25, 2023
e298ce1
moves unsolved annotations to the cursorinspector; replaces code anno…
RaefM Jan 25, 2023
2927ce5
quick fix to compiler error
RaefM Jan 25, 2023
55f3631
quick change to unsolved printing to make it neater
RaefM Jan 26, 2023
b03f2c8
fixed issue where cursor is misdrawn after hole suggestions change
anandrav Jan 26, 2023
ead7b45
fix printing of annotations types to be consistent; fix annotation co…
RaefM Jan 26, 2023
bdb43df
comments for our roadmap for non global inf maps
RaefM Jan 29, 2023
0f9aa93
create annotations in Editor.new_state
anandrav Jan 29, 2023
a2fe31b
removed global annotation_map from Measured, still present in Code.of…
anandrav Jan 29, 2023
493febf
removed global annotation_map from Code.of_grout
anandrav Jan 29, 2023
4c78da2
removed globals from svg_display_settings() (makes grout red)
anandrav Jan 29, 2023
b61229f
no longer using var accumulated_annotations, still using annotations_…
anandrav Jan 29, 2023
1e305f4
fix bug where type annotations don't show when editor first loaded
anandrav Jan 31, 2023
aa9e622
removed type annotations from editor.state.meta
anandrav Jan 31, 2023
677cf8d
remove annotations_enabled global var and refactor names of types
RaefM Feb 2, 2023
2a37937
add accept suggestions on clicking enter when to the right of a solve…
RaefM Feb 2, 2023
a2e767d
small fix related to hole molds
RaefM Feb 3, 2023
9fd5630
remove prov specific typing in annotations (makes acceptance suggesti…
RaefM Feb 9, 2023
715d5cd
merge in dev
RaefM Feb 9, 2023
a4a1f68
add documentation (housed in rei files where possible) and did some c…
RaefM Feb 9, 2023
0d47347
merge more recent dev changes
RaefM Feb 9, 2023
24a96d9
updated UI
anandrav Feb 28, 2023
ea15b86
dotted line around unsolved type hole
anandrav Feb 28, 2023
e2645a1
removed ? from CI and added ! to unsolved hole in editor
anandrav Mar 1, 2023
7d5925a
renames eqclasses to potential type sets
RaefM Mar 1, 2023
981f15a
merge dev
RaefM Mar 19, 2023
afd91e8
fill type hole is atomic action
anandrav Mar 23, 2023
444490b
hole filling on click (not hover yet)
anandrav Mar 24, 2023
0c8f678
makes the buttons for cursorinspector suggestions hoverable to see re…
RaefM Mar 24, 2023
5f81e86
made buttons brighter on hover
RaefM Mar 24, 2023
14cb043
refactor and combine certain functions
RaefM Apr 8, 2023
b4dbdf7
wip
RaefM Apr 8, 2023
c471ad6
refactor inference results code to be more consistent
RaefM May 12, 2023
db487be
CI hexagons looking good- grout suggestions being funky with lines an…
RaefM May 22, 2023
3e32023
Merge branch 'dev' of https://github.com/hazelgrove/hazel into haz3l-…
RaefM May 22, 2023
86ac43f
fixes issues with svg in suggestions but introduces new issue with th…
RaefM Jun 12, 2023
866be93
fix weird positioning issues
RaefM Jun 14, 2023
7e4d53d
makes parenthesization less/un ambiguous (always parenthesizes left c…
RaefM Jun 14, 2023
34fbb14
Merge branch 'dev' of https://github.com/hazelgrove/hazel into haz3l-…
RaefM Jun 14, 2023
c497f61
Fix UI bugs
RaefM Jul 11, 2023
8af2bea
add message to CI on errors
RaefM Jul 12, 2023
64d109e
fix weird hover bug
RaefM Jul 12, 2023
7985faf
add text to consistent suggestions in ci
RaefM Jul 12, 2023
7607246
merged type_provenance cases 'Internal' and 'TypeHole'
anandrav Aug 23, 2023
1afa3ee
rename Anonymous to NoProvenance
anandrav Aug 23, 2023
4119c85
renamed Inference prov case to Matched
anandrav Aug 23, 2023
1db78ad
rewrite pt. 1
anandrav Aug 25, 2023
25f1808
rewrite pt. 2
anandrav Aug 26, 2023
7c431e9
functional again
anandrav Aug 26, 2023
887574b
cleanup
anandrav Aug 26, 2023
e7aee26
must resolve conflicts in Statics and CursorInspector
anandrav Oct 8, 2023
788fd55
attempt to resolve cursorinspector merge errors
disconcision Oct 8, 2023
44a649f
statics still WIP, does not compile
anandrav Oct 8, 2023
1c2f440
resolving remaining merge type errors. starts up fine but UI is utter…
disconcision Oct 10, 2023
3251d22
resolve some css issues; UI now renders okay, but still some issues
disconcision Oct 10, 2023
8afd381
Update Elaborator.re
disconcision Oct 10, 2023
c07e305
add logging
RaefM Nov 15, 2023
6b60d72
setup logging
anandrav Nov 15, 2023
adf926e
consider tuples conflicting if they have different arity
anandrav Nov 15, 2023
30442f0
fixed how unknown types are displayed
anandrav Nov 15, 2023
7484d17
added comments to clarify last change
anandrav Nov 15, 2023
a8bf67f
occurs check
anandrav Nov 15, 2023
3179e5a
Fix a bunch of todos and missing constraints
RaefM Dec 6, 2023
9a78e94
changed grout width back to 1 for inference suggestions
anandrav Dec 11, 2023
bdacad6
added labels for more clarity
anandrav Dec 11, 2023
6de7a0b
merged dev, probably does not compile.
anandrav Dec 11, 2023
9d17cf2
fixed some compiler errors, more to go...
anandrav Dec 11, 2023
51819c7
Merge branch 'dev' of https://github.com/hazelgrove/hazel into thi-me…
RaefM Dec 19, 2023
6a4bdc9
fix build failures after latest merge
RaefM Dec 19, 2023
3571c92
Fix join constraint threading
RaefM Dec 19, 2023
03facf9
Fix some issues with join_constraints and missing constraints for uex…
RaefM Dec 19, 2023
2b3152b
Review and fix issues in upat_to_info_map
RaefM Dec 19, 2023
ab14eeb
Refactor to use new provenances where synswitch is separated out to e…
RaefM Dec 23, 2023
c0b0820
make debug print string more useful
RaefM Dec 23, 2023
6650633
sub in old inference module
RaefM Dec 23, 2023
26c7fa1
Make things compile after substituting in the old inference algos
RaefM Dec 23, 2023
bf04f1c
debug wip
RaefM Dec 24, 2023
301117e
remove init syn; still broken lines
RaefM Dec 25, 2023
d89198a
Fix UI measured-grout view mismatch issues; Add PatternVar provenance…
RaefM Dec 25, 2023
51336d5
get rid of debug logs
RaefM Dec 25, 2023
4efc804
Add logic to also build out indirect suggestions in global_inference_…
RaefM Dec 26, 2023
115b25f
ADTs seem to work; stack overflowing on the examples page for ADTs th…
RaefM Dec 26, 2023
dcb3d72
fix stack overflow issue
RaefM Dec 28, 2023
4049dfe
Fix issue where solved as type alias and its body type val resulted i…
RaefM Dec 28, 2023
36bc5af
Fix CI hover issues
RaefM Dec 28, 2023
3187947
Add logic to suggest results for unsolved exp holes, but the paste ha…
RaefM Dec 31, 2023
92c5a82
Add directional jump; unsolved exphole suggestions working
RaefM Dec 31, 2023
0e757f8
remove debug logs
RaefM Dec 31, 2023
732fff7
Add suggestions for solved/nested inconsistency exp holes too (easily…
RaefM Dec 31, 2023
1ab2c53
fix issue where annotated patterns were also candidates for annot ins…
RaefM Dec 31, 2023
ba8f2a2
rename NonTypeHoleId to NotSuggestableHoleId
RaefM Dec 31, 2023
d0639da
fix issue of ? being pasted in
RaefM Dec 31, 2023
757b07d
autoformatting
RaefM Dec 31, 2023
19fc24e
fix ADT issue
RaefM Jan 5, 2024
32d0d55
Moved acceptance logic into Tab and out of Enter. Should talk to Andr…
RaefM Jan 6, 2024
4916324
fix text alignment in CI
RaefM Jan 6, 2024
051cb41
fix issue where holes become offset when UpdateAssistant operations o…
RaefM Jan 6, 2024
f529616
make exp hole suggestions only pop up on directly constrained unannot…
RaefM Jan 7, 2024
aa06ada
fix sneaky internals causing not-as-good-as-they-could-be solutions
RaefM Jan 12, 2024
ed8a2bf
Added new update settings_action
RaefM Jan 12, 2024
887c67f
switched all logic over to new toggle in nut bar
RaefM Jan 12, 2024
8114313
fix stray debug change
RaefM Jan 12, 2024
7374be6
cleanup prints and todos
RaefM Jan 13, 2024
95ddccd
fix measurement issue after suggestion accept
RaefM Jan 13, 2024
db7ef98
Add inference_enabled to init to fix issue of weird offset holes on s…
RaefM Jan 13, 2024
c988481
fix stack overflow issue for nested occurs check failures
RaefM Jan 13, 2024
d533620
make occurs check failures have special ci text
RaefM Jan 13, 2024
1247487
fix clunky CI types when parens involved
RaefM Jan 13, 2024
5255070
Fix issue where occurs failures were given solved UI. Fix issue where…
RaefM Jan 14, 2024
c7ddca2
Make all CI unknowns be the hexagon
RaefM Jan 14, 2024
6d9b105
remove debug logs again
RaefM Jan 15, 2024
fe27c3a
hackily disable cons suggestion in patterns
disconcision Jan 15, 2024
12c3f12
Make occurs failures involving type holes show conflicts in CI. Shift…
RaefM Jan 18, 2024
7f60039
Simplify CI text; fix bug where sum was being printed as prod
RaefM Jan 18, 2024
6ce7dc7
Add names when ityps are made into sum types based on position
RaefM Jan 18, 2024
c765aac
Fix stack overflow issue when nullary sum occurs
RaefM Jan 18, 2024
e263e23
fix ambiguous parens on sums in arrows
RaefM Jan 18, 2024
11e6aa6
Hackily disable cons suggestion in patterns (#1162)
cyrus- Jan 18, 2024
76c382e
merge updated nut menu
RaefM Jan 22, 2024
db7f533
Merge branch 'thi-old-engine-with-merge' of https://github.com/hazelg…
RaefM Jan 22, 2024
2f43770
finalize merge conflicts
RaefM Jan 22, 2024
5fad881
make it so if statics turns off, infernce does too
RaefM Jan 22, 2024
14f1e19
Fix empty list type paste bug and solutions
RaefM Feb 26, 2024
dc83c58
Fix issue where type aliases weren't always constrainted to self
RaefM Feb 26, 2024
298a51d
whoops- fix usage of wrong type in prev commit
RaefM Feb 26, 2024
d7f07bf
test - rerun GitHub Action
thomasporter522 Mar 29, 2024
55273cb
added constructor names to internal types
thomasporter522 Apr 1, 2024
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
1 change: 1 addition & 0 deletions note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Note: this push is a test to reactivate the GitHub Action and rerun test cases, in case there was a collision during the last push.
27 changes: 24 additions & 3 deletions src/haz3lcore/Measured.re
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,15 @@ let is_indented_map = (seg: Segment.t) => {
go(seg);
};

let of_segment = (~old: t=empty, ~touched=Touched.empty, seg: Segment.t): t => {
let of_segment =
(
~old: t=empty,
~touched=Touched.empty,
~global_inference_info=InferenceResult.empty_info(),
seg: Segment.t,
)
: t => {
let is_indented = is_indented_map(seg);

// recursive across seg's bidelimited containers
let rec go_nested =
(
Expand Down Expand Up @@ -356,7 +362,22 @@ let of_segment = (~old: t=empty, ~touched=Touched.empty, seg: Segment.t): t => {
let map = map |> add_w(w, {origin, last});
(contained_indent, last, map);
| Grout(g) =>
let last = {...origin, col: origin.col + 1};
let annotation_offset =
switch (
InferenceResult.get_suggestion_text_for_id(
g.id,
global_inference_info,
)
) {
| (Solvable(suggestion_string), TypHole)
| (NestedInconsistency(suggestion_string), TypHole) =>
String.length(suggestion_string)
| (_, ExpHole)
| (_, None)
| (NoSuggestion(_), _) => 1
};

let last = {...origin, col: origin.col + annotation_offset};
let map = map |> add_g(g, {origin, last});
(contained_indent, last, map);
| Tile(t) =>
Expand Down
34 changes: 25 additions & 9 deletions src/haz3lcore/assistant/AssistantCtx.re
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,30 @@ let suggest_variable = (ci: Info.t): list(Suggestion.t) => {
let ctx = Info.ctx_of(ci);
switch (ci) {
| InfoExp({mode, _}) =>
bound_variables(Mode.ty_of(mode), ctx)
@ bound_aps(Mode.ty_of(mode), ctx)
@ bound_constructors(x => Exp(Common(x)), Mode.ty_of(mode), ctx)
@ bound_constructor_aps(x => Exp(Common(x)), Mode.ty_of(mode), ctx)
bound_variables(Mode.assistant_ty_of(mode), ctx)
@ bound_aps(Mode.assistant_ty_of(mode), ctx)
@ bound_constructors(
x => Exp(Common(x)),
Mode.assistant_ty_of(mode),
ctx,
)
@ bound_constructor_aps(
x => Exp(Common(x)),
Mode.assistant_ty_of(mode),
ctx,
)
| InfoPat({mode, co_ctx, _}) =>
free_variables(Mode.ty_of(mode), ctx, co_ctx)
@ bound_constructors(x => Pat(Common(x)), Mode.ty_of(mode), ctx)
@ bound_constructor_aps(x => Pat(Common(x)), Mode.ty_of(mode), ctx)
free_variables(Mode.assistant_ty_of(mode), ctx, co_ctx)
@ bound_constructors(
x => Pat(Common(x)),
Mode.assistant_ty_of(mode),
ctx,
)
@ bound_constructor_aps(
x => Pat(Common(x)),
Mode.assistant_ty_of(mode),
ctx,
)
| InfoTyp(_) => typ_context_entries(ctx)
| _ => []
};
Expand Down Expand Up @@ -141,7 +157,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.assistant_ty_of(mode)) {
| List(ty) =>
List.map(restrategize(" )::"), exp_aps(ty))
@ List.map(restrategize("::"), exp_refs(ty))
Expand All @@ -165,7 +181,7 @@ let suggest_lookahead_variable = (ci: Info.t): list(Suggestion.t) => {
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.assistant_ty_of(mode)) {
| List(ty) =>
List.map(restrategize(" )::"), pat_aps(ty))
@ List.map(restrategize("::"), pat_refs(ty))
Expand Down
6 changes: 3 additions & 3 deletions src/haz3lcore/assistant/AssistantForms.re
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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(NoProvenance, false);

let of_const_mono_delim: list((Token.t, Typ.t)) = [
("true", Bool),
Expand Down Expand Up @@ -70,8 +70,8 @@ module Typ = {
let expected: Info.t => Typ.t =
fun
| InfoExp({mode, _})
| InfoPat({mode, _}) => Mode.ty_of(mode)
| _ => Unknown(Internal);
| InfoPat({mode, _}) => Mode.assistant_ty_of(mode)
| _ => Unknown(NoProvenance, false);

let filter_by =
(
Expand Down
4 changes: 4 additions & 0 deletions src/haz3lcore/assistant/TyDi.re
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ let set_buffer = (~settings, ~ctx: Ctx.t, z: Zipper.t): option(Zipper.t) => {
suggestions
|> List.filter(({content, _}: Suggestion.t) =>
String.starts_with(~prefix=tok_to_left, content)
/* HACK(andrew): Below filtering of cons suggestion
* should be done in a more principled way when a
* ranker is implemented */
&& !(Info.sort_of(ci) == Pat && content == "::")
);
let* top_suggestion = suggestions |> Util.ListUtil.hd_opt;
let* suggestion_suffix = suffix_of(top_suggestion.content, tok_to_left);
Expand Down
7 changes: 6 additions & 1 deletion src/haz3lcore/dynamics/DH.re
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,13 @@ module rec DHExp: {
| [_] => failwith("mk_tuple: expected at least 2 elements")
| xs => Tuple(xs);

let is_any_synswitch: Typ.t => bool =
fun
| Unknown(_, s) => s
| _ => false;

let cast = (d: t, t1: Typ.t, t2: Typ.t): t =>
if (Typ.eq(t1, t2) || t2 == Unknown(SynSwitch)) {
if (Typ.eq(t1, t2) || is_any_synswitch(t2)) {
d;
} else {
Cast(d, t1, t2);
Expand Down
61 changes: 34 additions & 27 deletions src/haz3lcore/dynamics/Elaborator.re
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ let fixed_pat_typ = (m: Statics.Map.t, p: Term.UPat.t): option(Typ.t) =>
| _ => None
};

let cast = (ctx: Ctx.t, mode: Mode.t, self_ty: Typ.t, d: DHExp.t) =>
let cast = (ctx: Ctx.t, id: Id.t, mode: Mode.t, self_ty: Typ.t, d: DHExp.t) =>
switch (mode) {
| Syn => d
| SynFun =>
switch (self_ty) {
| Unknown(prov) =>
DHExp.cast(d, Unknown(prov), Arrow(Unknown(prov), Unknown(prov)))
| Unknown(prov, s) =>
DHExp.cast(
d,
Unknown(prov, s),
Arrow(Unknown(prov, s), Unknown(prov, s)),
)
| Arrow(_) => d
| _ => failwith("Elaborator.wrap: SynFun non-arrow-type")
}
Expand All @@ -45,26 +49,28 @@ let cast = (ctx: Ctx.t, mode: Mode.t, self_ty: Typ.t, d: DHExp.t) =>
| ListConcat(_)
| Cons(_) =>
switch (ana_ty) {
| Unknown(prov) => DHExp.cast(d, List(Unknown(prov)), Unknown(prov))
| Unknown(prov, s) =>
DHExp.cast(d, List(Unknown(prov, s)), Unknown(prov, s))
| _ => d
}
| Fun(_) =>
/* See regression tests in Examples/Dynamics */
let (_, ana_out) = Typ.matched_arrow(ctx, ana_ty);
let (self_in, _) = Typ.matched_arrow(ctx, self_ty);
let ((_, ana_out), _) = Typ.matched_arrow(ctx, id, ana_ty);
let ((self_in, _), _) = Typ.matched_arrow(ctx, id, self_ty);
DHExp.cast(d, Arrow(self_in, ana_out), ana_ty);
| Tuple(ds) =>
switch (ana_ty) {
| Unknown(prov) =>
let us = List.init(List.length(ds), _ => Typ.Unknown(prov));
DHExp.cast(d, Prod(us), Unknown(prov));
| Unknown(prov, s) =>
let us = List.init(List.length(ds), _ => Typ.Unknown(prov, s));
DHExp.cast(d, Prod(us), Unknown(prov, s));
| _ => d
}
| Ap(Constructor(_), _)
| Constructor(_) =>
switch (ana_ty, self_ty) {
| (Unknown(prov), Rec(_, Sum(_)))
| (Unknown(prov), Sum(_)) => DHExp.cast(d, self_ty, Unknown(prov))
| (Unknown(prov, s), Rec(_, Sum(_)))
| (Unknown(prov, s), Sum(_)) =>
DHExp.cast(d, self_ty, Unknown(prov, s))
| _ => d
}
/* Forms with special ana rules but no particular typing requirements */
Expand Down Expand Up @@ -104,24 +110,24 @@ let cast = (ctx: Ctx.t, mode: Mode.t, self_ty: Typ.t, d: DHExp.t) =>

/* Handles cast insertion and non-empty-hole wrapping
for elaborated expressions */
let wrap = (ctx: Ctx.t, u: Id.t, mode: Mode.t, self, d: DHExp.t): DHExp.t =>
let wrap = (ctx: Ctx.t, id: Id.t, mode: Mode.t, self, d: DHExp.t): DHExp.t =>
switch (Info.status_exp(ctx, mode, self)) {
| NotInHole(_) =>
let self_ty =
switch (Self.typ_of_exp(ctx, self)) {
| Some(self_ty) => Typ.normalize(ctx, self_ty)
| None => Unknown(Internal)
| None => Unknown(NoProvenance, false)
};
cast(ctx, mode, self_ty, d);
| InHole(_) => NonEmptyHole(TypeInconsistent, u, 0, d)
cast(ctx, id, mode, self_ty, d);
| InHole(_) => NonEmptyHole(TypeInconsistent, id, 0, d)
};

let rec dhexp_of_uexp =
(m: Statics.Map.t, uexp: Term.UExp.t): option(DHExp.t) => {
switch (Id.Map.find_opt(Term.UExp.rep_id(uexp), m)) {
let id = Term.UExp.rep_id(uexp); /* NOTE: using term uids for hole ids */
switch (Id.Map.find_opt(id, m)) {
| Some(InfoExp({mode, self, ctx, _})) =>
let err_status = Info.status_exp(ctx, mode, self);
let id = Term.UExp.rep_id(uexp); /* NOTE: using term uids for hole ids */
let+ d: DHExp.t =
switch (uexp.term) {
| Invalid(t) => Some(DHExp.InvalidText(id, 0, t))
Expand All @@ -139,7 +145,7 @@ let rec dhexp_of_uexp =
| ListLit(es) =>
let* ds = es |> List.map(dhexp_of_uexp(m)) |> OptUtil.sequence;
let+ ty = fixed_exp_typ(m, uexp);
let ty = Typ.matched_list(ctx, ty);
let (ty, _) = Typ.matched_list(ctx, id, ty);
DHExp.ListLit(id, 0, ty, ds);
| Fun(p, body) =>
let* dp = dhpat_of_upat(m, p);
Expand Down Expand Up @@ -281,26 +287,26 @@ let rec dhexp_of_uexp =
};
}
and dhpat_of_upat = (m: Statics.Map.t, upat: Term.UPat.t): option(DHPat.t) => {
switch (Id.Map.find_opt(Term.UPat.rep_id(upat), m)) {
let id = Term.UPat.rep_id(upat); /* NOTE: using term uids for hole ids */
switch (Id.Map.find_opt(id, m)) {
| Some(InfoPat({mode, self, ctx, _})) =>
let err_status = Info.status_pat(ctx, mode, self);
let maybe_reason: option(ErrStatus.HoleReason.t) =
switch (err_status) {
| NotInHole(_) => None
| InHole(_) => Some(TypeInconsistent)
};
let u = Term.UPat.rep_id(upat); /* NOTE: using term uids for hole ids */
let wrap = (d: DHPat.t): option(DHPat.t) =>
switch (maybe_reason) {
| None => Some(d)
| Some(reason) => Some(NonEmptyHole(reason, u, 0, d))
| Some(reason) => Some(NonEmptyHole(reason, id, 0, d))
};
switch (upat.term) {
| Invalid(t) => Some(DHPat.InvalidText(u, 0, t))
| EmptyHole => Some(EmptyHole(u, 0))
| Invalid(t) => Some(DHPat.InvalidText(id, 0, t))
| EmptyHole => Some(EmptyHole(id, 0))
| MultiHole(_) =>
// TODO: dhexp, eval for multiholes
Some(EmptyHole(u, 0))
Some(EmptyHole(id, 0))
| Wild => wrap(Wild)
| Bool(b) => wrap(BoolLit(b))
| Int(n) => wrap(IntLit(n))
Expand All @@ -310,11 +316,12 @@ and dhpat_of_upat = (m: Statics.Map.t, upat: Term.UPat.t): option(DHPat.t) => {
| ListLit(ps) =>
let* ds = ps |> List.map(dhpat_of_upat(m)) |> OptUtil.sequence;
let* ty = fixed_pat_typ(m, upat);
wrap(ListLit(Typ.matched_list(ctx, ty), ds));
let (ty', _) = Typ.matched_list(ctx, id, ty);
wrap(ListLit(ty', ds));
| Constructor(name) =>
switch (err_status) {
| InHole(Common(NoType(FreeConstructor(_)))) =>
Some(BadConstructor(u, 0, name))
Some(BadConstructor(id, 0, name))
| _ => wrap(Constructor(name))
}
| Cons(hd, tl) =>
Expand Down Expand Up @@ -349,7 +356,7 @@ let uexp_elab = (m: Statics.Map.t, uexp: Term.UExp.t): ElaborationResult.t =>
let ty =
switch (fixed_exp_typ(m, uexp)) {
| Some(ty) => ty
| None => Typ.Unknown(Internal)
| None => Typ.Unknown(NoProvenance, false)
};
Elaborates(d, ty, Delta.empty);
};
18 changes: 13 additions & 5 deletions src/haz3lcore/dynamics/PatternMatch.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type match_result =
| DoesNotMatch
| IndetMatch;

let const_unknown: 'a => Typ.t = _ => Unknown(Internal);
let const_unknown: 'a => Typ.t = _ => Unknown(NoProvenance, false);

let cast_sum_maps =
(sm1: Typ.sum_map, sm2: Typ.sum_map)
Expand Down Expand Up @@ -191,9 +191,9 @@ let rec matches = (dp: DHPat.t, d: DHExp.t): match_result =>
| (Cons(_) | ListLit(_), Cast(d, List(ty1), List(ty2))) =>
matches_cast_Cons(dp, d, [(ty1, ty2)])
| (Cons(_) | ListLit(_), Cast(d, Unknown(_), List(ty2))) =>
matches_cast_Cons(dp, d, [(Unknown(Internal), ty2)])
matches_cast_Cons(dp, d, [(Unknown(NoProvenance, false), ty2)])
| (Cons(_) | ListLit(_), Cast(d, List(ty1), Unknown(_))) =>
matches_cast_Cons(dp, d, [(ty1, Unknown(Internal))])
matches_cast_Cons(dp, d, [(ty1, Unknown(NoProvenance, false))])
| (Cons(_, _), Cons(_, _))
| (ListLit(_, _), Cons(_, _))
| (Cons(_, _), ListLit(_))
Expand Down Expand Up @@ -459,9 +459,17 @@ and matches_cast_Cons =
| Cast(d', List(ty1), List(ty2)) =>
matches_cast_Cons(dp, d', [(ty1, ty2), ...elt_casts])
| Cast(d', List(ty1), Unknown(_)) =>
matches_cast_Cons(dp, d', [(ty1, Unknown(Internal)), ...elt_casts])
matches_cast_Cons(
dp,
d',
[(ty1, Unknown(NoProvenance, false)), ...elt_casts],
)
| Cast(d', Unknown(_), List(ty2)) =>
matches_cast_Cons(dp, d', [(Unknown(Internal), ty2), ...elt_casts])
matches_cast_Cons(
dp,
d',
[(Unknown(NoProvenance, false), ty2), ...elt_casts],
)
| Cast(_, _, _) => DoesNotMatch
| BoundVar(_) => DoesNotMatch
| FreeVar(_) => IndetMatch
Expand Down
10 changes: 6 additions & 4 deletions src/haz3lcore/dynamics/Transition.re
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,21 @@ module CastHelpers = {
| Ground
| NotGroundOrHole(Typ.t) /* the argument is the corresponding ground type */;

let const_unknown: 'a => Typ.t = _ => Unknown(Internal);
let const_unknown: 'a => Typ.t = _ => Unknown(NoProvenance, false);

let grounded_Arrow =
NotGroundOrHole(Arrow(Unknown(Internal), Unknown(Internal)));
NotGroundOrHole(
Arrow(Unknown(NoProvenance, false), Unknown(NoProvenance, false)),
);
let grounded_Prod = length =>
NotGroundOrHole(
Prod(ListUtil.replicate(length, Typ.Unknown(Internal))),
Prod(ListUtil.replicate(length, Typ.Unknown(NoProvenance, false))),
);
let grounded_Sum = (sm: Typ.sum_map): ground_cases => {
let sm' = sm |> ConstructorMap.map(Option.map(const_unknown));
NotGroundOrHole(Sum(sm'));
};
let grounded_List = NotGroundOrHole(List(Unknown(Internal)));
let grounded_List = NotGroundOrHole(List(Unknown(NoProvenance, false)));

let rec ground_cases_of = (ty: Typ.t): ground_cases => {
let is_ground_arg: option(Typ.t) => bool =
Expand Down
Loading
Loading