feat: add PtrEqResult

This commit is contained in:
Leonardo de Moura 2020-02-29 11:00:50 -08:00
parent 94cfcbbefe
commit 684554e979
2 changed files with 8 additions and 16 deletions

View file

@ -306,18 +306,6 @@ abbrev DecidableEq (α : Sort u) :=
def decEq {α : Sort u} [s : DecidableEq α] (a b : α) : Decidable (a = b) :=
s a b
class inductive SemiDeciable (p : Prop)
| unknown {} : SemiDeciable
| isTrue (h : p) : SemiDeciable
def Decidable.toSemiDecidable {p : Prop} (d : Decidable p) : SemiDeciable p :=
match d with
| Decidable.isTrue h => SemiDeciable.isTrue h
| _ => SemiDeciable.unknown
instance SemiDeciable.ofDecidable {p : Prop} [d : Decidable p] : SemiDeciable p :=
d.toSemiDecidable
inductive Option (α : Type u)
| none {} : Option
| some (val : α) : Option

View file

@ -47,8 +47,12 @@ k (ptrAddrUnsafe a)
@[inline] unsafe def withPtrEqUnsafe {α : Type u} (a b : α) (k : Unit → Bool) (h : a = b → k () = true) : Bool :=
if ptrAddrUnsafe a == ptrAddrUnsafe b then true else k ()
@[inline] unsafe def withPtrEqResultUnsafe {α : Type u} {β : Type v} [Subsingleton β] (a b : α) (k : SemiDeciable (a = b) → β) : β :=
if ptrAddrUnsafe a == ptrAddrUnsafe b then k (SemiDeciable.isTrue lcProof) else k SemiDeciable.unknown
inductive PtrEqResult {α : Type u} (x y : α) : Prop
| unknown {} : PtrEqResult
| yes (h : x = y) : PtrEqResult
@[inline] unsafe def withPtrEqResultUnsafe {α : Type u} {β : Type v} [Subsingleton β] (a b : α) (k : PtrEqResult a b → β) : β :=
if ptrAddrUnsafe a == ptrAddrUnsafe b then k (PtrEqResult.yes lcProof) else k PtrEqResult.unknown
@[implementedBy withPtrEqUnsafe]
def withPtrEq {α : Type u} (a b : α) (k : Unit → Bool) (h : a = b → k () = true) : Bool :=
@ -63,8 +67,8 @@ condEq b
/-- Similar to `withPtrEq`, but executes the continuation `k` with the "result" of the pointer equality test. -/
@[implementedBy withPtrEqResultUnsafe]
def withPtrEqResult {α : Type u} {β : Type v} [Subsingleton β] (a b : α) (k : SemiDeciable (a = b) → β) : β :=
k SemiDeciable.unknown
def withPtrEqResult {α : Type u} {β : Type v} [Subsingleton β] (a b : α) (k : PtrEqResult a b → β) : β :=
k PtrEqResult.unknown
@[implementedBy withPtrAddrUnsafe]
def withPtrAddr {α : Type u} {β : Type v} (a : α) (k : USize → β) (h : ∀ u₁ u₂, k u₁ = k u₂) : β :=