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

Allow unfolding of basic non-recursive predicates #12

Open
wants to merge 6 commits into
base: StagedSL
Choose a base branch
from

Conversation

EmilyOng
Copy link
Collaborator

@EmilyOng EmilyOng commented Feb 5, 2024

Closes #10

Allow unfolding of basic non-recursive predicates by travering the predicate's disj_spec body during instantiation to check if the predicate name occurs in any function stages.

@EmilyOng EmilyOng marked this pull request as draft February 5, 2024 04:02
Copy link
Collaborator

@dariusf dariusf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Feel free to merge once you find a good place for find_rec.

parsing/Pretty.ml Outdated Show resolved Hide resolved
@@ -305,7 +305,7 @@ let instantiate_pred : pred_def -> term list -> term -> pred_def =
(string_of_list (string_of_list string_of_staged_spec) bbody); *)
bbody
in
{ pred with p_body }
{ pred with p_body; p_rec = (find_rec pred.p_name)#visit_disj_spec () p_body }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to set this here? Seems like it should already be set.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It is not needed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, I think you were right to include it initially... I missed the call to instantiateStages, which can replace higher-order stages and change whether a predicate is recursive. Does that agree with your tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry for the late reply:

I think adding the assignment here might not help. For example, in this program:

let rec call_ret f n
= if n = 0 then f 100
  else let g = call_ret in g f (n - 1)

let test_non_rec_pred n
(*@ ens res=100 @*)
= let id i = i in

  call_ret id n

We will check if the predicate name call_ret occurs in the following staged specification:

ex v74; ens (n==0)=true; v54(100, v74); ens v52=v74 \/ ex v79 v80 v81; ens (n==0)=false/\v81=call_ret/\v80=n-1; v81(v54, v80, v79); ens v52=v79

Which will be false because call_ret != v81 so p_rec will be wrongly assigned as non-recursive.

I tried to fix this by including an additional visit_Atomic in the visitor, so that it can check for v81=call_ret.

@@ -32,8 +32,8 @@ let main ()
(* L2: the call here is only valid after L1*)
call_ret swap

let main1_false ()
(*@ Norm(emp, 1) @*)
let main1 ()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed _false and moved this into the test file since this example works now

@EmilyOng EmilyOng marked this pull request as ready for review February 7, 2024 08:40
@EmilyOng
Copy link
Collaborator Author

EmilyOng commented Feb 13, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use of inferred specification in entailment
2 participants