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

Unable to build on GHC 8 #37

Closed
ekmett opened this issue Jan 16, 2016 · 5 comments
Closed

Unable to build on GHC 8 #37

ekmett opened this issue Jan 16, 2016 · 5 comments

Comments

@ekmett
Copy link

ekmett commented Jan 16, 2016

(The template-haskell bounds are too tight.)

@davean
Copy link

davean commented May 9, 2016

Additionally, once said are loosened, the code no longer compiles due mostly to the addition of fields. As per the migration guide additional fields have been added for Kind and instance overlaps.

The below patch compiles on GHC 8.0.1-rc4, and passes the included tests:

diff --git a/src/Data/SafeCopy/Derive.hs b/src/Data/SafeCopy/Derive.hs
index a1b9910..5c7e6ac 100644
--- a/src/Data/SafeCopy/Derive.hs
+++ b/src/Data/SafeCopy/Derive.hs
@@ -244,18 +244,18 @@ internalDeriveSafeCopy :: DeriveType -> Version a -> Name -> Name -> Q [Dec]
 internalDeriveSafeCopy deriveType versionId kindName tyName = do
   info <- reify tyName
   case info of
-    TyConI (DataD context _name tyvars cons _derivs)
+    TyConI (DataD context _name tyvars Nothing cons _derivs)
       | length cons > 255 -> fail $ "Can't derive SafeCopy instance for: " ++ show tyName ++
                                     ". The datatype must have less than 256 constructors."
       | otherwise         -> worker context tyvars (zip [0..] cons)
-    TyConI (NewtypeD context _name tyvars con _derivs) ->
+    TyConI (NewtypeD context _name tyvars Nothing con _derivs) ->
       worker context tyvars [(0, con)]
     FamilyI _ insts -> do
       decs <- forM insts $ \inst ->
         case inst of
-          DataInstD context _name ty cons _derivs ->
+          DataInstD context _name ty Nothing cons _derivs ->
               worker' (foldl appT (conT tyName) (map return ty)) context [] (zip [0..] cons)
-          NewtypeInstD context _name ty con _derivs ->
+          NewtypeInstD context _name ty Nothing con _derivs ->
               worker' (foldl appT (conT tyName) (map return ty)) context [] [(0, con)]
           _ -> fail $ "Can't derive SafeCopy instance for: " ++ show (tyName, inst)
       return $ concat decs
@@ -286,12 +286,12 @@ internalDeriveSafeCopyIndexedType deriveType versionId kindName tyName tyIndex'
     FamilyI _ insts -> do
       decs <- forM insts $ \inst ->
         case inst of
-          DataInstD context _name ty cons _derivs
+          DataInstD context _name ty Nothing cons _derivs
             | ty == tyIndex ->
               worker' (foldl appT (conT tyName) (map return ty)) context [] (zip [0..] cons)
             | otherwise ->
               return []
-          NewtypeInstD context _name ty con _derivs
+          NewtypeInstD context _name ty Nothing con _derivs
             | ty == tyIndex ->
               worker' (foldl appT (conT tyName) (map return ty)) context [] [(0, con)]
             | otherwise ->
@@ -405,6 +405,8 @@ conSize (NormalC _name args) = length args
 conSize (RecC _name recs)    = length recs
 conSize InfixC{}             = 2
 conSize ForallC{}            = error "Found complex constructor. Cannot derive SafeCopy for it."
+conSize GadtC{}              = error "Found GADT constructor. Cannot derive SafeCopy for it."
+conSize RecGadtC{}           = error "Found Record GADT constructor. Cannot derive SafeCopy for it."

 conName :: Con -> Name
 conName (NormalC name _args) = name
diff --git a/src/Data/SafeCopy/SafeCopy.hs b/src/Data/SafeCopy/SafeCopy.hs
index ddfb000..69b5f7b 100644
--- a/src/Data/SafeCopy/SafeCopy.hs
+++ b/src/Data/SafeCopy/SafeCopy.hs
@@ -214,7 +214,7 @@ getSafePut

 -- | The extended_base kind lets the system know that there is
 --   at least one future version of this type.
