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

Variant records for globals #615

Open
strub opened this issue Sep 24, 2024 · 2 comments
Open

Variant records for globals #615

strub opened this issue Sep 24, 2024 · 2 comments

Comments

@strub
Copy link
Member

strub commented Sep 24, 2024

This would allow to refer to the components of a glob by name.

@alleystoughton
Copy link
Member

As someone who is trying to machine-generate code involving glob, it would be helpful if the field names were easily predictable. (Of course we can always reverse engineer from the EC code, but...)

@alleystoughton
Copy link
Member

Here is an example of thinking of glob in a hierarchical way. Unfortunately, in proof goals, glob is always eagerly expanded out into its components, which in the case of a complex hierarchy would be distracting and take up a lot of screen space. Is there a way to keep glob symbolic longer? I'm thinking/hoping this might be a consequence of moving to records for glob, which is why I'm posing this question on this issue.

require import AllCore.

module N = {
  var x : int
  proc f() : unit = {
    x <- x - 1;
  }
}.

(* we make all the metrics smt_opaque so SMT has to treat them
   as black boxes *)

op [smt_opaque] metric_N (g : glob N) : int = g.

lemma N_f_metric (n : int) :
  hoare [N.f : metric_N (glob N) = n ==> metric_N (glob N) < n].
proof.
rewrite /metric_N; proc; auto; smt().
qed.

module M = {
  var b : bool
  proc f() : unit = {
    if (b) {
      b <- false;
    }
    else {
      N.f();
    }
  }
}.

op glob_M_self (g : glob M) / : bool = g.`1.

op glob_M_to_N (g : glob M) / : glob N = g.`2.

op [smt_opaque] metric_M (g : glob M) : int =
  (if glob_M_self g then 1 else 0) +
  metric_N (glob_M_to_N g).

lemma M_f_metric (n : int) :
  hoare [M.f : metric_M (glob M) = n ==> metric_M (glob M) < n].
proof.
(*
Current goal

Type variables: <none>

n: int
------------------------------------------------------------------------
pre = metric_M (M.b, N.x) = n

    M.f

post = metric_M (M.b, N.x) < n
*)
proc.
if.
rewrite /metric_M; auto => |> /= /#.
exlim (glob M) => g.
call (N_f_metric (metric_N (glob_M_to_N g))).
rewrite /metric_M; auto => |>.
qed.

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

No branches or pull requests

2 participants