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

[WIP] Use MoCHi as back-end #36

Open
wants to merge 113 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
9e51593
update .gitignore
artoy Apr 24, 2023
76a3fba
update .gitignore
artoy May 7, 2023
470a0c7
some fix
artoy May 7, 2023
a8e1bdd
update lexer and parser
artoy May 7, 2023
edc5a8e
Merge branch 'develop/mochi-backend' of github.com:SoftwareFoundation…
artoy May 7, 2023
eed6e27
fix cons and match
artoy May 7, 2023
e81e6f3
fix lexer
artoy May 7, 2023
e2fbc28
fix parser (but occurs shift/reduce conflict)
artoy May 8, 2023
5a97cdf
add match
artoy May 8, 2023
08433d7
implement nil in simplify_expr
artoy May 10, 2023
cb05842
complete surfaceAST
artoy May 11, 2023
235de7e
add tests
artoy May 12, 2023
1ee6dad
add intlist
artoy May 17, 2023
1ce1170
add definition fold and unfold
artoy May 18, 2023
756affc
add process recursive types
artoy May 18, 2023
5d74cdb
fix error
artoy May 18, 2023
1c916cb
wip
artoy May 18, 2023
7a13d06
fix match statement
artoy May 21, 2023
4419afd
complete simple type check of list and match
artoy May 21, 2023
46d8599
some fix
artoy May 22, 2023
979bad4
fix
artoy May 22, 2023
2225a4f
complete simple type checking and fix test
artoy May 22, 2023
d723acc
handle IntList (WIP)
artoy May 22, 2023
0cbea1c
print variables and their types binded in match
artoy May 24, 2023
0fbd1a6
fix print
artoy May 24, 2023
589bcdb
update test for linked list
artoy May 25, 2023
3021ea6
change TyCons to Ref (WIP)
artoy May 28, 2023
e1ca193
delete Mu (WIP)
artoy May 29, 2023
f5fbb73
complete simpleChecker
artoy May 29, 2023
e646c77
delete flow inference and verifying with solver
artoy May 30, 2023
218ca4b
fix let in simple type checking
artoy Jun 1, 2023
0a8286c
simplify tests
artoy Jun 1, 2023
3b26437
fix match test
artoy Jun 1, 2023
3df469a
delete Mu (WIP)
artoy Jun 1, 2023
6160dd3
add IntList to lift_to_ownership (WIP)
artoy Jun 5, 2023
8fe1e34
complete lift_to_ownership
artoy Jun 5, 2023
a443be6
wip
artoy Jun 5, 2023
854496f
update AST printer
artoy Jun 6, 2023
73c67fd
add ownership arity to options
artoy Jun 7, 2023
3f14361
change some functions
artoy Jun 7, 2023
c4d03a8
update constrain_rel
artoy Jun 8, 2023
8ea7779
update some functions
artoy Jun 9, 2023
dc07082
update ownership inference
artoy Jun 12, 2023
d7d9e6e
add o_arity argument to some functions
artoy Jun 12, 2023
284152b
fix split_type (WIP)
artoy Jun 15, 2023
a9cce67
update split_type
artoy Jun 16, 2023
42a1cef
some fix
artoy Jun 16, 2023
0e29894
add tests and functions
artoy Jun 16, 2023
0679c30
implement pattern matching (WIP)
artoy Jun 18, 2023
7ea6d9e
add process pattern matching
artoy Jun 19, 2023
85bf351
Merge branch 'develop/mochi-backend' of github.com:SoftwareFoundation…
artoy Jun 19, 2023
76f4bff
complete implement match statement
artoy Jun 19, 2023
fe3e446
add WeakSplit (WIP)
artoy Jun 20, 2023
d639b63
implement cons (WIP)
artoy Jun 22, 2023
e49f75b
WIP
artoy Jun 24, 2023
f02da0c
implemented (but error occurs)
artoy Jun 25, 2023
7047d0a
fix simple type checker where assign int
artoy Jun 29, 2023
06b1f3b
refix ownership inference
artoy Jun 29, 2023
cef561f
add test
artoy Jun 29, 2023
0c1574f
fix a bug about mkref intlist
artoy Jul 1, 2023
a2b82e2
fix match statement (is this really correct?)
artoy Jul 3, 2023
2ec1692
update test
artoy Jul 3, 2023
7e7ce3c
implement simple type checking of .Cons.2 alias
artoy Jul 6, 2023
eb0989e
delete an unused function
artoy Jul 6, 2023
2dabacf
implement ownership inference of .cons.2
artoy Jul 10, 2023
f54fa86
fix a test
artoy Jul 13, 2023
b847fda
update consort.ml
artoy Jul 13, 2023
d4929b4
output constraints of ownership variables
artoy Jul 13, 2023
2c53f39
fix .cons.2 in alias statements
artoy Jul 13, 2023
05f3eee
add convmochi
artoy Jul 14, 2023
35b99c2
WIP
artoy Jul 28, 2023
b52b3ee
add patterns of IntList
artoy Jul 30, 2023
560c52e
WIP
artoy Jul 30, 2023
800d909
add a test
artoy Jul 31, 2023
681da2e
add test
artoy Aug 3, 2023
06eb5da
implement alias_to_mochi
artoy Aug 3, 2023
1010212
support for pretty printing of alias
artoy Aug 4, 2023
9188d59
move a test
artoy Aug 9, 2023
55c5882
some fix
artoy Aug 10, 2023
001d25e
add a comment and some fix
artoy Aug 10, 2023
dd704c0
fix alias statment
artoy Aug 11, 2023
2d383b8
add a test
artoy Aug 12, 2023
280f2b3
support for undet IntList
artoy Aug 13, 2023
ea58b0d
some fix and add tests
artoy Aug 24, 2023
881902f
update tests
artoy Aug 24, 2023
3361880
update built-in functions
artoy Aug 28, 2023
1797552
fix a test
artoy Sep 4, 2023
49b4033
fix decision of the way of assign when alias
artoy Sep 4, 2023
2a2be1b
fix tests
artoy Sep 4, 2023
0dd53ff
add comment
artoy Sep 4, 2023
4c163cd
delete comment
artoy Sep 4, 2023
73dd5b0
insert "int list" to argument automatically
artoy Sep 4, 2023
1c3f86b
change default ownership arity
artoy Sep 4, 2023
bb17ed3
Change the syntax of Cons.
aigarashi Sep 13, 2023
5dca92e
Merge pull request #38 from SoftwareFoundationGroupAtKyotoU/fix/shift…
artoy Sep 13, 2023
c10c4af
add a test
artoy Sep 25, 2023
5115e0d
fix a test
artoy Sep 25, 2023
6d1ddaf
fix a test
artoy Sep 25, 2023
d690b0b
add and fix tests
artoy Sep 30, 2023
89d7a7e
add tests
artoy Oct 10, 2023
26acaa9
add callMoCHi
artoy Nov 4, 2023
ee5a3c4
add call mochi
artoy Nov 6, 2023
b6a043c
run mochi automatically (may error occurs)
artoy Nov 6, 2023
70d776e
comment out
artoy Nov 7, 2023
b0b5055
add test files
artoy Nov 30, 2023
6eabb96
update
artoy Mar 19, 2024
3d5a9b8
wip
artoy Mar 20, 2024
bcdd83e
wip
artoy Mar 20, 2024
c44a49a
fix calculation of ownership
artoy Mar 21, 2024
426c77d
Merge branch 'develop/mochi-backend' of github.com:SoftwareFoundation…
artoy Mar 21, 2024
130d1ec
call mochi
artoy Mar 21, 2024
088f7ee
add comment
artoy Mar 21, 2024
b17ea89
Merge pull request #41 from SoftwareFoundationGroupAtKyotoU/feature/c…
artoy Mar 21, 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ paper/related_work.tex
paper/semantics.tex
paper/typesystem.tex
paper/wf_rules.tex
src/test/to_mochi.ml
10 changes: 9 additions & 1 deletion src/argOptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ module ExecMode = struct
| Consort
| Ownership
| Typecheck
| ConvMoCHi

