Skip to content

Commit dc3bcbd

Browse files
authored
Merge pull request #759 from formal-land/guillaume-claret@more-instructions-simulate
simulate: support more instructions
2 parents cb352f2 + b7c69b5 commit dc3bcbd

File tree

15 files changed

+794
-264
lines changed

15 files changed

+794
-264
lines changed

CoqOfRust/M.v

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ Module LowM.
392392
| LetAlloc (ty : Ty.t) (e : t A) (k : A -> t A)
393393
| Loop (ty : Ty.t) (body : t A) (k : A -> t A)
394394
| MatchTuple (tuple : Value.t) (k : list Value.t -> t A)
395+
| IfThenElse (ty : Ty.t) (cond : Value.t) (then_ : t A) (else_ : t A) (k : A -> t A)
395396
| Impossible (message : string).
396397
Arguments Pure {_}.
397398
Arguments CallPrimitive {_}.
@@ -401,6 +402,7 @@ Module LowM.
401402
Arguments LetAlloc {_}.
402403
Arguments Loop {_}.
403404
Arguments MatchTuple {_}.
405+
Arguments IfThenElse {_}.
404406
Arguments Impossible {_}.
405407

406408
Fixpoint let_ {A : Set} (e1 : t A) (e2 : A -> t A) : t A :=
@@ -420,6 +422,8 @@ Module LowM.
420422
LetAlloc ty e (fun v => let_ (k v) e2)
421423
| MatchTuple tuple k =>
422424
MatchTuple tuple (fun fields => let_ (k fields) e2)
425+
| IfThenElse ty cond then_ else_ k =>
426+
IfThenElse ty cond then_ else_ (fun v => let_ (k v) e2)
423427
| Impossible message => Impossible message
424428
end.
425429
End LowM.
@@ -922,13 +926,8 @@ Module SubPointer.
922926
Parameter get_slice_rest : Value.t -> Z -> Z -> M.
923927
End SubPointer.
924928

925-
(** Explicit definition to simplify the links later *)
926-
Definition if_then_else_bool (condition : Value.t) (then_ else_ : M) : M :=
927-
match condition with
928-
| Value.Bool true => then_
929-
| Value.Bool false => else_
930-
| _ => impossible "if_then_else_bool: expected a boolean"
931-
end.
929+
Definition if_then_else_bool (ty : Ty.t) (condition : Value.t) (then_ else_ : M) : M :=
930+
LowM.IfThenElse ty condition then_ else_ LowM.Pure.
932931

933932
Definition is_struct_tuple (value : Value.t) (constructor : string) : M :=
934933
let* value := deref value in

CoqOfRust/core/ops/links/function.v

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ Module Impl_FnOnce_for_Function2.
3939
{ constructor.
4040
destruct args as [a1 a2].
4141
with_strategy transparent [φ] cbn.
42-
run_symbolic_closure.
43-
intros []; run_symbolic.
42+
run_symbolic.
4443
}
4544
Defined.
4645

CoqOfRust/examples/default/examples/custom/simulate/mutations.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Module Option.
1313

1414
Lemma unwrap_or_eq {A : Set} `{Link A} (value : option A) (default : A) :
1515
{{
16-
StackM.eval_f (Stack := []) (run_unwrap_or value default) tt 🌲
16+
SimulateM.eval_f (Stack := []) (run_unwrap_or value default) tt 🌲
1717
(Output.Success (unwrap_or value default), tt)
1818
}}.
1919
Proof.
@@ -37,7 +37,7 @@ Lemma apply_duplicate_eq (numbers : Numbers.t) :
3737
let ref_numbers :=
3838
{| Ref.core := Ref.Core.Mutable (A := Numbers.t) 0%nat [] φ Some (fun _ => Some) |} in
3939
{{
40-
StackM.eval_f (Stack := [_]) (run_apply_duplicate ref_numbers) (numbers, tt) 🌲
40+
SimulateM.eval_f (Stack := [_]) (run_apply_duplicate ref_numbers) (numbers, tt) 🌲
4141
(Output.Success tt, (apply_duplicate numbers, tt))
4242
}}.
4343
Proof.
@@ -54,7 +54,7 @@ Lemma duplicate_eq (a b c : U64.t) :
5454
let ref_b := {| Ref.core := Ref.Core.Mutable (A := U64.t) 1%nat [] φ Some (fun _ => Some) |} in
5555
let ref_c := {| Ref.core := Ref.Core.Mutable (A := U64.t) 2%nat [] φ Some (fun _ => Some) |} in
5656
{{
57-
StackM.eval_f (Stack := [_; _; _]) (run_duplicate ref_a ref_b ref_c) (a, (b, (c, tt))) 🌲
57+
SimulateM.eval_f (Stack := [_; _; _]) (run_duplicate ref_a ref_b ref_c) (a, (b, (c, tt))) 🌲
5858
(Output.Success tt, (a, (a, (a, tt))))
5959
}}.
6060
Proof.

CoqOfRust/lib/lib.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ Global Opaque repeat.
295295

296296
Definition is_constant_or_break_match (value expected_value : Value.t) : M :=
297297
let* are_equal := M.call_closure (Ty.path "bool") BinOp.eq [value; expected_value] in
298-
if_then_else_bool are_equal (pure (Value.Tuple [])) break_match.
298+
if_then_else_bool (Ty.tuple []) are_equal (pure (Value.Tuple [])) break_match.
299299

300300
(** There is an automatic instanciation of the function traits for closures and functions. *)
301301
Module FunctionTraitAutomaticImpl.

0 commit comments

Comments
 (0)