diff options
-rw-r--r-- | backends/lean/Base/Primitives/Base.lean | 5 | ||||
-rw-r--r-- | backends/lean/Base/Primitives/Core.lean | 8 | ||||
-rw-r--r-- | backends/lean/Base/Primitives/Scalar.lean | 5 | ||||
-rw-r--r-- | compiler/ExtractBuiltin.ml | 2 | ||||
-rw-r--r-- | tests/coq/betree/BetreeMain_FunsExternal_Template.v | 7 | ||||
-rw-r--r-- | tests/fstar/betree/BetreeMain.FunsExternal.fsti | 6 | ||||
-rw-r--r-- | tests/fstar/betree_back_stateful/BetreeMain.FunsExternal.fsti | 6 | ||||
-rw-r--r-- | tests/lean/BetreeMain/FunsExternal.lean | 5 | ||||
-rw-r--r-- | tests/lean/BetreeMain/FunsExternal_Template.lean | 6 | ||||
-rw-r--r-- | tests/lean/External/FunsExternal.lean | 1 |
10 files changed, 15 insertions, 36 deletions
diff --git a/backends/lean/Base/Primitives/Base.lean b/backends/lean/Base/Primitives/Base.lean index 94134d86..d682e926 100644 --- a/backends/lean/Base/Primitives/Base.lean +++ b/backends/lean/Base/Primitives/Base.lean @@ -76,6 +76,11 @@ def eval_global {α: Type u} (x: Result α) (_: ok? x := by prove_eval_global) : | fail _ | div => by contradiction | ok x => x +def Result.ofOption {a : Type u} (x : Option a) (e : Error) : Result a := + match x with + | some x => ok x + | none => fail e + /- DO-DSL SUPPORT -/ def bind {α : Type u} {β : Type v} (x: Result α) (f: α → Result β) : Result β := diff --git a/backends/lean/Base/Primitives/Core.lean b/backends/lean/Base/Primitives/Core.lean index 99f65985..b7dd6d2c 100644 --- a/backends/lean/Base/Primitives/Core.lean +++ b/backends/lean/Base/Primitives/Core.lean @@ -51,4 +51,12 @@ def clone.CloneBool : clone.Clone Bool := { clone := fun b => ok (clone.impls.CloneBool.clone b) } +namespace option + +/- [core::option::{core::option::Option<T>}::unwrap] -/ +def Option.unwrap (T : Type) (x : Option T) : Result T := + Result.ofOption x Error.panic + +end option -- core.option + end core diff --git a/backends/lean/Base/Primitives/Scalar.lean b/backends/lean/Base/Primitives/Scalar.lean index 014decb1..2bee8a2f 100644 --- a/backends/lean/Base/Primitives/Scalar.lean +++ b/backends/lean/Base/Primitives/Scalar.lean @@ -364,11 +364,6 @@ def Scalar.tryMkOpt (ty : ScalarTy) (x : Int) : Option (Scalar ty) := some (Scalar.ofIntCore x (Scalar.check_bounds_imp_in_bounds h)) else none -def Result.ofOption {a : Type u} (x : Option a) (e : Error) : Result a := - match x with - | some x => ok x - | none => fail e - def Scalar.tryMk (ty : ScalarTy) (x : Int) : Result (Scalar ty) := Result.ofOption (tryMkOpt ty x) integerOverflow diff --git a/compiler/ExtractBuiltin.ml b/compiler/ExtractBuiltin.ml index c6827bbe..d4a6f736 100644 --- a/compiler/ExtractBuiltin.ml +++ b/compiler/ExtractBuiltin.ml @@ -387,6 +387,8 @@ let builtin_funs () : (pattern * bool list option * builtin_fun_info) list = @A>>}::deref_mut" (Some "alloc.vec.DerefMutVec.deref_mut") (Some [ true; false ]); + mk_fun "core::option::{core::option::Option<@T>}::unwrap" + (Some "core.option.Option.unwrap") None; ] @ List.flatten (List.map diff --git a/tests/coq/betree/BetreeMain_FunsExternal_Template.v b/tests/coq/betree/BetreeMain_FunsExternal_Template.v index 1367bac2..58be2733 100644 --- a/tests/coq/betree/BetreeMain_FunsExternal_Template.v +++ b/tests/coq/betree/BetreeMain_FunsExternal_Template.v @@ -37,11 +37,4 @@ Axiom betree_utils_store_leaf_node : u64 -> betree_List_t (u64 * u64) -> state -> result (state * unit) . -(** [core::option::{core::option::Option<T>}::unwrap]: - Source: '/rustc/d59363ad0b6391b7fc5bbb02c9ccf9300eef3753/library/core/src/option.rs', lines 932:4-932:34 - Name pattern: core::option::{core::option::Option<@T>}::unwrap *) -Axiom core_option_Option_unwrap : - forall(T : Type), option T -> state -> result (state * T) -. - End BetreeMain_FunsExternal_Template. diff --git a/tests/fstar/betree/BetreeMain.FunsExternal.fsti b/tests/fstar/betree/BetreeMain.FunsExternal.fsti index 3aad9390..8be98acf 100644 --- a/tests/fstar/betree/BetreeMain.FunsExternal.fsti +++ b/tests/fstar/betree/BetreeMain.FunsExternal.fsti @@ -28,9 +28,3 @@ val betree_utils_load_leaf_node val betree_utils_store_leaf_node : u64 -> betree_List_t (u64 & u64) -> state -> result (state & unit) -(** [core::option::{core::option::Option<T>}::unwrap]: - Source: '/rustc/d59363ad0b6391b7fc5bbb02c9ccf9300eef3753/library/core/src/option.rs', lines 932:4-932:34 - Name pattern: core::option::{core::option::Option<@T>}::unwrap *) -val core_option_Option_unwrap - (t : Type0) : option t -> state -> result (state & t) - diff --git a/tests/fstar/betree_back_stateful/BetreeMain.FunsExternal.fsti b/tests/fstar/betree_back_stateful/BetreeMain.FunsExternal.fsti index 3aad9390..8be98acf 100644 --- a/tests/fstar/betree_back_stateful/BetreeMain.FunsExternal.fsti +++ b/tests/fstar/betree_back_stateful/BetreeMain.FunsExternal.fsti @@ -28,9 +28,3 @@ val betree_utils_load_leaf_node val betree_utils_store_leaf_node : u64 -> betree_List_t (u64 & u64) -> state -> result (state & unit) -(** [core::option::{core::option::Option<T>}::unwrap]: - Source: '/rustc/d59363ad0b6391b7fc5bbb02c9ccf9300eef3753/library/core/src/option.rs', lines 932:4-932:34 - Name pattern: core::option::{core::option::Option<@T>}::unwrap *) -val core_option_Option_unwrap - (t : Type0) : option t -> state -> result (state & t) - diff --git a/tests/lean/BetreeMain/FunsExternal.lean b/tests/lean/BetreeMain/FunsExternal.lean index 71d26da4..d26177fb 100644 --- a/tests/lean/BetreeMain/FunsExternal.lean +++ b/tests/lean/BetreeMain/FunsExternal.lean @@ -28,8 +28,3 @@ def betree_utils.load_leaf_node def betree_utils.store_leaf_node : U64 → betree.List (U64 × U64) → State → Result (State × Unit) := fun _ _ _ => .fail .panic - -/- [core::option::Option::{0}::unwrap] -/ -def core.option.Option.unwrap - (T : Type) : Option T → State → Result (State × T) := - fun _ _ => .fail .panic diff --git a/tests/lean/BetreeMain/FunsExternal_Template.lean b/tests/lean/BetreeMain/FunsExternal_Template.lean index 0b3e4ef4..0dcce5ca 100644 --- a/tests/lean/BetreeMain/FunsExternal_Template.lean +++ b/tests/lean/BetreeMain/FunsExternal_Template.lean @@ -28,9 +28,3 @@ axiom betree_utils.load_leaf_node axiom betree_utils.store_leaf_node : U64 → betree.List (U64 × U64) → State → Result (State × Unit) -/- [core::option::{core::option::Option<T>}::unwrap]: - Source: '/rustc/d59363ad0b6391b7fc5bbb02c9ccf9300eef3753/library/core/src/option.rs', lines 932:4-932:34 - Name pattern: core::option::{core::option::Option<@T>}::unwrap -/ -axiom core.option.Option.unwrap - (T : Type) : Option T → State → Result (State × T) - diff --git a/tests/lean/External/FunsExternal.lean b/tests/lean/External/FunsExternal.lean index 28ba2077..c3e8dd79 100644 --- a/tests/lean/External/FunsExternal.lean +++ b/tests/lean/External/FunsExternal.lean @@ -14,4 +14,3 @@ def core.cell.Cell.get def core.cell.Cell.get_mut (T : Type) (c : core.cell.Cell T) (s : State) : Result (State × (T × (T → State → Result (State × (core.cell.Cell T))))) := sorry - |