Skip to content

Commit

Permalink
Two small bug fixes. More logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Mar 15, 2015
1 parent 1f082ab commit d3800e9
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 139 deletions.
8 changes: 4 additions & 4 deletions examples/liquid_bsearch2_harder3.ml.target
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ let bsearch
(fun key vec ->
let Ex3 xcase =
let rec look :
type (*i*) (*k*) (*n*) a (*0 ≤ n + 1 ∧ 0 ≤ k
n + 1 ≤ i*). (a -> (a (* i *)) array -> (* k *) num -> (* n *) num ->
(* n *) ex3)
type (*i*) (*j*) (*k*) b (*0 ≤ k + 1 ∧ 0 ≤ i
k + 1 ≤ j*). (b -> (b (* j *)) array -> (* i *) num -> (* k *) num ->
(* k *) ex3)
=
(fun key vec lo hi ->
(if lo <= hi then
Expand All @@ -44,6 +44,6 @@ let bsearch
| EQ ->
(if equal key x then let xcase = m in Ex3 xcase else
let xcase = -1 in Ex3 xcase))) :
(* n *) ex3) else let xcase = -1 in Ex3 xcase)) in
(* k *) ex3) else let xcase = -1 in Ex3 xcase)) in
look key vec 0 (array_length vec + -1) in Ex4 xcase)

2 changes: 1 addition & 1 deletion examples/liquid_gauss_asserted.gadti.target
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ val rowElim :
∀i, j, k, n[0 ≤ n ∧ k ≤ i ∧ n + 1 ≤ i ∧ k ≤ j].
Array (Float, j) → Array (Float, i) → Num k → Num n → ()

val gauss : ∀n[0 ≤ n]. Matrix (n, n + 1) → ()
val gauss : ∀n[1 ≤ n]. Matrix (n, n + 1) → ()
2 changes: 1 addition & 1 deletion examples/liquid_gauss_simpler_asserted.gadti.target
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ external rowElim :
∀i, j, k, n[0 ≤ n ∧ n + 1 ≤ i ∧ k ≤ i ∧ k ≤ j].
Array (Float, j) → Array (Float, i) → Num k → Num n → ()

val gauss : ∀n[0 ≤ n]. Matrix (n, n + 1) → ()
val gauss : ∀n[1 ≤ n]. Matrix (n, n + 1) → ()
2 changes: 1 addition & 1 deletion examples/liquid_simplex_step_3a.gadti.target
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ external is_neg_aux :
external is_neg :
∀i, k, n[1 ≤ k ∧ n ≤ i + 1]. Matrix (k, i) → Num n → Bool

val main_step3_test : ∀k, n[1 ≤ n ∧ 2 ≤ k]. Matrix (n, k) → Float
val main_step3_test : ∀k, n[1 ≤ n ∧ 3 ≤ k]. Matrix (n, k) → Float
6 changes: 3 additions & 3 deletions examples/mutual_recursion_eval_docs.ml.target
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ex3 =
be easier to only expose the external one. *)
let (calc, eval) (*: type a . ((calc -> ex3) * (a term -> a))*) =
(** [eval] has to expose its "helper" function. *)
let rec eval : type a . ((calc -> ex3) * (a term -> a)) =
let rec eval : type b . ((calc -> ex3) * (b term -> b)) =
let rec calc : (calc -> ex3) =
((function Lit i -> let xcase = i in Ex3 xcase
| Plus (x, y) ->
Expand All @@ -58,7 +58,7 @@ let (calc, eval) (*: type a . ((calc -> ex3) * (a term -> a))*) =
let Ex3 r = calc x in is_zero r
| If (b, t, e) -> (if snd eval b then snd eval t else snd eval e)
| Pair (x, y) -> (snd eval x, snd eval y)
| Fst p -> let ((x, y): (a * _)) = snd eval p in x
| Snd p -> let ((x, y): (_ * a)) = snd eval p in y): a term -> a)) in
| Fst p -> let ((x, y): (b * _)) = snd eval p in x
| Snd p -> let ((x, y): (_ * b)) = snd eval p in y): b term -> b)) in
eval

