Skip to content

Commit

Permalink
Remove EnvIdGen, use Uuidm instead
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfettes committed Oct 23, 2023
1 parent 2c79f63 commit eea6aad
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 172 deletions.
28 changes: 10 additions & 18 deletions src/haz3lcore/dynamics/DH.re
Original file line number Diff line number Diff line change
Expand Up @@ -333,33 +333,25 @@ and ClosureEnvironment: {

let to_list: t => list((Var.t, DHExp.t));

let of_environment:
(Environment.t, EnvironmentIdGen.t) => (t, EnvironmentIdGen.t);
let of_environment: Environment.t => t;

let id_equal: (t, t) => bool;

let empty: EnvironmentIdGen.t => (t, EnvironmentIdGen.t);
let empty: t;
let is_empty: t => bool;
let length: t => int;

let lookup: (t, Var.t) => option(DHExp.t);
let contains: (t, Var.t) => bool;
let update:
(Environment.t => Environment.t, t, EnvironmentIdGen.t) =>
(t, EnvironmentIdGen.t);
let update: (Environment.t => Environment.t, t) => t;
let update_keep_id: (Environment.t => Environment.t, t) => t;
let extend:
(t, (Var.t, DHExp.t), EnvironmentIdGen.t) => (t, EnvironmentIdGen.t);
let extend: (t, (Var.t, DHExp.t)) => t;
let extend_keep_id: (t, (Var.t, DHExp.t)) => t;
let union: (t, t, EnvironmentIdGen.t) => (t, EnvironmentIdGen.t);
let union: (t, t) => t;
let union_keep_id: (t, t) => t;
let map:
(((Var.t, DHExp.t)) => DHExp.t, t, EnvironmentIdGen.t) =>
(t, EnvironmentIdGen.t);
let map: (((Var.t, DHExp.t)) => DHExp.t, t) => t;
let map_keep_id: (((Var.t, DHExp.t)) => DHExp.t, t) => t;
let filter:
(((Var.t, DHExp.t)) => bool, t, EnvironmentIdGen.t) =>
(t, EnvironmentIdGen.t);
let filter: (((Var.t, DHExp.t)) => bool, t) => t;
let filter_keep_id: (((Var.t, DHExp.t)) => bool, t) => t;
let fold: (((Var.t, DHExp.t), 'b) => 'b, 'b, t) => 'b;

Expand All @@ -386,9 +378,9 @@ and ClosureEnvironment: {

let to_list = env => env |> map_of |> Environment.to_listo;

let of_environment = (map, eig) => {
let (ei, eig) = EnvironmentIdGen.next(eig);
(wrap(ei, map), eig);
let of_environment = map => {
let ei = Id.mk();
wrap(ei, map);
};

/* Equals only needs to check environment id's (faster than structural equality
Expand Down
11 changes: 1 addition & 10 deletions src/haz3lcore/dynamics/EnvironmentId.re
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
open Sexplib.Std;

[@deriving (show({with_path: false}), sexp, yojson)]
type t = int;

let init = 0;
let equal = (==);

let invalid = (-1);
let is_invalid = equal(invalid);
include Id;
30 changes: 1 addition & 29 deletions src/haz3lcore/dynamics/EnvironmentId.rei
Original file line number Diff line number Diff line change
@@ -1,29 +1 @@
/**
Identifier for environments.
*/

/**
The type for identifiers.
*/
[@deriving (show({with_path: false}), sexp, yojson)]
type t = int;

/**
[init] is the initial identifier.
*/
let init: t;

/**
[equal ei ei'] is true if and only if [ei] and [ei'] are equal.
*/
let equal: (t, t) => bool;

/**
[invalid] is an invalid identifier.
*/
let invalid: t;

/**
[is_invalid ei] is [equal invalid ei].
*/
let is_invalid: t => bool;
include (module type of Id);
9 changes: 0 additions & 9 deletions src/haz3lcore/dynamics/EnvironmentIdGen.re

This file was deleted.

19 changes: 0 additions & 19 deletions src/haz3lcore/dynamics/EnvironmentIdGen.rei

This file was deleted.

2 changes: 1 addition & 1 deletion src/haz3lcore/dynamics/EnvironmentIdMap.re
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include Util.IntMap;
include Id.Map;
2 changes: 1 addition & 1 deletion src/haz3lcore/dynamics/EnvironmentIdMap.rei
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Used in HoleInstanceInfo_.re
*/
include (module type of Util.IntMap);
include (module type of Id.Map);
20 changes: 10 additions & 10 deletions src/haz3lcore/dynamics/Evaluator.re
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,13 @@ let rec evaluate: (ClosureEnvironment.t, DHExp.t) => m(EvaluatorResult.t) =
| IndetMatch
| DoesNotMatch => Indet(Closure(env, Let(dp, d1, d2))) |> return
| Matches(env') =>
let* env = evaluate_extend_env(env', env);
let env = evaluate_extend_env(env', env);
evaluate(env, d2);
}
};

| FixF(f, _, d') =>
let* env' = evaluate_extend_env(Environment.singleton((f, d)), env);
let env' = evaluate_extend_env(Environment.singleton((f, d)), env);
evaluate(env', d');

| Fun(_) => BoxedValue(Closure(env, d)) |> return
Expand All @@ -694,7 +694,7 @@ let rec evaluate: (ClosureEnvironment.t, DHExp.t) => m(EvaluatorResult.t) =
| Matches(env') =>
// evaluate a closure: extend the closure environment with the
// new bindings introduced by the function application.
let* env = evaluate_extend_env(env', closure_env);
let env = evaluate_extend_env(env', closure_env);
evaluate(env, d3);
}
};
Expand Down Expand Up @@ -1158,7 +1158,7 @@ and eval_rule =
|> return;
| Matches(env') =>
// extend environment with new bindings introduced
let* env = evaluate_extend_env(env', env);
let env = evaluate_extend_env(env', env);
evaluate(env, d);
// by the rule and evaluate the expression.
| DoesNotMatch =>
Expand All @@ -1172,10 +1172,11 @@ and eval_rule =
*/
and evaluate_extend_env =
(new_bindings: Environment.t, to_extend: ClosureEnvironment.t)
: m(ClosureEnvironment.t) => {
let map =
Environment.union(new_bindings, ClosureEnvironment.map_of(to_extend));
map |> ClosureEnvironment.of_environment |> with_eig;
: ClosureEnvironment.t => {
to_extend
|> ClosureEnvironment.map_of
|> Environment.union(new_bindings)
|> ClosureEnvironment.of_environment;
}

/**
Expand Down Expand Up @@ -1274,7 +1275,6 @@ and evaluate_test_eq =

let evaluate = (env, d) => {
let es = EvaluatorState.init;
let (env, es) =
es |> EvaluatorState.with_eig(ClosureEnvironment.of_environment(env));
let env = ClosureEnvironment.of_environment(env);
evaluate(env, d, es);
};
4 changes: 0 additions & 4 deletions src/haz3lcore/dynamics/EvaluatorMonad.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ include Util.StateMonad.Make(EvaluatorState);

open Syntax;

let get_eig = get >>| EvaluatorState.get_eig;
let put_eig = eig => modify(EvaluatorState.put_eig(eig));
let with_eig = f => modify'(EvaluatorState.with_eig(f));

let take_step = get >>= (state => put(EvaluatorState.take_step(state)));

let add_test = (id, report) =>
Expand Down
15 changes: 0 additions & 15 deletions src/haz3lcore/dynamics/EvaluatorMonad.rei
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,6 @@

include Util.StateMonad.S with type state = EvaluatorState.t;

/**
See {!val:EvaluatorState.get_eig}.
*/
let get_eig: t(EnvironmentIdGen.t);

/**
See {!val:EvaluatorState.put_eig}.
*/
let put_eig: EnvironmentIdGen.t => t(unit);

/**
See {!val:EvaluatorState.with_eig}.
*/
let with_eig: (EnvironmentIdGen.t => ('a, EnvironmentIdGen.t)) => t('a);

/**
See {!val:EvaluatorState.take_step}
*/
Expand Down
34 changes: 10 additions & 24 deletions src/haz3lcore/dynamics/EvaluatorPost.re
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
module PpMonad = {
include Util.StateMonad.Make({
[@deriving sexp]
type t = (
EnvironmentIdMap.t(ClosureEnvironment.t),
HoleInstanceInfo_.t,
EnvironmentIdGen.t,
);
type t = (EnvironmentIdMap.t(ClosureEnvironment.t), HoleInstanceInfo_.t);
});

open Syntax;

let get_pe = get >>| (((pe, _, _)) => pe);
let get_pe = get >>| (((pe, _)) => pe);
let pe_add = (ei, env) =>
modify(((pe, hii, eig)) =>
(pe |> EnvironmentIdMap.add(ei, env), hii, eig)
);
modify(((pe, hii)) => (pe |> EnvironmentIdMap.add(ei, env), hii));

let hii_add_instance = (u, env) =>
modify'(((pe, hii, eig)) => {
modify'(((pe, hii)) => {
let (hii, i) = HoleInstanceInfo_.add_instance(hii, u, env);
(i, (pe, hii, eig));
});

let with_eig = f =>
modify'(((pe, hii, eig)) => {
let (x, eig) = f(eig);
(x, (pe, hii, eig));
(i, (pe, hii));
});
};

Expand Down Expand Up @@ -242,7 +230,7 @@ and pp_eval_env = (env: ClosureEnvironment.t): m(ClosureEnvironment.t) => {
FixF(f, ty, d1);
| d => pp_eval(d)
};
with_eig(ClosureEnvironment.extend(env', (x, d')));
ClosureEnvironment.extend(env', (x, d')) |> return;
},
Environment.empty |> ClosureEnvironment.wrap(ei) |> return,
);
Expand Down Expand Up @@ -551,13 +539,11 @@ let track_children = (hii: HoleInstanceInfo.t): HoleInstanceInfo.t =>
hii,
);

let postprocess =
(d: DHExp.t, eig: EnvironmentIdGen.t)
: ((HoleInstanceInfo.t, DHExp.t), EnvironmentIdGen.t) => {
let postprocess = (d: DHExp.t): (HoleInstanceInfo.t, DHExp.t) => {
/* Substitution and hole numbering postprocessing */
let ((_, hii, eig), d) =
let ((_, hii), d) =
Util.TimeUtil.measure_time("pp_eval", true, () =>
pp_eval(d, (EnvironmentIdMap.empty, HoleInstanceInfo_.empty, eig))
pp_eval(d, (EnvironmentIdMap.empty, HoleInstanceInfo_.empty))
);

/* Build hole instance info. */
Expand Down Expand Up @@ -591,5 +577,5 @@ let postprocess =
);

/* Perform hole parent tracking. */
((hii, d), eig);
(hii, d);
};
4 changes: 1 addition & 3 deletions src/haz3lcore/dynamics/EvaluatorPost.rei
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,4 @@ exception Exception(error);
See also HoleInstanceInfo.rei/HoleInstanceInfo_.rei.
*/
let postprocess:
(DHExp.t, EnvironmentIdGen.t) =>
((HoleInstanceInfo.t, DHExp.t), EnvironmentIdGen.t);
let postprocess: DHExp.t => (HoleInstanceInfo.t, DHExp.t);
14 changes: 1 addition & 13 deletions src/haz3lcore/dynamics/EvaluatorState.re
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
[@deriving (show({with_path: false}), sexp, yojson)]
type t = {
eig: EnvironmentIdGen.t,
stats: EvaluatorStats.t,
tests: TestMap.t,
};

let init = {
eig: EnvironmentIdGen.init,
stats: EvaluatorStats.initial,
tests: TestMap.empty,
};

let get_eig = ({eig, _}) => eig;
let put_eig = (eig, es) => {...es, eig};
let with_eig = (f, es) => {
let (x, eig) = es |> get_eig |> f;
(x, es |> put_eig(eig));
};
let init = {stats: EvaluatorStats.initial, tests: TestMap.empty};

let take_step = ({stats, _} as es) => {
...es,
Expand Down
16 changes: 0 additions & 16 deletions src/haz3lcore/dynamics/EvaluatorState.rei
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ type t;
*/
let init: t;

/**
[get_eig es] is current environment id generator.
*/
let get_eig: t => EnvironmentIdGen.t;

/**
[put_eig eig es] is [es] with the environment id generator [eig].
*/
let put_eig: (EnvironmentIdGen.t, t) => t;

/**
[with_eig f es] calls [f] with the current environment id generator, updating
[es] afterwards.
*/
let with_eig: (EnvironmentIdGen.t => ('a, EnvironmentIdGen.t), t) => ('a, t);

/**
[take_step es] is [es] with the updated step count.
*/
Expand Down

0 comments on commit eea6aad

Please sign in to comment.