Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update max index for ProjIdx to LLVM i32 type #32

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM fpco/stack-build:lts-20.14
FROM fpco/stack-build:lts-21.25
ENV TROUPE /Troupe
ENV STACK_OPTS --system-ghc
WORKDIR $TROUPE
Expand Down
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 @@ -331,8 +331,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 compiler/stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-20.14
resolver: lts-21.25

# User packages to be built.
# Various formats can be used as shown in the example below.
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
Loading