Skip to content

Commit

Permalink
feat: non-opaque UInt64.toUSize (#6202)
Browse files Browse the repository at this point in the history
This PR makes `USize.toUInt64` a regular non-opaque definition. 

It also moves it to `Init.Data.UInt.Basic`, as it is not actually used
in `Init.Prelude` anymore.
  • Loading branch information
tydeu authored Nov 25, 2024
1 parent 20acc72 commit 935fcfb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Init/Data/UInt/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ def USize.shiftRight (a b : USize) : USize := ⟨a.toBitVec >>> (mod b (USize.of
def UInt32.toUSize (a : UInt32) : USize := USize.ofNat32 a.toBitVec.toNat a.toBitVec.isLt
@[extern "lean_usize_to_uint32"]
def USize.toUInt32 (a : USize) : UInt32 := a.toNat.toUInt32
/-- Converts a `UInt64` to a `USize` by reducing modulo `USize.size`. -/
@[extern "lean_uint64_to_usize"]
def UInt64.toUSize (a : UInt64) : USize := a.toNat.toUSize

instance : Mul USize := ⟨USize.mul⟩
instance : Mod USize := ⟨USize.mod⟩
Expand Down
4 changes: 0 additions & 4 deletions src/Init/Prelude.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3432,10 +3432,6 @@ class Hashable (α : Sort u) where

export Hashable (hash)

/-- Converts a `UInt64` to a `USize` by reducing modulo `USize.size`. -/
@[extern "lean_uint64_to_usize"]
opaque UInt64.toUSize (u : UInt64) : USize

/--
Upcast a `USize` to a `UInt64`.
This is lossless because `USize.size` is either `2^32` or `2^64`.
Expand Down

0 comments on commit 935fcfb

Please sign in to comment.