summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Eisenberg <eir@cis.upenn.edu>2014-11-07 17:34:59 -0500
committerRichard Eisenberg <eir@cis.upenn.edu>2014-11-20 15:26:24 -0500
commite394e74df5ca8081c0ffd147d34e788d290fb21a (patch)
tree90f3625fba0f43bc0fa107ffd18c65edf068e307
parent5a8ae60ef9dc52ab04350ffbcf2945c9177eac87 (diff)
downloadhaskell-e394e74df5ca8081c0ffd147d34e788d290fb21a.tar.gz
Fix #9220 by adding role annotations.
This includes a submodule update for `array`. There is also an added test in libraries/array/tests/T9220.
m---------libraries/array0
-rw-r--r--libraries/base/GHC/Arr.hs6
-rw-r--r--libraries/base/GHC/IOArray.hs5
-rw-r--r--testsuite/tests/roles/should_compile/all.T1
-rw-r--r--testsuite/tests/roles/should_fail/RolesIArray.hs (renamed from testsuite/tests/roles/should_compile/RolesIArray.hs)0
-rw-r--r--testsuite/tests/roles/should_fail/RolesIArray.stderr100
-rw-r--r--testsuite/tests/roles/should_fail/all.T1
7 files changed, 110 insertions, 3 deletions
diff --git a/libraries/array b/libraries/array
-Subproject 19b7aebd7dff912728029778749aaa8a9ed1cff
+Subproject 4baaf0b6d1e7498f529e41eaa3a065cfa84b078
diff --git a/libraries/base/GHC/Arr.hs b/libraries/base/GHC/Arr.hs
index e68c70f6bc..cefef97f0f 100644
--- a/libraries/base/GHC/Arr.hs
+++ b/libraries/base/GHC/Arr.hs
@@ -1,5 +1,5 @@
{-# LANGUAGE Unsafe #-}
-{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}
+{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples, RoleAnnotations #-}
{-# OPTIONS_HADDOCK hide #-}
-----------------------------------------------------------------------------
@@ -385,6 +385,10 @@ data STArray s i e
-- No Ix context for STArray. They are stupid,
-- and force an Ix context on the equality instance.
+-- Index types should have nominal role, because of Ix class. See also #9220.
+type role Array nominal representational
+type role STArray nominal nominal representational
+
-- Just pointer equality on mutable arrays:
instance Eq (STArray s i e) where
STArray _ _ _ arr1# == STArray _ _ _ arr2# =
diff --git a/libraries/base/GHC/IOArray.hs b/libraries/base/GHC/IOArray.hs
index ff9e545817..33b1804dbb 100644
--- a/libraries/base/GHC/IOArray.hs
+++ b/libraries/base/GHC/IOArray.hs
@@ -1,5 +1,5 @@
{-# LANGUAGE Unsafe #-}
-{-# LANGUAGE NoImplicitPrelude, AutoDeriveTypeable #-}
+{-# LANGUAGE NoImplicitPrelude, AutoDeriveTypeable, RoleAnnotations #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
{-# OPTIONS_HADDOCK hide #-}
@@ -41,6 +41,9 @@ import Data.Typeable.Internal
newtype IOArray i e = IOArray (STArray RealWorld i e) deriving( Typeable )
+-- index type should have a nominal role due to Ix class. See also #9220.
+type role IOArray nominal representational
+
-- explicit instance because Haddock can't figure out a derived one
instance Eq (IOArray i e) where
IOArray x == IOArray y = x == y
diff --git a/testsuite/tests/roles/should_compile/all.T b/testsuite/tests/roles/should_compile/all.T
index 744b9342a6..0bd779ff3b 100644
--- a/testsuite/tests/roles/should_compile/all.T
+++ b/testsuite/tests/roles/should_compile/all.T
@@ -4,5 +4,4 @@ test('Roles3', only_ways('normal'), compile, ['-ddump-tc'])
test('Roles4', only_ways('normal'), compile, ['-ddump-tc'])
test('Roles13', only_ways('normal'), compile, ['-ddump-simpl -dsuppress-uniques'])
test('Roles14', only_ways('normal'), compile, ['-ddump-tc'])
-test('RolesIArray', only_ways('normal'), compile, [''])
test('T8958', [normalise_fun(normalise_errmsg), only_ways('normal')], compile, ['-ddump-tc -dsuppress-uniques'])
diff --git a/testsuite/tests/roles/should_compile/RolesIArray.hs b/testsuite/tests/roles/should_fail/RolesIArray.hs
index a79909d827..a79909d827 100644
--- a/testsuite/tests/roles/should_compile/RolesIArray.hs
+++ b/testsuite/tests/roles/should_fail/RolesIArray.hs
diff --git a/testsuite/tests/roles/should_fail/RolesIArray.stderr b/testsuite/tests/roles/should_fail/RolesIArray.stderr
new file mode 100644
index 0000000000..aad2f2b18a
--- /dev/null
+++ b/testsuite/tests/roles/should_fail/RolesIArray.stderr
@@ -0,0 +1,100 @@
+
+RolesIArray.hs:10:13:
+ Could not coerce from ‘UArray i Word64’ to ‘UArray i N’
+ because the second type argument of ‘UArray’ has role Nominal,
+ but the arguments ‘Word64’ and ‘N’ differ
+ arising from the coercion of the method ‘Data.Array.Base.unsafeAccumArray’
+ from type ‘forall e' i.
+ Ix i =>
+ (Word64 -> e' -> Word64)
+ -> Word64 -> (i, i) -> [(Int, e')] -> UArray i Word64’
+ to type ‘forall e' i.
+ Ix i =>
+ (N -> e' -> N) -> N -> (i, i) -> [(Int, e')] -> UArray i N’
+ Possible fix:
+ use a standalone 'deriving instance' declaration,
+ so you can specify the instance context yourself
+ When deriving the instance for (IArray UArray N)
+
+RolesIArray.hs:10:13:
+ Could not coerce from ‘UArray i Word64’ to ‘UArray i N’
+ because the second type argument of ‘UArray’ has role Nominal,
+ but the arguments ‘Word64’ and ‘N’ differ
+ arising from the coercion of the method ‘Data.Array.Base.unsafeAccum’
+ from type ‘forall e' i.
+ Ix i =>
+ (Word64 -> e' -> Word64)
+ -> UArray i Word64 -> [(Int, e')] -> UArray i Word64’
+ to type ‘forall e' i.
+ Ix i =>
+ (N -> e' -> N) -> UArray i N -> [(Int, e')] -> UArray i N’
+ Possible fix:
+ use a standalone 'deriving instance' declaration,
+ so you can specify the instance context yourself
+ When deriving the instance for (IArray UArray N)
+
+RolesIArray.hs:10:13:
+ Could not coerce from ‘UArray i Word64’ to ‘UArray i N’
+ because the second type argument of ‘UArray’ has role Nominal,
+ but the arguments ‘Word64’ and ‘N’ differ
+ arising from the coercion of the method ‘Data.Array.Base.unsafeReplace’
+ from type ‘forall i.
+ Ix i =>
+ UArray i Word64 -> [(Int, Word64)] -> UArray i Word64’
+ to type ‘forall i.
+ Ix i =>
+ UArray i N -> [(Int, N)] -> UArray i N’
+ Possible fix:
+ use a standalone 'deriving instance' declaration,
+ so you can specify the instance context yourself
+ When deriving the instance for (IArray UArray N)
+
+RolesIArray.hs:10:13:
+ Could not coerce from ‘UArray i Word64’ to ‘UArray i N’
+ because the second type argument of ‘UArray’ has role Nominal,
+ but the arguments ‘Word64’ and ‘N’ differ
+ arising from the coercion of the method ‘Data.Array.Base.unsafeAt’
+ from type ‘forall i. Ix i => UArray i Word64 -> Int -> Word64’
+ to type ‘forall i. Ix i => UArray i N -> Int -> N’
+ Possible fix:
+ use a standalone 'deriving instance' declaration,
+ so you can specify the instance context yourself
+ When deriving the instance for (IArray UArray N)
+
+RolesIArray.hs:10:13:
+ Could not coerce from ‘UArray i Word64’ to ‘UArray i N’
+ because the second type argument of ‘UArray’ has role Nominal,
+ but the arguments ‘Word64’ and ‘N’ differ
+ arising from the coercion of the method ‘Data.Array.Base.unsafeArray’
+ from type ‘forall i.
+ Ix i =>
+ (i, i) -> [(Int, Word64)] -> UArray i Word64’
+ to type ‘forall i. Ix i => (i, i) -> [(Int, N)] -> UArray i N’
+ Possible fix:
+ use a standalone 'deriving instance' declaration,
+ so you can specify the instance context yourself
+ When deriving the instance for (IArray UArray N)
+
+RolesIArray.hs:10:13:
+ Could not coerce from ‘UArray i Word64’ to ‘UArray i N’
+ because the second type argument of ‘UArray’ has role Nominal,
+ but the arguments ‘Word64’ and ‘N’ differ
+ arising from the coercion of the method ‘Data.Array.Base.numElements’
+ from type ‘forall i. Ix i => UArray i Word64 -> Int’
+ to type ‘forall i. Ix i => UArray i N -> Int’
+ Possible fix:
+ use a standalone 'deriving instance' declaration,
+ so you can specify the instance context yourself
+ When deriving the instance for (IArray UArray N)
+
+RolesIArray.hs:10:13:
+ Could not coerce from ‘UArray i Word64’ to ‘UArray i N’
+ because the second type argument of ‘UArray’ has role Nominal,
+ but the arguments ‘Word64’ and ‘N’ differ
+ arising from the coercion of the method ‘bounds’
+ from type ‘forall i. Ix i => UArray i Word64 -> (i, i)’
+ to type ‘forall i. Ix i => UArray i N -> (i, i)’
+ Possible fix:
+ use a standalone 'deriving instance' declaration,
+ so you can specify the instance context yourself
+ When deriving the instance for (IArray UArray N)
diff --git a/testsuite/tests/roles/should_fail/all.T b/testsuite/tests/roles/should_fail/all.T
index 1c69b7c48c..94674daa26 100644
--- a/testsuite/tests/roles/should_fail/all.T
+++ b/testsuite/tests/roles/should_fail/all.T
@@ -10,3 +10,4 @@ test('Roles12',
test('T8773', normal, compile_fail, [''])
test('T9204', extra_clean(['T9204.o-boot', 'T9204.hi-boot']),
run_command, ['$MAKE --no-print-directory -s T9204'])
+test('RolesIArray', normal, compile_fail, [''])