danielg / ghc-syb Goto Github PK
View Code? Open in Web Editor NEWScrap Your Boilerplate instances for GHC's data types
Scrap Your Boilerplate instances for GHC's data types
CC @alanz
Continuing my analysis of Haskell packages, I stumbled upon a weird error with some Pandoc code. Here is the stripped down version of it:
{-# LANGUAGE Arrows #-}
-- | First argument: basis for a new "pretty" anchor if none exists yet
-- Second argument: a key ("ugly" anchor)
-- Returns: saved "pretty" anchor or created new one
getPrettyAnchor :: OdtReaderSafe (AnchorPrefix, Anchor) Anchor
getPrettyAnchor = proc (baseIdent, uglyAnchor) -> do
state <- getExtraState -< ()
returnA -< prettyAnchor
While GHC 7.10.2 works as usual, GHC 7.8.4 crashes while traversing the AST. Unlike other times, the program stops with
argon: Prelude.undefined
From my understanding, there should be an undefined
somewhere and it's getting evaluated. However, I couldn't find any undefined related to arrows types.
Now I've downloaded the GHC 7.8.4 source code in the hope of finding something with grep.
When running cabal install ghc-syb-utils
I get the following error. I'm completely new to Haskell, so I have no idea what this means, but there seems to be a compilation error with the library. Any idea how I can fix it?
GHC version is 8.4.3 (the current latest).
Resolving dependencies...
Configuring ghc-syb-utils-0.2.3.3...
Building ghc-syb-utils-0.2.3.3...
Failed to install ghc-syb-utils-0.2.3.3
Build log ( /Users/ines/.cabal/logs/ghc-8.4.2/ghc-syb-utils-0.2.3.3-IUVEFDznc7a5BD9bwzj1Oj.log ):
cabal: Entering directory '/var/folders/qq/qsg3wfvj3nqfzkdnn9ggp2vc0000gn/T/cabal-tmp-8763/ghc-syb-utils-0.2.3.3'
Configuring ghc-syb-utils-0.2.3.3...
clang: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
Preprocessing library for ghc-syb-utils-0.2.3.3..
Building library for ghc-syb-utils-0.2.3.3..
[1 of 1] Compiling GHC.SYB.Utils ( GHC/SYB/Utils.hs, dist/build/GHC/SYB/Utils.o )
GHC/SYB/Utils.hs:258:64: error:
• Could not deduce (HasSourceText (XHsChar RdrName))
arising from a use of ‘ppr’
from the context: Data a
bound by the type signature for:
showData :: forall a. Data a => Stage -> Int -> a -> String
at GHC/SYB/Utils.hs:229:1-49
• In the second argument of ‘(.)’, namely ‘ppr’
In the second argument of ‘(.)’, namely ‘showSDoc_ . ppr’
In the second argument of ‘(.)’, namely
‘(++ "}") . showSDoc_ . ppr’
|
258 | overLit = ("{HsOverLit:"++) . (++"}") . showSDoc_ . ppr
| ^^^
GHC/SYB/Utils.hs:261:73: error:
• Could not deduce (Data (XHsChar RdrName))
arising from a use of ‘list’
from the context: Data a
bound by the type signature for:
showData :: forall a. Data a => Stage -> Int -> a -> String
at GHC/SYB/Utils.hs:229:1-49
• In the first argument of ‘(.)’, namely ‘list’
In the second argument of ‘(.)’, namely ‘list . bagToList’
In the second argument of ‘(.)’, namely
‘(++ "}") . list . bagToList’
|
261 | bagRdrName = ("{Bag(Located (HsBind RdrName)): "++) . (++"}") . list . bagToList
| ^^^^
GHC/SYB/Utils.hs:263:70: error:
• Could not deduce (Data (XHsChar Name))
arising from a use of ‘list’
from the context: Data a
bound by the type signature for:
showData :: forall a. Data a => Stage -> Int -> a -> String
at GHC/SYB/Utils.hs:229:1-49
• In the first argument of ‘(.)’, namely ‘list’
In the second argument of ‘(.)’, namely ‘list . bagToList’
In the second argument of ‘(.)’, namely
‘(++ "}") . list . bagToList’
|
263 | bagName = ("{Bag(Located (HsBind Name)): "++) . (++"}") . list . bagToList
| ^^^^
GHC/SYB/Utils.hs:265:69: error:
• Could not deduce (Data (XHsChar Var))
arising from a use of ‘list’
from the context: Data a
bound by the type signature for:
showData :: forall a. Data a => Stage -> Int -> a -> String
at GHC/SYB/Utils.hs:229:1-49
• In the first argument of ‘(.)’, namely ‘list’
In the second argument of ‘(.)’, namely ‘list . bagToList’
In the second argument of ‘(.)’, namely
‘(++ "}") . list . bagToList’
|
265 | bagVar = ("{Bag(Located (HsBind Var)): "++) . (++"}") . list . bagToList
| ^^^^
cabal: Leaving directory '/var/folders/qq/qsg3wfvj3nqfzkdnn9ggp2vc0000gn/T/cabal-tmp-8763/ghc-syb-utils-0.2.3.3'
cabal: Error: some packages failed to install:
ghc-syb-utils-0.2.3.3-IUVEFDznc7a5BD9bwzj1Oj failed during the building phase.
The exception was:
ExitFailure 1
It fails with long list of type errors:
[1 of 1] Compiling GHC.SYB.Utils ( GHC/SYB/Utils.hs, dist/build/GHC/SYB/Utils.o )
GHC/SYB/Utils.hs:221:48:
Couldn't match type `SDoc -> String' with `[Char]'
Expected type: DynFlags -> [Char]
Actual type: DynFlags -> SDoc -> String
In the first argument of `(.)', namely `showSDoc'
In the second argument of `(.)', namely `showSDoc . ppr'
In the second argument of `(.)', namely `(++ "}") . showSDoc . ppr'
GHC/SYB/Utils.hs:221:59:
Couldn't match type `SDoc' with `DynFlags'
Expected type: Name -> DynFlags
Actual type: Name -> SDoc
In the second argument of `(.)', namely `ppr'
In the second argument of `(.)', namely `showSDoc . ppr'
In the second argument of `(.)', namely `(++ "}") . showSDoc . ppr'
....
Currently test suite of 0.2.3.2 release fails when building with GHC 8.0.x with the following error:
===== Type-checked Source ============================
regression-tests: Data.ByteString.ByteString.toConstr
CallStack (from HasCallStack):
error, called at libraries/bytestring/Data/ByteString/Internal.hs:184:20 in bytestring-0.10.8.1:Data.ByteString.Internal
Test suite regression-tests: FAIL
Test suite logged to: dist/test/ghc-syb-utils-0.2.3.2-regression-tests.log
0 of 1 test suites (0 of 1 test cases) passed.
After a bit of digging this appears to be related to HsStringPrim constructor which contains a ByteString
field. ByteString
's implementation of toConstr
is toConstr _ = error "...."
so everything blows up in showData.generic
. To confirm this I applied the following patch:
diff --git a/utils/GHC/SYB/Utils.hs b/utils/GHC/SYB/Utils.hs
index 7b53b79..df7a880 100644
--- a/utils/GHC/SYB/Utils.hs
+++ b/utils/GHC/SYB/Utils.hs
@@ -181,6 +181,7 @@ import DynFlags
import GHC hiding (moduleName)
import Outputable hiding (space)
import SrcLoc()
+import qualified Data.ByteString as BS
import qualified OccName(occNameString)
import Bag(Bag,bagToList)
import Var(Var)
@@ -228,7 +229,7 @@ data Stage = Parser | Renamer | TypeChecker deriving (Eq,Ord,Show)
-- (based on the 'Stage' that generated the Ast)
showData :: Data a => Stage -> Int -> a -> String
showData stage n =
- generic `ext1Q` list `extQ` string `extQ` fastString `extQ` srcSpan
+ generic `ext1Q` list `extQ` string `extQ` fastString `extQ` srcSpan `extQ` byteString
`extQ` name `extQ` occName `extQ` moduleName `extQ` var `extQ` dataCon
`extQ` overLit
`extQ` bagName `extQ` bagRdrName `extQ` bagVar `extQ` nameSet
@@ -244,6 +245,7 @@ showData stage n =
indent i = "\n" ++ replicate i ' '
string = show :: String -> String
fastString = ("{FastString: "++) . (++"}") . show :: FastString -> String
+ byteString = ("{ByteString: "++) . (++"}") . show :: BS.ByteString -> String
list l = indent n ++ "["
++ concat (intersperse "," (map (showData stage (n+1)) l)) ++ "]"
diff --git a/utils/ghc-syb-utils.cabal b/utils/ghc-syb-utils.cabal
index 72958b0..dccf41d 100644
--- a/utils/ghc-syb-utils.cabal
+++ b/utils/ghc-syb-utils.cabal
@@ -18,6 +18,7 @@ extra-source-files: test/test-cases/*.hs
library
build-depends: base >= 4 && < 5
+ , bytestring
, syb >= 0.1.0
if impl(ghc >= 7.0)
that allows the test suite to pass. Output of a successful run.
I'm not familiar at all with the problem domain here so I have no idea if that's a proper / acceptable solution. Hopefully this gives enough details for someone more knowledgeable in this area to come up with an adequate fix if (assuming such a fix is desired).
Could I provide a pull request to bring over the SYB versions of staged schemes from https://github.com/alanz/HaRe/blob/master/src/Language/Haskell/Refact/Utils/GhcUtils.hs to ghc-syb?
In particular
-- * SYB versions
everythingButStaged
, somethingStaged
, everythingStaged
, somewhereMStaged
, somewhereMStagedBu
, everywhereMStaged
, everywhereMStaged'
, everywhereStaged
, everywhereStaged'
, onelayerStaged
, listifyStaged
-- ** SYB Utility
, checkItemRenamer
Correct me if I am wrong but it seems to me that ghc-syb-utils no longer uses bytestring so the dep can be dropped from ghc-syb-utils.cabal
.
Hey,
I need 190c787 for ghc-mod to work out of the box once ghc-7.10 is released, would be cool if you could do a release.
> /tmp/stackage-build13/ghc-syb-utils-0.2.3.1$ ghc -clear-package-db -global-package-db -package-db=/var/stackage/work/builds/nightly/pkgdb Setup
> /tmp/stackage-build13/ghc-syb-utils-0.2.3.1$ ./Setup configure --enable-tests --package-db=clear --package-db=global --package-db=/var/stackage/work/builds/nightly/pkgdb --libdir=/var/stackage/work/builds/nightly/lib --bindir=/var/stackage/work/builds/nightly/bin --datadir=/var/stackage/work/builds/nightly/share --libexecdir=/var/stackage/work/builds/nightly/libexec --sysconfdir=/var/stackage/work/builds/nightly/etc --docdir=/var/stackage/work/builds/nightly/doc/ghc-syb-utils-0.2.3.1 --htmldir=/var/stackage/work/builds/nightly/doc/ghc-syb-utils-0.2.3.1 --haddockdir=/var/stackage/work/builds/nightly/doc/ghc-syb-utils-0.2.3.1 --flags=
Configuring ghc-syb-utils-0.2.3.1...
> /tmp/stackage-build13/ghc-syb-utils-0.2.3.1$ ghc -clear-package-db -global-package-db -package-db=/var/stackage/work/builds/nightly/pkgdb Setup
> /tmp/stackage-build13/ghc-syb-utils-0.2.3.1$ ./Setup build
Building ghc-syb-utils-0.2.3.1...
Preprocessing library ghc-syb-utils-0.2.3.1...
[1 of 1] Compiling GHC.SYB.Utils ( GHC/SYB/Utils.hs, dist/build/GHC/SYB/Utils.o ) [dist/build/autogen/cabal_macros.h changed]
Preprocessing test suite 'regression-tests' for ghc-syb-utils-0.2.3.1...
[1 of 1] Compiling Main ( test/Regression.hs, dist/build/regression-tests/regression-tests-tmp/Main.o )
Linking dist/build/regression-tests/regression-tests ...
> /tmp/stackage-build13/ghc-syb-utils-0.2.3.1$ dist/build/regression-tests/regression-tests
<no location info>: error:
can't find file: /tmp/stackage-build13/ghc-syb-utils-0.2.3.1/test/test-cases/GithubIssue9.hs
[1 of 1] Compiling GHC.SYB.Utils ( GHC/SYB/Utils.hs, dist/build/GHC/SYB/Utils.o )
GHC/SYB/Utils.hs:188:24:
Module ‘NameSet’ does not export ‘nameSetToList’
cabal: Error: some packages failed to install:
ghc-syb-utils-0.2.2 failed during the building phase. The exception was:
ExitFailure 1
is that expected? Have reverted to 0.1.1.1
CC @alanz
I've analyzed many popular Haskell packages and I've been able to find only this one bug.
Given this code:
module Internal.Sparse where
import Foreign.C.Types(CInt(..))
import Foreign(Ptr)
-- SmxV is not defined anywhere but that does not matter because we are just parsing
foreign import ccall unsafe "smXv"
c_smXv :: SMxV
foreign import ccall unsafe "smTXv"
c_smTXv :: SMxV
everythingStaged
explodes with:
argon: argon: panic! (the 'impossible' happened)
(GHC version 7.8.4 for x86_64-unknown-linux):
ForeignImport coercion evaluated before typechecking
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
I wasn't been able to really understand what's going on there.
Preprocessing library ghc-syb-utils-0.2.3.2...
[1 of 1] Compiling GHC.SYB.Utils ( GHC/SYB/Utils.hs, dist/build/GHC/SYB/Utils.o )
GHC/SYB/Utils.hs:189:24: error:
Module ‘NameSet’ does not export ‘nameSetElemsStable’
GHC is at 8.0.1.
While traversing the AST with everythingStaged Parser
GHC 7.8.4 crashes on mkHsTyWithBndrs
:
argon: argon: panic! (the 'impossible' happened)
(GHC version 7.8.4 for x86_64-unknown-linux):
mkHsTyWithBndrs:kvs
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
As far as I understand, this shouldn't happen, as everythingStaged
is supposed to avoid known potholes.
Here is how everythingStaged
is being used:
https://github.com/rubik/argon/blob/master/src/Argon/Visitor.hs
I have code
{-# LANGUAGE TemplateHaskell #-}
module Blow where
import Language.Haskell.TH
foo :: Q Exp
foo = [| \f -> f 2 |]
that manages to blow up showData
after typechecking. I added some unsafePerformIO+evaluate magic to catch it, output:
{Bag(Located (HsBind Var)):
[
(L {experimental/users/robinpalotai/ghcapi/Blow.hs:6:8-12}
(AbsBinds
[]
[]
[
(ABE {Var: Blow.foo} {Var: foo}
(WpHole)
(SpecPrags
[]))]
({abstract:TcEvBinds}) {Bag(Located (HsBind Var)):
[
(L {experimental/users/robinpalotai/ghcapi/Blow.hs:7:1-21}
(FunBind
(L {experimental/users/robinpalotai/ghcapi/Blow.hs:7:1-3} {Var: foo})
(False)
(MG
[
(L {experimental/users/robinpalotai/ghcapi/Blow.hs:7:1-21}
(Match
[]
(Nothing)
(GRHSs
[
(L {experimental/users/robinpalotai/ghcapi/Blow.hs:7:7-21}
(GRHS
[]
(L {experimental/users/robinpalotai/ghcapi/Blow.hs:7:7-21}
(HsTcBracketOut
(ExpBr
(L {experimental/users/robinpalotai/ghcapi/Blow.hs:7:10-18}
(HsLam
(MG
[
(L {experimental/users/robinpalotai/ghcapi/Blow.hs:7:10-18}
(Match
[
(L {experimental/users/robinpalotai/ghcapi/Blow.hs:7:11}
(VarPat {Name: f}))]
(Nothing)
(GRHSs
[
(L {experimental/users/robinpalotai/ghcapi/Blow.hs:7:16-18}
(GRHS
[]
(L {experimental/users/robinpalotai/ghcapi/Blow.hs:7:16-18}
(HsApp
(L {experimental/users/robinpalotai/ghcapi/Blow.hs:7:16}
(HsVar {Name: f}))
(L {experimental/users/robinpalotai/ghcapi/Blow.hs:7:18}
(HsOverLit
(OverLit
(HsIntegral
(2))
(False)
HERE ---> (HsVar {Name: GHC.Num.fromInteger}) PostTcType blew up!)))))))]
(EmptyLocalBinds))))]
[] PostTcType blew up!
(FromSource)))))
[]))))]
(EmptyLocalBinds))))]
[] Language.Haskell.TH.Syntax.Q Language.Haskell.TH.Syntax.Exp
(FromSource))
(WpHole) {!NameSet placeholder here!}
(Nothing)))]}))]}
Blow.foo
It would be nice if it didn't.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.