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

Draft: Revm: more automation and cases for the links #672

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions CoqOfRust/M.v
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ Module LowM.
| CallPrimitive (primitive : Primitive.t) (k : Value.t -> t A)
| CallClosure (ty : Ty.t) (closure : Value.t) (args : list Value.t) (k : A -> t A)
| Let (ty : Ty.t) (e : t A) (k : A -> t A)
| Loop (body : t A) (k : A -> t A)
| Loop (ty : Ty.t) (body : t A) (k : A -> t A)
| Impossible (message : string).
Arguments Pure {_}.
Arguments CallPrimitive {_}.
Expand All @@ -320,8 +320,8 @@ Module LowM.
CallClosure ty f args (fun v => let_ (k v) e2)
| Let ty e k =>
Let ty e (fun v => let_ (k v) e2)
| Loop body k =>
Loop body (fun v => let_ (k v) e2)
| Loop ty body k =>
Loop ty body (fun v => let_ (k v) e2)
| Impossible message => Impossible message
end.
End LowM.
Expand Down Expand Up @@ -704,8 +704,9 @@ Definition catch_break (body : M) : M :=
end
).

Definition loop (body : M) : M :=
Definition loop (ty : Ty.t) (body : M) : M :=
LowM.Loop
ty
(catch_continue body)
(fun result =>
catch_break (LowM.Pure result)).
Expand Down Expand Up @@ -765,6 +766,21 @@ Definition never_to_any (x : Value.t) : M :=
Definition use (x : Value.t) : Value.t :=
x.

Definition borrow (kind : Pointer.Kind.t) (value : Value.t) : M :=
match value with
| Value.Pointer {| Pointer.kind := Pointer.Kind.Raw; Pointer.core := core |} =>
pure (Value.Pointer {| Pointer.kind := kind; Pointer.core := core |})
| _ => impossible "expected a raw pointer"
end.
Global Opaque borrow.

Definition deref (value : Value.t) : M :=
match value with
| Value.Pointer pointer => pure (Value.Pointer (Pointer.deref pointer))
| _ => impossible "expected a pointer"
end.
Global Opaque deref.

Module SubPointer.
Definition get_tuple_field (value : Value.t) (index : Z) : M :=
get_sub_pointer value (Pointer.Index.Tuple index).
Expand All @@ -776,7 +792,9 @@ Module SubPointer.
end.

Definition get_struct_tuple_field (value : Value.t) (constructor : string) (index : Z) : M :=
let* value := deref value in
get_sub_pointer value (Pointer.Index.StructTuple constructor index).
Arguments get_struct_tuple_field /.

Definition get_struct_record_field (value : Value.t) (constructor field : string) : M :=
get_sub_pointer value (Pointer.Index.StructRecord constructor field).
Expand All @@ -801,21 +819,6 @@ Definition if_then_else_bool (condition : Value.t) (then_ else_ : M) : M :=
| _ => impossible "if_then_else_bool: expected a boolean"
end.

Definition borrow (kind : Pointer.Kind.t) (value : Value.t) : M :=
match value with
| Value.Pointer {| Pointer.kind := Pointer.Kind.Raw; Pointer.core := core |} =>
pure (Value.Pointer {| Pointer.kind := kind; Pointer.core := core |})
| _ => impossible "expected a raw pointer"
end.
Global Opaque borrow.

Definition deref (value : Value.t) : M :=
match value with
| Value.Pointer pointer => pure (Value.Pointer (Pointer.deref pointer))
| _ => impossible "expected a pointer"
end.
Global Opaque deref.

