-
Notifications
You must be signed in to change notification settings - Fork 85
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
Monadic grammar, threaded lexer, -a
enabled, but no type signature, fails to compile
#94
Comments
@harpocrates Isn't there's a chance this is due to GHC changes? But I do get superficially similar errors in 1.19.6 over 1.19.5 (details in linked Agda issue). If your bug is with 1.19.5, however, it might be a different one (sorry, can't tell right now). |
@Blaisorblade I just double-checked again and you are right - I can only trigger the bug with HEAD, not 1.19.5. I'll try to do a git-bisect and report back. That said, are you compiling happy with only |
I'm somewhat clueless honestly—Agda build seems to use happy in as default a way as possible. I could only tell my symptoms were somewhat similar. I just installed happy, tried building Agda and did a report, and this was the only issue that seemed relevant — people on the linked agda issue (agda/agda#2731) might have a clue on their side. I mean, the whole config is https://github.com/agda/agda/blob/4ea8f42f3c9f517750127a03f5c4cacb89c63997/Agda.cabal#L320, which tells cabal to build https://github.com/agda/agda/blob/release-2.5.2/src/full/Agda/Syntax/Parser/Parser.y automatically (using support documented here: https://www.haskell.org/cabal/users-guide/developing-packages.html). |
Update: the output uses unsafeCoerce#, mentions GHC and uses
EDIT: also, forgot to thank you for your quick followup investigation! |
Alright. I did some bisecting (using the above sample file
Here is what happened over the course of those three commits. |
So those commits are from #49. The PR allows me to form an initial hypothesis. I have a million question marks and details won't be quite right, but hope this helps and isn't too much nonsense. @simonmar, @emc2, does that make sense?
For our purposes, we can simplify the failed generated code to the following incorrect code: v :: t13
v = () Though my real output is closer to the following (where only happyReduce_114 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn t13 t14 t15 t38 t41 t44 t45 t46 t54 t55 t84) -> Parser (HappyAbsSyn t13 t14 t15 t38 t41 t44 t45 t46 t54 t55 t84)
happyReduce_114 = happySpecReduce_0 4# happyReduction_114
happyReduction_114 = happyIn13 (())
happyIn13 :: t13 -> (HappyAbsSyn t13 t14 t15 t38 t41 t44 t45 t46 t54 t55 t84)
happyIn13 x = Happy_GHC_Exts.unsafeCoerce# x Before, no type declaration was generated—now the above is generated. If you declare a return type A problem we are seeing is just that happy does NOT infer the return type of productions — it didn't need to before. The patch seems to assume that those parsers must be universally quantified. That's not good. It's also not clear to me why using type classes requires generating signatures. I can only see it requires disabling the monomorphism restriction if you have definitions without arguments. == The PR suggests it affects parser specifying a monad and a lexer, like both your example and mine:
|
We added the signatures following a suggestion by Paolo G. Giarrusso. See also haskell/happy#94.
@emc2 could you take a look at this please? |
@harpocrates I was confused because I suffered the bug but I have -agc all enabled, maybe the mismatch is because you were using merged but unreleased PR #97 ? Not sure why though. |
@Blaisorblade I think #97 was indeed the interfering problem I had. I ran into several problems all at once and had some difficulty initially separating them in my bug reports :). I just checked and I can reproduce the bug with To set the record straight and avoid any more confusion: you need at least Also, to back up your comment
I actually did precisely this a while ago and it worked fine with Happy 1.19.5. |
Haven't checked the 1st part myself, but agda/agda@888cb9a seems to confirm that this workaround indeed works. (To be sure, my understanding of this is very shallow and built very lazily — apologies for any nonsense).
OK, so the silly question is: could one revert that patch, enable the monomorphism restriction or suggest that users enable it, and remove the regression? I'll leave the answer to somebody with more clue. Luckily, #49 includes some tests, so it should be easy to verify this works. I do understand there are downsides to disabling the monomorphism restriction: the generated class constraint might turn a one-time computation into something that is regenerated at each call, even if you always use a single monad. But I doubt this is relevant here: adding signatures does not improve performance, it just silences a warning. |
Should I just revert the offending commits here? |
@simonmar That makes sense to me — just please, don't take my word for it as explained :-). @harpocrates ? |
I've been thinking about what we could do to fix this, but nothing simple comes to mind. The only easy fix is reverting. Here are some other more constructive ideas:
The first bullet point is the simplest to implement, and pretty tidy IMO. Seems like a net gain compared to just reverting. That said, it also means that as soon as you are missing even just one signature, you fall off a cliff and the generated code will suddenly have a lot less signatures and won't support type classes without enabling Thoughts @simonmar? FWIW, I'd be willing to put together a quick PR for the first point, just to fix the breakage this is causing. |
* for versions of GHC >= 7.10.3, use `-XPartialTypeSignatures` and put in `_` wildcards instead of type variables for the type variables on `HappyAbsSyn` * otherwise, only generate problematic signatures when all productions have type signatures
* for versions of GHC >= 7.10.3, use `-XPartialTypeSignatures` and put in `_` wildcards instead of type variables for the type variables on `HappyAbsSyn` * otherwise, only generate problematic signatures when all productions have type signatures
* for versions of GHC >= 7.10.3, use `-XPartialTypeSignatures` and put in `_` wildcards instead of type variables for the type variables on `HappyAbsSyn` * otherwise, only generate problematic signatures when all productions have type signatures
* for versions of GHC >= 7.10.3, use `-XPartialTypeSignatures` and put in `_` wildcards instead of type variables for the type variables on `HappyAbsSyn` * otherwise, only generate problematic signatures when all productions have type signatures
* for versions of GHC >= 7.10.3, use `-XPartialTypeSignatures` and put in `_` wildcards instead of type variables for the type variables on `HappyAbsSyn` * otherwise, only generate problematic signatures when all productions have type signatures
* for versions of GHC >= 7.10.3, use `-XPartialTypeSignatures` and put in `_` wildcards instead of type variables for the type variables on `HappyAbsSyn` * otherwise, only generate problematic signatures when all productions have type signatures
@simonmar a gentle ping on this. |
I noticed that when I have a monadic grammar with a threaded lexer, generated with
(just)-a
enabled, and do not include a type signature on a production, I get type errors in the generated code. I don’t think this is the expected behaviour. Here is an example of such a grammar:Without the type signature:
With the type signature uncommented:
Note that this is a regression (I have at least some older version of Happy on which the type signature is not required to generate compiling code). This bug seems present in at least
1.19.5 andHEAD.The text was updated successfully, but these errors were encountered: