From eb5b2e76de6e2c6780b9817c1424777276ea5e00 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Thu, 25 Apr 2024 16:27:43 +0200 Subject: Update the backend and ExtractBuiltin.ml --- backends/coq/Primitives.v | 7 +++++++ backends/fstar/Primitives.fst | 6 ++++++ backends/lean/Base/Primitives/Core.lean | 2 +- compiler/ExtractBuiltin.ml | 5 ++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/backends/coq/Primitives.v b/backends/coq/Primitives.v index 5ffda12f..b29fce43 100644 --- a/backends/coq/Primitives.v +++ b/backends/coq/Primitives.v @@ -564,6 +564,13 @@ Definition core_clone_CloneI128 : core_clone_Clone i128 := {| clone := fun x => Ok (core_clone_impls_CloneI128_clone x) |}. +(** [core::option::{core::option::Option}::unwrap] *) +Definition core_option_Option_unwrap (T : Type) (x : option T) : result T := + match x with + | None => Fail_ Failure + | Some x => Ok x + end. + (*** core::ops *) (* Trait declaration: [core::ops::index::Index] *) diff --git a/backends/fstar/Primitives.fst b/backends/fstar/Primitives.fst index c7c9f9db..9951ccc3 100644 --- a/backends/fstar/Primitives.fst +++ b/backends/fstar/Primitives.fst @@ -540,6 +540,12 @@ let core_clone_CloneI128 : core_clone_Clone i128 = { clone = fun x -> Ok (core_clone_impls_CloneI128_clone x) } +(** [core::option::{core::option::Option}::unwrap] *) +let core_option_Option_unwrap (t : Type0) (x : option t) : result t = + match x with + | None -> Fail Failure + | Some x -> Ok x + (*** core::ops *) // Trait declaration: [core::ops::index::Index] diff --git a/backends/lean/Base/Primitives/Core.lean b/backends/lean/Base/Primitives/Core.lean index b7dd6d2c..14a51bc1 100644 --- a/backends/lean/Base/Primitives/Core.lean +++ b/backends/lean/Base/Primitives/Core.lean @@ -51,7 +51,7 @@ def clone.CloneBool : clone.Clone Bool := { clone := fun b => ok (clone.impls.CloneBool.clone b) } -namespace option +namespace option -- core.option /- [core::option::{core::option::Option}::unwrap] -/ def Option.unwrap (T : Type) (x : Option T) : Result T := diff --git a/compiler/ExtractBuiltin.ml b/compiler/ExtractBuiltin.ml index d4a6f736..248d0fa8 100644 --- a/compiler/ExtractBuiltin.ml +++ b/compiler/ExtractBuiltin.ml @@ -554,14 +554,17 @@ let builtin_fun_effects = (fun n -> (n, { can_fail = false; stateful = false })) no_fail_no_state_funs in + (* TODO: all the functions registered in the [builtin_funs] above should + be considered a not using a state. There is a lot of redundancy + right now. *) let no_state_funs = [ - (* TODO: redundancy with the funs information above *) "alloc::vec::{alloc::vec::Vec<@T, @A>}::push"; "alloc::vec::{core::ops::index::Index, \ @I>}::index"; "alloc::vec::{core::ops::index::IndexMut, \ @I>}::index_mut"; + "core::option::{core::option::Option<@T>}::unwrap"; ] in let no_state_funs = -- cgit v1.2.3