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

Fix deferrals #1402

Merged
merged 8 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion src/haz3lcore/dynamics/Elaborator.re
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ let rec elaborate = (m: Statics.Map.t, uexp: UExp.t): (DHExp.t, Typ.t) => {
((arg, _)) => Exp.is_deferral(arg),
List.combine(args, ty_fargs),
);
let remaining_arg_ty = Prod(List.map(snd, remaining_args)) |> Typ.temp;
let remaining_arg_ty =
List.length(remaining_args) == 1
? snd(List.hd(remaining_args))
: Prod(List.map(snd, remaining_args)) |> Typ.temp;
DeferredAp(f'', args'')
|> rewrap
|> cast_from(Arrow(remaining_arg_ty, tyf2) |> Typ.temp);
Expand Down
1 change: 1 addition & 0 deletions src/haz3lcore/dynamics/Evaluator.re
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ module EvaluatorEVMode: {
| (BoxedReady, Constructor) => (BoxedValue, c)
| (IndetReady, Constructor) => (Indet, c)
| (IndetBlocked, _) => (Indet, c)
| (_, Value) => (BoxedValue, c)
| (_, Indet) => (Indet, c)
};
};
Expand Down
2 changes: 2 additions & 0 deletions src/haz3lcore/dynamics/EvaluatorStep.re
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ module Decompose = {
| (undo, Result.BoxedValue, env, v) =>
switch (rl(v)) {
| Constructor => Result.BoxedValue
| Value => Result.BoxedValue
| Indet => Result.Indet
| Step(s) => Result.Step([EvalObj.mk(Mark, env, undo, s.kind)])
// TODO: Actually show these exceptions to the user!
Expand Down Expand Up @@ -187,6 +188,7 @@ module TakeStep = {
state_update();
Some(expr);
| Constructor
| Value
| Indet => None
};

Expand Down
18 changes: 13 additions & 5 deletions src/haz3lcore/dynamics/Transition.re
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ type rule =
is_value: bool,
})
| Constructor
| Indet;
| Indet
| Value;