let pairs = [
("consort", Consort);
("ownership", Ownership);
("typecheck", Typecheck)
("typecheck", Typecheck);
("convmochi", ConvMoCHi)
]
let default = "consort"
let candidates = List.map (fun (s, _) -> s) pairs
Expand Down Expand Up @@ -69,6 +71,7 @@ type t = {
file_list : Arg.usage_msg list;
output_channel : out_channel Cache.t;
intrinsics : Intrinsics.interp_t Cache.t;
ownership_arity : int;
}

let default = {
Expand All @@ -95,6 +98,7 @@ let default = {
file_list = [];
output_channel = ref None;
intrinsics = ref None;
ownership_arity = 2;
}
let close_output ~opts =
Option.iter close_out !(opts.output_channel);
Expand Down Expand Up @@ -132,6 +136,7 @@ let parse anon_fun usage_msg =
let cfa = ref default.cfa in
let intrinsics_file = ref None in
let file_list = ref default.file_list in
let ownership_arity = ref default.ownership_arity in
let show_all () =
List.iter (fun r -> r := true) show_all_flags; Log.all () in
let debug s =
Expand Down Expand Up @@ -191,6 +196,8 @@ let parse anon_fun usage_msg =
"<file>\t Load definitions of standard operations from <file>");
("-files", Rest (fun s -> file_list := s::!file_list),
"<file> ...\t Interpret all remaining arguments as files to test");
("-ownership-arity", Set_int ownership_arity,
"<integer>\t The number of different ownership variables used in recursive data structure (default: 2)");
] in
Arg.parse spec anon_fun usage_msg;
{
Expand All @@ -217,4 +224,5 @@ let parse anon_fun usage_msg =
file_list = !file_list;
output_channel = default.output_channel;
intrinsics = default.intrinsics;
ownership_arity = !ownership_arity;
}
7 changes: 5 additions & 2 deletions src/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ type lhs =
| Nondet of RefinementTypes.concr_refinement option
| Read of string * string
| LengthOf of string
| Null [@@deriving sexp]
| Null
| Nil
| Cons of lhs * lhs [@@deriving sexp]

