Skip to content

Commit 5febecb

Browse files
committed
simulations: evaluation of a function with a reference and a sub-pointer
1 parent 4bf96a4 commit 5febecb

File tree

8 files changed

+408
-177
lines changed

8 files changed

+408
-177
lines changed

CoqOfRust/M.v

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ Module Pointer.
131131

132132
Module Core.
133133
Inductive t (Value : Set) : Set :=
134-
| Immediate (value : Value)
134+
(** The immediate value is optional in case with have a sub-pointer of an immediate pointer for
135+
an enum case that is not the current one. *)
136+
| Immediate (value : option Value)
135137
| Mutable {Address : Set} (address : Address) (path : Path.t).
136138
Arguments Immediate {_}.
137139
Arguments Mutable {_ _}.
@@ -910,13 +912,13 @@ Fixpoint run_constant (constant : M) : Value.t :=
910912
| Primitive.StateAlloc value =>
911913
Value.Pointer {|
912914
Pointer.kind := Pointer.Kind.Raw;
913-
Pointer.core := Pointer.Core.Immediate value;
915+
Pointer.core := Pointer.Core.Immediate (Some value);
914916
|}
915917
| Primitive.StateRead pointer =>
916918
match pointer with
917919
| Value.Pointer {|
918920
Pointer.kind := Pointer.Kind.Raw;
919-
Pointer.core := Pointer.Core.Immediate value;
921+
Pointer.core := Pointer.Core.Immediate (Some value);
920922
|} =>
921923
value
922924
| _ => Value.Error "expected an immediate raw pointer"

CoqOfRust/blacklist.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ examples/axiomatized/examples/subtle.v
99
# These files take a very long time (ten minutes)
1010
# revm/revm_bytecode/opcode.v
1111
revm/types.v
12-
revm/revm_interpreter/simulations/gas.v
1312
core/array/mod.v
1413
core/future/async_drop.v
1514
core/iter/adapters/flatten.v

