Skip to content

Commit 13ee473

Browse files
authored
Optimize VConstr bounds check in CEK machine (#7479)
Simplify the type conversion in VConstr index validation by eliminating unnecessary intermediate conversion through Integer. Changed from: fromIntegral @_ @integer i > fromIntegral @int @integer maxBound To: i > fromIntegral @int @Word64 maxBound Since i is already Word64, we can directly compare it to maxBound converted to Word64, which is more efficient and clearer. Also updated Note [Integral types as Integer] to clarify that all non-64-bit systems (not just 32-bit) are banned for node deployment. Fixes #7478
1 parent ffc6471 commit 13ee473

File tree

2 files changed

+3
-3
lines changed
  • plutus-core
    • plutus-core/src/PlutusCore/Default
    • untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek

2 files changed

+3
-3
lines changed

plutus-core/plutus-core/src/PlutusCore/Default/Universe.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,8 @@ So, what to do? We adopt the following strategy:
489489
- We allow lifting/unlifting 'Int' via 'Int64' and 'Word' via 'Word64', constraining the conversion
490490
between them to 64-bit architectures where this conversion is safe.
491491
492-
Doing this effectively bans builds on 32-bit systems, but that's fine, since we don't care about
493-
supporting 32-bit systems anyway, and this way any attempts to build on them will fail fast.
492+
Doing this effectively bans builds on all non-64-bit systems, which is acceptable since 64-bit
493+
systems are required for node deployment, and this way any attempts to build on them will fail fast.
494494
495495
We used to use newtype- and via-deriving for implementations of relevant instances, but at some
496496
point GHC stopped attaching @INLINE@ annotations to those causing the GHC Core for builtins to have

plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ enterComputeCek = computeCek
927927
-- Word64 value wraps to -1 as an Int64. So you can't wrap around enough to get an
928928
-- "apparently good" value.
929929
(VConstr i _)
930-
| fromIntegral @_ @Integer i > fromIntegral @Int @Integer maxBound ->
930+
| i > fromIntegral @Int @Word64 maxBound ->
931931
throwErrorDischarged (StructuralError (MissingCaseBranchMachineError i)) e
932932
-- Otherwise, we can safely convert the index to an Int and use it.
933933
(VConstr i args) -> case (V.!?) cs (fromIntegral i) of

0 commit comments

Comments
 (0)