From c264b08cfb9beb5fe34d872b02a8f4cd1e12d45e Mon Sep 17 00:00:00 2001 From: Ryan Lahfa Date: Tue, 16 Apr 2024 23:30:47 +0200 Subject: compiler: map `core::option::Option::take` to identity function `take` in a pure functional model is the identity function and everything related to borrow checking is handled by the forward/backward mechanism. Signed-off-by: Ryan Lahfa --- backends/lean/Base/Primitives/Base.lean | 2 ++ 1 file changed, 2 insertions(+) (limited to 'backends/lean/Base/Primitives/Base.lean') diff --git a/backends/lean/Base/Primitives/Base.lean b/backends/lean/Base/Primitives/Base.lean index 4c5b2795..62546ac3 100644 --- a/backends/lean/Base/Primitives/Base.lean +++ b/backends/lean/Base/Primitives/Base.lean @@ -130,6 +130,8 @@ def Result.attach {α: Type} (o : Result α): Result { x : α // o = ok x } := ---------- @[simp] def core.mem.replace (a : Type) (x : a) (_ : a) : a × a := (x, x) +/- [core::option::Option::take] -/ +@[simp] def Option.take (T: Type) (self: Option T): Option T × Option T := (self, .none) /-- Aeneas-translated function -- useful to reduce non-recursive definitions. Use with `simp [ aeneas ]` -/ -- cgit v1.2.3 From 18484e28ef7b13b95dc3af0b1e34c2181e1778e5 Mon Sep 17 00:00:00 2001 From: Ryan Lahfa Date: Wed, 17 Apr 2024 00:01:34 +0200 Subject: compiler: map `core::mem::swap` to the pure swap In the pure functional model, `swap` is mostly about borrow checking and should simplify to the pure swap in our backends. Other backends than Lean are not done in this commit. Signed-off-by: Ryan Lahfa --- backends/lean/Base/Primitives/Base.lean | 2 ++ 1 file changed, 2 insertions(+) (limited to 'backends/lean/Base/Primitives/Base.lean') diff --git a/backends/lean/Base/Primitives/Base.lean b/backends/lean/Base/Primitives/Base.lean index 62546ac3..94134d86 100644 --- a/backends/lean/Base/Primitives/Base.lean +++ b/backends/lean/Base/Primitives/Base.lean @@ -132,6 +132,8 @@ def Result.attach {α: Type} (o : Result α): Result { x : α // o = ok x } := @[simp] def core.mem.replace (a : Type) (x : a) (_ : a) : a × a := (x, x) /- [core::option::Option::take] -/ @[simp] def Option.take (T: Type) (self: Option T): Option T × Option T := (self, .none) +/- [core::mem::swap] -/ +@[simp] def core.mem.swap (T: Type) (a b: T): T × T := (b, a) /-- Aeneas-translated function -- useful to reduce non-recursive definitions. Use with `simp [ aeneas ]` -/ -- cgit v1.2.3