CoqOfRust/core/links/array.v

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,18 @@ Proof.
6262
rewrite repeat_nat_φ_eq.
6363
reflexivity.
6464
Qed.
65+
66+
Definition of_value (times : Z) (value' : Value.t) :
67+
OfValue.t value' ->
68+
OfValue.t (
69+
Value.Array (repeat_nat (Z.to_nat times) value')
70+
).
71+
Proof.
72+
intros [A ? item].
73+
eapply OfValue.Make with
74+
(A := t A {| Integer.value := times |})
75+
(value := {| value := repeat_nat (Z.to_nat times) item |}).
76+
subst.
77+
now rewrite repeat_nat_φ_eq.
78+
Defined.
79+
Smpl Add eapply of_value : of_value.

CoqOfRust/links/M.v

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ End Slice.
362362
Module Ref.
363363
Module Core.
364364
Inductive t (A : Set) `{Link A} : Set :=
365-
| Immediate (value : A)
365+
(** The value is optional for pointers to an enum case that is not the current one. *)
366+
| Immediate (value : option A)
366367
| Mutable {Address Big_A : Set}
367368
(address : Address)
368369
(path : Pointer.Path.t)
@@ -375,7 +376,7 @@ Module Ref.
375376
Definition to_core {A : Set} `{Link A} (ref : t A) : Pointer.Core.t Value.t :=
376377
match ref with
377378
| Immediate value =>
378-
Pointer.Core.Immediate (φ value)
379+
Pointer.Core.Immediate (Option.map value φ)
379380
| Mutable address path big_to_value projection injection =>
380381
Pointer.Core.Mutable address path
381382
end.
@@ -403,7 +404,7 @@ Module Ref.
403404
}.
404405

405406
Definition immediate (kind : Pointer.Kind.t) {A : Set} `{Link A} (value : A) : t kind A :=
406-
{| core := Core.Immediate value |}.
407+
{| core := Core.Immediate (Some value) |}.
407408

408409
Definition cast_to {A : Set} `{Link A} {kind_source : Pointer.Kind.t}
409410
(kind_target : Pointer.Kind.t) (ref : t kind_source A) :
@@ -495,7 +496,7 @@ Module Ref.
495496
value' = φ value ->
496497
Value.Pointer {|
497498
Pointer.kind := Pointer.Kind.Raw;
498-
Pointer.core := Pointer.Core.Immediate value';
499+
Pointer.core := Pointer.Core.Immediate (Some value');
499500
|} = φ (immediate Pointer.Kind.Raw value).
500501
Proof.
501502
now intros; subst.
@@ -506,7 +507,7 @@ Module Ref.
506507
OfValue.t value' ->
507508
OfValue.t (Value.Pointer {|
508509
Pointer.kind := Pointer.Kind.Raw;
509-
Pointer.core := Pointer.Core.Immediate value';
510+
Pointer.core := Pointer.Core.Immediate (Some value');
510511
|}).
511512
Proof.
512513
intros [A].
@@ -564,6 +565,52 @@ Module SubPointer.
564565
Value.write_index (φ a) index (φ sub_a);
565566
}.
566567
End Valid.
568+
569+
Definition apply {A : Set} `{Link A} {index : Pointer.Index.t}
570+
(ref_core : Ref.Core.t A)
571+
(runner : SubPointer.Runner.t A index) :
572+
let _ := runner.(H_Sub_A) in
573+
Ref.Core.t runner.(Sub_A).
574+
Proof.
575+
destruct
576+
ref_core as [| ? ? address path big_to_value projection injection],
577+
runner as [? ? runner_projection runner_injection];
578+
cbn.
579+
{ (* Immediate *)
580+
exact (
581+
Ref.Core.Immediate (
582+
match value with
583+
| Some a => runner_projection a
584+
| None => None
585+
end
586+
)
587+
).
588+
}
589+
{ (* Mutable *)
590+
exact (
591+
Ref.Core.Mutable
592+
address
593+
(path ++ [index])
594+
big_to_value
595+
(fun big_a =>
596+
match projection big_a with
597+
| Some a => runner_projection a
598+
| None => None
599+
end
600+
)
601+
(fun big_a new_sub_a =>
602+
match projection big_a with
603+
| Some a =>
604+
match runner_injection a new_sub_a with
605+
| Some new_a => injection big_a new_a
606+
| None => None
607+
end
608+
| None => None
609+
end
610+
)
611+
).
612+
}
613+
Defined.
567614
End Runner.
568615
End SubPointer.
569616

@@ -693,6 +740,9 @@ Module Output.
693740
inr exception' = to_value (Output.Exception (R := R) exception).
694741
Proof. now intros; subst. Qed.
695742
Smpl Add apply of_exception_eq : of_output.
743+
744+
Definition panic {R Output : Set} (message : string) : t R Output :=
745+
Exception (Exception.Panic (Panic.Make message)).
696746
End Output.
697747

698748
(** For the output of closure calls, where we know it can only be a success or panic, but not a
@@ -716,6 +766,15 @@ Module SuccessOrPanic.
716766
| Success output => Output.Success output
717767
| Panic panic => Output.Exception (Output.Exception.Panic panic)
718768
end.
769+
770+
Definition of_output {Output : Set} (output : Output.t Output Output) :
771+
t Output :=
772+
match output with
773+
| Output.Success output => Success output
774+
| Output.Exception (Output.Exception.Panic panic) => Panic panic
775+
| Output.Exception _ =>
776+
Panic (Panic.Make "unexpected return, break, or continue escaping a function")
777+
end.
719778
End SuccessOrPanic.
720779

721780
Module Run.
@@ -1082,8 +1141,16 @@ Ltac run_symbolic_pure :=
10821141
repeat smpl of_value
10831142
).
10841143

1144+
Ltac run_symbolic_state_alloc :=
1145+
unshelve eapply Run.CallPrimitiveStateAlloc; [
1146+
repeat smpl of_value |
1147+
cbn; intros
1148+
].
1149+
10851150
Ltac run_symbolic_state_alloc_immediate :=
1086-
unshelve eapply Run.CallPrimitiveStateAllocImmediate; [now repeat smpl of_value |].
1151+
unshelve eapply Run.CallPrimitiveStateAllocImmediate; [
1152+
repeat smpl of_value |
1153+
].
10871154

10881155
Ltac run_symbolic_state_read :=
10891156
eapply Run.CallPrimitiveStateRead;
@@ -1294,7 +1361,11 @@ Ltac rewrite_cast_integer :=
12941361
end.
12951362

12961363
Ltac run_symbolic_let :=
1297-
unshelve eapply Run.Let; [repeat smpl of_ty | | cbn; intros []].
1364+
unshelve eapply Run.Let; [
1365+
repeat smpl of_ty |
1366+
try run_symbolic_state_alloc |
1367+
cbn; intros []
1368+
].
12981369

12991370
Ltac run_symbolic_are_equal_bool :=
13001371
eapply Run.CallPrimitiveAreEqualBool;

0 commit comments

Comments
 (0)