Skip to content

Commit 5c81953

Browse files
committed
refactor: use GHC.Num.Integer.integerLog2 in Logarithmic instance
Modernize logarithm calculation in the Logarithmic ExMemoryUsage instance by switching from the compatibility module GHC.Integer.Logarithms to the modern GHC.Num.Integer API. Changes: - Replace integerLog2# (unboxed, from GHC.Integer.Logarithms) with integerLog2 (boxed, from GHC.Num.Integer) - Simplify code by removing unboxing boilerplate: I# (integerLog2# x) becomes integerLog2 x - Keep other imports (GHC.Integer.Logarithms, GHC.Exts) as they are still used elsewhere in the file (memoryUsageInteger function) This addresses code review feedback to use the modern ghc-bignum API instead of the legacy compatibility module, while maintaining the same computational semantics. Cost model regeneration verified no regression in derived parameters.
1 parent e8a9f53 commit 5c81953

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExMemoryUsage.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ import Data.Text qualified as T
3535
import Data.Vector.Strict (Vector)
3636
import Data.Vector.Strict qualified as Vector
3737
import Data.Word
38-
import GHC.Exts (Int (I#))
38+
import GHC.Exts (Int (I#), quotInt#)
3939
import GHC.Integer
4040
import GHC.Integer.Logarithms
4141
import GHC.Natural
42-
import GHC.Prim
42+
import GHC.Num.Integer (integerLog2)
4343
import Universe
4444

4545
{-
@@ -411,7 +411,7 @@ instance ExMemoryUsage n => ExMemoryUsage (Logarithmic n) where
411411
CostRose size _ ->
412412
let sizeInteger :: Integer
413413
sizeInteger = fromSatInt size
414-
logSize = I# (integerLog2# sizeInteger)
414+
logSize = integerLog2 sizeInteger
415415
in singletonRose $ max 1 (fromIntegral (logSize + 1))
416416
{-# INLINE memoryUsage #-}
417417

0 commit comments

Comments
 (0)