4 changes: 2 additions & 2 deletions src/Abduction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -952,9 +952,9 @@ let abd q ~bvs ~xbvs ?orig_ren ?b_of_v ~upward_of ~nonparam_vars
with Contradiction _ -> None)
neg_brs in
let verif_brs = List.map2
(fun (prem, concl_ty) (_, _, _, concl_num) ->
(fun (prem, concl_ty) (_, _, prem_num, concl_num) ->
VarSet.union (fvs_sb concl_ty) (NumDefs.fvs_formula concl_num),
prem, concl_ty, concl_num)
prem, concl_ty, prem_num @ concl_num)
brs_typ brs_num in
let validation =
map_some
Expand Down
44 changes: 42 additions & 2 deletions src/Infer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,15 @@ let annotate_expr q res_sb chi_sb nice_sb e : texpr =
let _, ans =
try List.find (fun (k,_) -> List.mem k ns) chi_sb
with Not_found -> assert false in
(*[* Format.printf
"annotate_expr-typ_sch: ans=@ %a@\n%!" pr_ans ans; *]*)
let nice_sb, (vs, phi) = nice_ans ~sb:nice_sb ans in
(*[* Format.printf
"annotate_expr-typ_sch: phi=@ %a@\n%!" pr_formula phi; *]*)
let sb, phi =
separate_subst ~bvs:(vars_of_list vs) ~apply:true q phi in
(*[* Format.printf
"annotate_expr-typ_sch: sb=@ %a@\n%!" pr_subst sb; *]*)
let res, _ = VarMap.find delta sb in
let vs = VarSet.inter
(VarSet.union (fvs_formula phi) (fvs_typ res))
Expand Down Expand Up @@ -1019,15 +1025,31 @@ let infer_prog solver prog =
let nice_sb, (vs, phi) =
try nice_ans (List.assoc chi_id sb_chi)
with Not_found -> assert false in
(*[* Format.printf
"Infer: nice_sb=%a@\n%!" pr_hvsubst nice_sb; *]*)
(*[* Format.printf
"Infer: [1] phi_res=%a@\n%!"
pr_formula phi_res; *]*)
let sb_res, phi_res =
separate_subst ~bvs:(vars_of_list (vs @ bvs))
~apply:true q phi_res in
(*[* Format.printf
"Infer: [2] sb_res=%a@ phi_res=%a@\n%!"
pr_subst sb_res pr_formula phi_res; *]*)
(*[* Format.printf
"Infer: [3] phi=%a@\n%!"
pr_formula phi; *]*)
let more_sb, phi =
separate_subst ~bvs:(vars_of_list (vs @ bvs))
~apply:true q phi in
(*[* Format.printf
"Infer: [4] more_sb=%a@ phi=%a@\n%!"
pr_subst more_sb pr_formula phi; *]*)
let sb = update_sb ~more_sb sb_res in
let e = annotate_expr q sb sb_chi nice_sb e
and tests = List.map (annotate_expr q sb sb_chi nice_sb) tests in
(*[* Format.printf
"Infer: [5] sb=%a@\n%!" pr_subst sb; *]*)
let e = annotate_expr q sb sb_chi nice_sb e in
let tests = List.map (annotate_expr q sb sb_chi nice_sb) tests in
let res, _ = VarMap.find delta sb in
let gvs = VarSet.elements
(VarSet.union (fvs_formula phi) (fvs_typ res)) in
Expand Down Expand Up @@ -1091,15 +1113,23 @@ let infer_prog solver prog =
~uses_pos_assertions:!uses_pos_assertions
~new_ex_types ~preserve cn in
let elim_extypes = !elim_cell in
(*[* Format.printf "Infer: solved.@\n%!"; *]*)
(*[* Format.printf
"Infer: [6] phi=%a@\n%!"
pr_formula phi; *]*)
let sb, phi =
separate_subst ~bvs:preserve ~apply:true q phi in
(*[* Format.printf
"Infer: [7] sb=%a@\n%!" pr_subst sb; *]*)
let res = subst_typ sb t in
let gvs = VarSet.union (fvs_formula phi) (fvs_typ res) in
(*[* Format.printf "LetVal: res=%a@ gvs=%a@ phi=%a@\n%!"
pr_ty res pr_vars gvs pr_formula phi; *]*)
let gvs = VarSet.elements gvs in
let nice_sb, (gvs, phi) =
nice_ans ~fvs:(fvs_typ res) (gvs, phi) in
(*[* Format.printf
"Infer: [8] nice_sb=%a@\n%!" pr_hvsubst nice_sb; *]*)
let sb = hvsubst_sb nice_sb sb in
let res = hvsubst_typ nice_sb res in
(*[* Format.printf
Expand All @@ -1109,8 +1139,13 @@ let infer_prog solver prog =
let top_sch = gvs, phi, res in
let e = annotate_expr q sb sb_chi nice_sb e in
let exphi = subst_formula sb exphi in
(*[* Format.printf
"Infer: [9] exphi=%a@\n%!"
pr_formula exphi; *]*)
let exsb, exphi =
separate_subst ~bvs:(add_vars gvs preserve) ~apply:true q exphi in
(*[* Format.printf
"Infer: [10] exsb=%a@\n%!" pr_subst sb; *]*)
let exsb = update_sb ~more_sb:exsb sb in
let ex_items =
update_new_ex_types q new_ex_types sb sb_chi in
Expand Down Expand Up @@ -1142,9 +1177,14 @@ let infer_prog solver prog =
let res = subst_typ exsb res in
let gvs, phi = prepare_scheme phi res in
let exvs, exphi = prepare_scheme exphi res in
(*[* Format.printf
"Infer: [11] exphi=%a@\n%!"
pr_formula exphi; *]*)
let more_sb, exphi =
separate_subst
~bvs:(VarSet.union exvs gvs) ~apply:true q exphi in
(*[* Format.printf
"Infer: [12] more_sb=%a@\n%!" pr_subst sb; *]*)
let sb = update_sb ~more_sb sb in
let exvs = VarSet.diff exvs (vars_of_list [delta; delta']) in
let gvs = VarSet.diff gvs (vars_of_list [delta; delta']) in
Expand Down
36 changes: 10 additions & 26 deletions src/InvarGenTTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ let tests = "InvarGenT" >::: [
test_case "flatten_quadrs" ());
"flatten_septs" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case ~ty_abd_timeout:3000
~abd_rotations:4 "flatten_septs" ());
Expand Down Expand Up @@ -447,7 +446,6 @@ let tests = "InvarGenT" >::: [
test_case "liquid_bsearch" ());
"liquid_bsearch-harder" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case "liquid_bsearch_harder" ());
"liquid_bsearch2-simpler" >::
Expand Down Expand Up @@ -485,7 +483,6 @@ let tests = "InvarGenT" >::: [
test_case "liquid_queen_simpler" ());
"liquid_queen" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case "liquid_queen" ());
"liquid_isort-simpler1" >::
Expand All @@ -494,7 +491,6 @@ let tests = "InvarGenT" >::: [
test_case "liquid_isort_simpler1" ());
"liquid_isort-simpler2" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case "liquid_isort_simpler2" ());
"liquid_isort-simpler3" >::
Expand All @@ -507,25 +503,23 @@ let tests = "InvarGenT" >::: [
test_case "liquid_isort_simpler" ());
"liquid_isort" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case "liquid_isort" ());
"liquid_isort-harder" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case "liquid_isort_harder" ());
"liquid_vecswap_simpler" >::
(fun () ->
skip_if !debug "debug";
todo "FIXME";
(* skip_if !debug "debug"; *)
test_case "liquid_vecswap_simpler" ());
"liquid_vecswap" >::
(fun () ->
skip_if !debug "debug";
test_case "liquid_vecswap" ());
"liquid_isort-full" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case "liquid_isort_full" ());
"liquid_tower_showposts" >::
Expand All @@ -538,15 +532,17 @@ let tests = "InvarGenT" >::: [
test_case "liquid_tower_simpler" ());
"liquid_tower_asserted" >::
(fun () ->
skip_if !debug "debug";
todo "FIXME";
(* skip_if !debug "debug"; *)
test_case "liquid_tower_asserted" ());
"liquid_tower" >::
(fun () ->
skip_if !debug "debug";
test_case "liquid_tower" ());
"liquid_tower_harder" >::
(fun () ->
skip_if !debug "debug";
todo "FIXME";
(* skip_if !debug "debug"; *)
test_case ~prefer_bound_to_local:true "liquid_tower_harder" ());
"liquid_matmult" >::
(fun () ->
Expand All @@ -570,12 +566,10 @@ let tests = "InvarGenT" >::: [
test_case "liquid_heapsort_heapify" ());
"liquid_heapsort-heapsort-simpler" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case "liquid_heapsort_heapsort_simpler" ());
"liquid_heapsort-heapsort" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case "liquid_heapsort_heapsort" ());
"liquid_heapsort" >::
Expand All @@ -599,8 +593,7 @@ let tests = "InvarGenT" >::: [
test_case "liquid_simplex_step_3" ());
"liquid_simplex_step_3a" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
(* skip_if !debug "debug"; *)
(* Type in target is slightly less general than most general type:
∀k, n[1 ≤ n ∧ 3 ≤ k]. Matrix (n, k) → Float *)
test_case ~prefer_bound_to_local:true
Expand All @@ -616,12 +609,10 @@ let tests = "InvarGenT" >::: [
test_case "liquid_simplex_step_4a" ());
"liquid_simplex_step_5a" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case "liquid_simplex_step_5a" ());
"liquid_simplex_step_6a_1" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case "liquid_simplex_step_6a_1" ());
"liquid_simplex_step_6_2" >::
Expand All @@ -630,7 +621,6 @@ let tests = "InvarGenT" >::: [
test_case "liquid_simplex_step_6_2" ());
"liquid_simplex_step_6a_2" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case ~prefer_bound_to_local:true
"liquid_simplex_step_6a_2" ());
Expand All @@ -640,12 +630,10 @@ let tests = "InvarGenT" >::: [
test_case "liquid_simplex_step_6_3" ());
"liquid_simplex_step_6a_3" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case "liquid_simplex_step_6a_3" ());
"liquid_simplex_step_6a" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case "liquid_simplex_step_6a" ());
"liquid_simplex_step_7a" >::
Expand All @@ -654,12 +642,10 @@ let tests = "InvarGenT" >::: [
test_case "liquid_simplex_step_7a" ());
"liquid_simplex" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case ~test_annot:true "liquid_simplex" ());
"liquid_simplex-harder" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
skip_if !short_tests_only "long test: 53s";
test_case "liquid_simplex_harder" ());
Expand Down Expand Up @@ -687,8 +673,7 @@ let tests = "InvarGenT" >::: [
test_case "liquid_gauss_simpler" ());
"liquid_gauss_simpler_asserted" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
(* skip_if !debug "debug"; *)
test_case "liquid_gauss_simpler_asserted" ());
"liquid_gauss" >::
(fun () ->
Expand All @@ -697,17 +682,16 @@ let tests = "InvarGenT" >::: [
"liquid_gauss2" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
(* skip_if !debug "debug"; *)
test_case ~prefer_bound_to_local:true "liquid_gauss2" ());
"liquid_gauss_asserted" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
test_case "liquid_gauss_asserted" ());
"liquid_gauss_harder_asserted" >::
(fun () ->
todo "FIXME";
skip_if !debug "debug";
(* skip_if !debug "debug"; *)
test_case "liquid_gauss_harder_asserted" ());
"liquid_gauss_harder" >::
(fun () ->
Expand Down
16 changes: 10 additions & 6 deletions src/Invariants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1423,10 +1423,12 @@ let solve ~uses_pos_assertions q_ops new_ex_types exty_res_chi brs =
| TVar b ->
(try
let vs, _ = List.assoc i sol1 in
(* Should not have variables not already in
the quantifier. *)
let renaming =
matchup_vars ~self_owned:false q b vs in
matchup_vars ~self_owned:true(* false *) q b vs in
(*[* Format.printf
"sb_chi_pos: chi%d(%s)@ lvs=%a;@ rvs=%a@\n%!"
"br_chi_pos: chi%d(%s)@ lvs=%a;@ rvs=%a@\n%!"
i (var_str b)
pr_vars (varmap_domain renaming)
pr_vars (vars_of_list (varmap_codom renaming));
Expand All @@ -1450,11 +1452,13 @@ let solve ~uses_pos_assertions q_ops new_ex_types exty_res_chi brs =
(fun x xvs acc ->
try
(*[* Format.printf
"xbvs: x=%s xvs=%a@ %!"
(var_str x) pr_vars xvs;
"xbvs: ? x=%s pos=%b xvs=%a@ %!"
(var_str x) (q.positive_b x) pr_vars xvs;
Format.printf "b=%d@\n%!" (q.find_chi x); *]*)
(*if q.positive_b x then acc
else*) (q.find_chi x, xvs)::acc
(* FIXME: make sure to include postconditions with
original parameters. *)
if q.positive_b x then acc
else (q.find_chi x, xvs)::acc
with Not_found -> acc)
q.b_vs [] in
let answer =
Expand Down
Loading

0 comments on commit d3800e9

Please sign in to comment.