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

Add more links definitions for the gas #652

Merged
merged 1 commit into from
Feb 3, 2025
Merged
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
8 changes: 3 additions & 5 deletions CoqOfRust/core/links/cmp.v
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Proof.
eapply Run.CallClosure. {
apply (run_call_once compare (Ref.immediate _ v1, Ref.immediate _ v2)).
}
intros [ordering |]; cbn; [|run_symbolic].
intros [ordering|]; run_symbolic.
destruct ordering; run_symbolic.
Defined.

Expand Down Expand Up @@ -110,8 +110,7 @@ Module Ord.
{| Function2.run := run_cmp |}
).
}
intros.
run_symbolic.
intros []; run_symbolic.
Defined.

Definition run_min {Self : Set} `{Link Self} (self other : Self)
Expand Down Expand Up @@ -146,8 +145,7 @@ Module Impl_Ord_for_u64.
eapply Run.CallClosure. {
apply (intrinsics.run_three_way_compare IntegerKind.U64).
}
intros.
run_symbolic.
intros []; run_symbolic.
}
Defined.

Expand Down
8 changes: 8 additions & 0 deletions CoqOfRust/core/links/intrinsics.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ Lemma run_three_way_compare (integer_kind : IntegerKind.t) (x y : Integer.t inte
{{ intrinsics.three_way_compare [] [ Φ (Integer.t integer_kind) ] [ φ x; φ y ] 🔽 Ordering.t }}.
Proof.
Admitted.

Lemma run_saturating_add (integer_kind : IntegerKind.t) (x y : Integer.t integer_kind) :
{{
intrinsics.saturating_add [] [ Φ (Integer.t integer_kind) ] [ φ x; φ y ] 🔽
Integer.t integer_kind
}}.
Proof.
Admitted.
29 changes: 28 additions & 1 deletion CoqOfRust/core/links/option.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,39 @@ Require Import CoqOfRust.CoqOfRust.
Require Import links.M.

Module Option.
Global Instance IsLink (A : Set) (_ : Link A) : Link (option A) := {
Global Instance IsLink (A : Set) `{Link A} : Link (option A) := {
Φ := Ty.apply (Ty.path "core::option::Option") [] [Φ A];
φ x :=
match x with
| None => Value.StructTuple "core::option::Option::None" []
| Some x => Value.StructTuple "core::option::Option::Some" [φ x]
end;
}.

Lemma of_value_with_None {A : Set} `{Link A} :
Value.StructTuple "core::option::Option::None" [] =
φ (None (A := A)).
Proof. reflexivity. Qed.
Smpl Add apply of_value_with_None : of_value.

Lemma of_value_with_Some {A : Set} `{Link A} (value : A) value' :
value' = φ value ->
Value.StructTuple "core::option::Option::Some" [value'] =
φ (Some value).
Proof. intros; subst; reflexivity. Qed.
Smpl Add apply of_value_with_Some : of_value.

Definition of_value_None {A : Set} `{Link A} :
OfValue.t (Value.StructTuple "core::option::Option::None" []).
Proof. eapply OfValue.Make with (A := option A); apply of_value_with_None. Defined.
Smpl Add eapply of_value_None : of_value.

Definition of_value_Some {A : Set} `{Link A} (value : A) value' :
value' = φ value ->
OfValue.t (Value.StructTuple "core::option::Option::Some" [value']).
Proof.
intros; eapply OfValue.Make with (A := option A).
apply of_value_with_Some; eassumption.
Defined.
Smpl Add eapply of_value_Some : of_value.
End Option.
31 changes: 31 additions & 0 deletions CoqOfRust/core/num/links/mod.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Require Import CoqOfRust.CoqOfRust.
Require Import CoqOfRust.links.lib.
Require Import CoqOfRust.links.M.
Require Import core.num.mod.
Require Import core.intrinsics.
Require core.links.intrinsics.

Import Run.

Module Impl_u64.
Definition Self : Set := U64.t.

(*
pub const fn saturating_add(self, rhs: Self) -> Self {
intrinsics::saturating_add(self, rhs)
}
*)
Lemma run_saturating_add (self rhs: Self) :
{{ num.Impl_u64.saturating_add [] [] [ φ self; φ rhs ] 🔽 Self }}.
Proof.
run_symbolic.
eapply Run.CallPrimitiveGetFunction. {
eapply intrinsics.Function_saturating_add.
}
run_symbolic.
eapply Run.CallClosure. {
apply (intrinsics.run_saturating_add IntegerKind.U64).
}
intros []; run_symbolic.
Defined.
End Impl_u64.
3 changes: 1 addition & 2 deletions CoqOfRust/core/ops/links/function.v
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ Module Impl_FnOnce_for_Function2.
eapply Run.CallClosure. {
apply self.
}
intros.
run_symbolic.
intros []; run_symbolic.
}
Defined.

Expand Down
Loading
Loading