type patt =
| PVar of string
Expand Down Expand Up @@ -64,7 +66,8 @@ type raw_exp =
| Let of patt * lhs * exp
| Alias of Paths.concr_ap * Paths.concr_ap * exp
| Assert of relation * exp
| Return of string [@@deriving sexp]
| Return of string
| Match of lhs * exp * string * string * exp [@@deriving sexp]

and exp = position * raw_exp [@@deriving sexp]

Expand Down
23 changes: 22 additions & 1 deletion src/astPrinter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ let pp_ap r =
| `Proj i::l ->
pf "%a.%d" (ul loop) l i
| `Deref::l -> pf "*%a" (ul loop) l
| `Cons(con, i) :: l ->
pf "%a.%s.%d" (ul loop) l con i
in
loop steps
| _ -> failwith "Unsupported operation ap"
Expand Down Expand Up @@ -75,7 +77,7 @@ let rec pp_ref_ast (r: RefinementTypes.concr_refinement) =
(ul pp_ref_ast) r2
| _ -> failwith @@ "Cannot annotate with relation " ^ (string_of_refinement r)

let pp_lhs = function
let rec pp_lhs = function
| Var x -> pv x
| Const i -> pi i
| Mkref il -> pl [
Expand Down Expand Up @@ -104,6 +106,15 @@ let pp_lhs = function
pf "%s[%s]" b i
| LengthOf v ->
pf "%s.length" v
| Cons (h, r) ->
pl [
ps "cons";
pp_lhs h;
ps "(";
pp_lhs r;
ps ")"
]
| Nil -> ps "nil"

let rec pp_patt = function
| PVar v -> pv v
Expand Down Expand Up @@ -161,6 +172,16 @@ let rec pp_expr ~ip:((po_id,pr_id) as ip) ~annot (id,e) =
| Unit -> ps "()"
| Return v -> pf "return%a %s" po_id id v
| Fail -> ps "fail"
| Match (e1, e2, h, r, e3) ->
pl [
pf "match %a with " (ul pp_lhs) e1;
pf "Nil -> { ";
pp_expr ~ip ~annot e2;
ps " } ";
pf "| Cons %s (%s) -> { " h r;
pp_expr ~ip ~annot e3;
ps "}";
]
in
match e with
| Seq _ -> e_printer
Expand Down
65 changes: 45 additions & 20 deletions src/consort.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ let result_to_string = function
| Verified -> "VERIFIED"
| Unverified r -> Printf.sprintf "UNVERIFIED (%s)" @@ reason_to_string r true

let solver_result_to_check_result =
(* let solver_result_to_check_result =
let open Solver in
function
| Unsat -> Unverified Unsafe
| Sat _ -> Verified
| Timeout -> Unverified Timeout
| Unhandled msg -> Unverified (UnhandledSolverOutput msg)
| Error msg -> Unverified (SolverError msg)
| Unknown -> Unverified Unknown
| Unknown -> Unverified Unknown *)

let choose_solver =
(* let choose_solver =
let open ArgOptions.Solver in
function
| Eldarica -> EldaricaBackend.solve
| Hoice -> HoiceBackend.solve
| Null -> NullSolver.solve
| Parallel -> ParallelBackend.solve
| Spacer -> HornBackend.solve
| Z3SMT -> SmtBackend.solve
| Z3SMT -> SmtBackend.solve *)

let pcomment ~body =
let open PrettyPrint in
Expand Down Expand Up @@ -75,13 +75,14 @@ let print_program ~o_map ~o_printer r ast =
pf "[%a]@ %a"
(ul print_type) t
(ul o_printer) (o_map o)
| Mu (id,t) ->
pf "%s '%d.@ %a"
Greek.mu
id
(ul print_type) t
| TVar id ->
pf "'%d" id
| IntList ol ->
pl [
ps "int list @[";
psep_gen (pf ", ") @@ List.map (fun o -> pf "%a" (ul o_printer) (o_map o)) ol;
ps "]"
]
in
let print_type_binding (k, t) = pb [pf "%s: " k; print_type t] in
let print_type_sep t = List.map print_type t |> psep_gen (pf ",@ ") in
Expand Down Expand Up @@ -113,12 +114,12 @@ let print_program ~o_map ~o_printer r ast =
in
AstPrinter.pretty_print_program ~annot:pp_ty_env ~annot_fn:pp_f_type stdout ast

let print_fold_locations simple_res =
(* let print_fold_locations simple_res =
let open SimpleChecker.SideAnalysis in
let _, side = simple_res in
print_endline "FOLD LOCATIONS >>>";
Std.IntSet.iter (Printf.printf "* %d\n") side.fold_locs;
print_endline "<<<"
print_endline "<<<" *)

let print_inference infer_res ast =
let open PrettyPrint in
Expand Down Expand Up @@ -164,10 +165,15 @@ let print_typecheck (f_types, side) ast =
let annot (id, _) e =
match Std.IntMap.find_opt id side.let_types, e with
| Some ty, Let (patt, _, _) -> from_ty_patt ty patt
| _ -> null in
| _ -> (
match Std.IntMap.find_opt id side.match_bindings, e with
| Some l, Match _ -> pl [ps "/* "; pl @@ List.map (fun (v, t) -> pf "%s: %s; " v @@ type_to_string t) l; ps "*/"; newline]
| _ -> null
)
in
AstPrinter.pretty_print_program ~annot_fn ~annot stdout ast

let to_hint o_res record =
(* let to_hint o_res record =
let open OwnershipInference in
let o_map = function
| OVar v -> List.assoc v o_res
Expand All @@ -176,15 +182,15 @@ let to_hint o_res record =
{
splits = SplitMap.map s_map record.splits;
gen = GenMap.map o_map record.gen
}
} *)

let get_solve ~opts =
(* let get_solve ~opts =
let open ArgOptions in
let module Backend = struct
let solve = choose_solver opts.solver
end in
let module S = FlowBackend.Make(Backend) in
S.solve
S.solve *)

let consort ~opts file =
let ast = AstUtil.parse_file file in
Expand All @@ -195,18 +201,18 @@ let consort ~opts file =
let ownership_res = OwnershipSolver.solve_ownership ~opts infer_res in
match ownership_res with
| None -> Unverified Aliasing
| Some o_res ->
let o_hint = to_hint o_res infer_res.op_record in
| Some _ -> Verified
(* let o_hint = to_hint o_res infer_res.op_record in
let solve = get_solve ~opts in
let ans = solve ~opts simple_res o_hint ast in
solver_result_to_check_result ans
solver_result_to_check_result ans *)

let ownership ~opts file =
let ast = AstUtil.parse_file file in
let intr_op = (ArgOptions.get_intr opts).op_interp in
let simple_op = RefinementTypes.to_simple_funenv intr_op in
let simple_res = SimpleChecker.typecheck_prog simple_op ast in
print_fold_locations simple_res;
(* print_fold_locations simple_res; *)
let infer_res = OwnershipInference.infer ~opts simple_res ast in
print_inference infer_res ast;
let ownership_res = OwnershipSolver.solve_ownership ~opts infer_res in
Expand All @@ -222,3 +228,22 @@ let typecheck ~opts file =
let simple_res = SimpleChecker.typecheck_prog simple_op ast in
print_typecheck simple_res ast;
Verified

let convmochi ~opts file =
let ast = AstUtil.parse_file file in
(* print_endline @@ Sexplib.Sexp.to_string @@ Ast.sexp_of_prog ast; *)
let intr_op = (ArgOptions.get_intr opts).op_interp in
let simple_op = RefinementTypes.to_simple_funenv intr_op in
let simple_res = SimpleChecker.typecheck_prog simple_op ast in
let infer_res = OwnershipInference.infer ~opts simple_res ast in
let ownership_res = OwnershipSolver.solve_ownership ~opts infer_res in
let prog =
ConvMoCHi.prog_to_mochi infer_res
((function Some x -> x | None -> assert false) ownership_res)
ast
in
(* ConvMoCHi.Mochi.print_prog prog; *)
let file = open_out "./test/to_mochi.ml" in
ConvMoCHi.Mochi.write_to_channel_prog prog file;
Out_channel.close file;
match ownership_res with None -> Unverified Aliasing | Some _ -> Verified
1 change: 1 addition & 0 deletions src/consort.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ val result_to_string : check_result -> string
val consort : opts:ArgOptions.t -> string -> check_result
val ownership : opts:ArgOptions.t -> string -> check_result
val typecheck : opts:ArgOptions.t -> string -> check_result
val convmochi : opts:ArgOptions.t -> string -> check_result
Loading
Loading