diff --git a/Dockerfile b/Dockerfile index 04cc320..d77705c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/compiler/src/Consts.hs b/compiler/src/Consts.hs new file mode 100644 index 0000000..a0a3f45 --- /dev/null +++ b/compiler/src/Consts.hs @@ -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 \ No newline at end of file diff --git a/compiler/src/IR.hs b/compiler/src/IR.hs index 70d9f3b..3ff20de 100644 --- a/compiler/src/IR.hs +++ b/compiler/src/IR.hs @@ -8,6 +8,7 @@ module IR where +import Consts import qualified Basics import RetCPS (VarName (..)) @@ -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. @@ -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 () diff --git a/compiler/stack.yaml b/compiler/stack.yaml index 184ba5a..8fae81c 100644 --- a/compiler/stack.yaml +++ b/compiler/stack.yaml @@ -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. diff --git a/tests/cmp/tuples_idx05b.golden b/tests/cmp/tuples_idx05b.golden index 2a0f6a6..38d474a 100644 --- a/tests/cmp/tuples_idx05b.golden +++ b/tests/cmp/tuples_idx05b.golden @@ -1 +1 @@ -troupec: ProjIdx: illegal index: 9007199254740992 (max index: 9007199254740991) +troupec: ProjIdx: illegal index: 2147483648 (max index: 2147483647) diff --git a/tests/cmp/tuples_idx05b.trp b/tests/cmp/tuples_idx05b.trp index 522c456..4b8dd9f 100644 --- a/tests/cmp/tuples_idx05b.trp +++ b/tests/cmp/tuples_idx05b.trp @@ -1 +1 @@ -(1,2,3).9007199254740992 \ No newline at end of file +(1,2,3).2147483648 \ No newline at end of file diff --git a/tests/rt/pos/core/tuples_idx05a.golden b/tests/rt/pos/core/tuples_idx05a.golden index c3e4a61..c054345 100644 --- a/tests/rt/pos/core/tuples_idx05a.golden +++ b/tests/rt/pos/core/tuples_idx05a.golden @@ -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 diff --git a/tests/rt/pos/core/tuples_idx05a.trp b/tests/rt/pos/core/tuples_idx05a.trp index 9fe5217..4e12ba7 100644 --- a/tests/rt/pos/core/tuples_idx05a.trp +++ b/tests/rt/pos/core/tuples_idx05a.trp @@ -1 +1 @@ -(1,2,3).9007199254740991 \ No newline at end of file +(1,2,3).2147483647 \ No newline at end of file