Skip to content

Commit

Permalink
Merge pull request #32 from felixwiemuth/fix/change-max-index
Browse files Browse the repository at this point in the history
Update max index for ProjIdx to LLVM i32 type
  • Loading branch information
aslanix committed Apr 9, 2024
2 parents 923fa90 + 7c76ba6 commit 78ac672
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
10 changes: 10 additions & 0 deletions compiler/src/Consts.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Consts where

-- * LLVM types

-- | 2^31-1
llvm_i32_maxBound :: Int
llvm_i32_maxBound = 2147483647

llvm_maxIndex :: Int
llvm_maxIndex = llvm_i32_maxBound
8 changes: 4 additions & 4 deletions compiler/src/IR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

module IR where

import Consts
import qualified Basics
import RetCPS (VarName (..))

Expand Down Expand Up @@ -53,8 +54,7 @@ data IRExpr
| WithRecord VarAccess Fields
| ProjField VarAccess Basics.FieldName
-- | Projection of a tuple field at the given index. The maximum allowed index
-- is 2^53-1 (9007199254740991), the maximum representable number with 52 bits (unsigned),
-- as the runtime uses the IEEE 754 double-precision number format with a mantissa of 52 bits.
-- is 2^31-1 (2147483647).
| ProjIdx VarAccess Word
| List [VarAccess]
-- | List cons of a value to a list.
Expand Down Expand Up @@ -333,8 +333,8 @@ instance WellFormedIRCheck IRExpr where
then return ()
else throwError $ "bad base function: " ++ fname
wfir (ProjIdx _ idx) =
when (idx > 9007199254740991) $ -- 2^53-1
throwError $ "ProjIdx: illegal index: " ++ show idx ++ " (max index: 9007199254740991)"
when (idx > (fromIntegral Consts.llvm_maxIndex :: Word)) $
throwError $ "ProjIdx: illegal index: " ++ show idx ++ " (max index: " ++ show Consts.llvm_maxIndex ++ ")"

wfir _ = return ()

Expand Down
2 changes: 1 addition & 1 deletion tests/cmp/tuples_idx05b.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
troupec: ProjIdx: illegal index: 9007199254740992 (max index: 9007199254740991)
troupec: ProjIdx: illegal index: 2147483648 (max index: 2147483647)
2 changes: 1 addition & 1 deletion tests/cmp/tuples_idx05b.trp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(1,2,3).9007199254740992
(1,2,3).2147483648
2 changes: 1 addition & 1 deletion tests/rt/pos/core/tuples_idx05a.golden
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
2024-02-14T11:33:50.114Z [RTM] info: Skipping network creation. Observe that all external IO operations will yield a runtime error.
Runtime error in thread b490728b-03f4-4cbb-af4e-349efbca03d4@{}%{}
>> Index out of bounds: tuple (1@{}%{}, 2@{}%{}, 3@{}%{}) does not have length more than 9007199254740991
>> Index out of bounds: tuple (1@{}%{}, 2@{}%{}, 3@{}%{}) does not have length more than 2147483647
2 changes: 1 addition & 1 deletion tests/rt/pos/core/tuples_idx05a.trp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(1,2,3).9007199254740991
(1,2,3).2147483647

0 comments on commit 78ac672

Please sign in to comment.