Skip to content

Commit

Permalink
Merge branch 'dev' into util_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrus- authored Oct 29, 2024
2 parents f328e21 + 73a7598 commit ef86936
Show file tree
Hide file tree
Showing 10 changed files with 383 additions and 27 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ setup-student:

dev-helper:
dune fmt --auto-promote || true
dune build @src/fmt --auto-promote src --profile dev
dune build @ocaml-index @src/fmt --auto-promote src --profile dev

dev: setup-instructor dev-helper

Expand All @@ -35,7 +35,7 @@ fmt:
dune fmt --auto-promote

watch: setup-instructor
dune build @src/fmt --auto-promote src --profile dev --watch
dune build @ocaml-index @src/fmt --auto-promote src --profile dev --watch

watch-release: setup-instructor
dune build @src/fmt --auto-promote src --profile release --watch
Expand All @@ -60,11 +60,11 @@ repl:

test:
dune fmt --auto-promote || true
dune build @src/fmt @test/fmt --auto-promote src test --profile dev
dune build @ocaml-index @src/fmt @test/fmt --auto-promote src test --profile dev
node $(TEST_DIR)/haz3ltest.bc.js

watch-test:
dune build @fmt @runtest --auto-promote --watch
dune build @ocaml-index @fmt @runtest --auto-promote --watch

clean:
dune clean
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);
};
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

0 comments on commit ef86936

Please sign in to comment.