let (let-unbox) = ((request, v), f) =>
switch (Unboxing.unbox(request, v)) {
Expand Down Expand Up @@ -331,7 +332,7 @@ module Transition = (EV: EV_MODE) => {
(d2, ds) => DeferredAp2(d1, d2, ds) |> wrap_ctx,
ds,
);
Constructor;
Value;
| Ap(dir, d1, d2) =>
let. _ = otherwise(env, (d1, (d2, _)) => Ap(dir, d1, d2) |> rewrap)
and. d1' =
Expand Down Expand Up @@ -392,18 +393,25 @@ module Transition = (EV: EV_MODE) => {
} else {
Indet;
}
/* This case isn't currently used because deferrals are elaborated away */
| DeferredAp(d3, d4s) =>
let n_args =
List.length(
List.map(
List.filter(
fun
| {term: Deferral(_), _} => true
| _ => false: Exp.t => bool,
d4s,
),
);
let-unbox args = (Tuple(n_args), d2);
let-unbox args =
if (n_args == 1) {
(
Tuple(n_args),
Tuple([d2]) |> fresh // TODO Should we not be going to a tuple?
);
} else {
(Tuple(n_args), d2);
};
7h3kk1d marked this conversation as resolved.
Show resolved Hide resolved
let new_args = {
let rec go = (deferred, args) =>
switch ((deferred: list(Exp.t))) {
Expand Down
1 change: 1 addition & 0 deletions src/haz3lcore/dynamics/ValueChecker.re
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module ValueCheckerEVMode: {
| (_, _, Constructor) => r
| (_, Expr, Indet) => Expr
| (_, _, Indet) => Indet
| (_, _, Value) => Value
| (true, _, Step(_)) => Expr
| (false, _, Step(_)) => r
};
Expand Down
127 changes: 126 additions & 1 deletion test/Test_Elaboration.re
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ let let_fun = () =>
let deferral = () =>
alco_check(
"string_sub(\"hello\", 1, _)",
DeferredAp(
Var("string_sub") |> Exp.fresh,
[
String("hello") |> Exp.fresh,
Int(1) |> Exp.fresh,
Deferral(InAp) |> Exp.fresh,
],
)
|> Exp.fresh,
dhexp_of_uexp(
DeferredAp(
Var("string_sub") |> Exp.fresh,
Expand All @@ -191,7 +200,13 @@ let deferral = () =>
)
|> Exp.fresh,
),
dhexp_of_uexp(
);

let ap_deferral_single_argument = () =>
alco_check(
"string_sub(\"hello\", 1, _)(2)",
Ap(
Forward,
DeferredAp(
Var("string_sub") |> Exp.fresh,
[
Expand All @@ -201,6 +216,106 @@ let deferral = () =>
],
)
|> Exp.fresh,
Int(2) |> Exp.fresh,
)
|> Exp.fresh,
dhexp_of_uexp(
Ap(
Forward,
DeferredAp(
Var("string_sub") |> Exp.fresh,
[
String("hello") |> Exp.fresh,
Int(1) |> Exp.fresh,
Deferral(InAp) |> Exp.fresh,
],
)
|> Exp.fresh,
Int(2) |> Exp.fresh,
)
|> Exp.fresh,
),
);

let ap_of_deferral_of_hole = () =>
alco_check(
"?(_, _, 3)(1., true)",
Ap(
Forward,
DeferredAp(
Cast(
Cast(
EmptyHole |> Exp.fresh,
Unknown(Internal) |> Typ.fresh,
Arrow(
Unknown(Internal) |> Typ.fresh,
Unknown(Internal) |> Typ.fresh,
)
|> Typ.fresh,
)
|> Exp.fresh,
Arrow(
Unknown(Internal) |> Typ.fresh,
Unknown(Internal) |> Typ.fresh,
)
|> Typ.fresh,
Arrow(
Prod([
Unknown(Internal) |> Typ.fresh,
Unknown(Internal) |> Typ.fresh,
Unknown(Internal) |> Typ.fresh,
])
|> Typ.fresh,
Unknown(Internal) |> Typ.fresh,
)
|> Typ.fresh,
)
|> Exp.fresh,
[
Deferral(InAp) |> Exp.fresh,
Deferral(InAp) |> Exp.fresh,
Cast(
Int(3) |> Exp.fresh,
Int |> Typ.fresh,
Unknown(Internal) |> Typ.fresh,
)
|> Exp.fresh,
],
)
|> Exp.fresh,
Tuple([
Cast(
Float(1.) |> Exp.fresh,
Float |> Typ.fresh,
Unknown(Internal) |> Typ.fresh,
)
|> Exp.fresh,
Cast(
Bool(true) |> Exp.fresh,
Bool |> Typ.fresh,
Unknown(Internal) |> Typ.fresh,
)
|> Exp.fresh,
])
|> Exp.fresh,
)
|> Exp.fresh,
dhexp_of_uexp(
Ap(
Forward,
DeferredAp(
EmptyHole |> Exp.fresh,
[
Deferral(InAp) |> Exp.fresh,
Deferral(InAp) |> Exp.fresh,
Int(3) |> Exp.fresh,
],
)
|> Exp.fresh,
Tuple([Float(1.) |> Exp.fresh, Bool(true) |> Exp.fresh])
|> Exp.fresh,
)
|> Exp.fresh,
),
);

Expand All @@ -220,4 +335,14 @@ let elaboration_tests = [
`Quick,
deferral,
),
test_case(
"Function application with a single remaining argument after deferral",
`Quick,
ap_deferral_single_argument,
),
test_case(
"Function application with a deferral of a hole",
`Quick,
ap_of_deferral_of_hole,
),
];
Loading
Loading