Skip to content

Commit

Permalink
Fix the too lenient inferred phantom role annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj committed Dec 4, 2023
1 parent bd1a84d commit 9d09ede
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Data/Array/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
Expand Down Expand Up @@ -124,6 +125,7 @@ prettyShowL l = render . pPrintPrec l 0
-- dimension starts you calculate vector index @offset + i*strides[0]@.
-- To find where item /i,j/ of the two outermost dimensions is you
-- calculate vector index @offset + i*strides[0] + j*strides[1]@, etc.
type role T representational nominal
data T v a = T
{ strides :: ![Int] -- length is tensor rank
, offset :: !Int -- offset into vector of values
Expand Down
2 changes: 2 additions & 0 deletions Data/Array/Internal/Dynamic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Array.Internal.Dynamic(
Expand Down Expand Up @@ -103,6 +104,7 @@ instance Vector V.Vector where
{-# INLINE vAny #-}
vAny = V.any

type role Array nominal
newtype Array a = A { unA :: G.Array V.Vector a }
deriving (Pretty, Generic, Data)

Expand Down
2 changes: 2 additions & 0 deletions Data/Array/Internal/DynamicG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE UndecidableInstances #-}
-- | Arrays of dynamic size. The arrays are polymorphic in the underlying
Expand Down Expand Up @@ -54,6 +55,7 @@ import Text.PrettyPrint.HughesPJClass hiding ((<>))
import Data.Array.Internal

-- | Arrays stored in a /v/ with values of type /a/.
type role Array representational nominal
data Array v a = A !ShapeL !(T v a)
deriving (Generic, Data)

Expand Down
2 changes: 2 additions & 0 deletions Data/Array/Internal/DynamicS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
Expand Down Expand Up @@ -110,6 +111,7 @@ instance Vector V.Vector where
{-# INLINE vAny #-}
vAny = V.any

type role Array nominal
newtype Array a = A { unA :: G.Array V.Vector a }
deriving (Pretty, Generic, Data)

Expand Down
2 changes: 2 additions & 0 deletions Data/Array/Internal/DynamicU.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Array.Internal.DynamicU(
Expand Down Expand Up @@ -107,6 +108,7 @@ instance Vector V.Vector where
{-# INLINE vAny #-}
vAny = V.any

type role Array nominal
newtype Array a = A { unA :: G.Array V.Vector a }
deriving (Pretty, Generic, Data)

Expand Down
2 changes: 2 additions & 0 deletions Data/Array/Internal/Ranked.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
Expand Down Expand Up @@ -61,6 +62,7 @@ import qualified Data.Array.Internal.RankedG as G
import Data.Array.Internal(ShapeL, Vector(..))
import Text.PrettyPrint.HughesPJClass hiding ((<>))

type role Array nominal nominal
newtype Array n a = A { unA :: G.Array n V.Vector a }
deriving (Pretty, Generic, Data)

Expand Down
2 changes: 2 additions & 0 deletions Data/Array/Internal/RankedG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
Expand Down Expand Up @@ -63,6 +64,7 @@ import Text.PrettyPrint.HughesPJClass hiding ((<>))
import Data.Array.Internal

-- | Arrays stored in a /v/ with values of type /a/.
type role Array nominal representational nominal
data Array (n :: Nat) v a = A !ShapeL !(T v a)
deriving (Generic, Data)

Expand Down
2 changes: 2 additions & 0 deletions Data/Array/Internal/RankedS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
Expand Down Expand Up @@ -64,6 +65,7 @@ import Data.Array.Internal(ShapeL, Vector(..))

type Unbox = V.Storable

type role Array nominal nominal
newtype Array n a = A { unA :: G.Array n V.Vector a }
deriving (Pretty, Generic, Data)

Expand Down
2 changes: 2 additions & 0 deletions Data/Array/Internal/RankedU.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
Expand Down Expand Up @@ -63,6 +64,7 @@ import Data.Array.Internal(ShapeL, Vector(..))

type Unbox = V.Unbox

type role Array nominal nominal
newtype Array n a = A { unA :: G.Array n V.Vector a }
deriving (Pretty, Generic, Data)

Expand Down
2 changes: 2 additions & 0 deletions Data/Array/Internal/Shaped.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
Expand Down Expand Up @@ -61,6 +62,7 @@ import qualified Data.Array.Internal.ShapedG as G
import Data.Array.Internal(ShapeL, Vector)
import Data.Array.Internal.Shape

type role Array nominal nominal
newtype Array sh a = A { unA :: G.Array sh V.Vector a }
deriving (Pretty, Generic, Data)

Expand Down
2 changes: 2 additions & 0 deletions Data/Array/Internal/ShapedG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
Expand Down Expand Up @@ -64,6 +65,7 @@ import Data.Array.Internal
import Data.Array.Internal.Shape

-- | Arrays stored in a /v/ with values of type /a/.
type role Array nominal representational nominal
newtype Array (sh :: [Nat]) v a = A (T v a)
deriving (Generic, Data)

Expand Down
2 changes: 2 additions & 0 deletions Data/Array/Internal/ShapedS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
Expand Down Expand Up @@ -65,6 +66,7 @@ import Data.Array.Internal.Shape

type Unbox = V.Storable

type role Array nominal nominal
newtype Array sh a = A { unA :: G.Array sh V.Vector a }
deriving (Pretty, Generic, Data)

Expand Down
2 changes: 2 additions & 0 deletions Data/Array/Internal/ShapedU.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
Expand Down Expand Up @@ -63,6 +64,7 @@ import Data.Array.Internal.Shape

type Unbox = V.Unbox

type role Array nominal nominal
newtype Array sh a = A { unA :: G.Array sh V.Vector a }
deriving (Pretty, Generic, Data)

Expand Down
2 changes: 2 additions & 0 deletions orthotope.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ source-repository head
library
hs-source-dirs: .
ghc-options: -Wall
-- if impl(ghc >= 9.8)
-- ghc-options: -Wmissing-role-annotations
exposed-modules: Data.Array.Convert
, Data.Array.Dynamic
, Data.Array.DynamicG
Expand Down

0 comments on commit 9d09ede

Please sign in to comment.