Skip to content

Commit

Permalink
Add an option to split the fwd/back functions and fix a minor issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sonmarcho committed Dec 22, 2023
1 parent 632e2dd commit 3688596
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,29 @@ testp-%: gen-llbcp-% tfstarp-% tcoqp-% tleanp-% thol4p-%
.PHONY: tfstar-%
tfstar-%: OPTIONS += -backend fstar
tfstar-%: BACKEND_SUBDIR := fstar
tfstar-%:
tfstar-%: tsplit-fstar-%
$(AENEAS_CMD)

# "p" stands for "Polonius"
.PHONY: tfstarp-%
tfstarp-%: OPTIONS += -backend fstar
tfstarp-%: BACKEND_SUBDIR := fstar
tfstarp-%:
tfstarp-%: tsplit-fstarp-%
$(AENEAS_CMD)

# Test where we split the forward/backward functions
.PHONY: tsplit-fstar-%
tsplit-fstar-%: OPTIONS += -backend fstar -split-fwd-back
tsplit-fstar-%: BACKEND_SUBDIR := fstar-split
tsplit-fstar-%:
$(AENEAS_CMD)

# Test where we split the forward/backward functions
# "p" stands for "Polonius"
.PHONY: tsplit-fstarp-%
tsplit-fstarp-%: OPTIONS += -backend fstar -split-fwd-back
tsplit-fstarp-%: BACKEND_SUBDIR := fstar-split
tsplit-fstarp-%:
$(AENEAS_CMD)

.PHONY: tcoq-%
Expand Down
3 changes: 3 additions & 0 deletions compiler/Main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ let () =
" Generate a default lakefile.lean (Lean only)" );
("-print-llbc", Arg.Set print_llbc, " Print the imported LLBC");
("-k", Arg.Clear fail_hard, " Do not fail hard in case of error");
( "-split-fwd-back",
Arg.Clear return_back_funs,
" Split the forward and backward functions." );
]
in

Expand Down
19 changes: 12 additions & 7 deletions compiler/SymbolicToPure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1076,24 +1076,29 @@ let translate_fun_sig_with_regions_hierarchy_to_decomposed
let inputs_no_state =
List.map (fun ty -> (Some "ret", ty)) inputs_no_state
in
(* We consider the backward function as stateful and potentially failing
(* In case we merge the forward/backward functions:
we consider the backward function as stateful and potentially failing
**only if it has inputs** (for the "potentially failing": if it has
not inputs, we directly evaluate it in the body of the forward function).
*)
let back_effect_info =
{
back_effect_info with
stateful = back_effect_info.stateful && inputs_no_state <> [];
can_fail = back_effect_info.can_fail && inputs_no_state <> [];
}
if !Config.return_back_funs then
let b = inputs_no_state <> [] in
{
back_effect_info with
stateful = back_effect_info.stateful && b;
can_fail = back_effect_info.can_fail && b;
}
else back_effect_info
in
let state =
if back_effect_info.stateful then [ (None, mk_state_ty) ] else []
in
let inputs = inputs_no_state @ state in
let output_names, outputs = compute_back_outputs_for_gid gid in
let filter =
!Config.simplify_merged_fwd_backs && inputs = [] && outputs = []
!Config.simplify_merged_fwd_backs
&& !Config.return_back_funs && inputs = [] && outputs = []
in
let info =
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: test-fstar test-coq test-lean test-hol4
all: test-fstar test-fstar-split test-coq test-lean test-hol4

test-%:
cd $* && $(MAKE) all

0 comments on commit 3688596

Please sign in to comment.