cgrep
cgrep copied to clipboard
cgrep 8.0.0/8.1.0 doesn't build
[19 of 29] Compiling CGrep.Output ( src/CGrep/Output.hs, dist/build/cgrep/cgrep-tmp/CGrep/Output.dyn_o )
src/CGrep/Output.hs:173:12: error:
• Illegal equational constraint GHC.Exts.Item a ~ B.Builder
(Use GADTs or TypeFamilies to permit this)
• When checking the inferred type
mkMatch :: forall {a}.
(GHC.Exts.Item a ~ B.Builder, Semigroup a, GHC.Exts.IsList a) =>
a -> Output -> a
In an equation for ‘jsonOutput’:
jsonOutput outs
= pure
$ mconcat . intersperse (B.char8 '\n')
$ [B.byteString "{ \"file\":\""
<> B.byteString fname <> B.byteString "\", \"matches\":["]
<>
[mconcat $ intersperse (B.char8 ',') (foldl mkMatch ... outs)]
<> [B.byteString "]}"]
where
fname | (Output f _ _ _) <- head outs = f
mkJToken chunk
= B.byteString "{ \"col\":"
<>
B.int64Dec (cOffset chunk)
<>
B.byteString ", \"token\":\""
<> B.byteString (cToken chunk) <> B.byteString "\" }"
mkMatch xs (Output _ n _ ts) = xs <> [...]
|
173 | mkMatch xs (Output _ n _ ts) =
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
I'm building with GHC 9.2.8 on Arch Linux x86_64.
Triggered by 3a6a67c8ccf99472cf85f06970c861130a4aaa34 cross checked by reverting that commit from v8.0.0 and v8.1.0 and both build.
Edit:
Work around add GADTs or TypeFamilies to Default-Extensions:
--- a/cgrep.cabal
+++ b/cgrep.cabal
@@ -38,6 +38,7 @@ Executable cgrep
Hs-Source-Dirs: src
Default-Extensions: FlexibleContexts
FlexibleInstances
+ GADTs
GeneralisedNewtypeDeriving
DerivingStrategies
MultiWayIf
It's the OverloadedLists feature caused this. By enabling it, the type became ambiguous for the compiler. Possible solutions may include:
- Turning off
OverloadedLists - Turning on
GADTsorTypeFamilies - Annotating the type to be a simple
[Builder]instead of a IsList type constraint
The last one may be the most straightforward one which causes minimal side-effects.
diff --git a/src/CGrep/Output.hs b/src/CGrep/Output.hs
index 7fed0da..9fbbf77 100644
--- a/src/CGrep/Output.hs
+++ b/src/CGrep/Output.hs
@@ -170,6 +170,7 @@ jsonOutput outs = pure $ mconcat . intersperse (B.char8 '\n') $
[ mconcat $ intersperse (B.char8 ',') (foldl mkMatch [] outs) ] <> [B.byteString "]}"]
where fname | (Output f _ _ _) <- head outs = f
mkJToken chunk = B.byteString "{ \"col\":" <> B.int64Dec (cOffset chunk) <> B.byteString ", \"token\":\"" <> B.byteString (cToken chunk) <> B.byteString "\" }"
+ mkMatch :: [B.Builder] -> Output -> [B.Builder]
mkMatch xs (Output _ n _ ts) =
xs <> [B.byteString "{ \"row\": " <> B.int64Dec n <> B.byteString ", \"tokens\":[" <>
mconcat (intersperse (B.byteString ",") (map mkJToken ts)) <> B.byteString "] }" ]
Could the reason this has not been detected / produced before be because GADTs is enabled by default in GHC2024?
@awgn do have you any preference on which solution to use to resolve the issue?
@felixonmars with your packaging of ghc 9.4.8 which has GADTs enabled by default the issue is no longer reproducible for me. Can you still reproduce it?
Indeed I can no longer reproduce it. Thanks for noticing!