-extended_extension :: (SafeCopy a, Migrate a, Migrate (Reverse a)) => Kind a
+extended_extension :: (Migrate a, Migrate (Reverse a)) => Kind a
 extended_extension = Extended extension

 -- | The extended_base kind lets the system know that there is
@@ -227,7 +227,7 @@ extended_base = Extended base
 --   can only extend a single other data type. However, it is
 --   perfectly fine to build chains of extensions. The migrations
 --   between each step is handled automatically.
-extension :: (SafeCopy a, Migrate a) => Kind a
+extension :: (Migrate a) => Kind a
 extension = Extends Proxy

 -- | The default kind. Does not extend any type.
@@ -379,7 +379,7 @@ versionFromProxy _ = version
 versionFromKind :: (SafeCopy a) => Kind a -> Version a
 versionFromKind _ = version

-versionFromReverseKind :: (SafeCopy a, SafeCopy (MigrateFrom (Reverse a))) => Kind a -> Version (MigrateFrom (Reverse a))
+versionFromReverseKind :: (SafeCopy (MigrateFrom (Reverse a))) => Kind a -> Version (MigrateFrom (Reverse a))
 versionFromReverseKind _ = version

 kindFromProxy :: SafeCopy a => Proxy a -> Kind a
diff --git a/test/instances.hs b/test/instances.hs
index 0636814..5ca7bdd 100644
--- a/test/instances.hs
+++ b/test/instances.hs
@@ -42,24 +42,14 @@ instance (Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e, Arbit
    arbitrary = (,,,,,,) <$> arbitrary <*> arbitrary <*> arbitrary <*>
                             arbitrary <*> arbitrary <*> arbitrary <*> arbitrary

-instance (Arbitrary a) => Arbitrary (V.Vector a) where
-   arbitrary = V.fromList <$> arbitrary
-
 instance (Arbitrary a, VP.Prim a) => Arbitrary (VP.Vector a) where
    arbitrary = VP.fromList <$> arbitrary

-instance (Arbitrary a, VS.Storable a) => Arbitrary (VS.Vector a) where
-   arbitrary = VS.fromList <$> arbitrary
-
-instance (Arbitrary a, VU.Unbox a) => Arbitrary (VU.Vector a) where
-   arbitrary = VU.fromList <$> arbitrary
-
 deriving instance (Arbitrary a) => Arbitrary (Prim a)
 deriving instance (Eq a) => Eq (Prim a)
 deriving instance (Show a) => Show (Prim a)

 deriving instance Eq ZonedTime
-deriving instance Show UniversalTime

 -- | Equality on the 'Right' value, showing the unequal value on failure;
 -- or explicit failure using the 'Left' message without equality testing.
@@ -113,7 +103,7 @@ do let a = conT ''Int
 #endif
    def <- a

-   let instances (ClassI _ decs) = [ typ | InstanceD _ (AppT _ typ) _ <- decs ]
+   let instances (ClassI _ decs) = [ typ | InstanceD _ _ (AppT _ typ) _ <- decs ]
        instances _ = []
        types = map instances classes

@hvr
Copy link

hvr commented May 28, 2016

I see #40 was merged; is there an ETA for a safecopy release? Currently, the old safecopy-0.3 is the only release on Hackage that's GHC 8 ready.

@juanpaucar
Copy link

I'm sorry to bother, but when are we going to have safecopy working with template-haskell for ghc 8? I see that it is already merged in the repo but it hasn't been uploaded to hackage yet.

@stepcut
Copy link
Member

stepcut commented May 30, 2016

safecopy-0.9.1 has been uploaded to hackage. I am holding off on closing this bug until lens-action is updated allowing the tests to build.

@stepcut
Copy link
Member

stepcut commented Nov 3, 2016

test suite passes. closing.

@stepcut stepcut closed this as completed Nov 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants