ivan-m / haskell-docs

Get the Haskell documentation of a name from a module
BSD 3-Clause "New" or "Revised" License
32 stars 8 forks source link

Fixes for GHC 8.0.1 #31

Closed dubiousjim closed 8 years ago

dubiousjim commented 8 years ago

I started playing around to see what changes are needed to build with GHC 8.0.1. I haven't tried to understand the source base, but perhaps this work will help someone who does more quickly update this package.

I made these changes to haskell-docs.cabal:

@@ -85,13 +85,15 @@
                      , cryptohash
                      , directory
                      , filepath
-                     , ghc >= 7.2 && < 7.11
+                     , ghc >= 7.2
                      , ghc-paths
                      , monad-loops
                      , process
                      , text
-                     , text
                      , unordered-containers
+  if impl(ghc>7.10)
+     build-depends:   haddock-api>2.16
+                    , haddock-library
   if impl(ghc==7.10.*)
      build-depends:   haddock-api==2.16.*
                     , haddock-library

Here are changes I made to the src directory:

diff -ur src~/Haskell/Docs/Ghc.hs src/Haskell/Docs/Ghc.hs
--- src~/Haskell/Docs/Ghc.hs    2016-06-26 11:24:00.000000000 +0200
+++ src/Haskell/Docs/Ghc.hs 2016-06-26 12:59:29.000000000 +0200
@@ -66,7 +66,7 @@
 #endif

 -- | Pretty print something to string.
-showppr dflags = Haskell.Docs.Ghc.showSDocForUser dflags neverQualify . ppr
+showppr dflags = showSDocForUser dflags neverQualify . ppr

 -- | Wraps 'Outputable.showSDocForUser'.
 #if __GLASGOW_HASKELL__ == 702
@@ -94,7 +94,10 @@
 #endif

 -- | Show the package name e.g. base.
-#if __GLASGOW_HASKELL__ >= 710
+#if __GLASGOW_HASKELL__ >= 800
+showPackageName :: UnitId -> String
+showPackageName = unitIdString
+#elif __GLASGOW_HASKELL__ >= 710
 showPackageName :: PackageKey -> String
 showPackageName = packageKeyString
 #else
diff -ur src~/Haskell/Docs/Haddock.hs src/Haskell/Docs/Haddock.hs
--- src~/Haskell/Docs/Haddock.hs    2016-06-26 11:24:00.000000000 +0200
+++ src/Haskell/Docs/Haddock.hs 2016-06-26 13:09:56.000000000 +0200
@@ -77,7 +77,9 @@

 -- | Obtain the current notion of a package identifier.
 getIdentifier :: PackageConfig -> PkgID
-#if __GLASGOW_HASKELL__ >= 710
+#if __GLASGOW_HASKELL__ >= 800
+getIdentifier = packageConfigId
+#elif __GLASGOW_HASKELL__ >= 710
 getIdentifier = packageKey
 #else
 getIdentifier = sourcePackageId
diff -ur src~/Haskell/Docs/Types.hs src/Haskell/Docs/Types.hs
--- src~/Haskell/Docs/Types.hs  2016-06-26 11:24:00.000000000 +0200
+++ src/Haskell/Docs/Types.hs   2016-06-26 12:55:13.000000000 +0200
@@ -18,7 +18,11 @@
 import GHC            (Id)
 import Module (ModuleName)

-#if __GLASGOW_HASKELL__ >= 710
+#if __GLASGOW_HASKELL__ >= 800
+import Module (UnitId)
+
+type PkgID = UnitId
+#elif __GLASGOW_HASKELL__ >= 710
 import Module (PackageKey)

 type PkgID = PackageKey

That's not quite enough to get the package to build though. There are still issues in src/Haskell/Docs/Cabal.hs and in src/Haskell/Docs/Index.hs. The former gives the error:

src/Haskell/Docs/Cabal.hs:38:6: error:
    • Couldn't match type ‘(FilePath, [PackageConfig])’
                     with ‘ghc-boot-8.0.1:GHC.PackageDb.InstalledPackageInfo
                             SourcePackageId PackageName UnitId Module.ModuleName’
      Expected type: Ghc [PackageConfig]
        Actual type: Ghc [(FilePath, [PackageConfig])]
    • In a stmt of a 'do' block:
        return (fromMaybe [] (pkgDatabase flags))
      In the expression:
        do { flags <- getSessionDynFlags;
             return (fromMaybe [] (pkgDatabase flags)) }
      In an equation for ‘getAllPackages’:
          getAllPackages _gs
            = do { flags <- getSessionDynFlags;
                   return (fromMaybe [] (pkgDatabase flags)) }

And the latter:

src/Haskell/Docs/Index.hs:91:62: error:
    • Couldn't match type ‘(FilePath, [PackageConfig.PackageConfig])’
                     with ‘ghc-boot-8.0.1:GHC.PackageDb.InstalledPackageInfo
                             PackageConfig.SourcePackageId
                             PackageConfig.PackageName
                             UnitId
                             ModuleName’
      Expected type: PackageConfig.PackageConfig
        Actual type: (FilePath, [PackageConfig.PackageConfig])
    • In the first argument of ‘getHaddockInterfacesByPackage’, namely
        ‘package’
      In a stmt of a 'do' block:
        files <- getHaddockInterfacesByPackage package
      In the expression:
        do { files <- getHaddockInterfacesByPackage package;
             return
               (concat
                  (map
                     (map
                        (\ iface
                           -> (getIdentifier package, instMod iface, 
                               instVisibleExports iface))
                      . ifInstalledIfaces)
                     (rights files))) }

src/Haskell/Docs/Index.hs:95:56: error:
    • Couldn't match type ‘(FilePath, [PackageConfig.PackageConfig])’
                     with ‘ghc-boot-8.0.1:GHC.PackageDb.InstalledPackageInfo
                             PackageConfig.SourcePackageId
                             PackageConfig.PackageName
                             UnitId
                             ModuleName’
      Expected type: PackageConfig.PackageConfig
        Actual type: (FilePath, [PackageConfig.PackageConfig])
    • In the first argument of ‘getIdentifier’, namely ‘package’
      In the expression: getIdentifier package
      In the expression:
        (getIdentifier package, instMod iface, instVisibleExports iface)
dubiousjim commented 8 years ago

These further changes will get the package to typecheck and compile. I'm not sure if the behavior is correct, but on casual inspection the built app seems to work ok. Also, cabal test reports:

1 of 1 test suites (1 of 1 test cases) passed.

Here are the patches:

diff -ru src/Haskell/Docs/Cabal.hs src2/Haskell/Docs/Cabal.hs
--- src/Haskell/Docs/Cabal.hs   2016-06-27 01:22:28.000000000 +0200
+++ src2/Haskell/Docs/Cabal.hs  2016-06-27 07:41:08.000000000 +0200
@@ -35,7 +35,7 @@
 getAllPackages :: [String] -> Ghc [PackageConfig.PackageConfig]
 getAllPackages _gs =
   do flags <- getSessionDynFlags
-     return (snd =<< fromMaybe [] (pkgDatabase flags))
+     return (fromMaybe [] (pkgDatabase flags))

 -- | Version-portable version of allPackagesByName.
 #if MIN_VERSION_Cabal (1,22,0)
diff -ru src/Haskell/Docs/Index.hs src2/Haskell/Docs/Index.hs
--- src/Haskell/Docs/Index.hs   2016-06-27 07:35:37.000000000 +0200
+++ src2/Haskell/Docs/Index.hs  2016-06-27 07:41:01.000000000 +0200
@@ -87,23 +87,22 @@
                        return (fromMaybe [] (pkgDatabase df)))
      fmap (concat . map explode . concat)
           (forM packages
-                (\packages' ->
-                   join <$> sequence [do files <- getHaddockInterfacesByPackage package
-                                         return
-                                           (concat
-                                              (map (map (\iface ->
-                                                           (getIdentifier package
-                                                           ,instMod iface
-                                                           ,instVisibleExports iface)) .
-                                                    ifInstalledIfaces)
-                                                   (rights files))) | package <- snd packages']))
+                (\package ->
+                   do files <- getHaddockInterfacesByPackage package
+                      return
+                        (concat
+                           (map (map (\iface ->
+                                        (getIdentifier package
+                                        ,instMod iface
+                                        ,instVisibleExports iface)) .
+                                 ifInstalledIfaces)
+                                (rights files)))))
   where explode (pkg,modu,names) =
           map (showPackageName pkg
               ,moduleNameString (moduleName modu)
               ,)
               (map getOccString names)

-
 -- | Save the index to file.
 saveIndex :: Index -> IO ()
 saveIndex i =
chrisdone commented 8 years ago

So I'm not working on haskell-docs anymore in favor of stack hoogle; are you interested in taking over maintainership?

dubiousjim commented 8 years ago

Thanks. I'm afraid I don't have the understanding of the code base nor the time.

ivan-m commented 8 years ago

@chrisdone I could take it over if you'd like.

chrisdone commented 8 years ago

Cool! I'll hand over the keys.

chrisdone commented 8 years ago

@ivan-m If you remove your clone of mine then I'll transfer ownership to you. 👍

ivan-m commented 8 years ago

Done.

ivan-m commented 8 years ago

/me lets the power get to his head

ahem

Anyway, I'll try and get this resolved in the next few days.

@chrisdone can you please transfer/add me to the maintainers list on Hackage as well please? (And I'm assuming this is on Stackage, so I'll need to transfer that as well.)

chrisdone commented 8 years ago

Added you to maintainership of Hackage.

dubiousjim commented 8 years ago

I don't think the patches I supplied above are quite right/adequate. The allow haskell-docs to build, but now it doesn't seem to locate module information. Witness:

$ haskell-docs Down
Package: base-4.9.0.0
Module: Data.Ord
Down
The Down type allows you to reverse sort order conveniently. A value of type
 `Down a` contains a value of type `a` (represented as `Down a`).
 If `a` has an `Ord` instance associated with it then comparing two
 values thus wrapped will give you the opposite of their normal sort order.
 This is particularly useful when sorting in generalised list comprehensions,
 as in: `then sortWith by Down x`
Provides Show and Read instances (*since: 4.7.0.0*).

but:

$ haskell-docs Data.Ord
Couldn't find any packages with that module.
dubiousjim commented 8 years ago

Also the parsing of package names probably isn't right:

$ haskell-docs mkRegex
Package: regex-compat-0.95.1-4nLo9klb6Pk7Tun1BAC3he
Module: Text.Regex
mkRegex :: String -> Regex
Makes a regular expression with the default options (multi-line,
 case-sensitive). The syntax of regular expressions is
 otherwise that of `egrep` (i.e. POSIX "extended" regular
 expressions).
ivan-m commented 8 years ago

OK, I've now made haskell-docs buildable with GHC 8.0.1 and released on Hackage as 4.2.7. If parsing issues still occur, please open a new issue.