Definition is_constant_or_break_match (value expected_value : Value.t) : M :=
let* are_equal := are_equal value expected_value in
if_then_else_bool are_equal (pure (Value.Tuple [])) break_match.
Expand Down Expand Up @@ -885,6 +888,6 @@ Fixpoint run_constant (constant : M) : Value.t :=
run_constant (k value)
| LowM.CallClosure _ _ _ _ => Value.Error "unexpected closure call"
| LowM.Let _ _ _ => Value.Error "unexpected let"
| LowM.Loop _ _ => Value.Error "unexpected loop"
| LowM.Loop _ _ _ => Value.Error "unexpected loop"
| LowM.Impossible _ => Value.Error "impossible"
end.
7 changes: 7 additions & 0 deletions CoqOfRust/alloc/collections/binary_heap/mod.v
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,7 @@ Module collections.
|) in
let~ _ : Ty.tuple [] :=
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (| Value.Tuple [] |),
Expand Down Expand Up @@ -2018,6 +2019,7 @@ Module collections.
|) in
let~ _ : Ty.tuple [] :=
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (| Value.Tuple [] |),
Expand Down Expand Up @@ -2326,6 +2328,7 @@ Module collections.
|) in
let~ _ : Ty.tuple [] :=
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (| Value.Tuple [] |),
Expand Down Expand Up @@ -2875,6 +2878,7 @@ Module collections.
|) in
let~ _ : Ty.tuple [] :=
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (| Value.Tuple [] |),
Expand Down Expand Up @@ -3453,6 +3457,7 @@ Module collections.
ltac:(M.monadic
(let iter := M.copy (| γ |) in
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(let~ _ : Ty.tuple [] :=
M.match_operator (|
Expand Down Expand Up @@ -3586,6 +3591,7 @@ Module collections.
|)
|) in
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (| Value.Tuple [] |),
Expand Down Expand Up @@ -7504,6 +7510,7 @@ Module collections.
(let self := M.alloc (| self |) in
M.read (|
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (| Value.Tuple [] |),
Expand Down
3 changes: 3 additions & 0 deletions CoqOfRust/alloc/collections/btree/append.v
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ Module collections.
ltac:(M.monadic
(let iter := M.copy (| γ |) in
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(let~ _ : Ty.tuple [] :=
M.match_operator (|
Expand Down Expand Up @@ -500,6 +501,7 @@ Module collections.
|) in
let~ _ : Ty.tuple [] :=
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (|
Expand Down Expand Up @@ -960,6 +962,7 @@ Module collections.
ltac:(M.monadic
(let iter := M.copy (| γ |) in
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(let~ _ : Ty.tuple [] :=
M.match_operator (|
Expand Down
1 change: 1 addition & 0 deletions CoqOfRust/alloc/collections/btree/dedup_sorted_iter.v
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Module collections.
(M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(let~ next : Ty.tuple [ K; V ] :=
M.copy (|
Expand Down
5 changes: 5 additions & 0 deletions CoqOfRust/alloc/collections/btree/fix.v
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ Module collections.
(M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.match_operator (|
M.alloc (|
Expand Down Expand Up @@ -683,6 +684,7 @@ Module collections.
let alloc := M.alloc (| alloc |) in
M.read (|
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (| Value.Tuple [] |),
Expand Down Expand Up @@ -1353,6 +1355,7 @@ Module collections.
|)
|) in
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (| Value.Tuple [] |),
Expand Down Expand Up @@ -1729,6 +1732,7 @@ Module collections.
let alloc := M.alloc (| alloc |) in
M.read (|
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (| Value.Tuple [] |),
Expand Down Expand Up @@ -2129,6 +2133,7 @@ Module collections.
let alloc := M.alloc (| alloc |) in
M.read (|
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (| Value.Tuple [] |),
Expand Down
3 changes: 3 additions & 0 deletions CoqOfRust/alloc/collections/btree/map.v
Original file line number Diff line number Diff line change
Expand Up @@ -15273,6 +15273,7 @@ Module collections.
(let self := M.alloc (| self |) in
M.read (|
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (| Value.Tuple [] |),
Expand Down Expand Up @@ -17662,6 +17663,7 @@ Module collections.
(M.read (|
let~ _ : Ty.tuple [] :=
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (| Value.Tuple [] |),
Expand Down Expand Up @@ -21321,6 +21323,7 @@ Module collections.
ltac:(M.monadic
(let iter := M.copy (| γ |) in
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(let~ _ : Ty.tuple [] :=
M.match_operator (|
Expand Down
12 changes: 12 additions & 0 deletions CoqOfRust/alloc/collections/btree/navigate.v
Original file line number Diff line number Diff line change
Expand Up @@ -5815,6 +5815,7 @@ Module collections.
M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.match_operator (|
M.alloc (|
Expand Down Expand Up @@ -6394,6 +6395,7 @@ Module collections.
M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.match_operator (|
M.alloc (|
Expand Down Expand Up @@ -6644,6 +6646,7 @@ Module collections.
M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.match_operator (|
M.alloc (|
Expand Down Expand Up @@ -6905,6 +6908,7 @@ Module collections.
M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.match_operator (|
M.alloc (|
Expand Down Expand Up @@ -7173,6 +7177,7 @@ Module collections.
M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.match_operator (|
M.alloc (|
Expand Down Expand Up @@ -7771,6 +7776,7 @@ Module collections.
M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.alloc (|
M.write (|
Expand Down Expand Up @@ -8759,6 +8765,7 @@ Module collections.
M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.alloc (|
M.write (|
Expand Down Expand Up @@ -9152,6 +9159,7 @@ Module collections.
M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.alloc (|
M.write (|
Expand Down Expand Up @@ -9520,6 +9528,7 @@ Module collections.
M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.alloc (|
M.write (|
Expand Down Expand Up @@ -9887,6 +9896,7 @@ Module collections.
M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.alloc (|
M.write (|
Expand Down Expand Up @@ -10404,6 +10414,7 @@ Module collections.
M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.alloc (|
M.write (|
Expand Down Expand Up @@ -10906,6 +10917,7 @@ Module collections.
|)
|) in
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(M.match_operator (|
M.alloc (| Value.Tuple [] |),
Expand Down
2 changes: 2 additions & 0 deletions CoqOfRust/alloc/collections/btree/node.v
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,7 @@ Module collections.
ltac:(M.monadic
(let iter := M.copy (| γ |) in
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(let~ _ : Ty.tuple [] :=
M.match_operator (|
Expand Down Expand Up @@ -10777,6 +10778,7 @@ Module collections.
M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(let~ _ : Ty.tuple [] :=
M.alloc (|
Expand Down
3 changes: 3 additions & 0 deletions CoqOfRust/alloc/collections/btree/search.v
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ Module collections.
(M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.alloc (|
M.write (|
Expand Down Expand Up @@ -1033,6 +1034,7 @@ Module collections.
M.never_to_any (|
M.read (|
M.loop (|
Ty.path "never",
ltac:(M.monadic
(M.match_operator (|
M.alloc (|
Expand Down Expand Up @@ -2264,6 +2266,7 @@ Module collections.
ltac:(M.monadic
(let iter := M.copy (| γ |) in
M.loop (|
Ty.tuple [],
ltac:(M.monadic
(let~ _ : Ty.tuple [] :=
M.match_operator (|
Expand Down
Loading
Loading