DanielG / ghc-syb

Scrap Your Boilerplate instances for GHC's data types
8 stars 10 forks source link

everythingStage crashes on mkHsTyWithBndrs:kvs #13

Closed rubik closed 8 years ago

rubik commented 8 years ago

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

rubik commented 8 years ago

Maybe @alanz can help shed light on this? I see he is very knowledgeable about this topic.

alanz commented 8 years ago

Can you provide the input file that causes the crash?

rubik commented 8 years ago

I'm sorry, I was sure I had included it. Here it is:

{-# LANGUAGE ScopedTypeVariables #-}

module Utility.Exception where

import Control.Monad.Catch as X hiding (Handler)
import qualified Control.Monad.Catch as M

catchNonAsync :: MonadCatch m => m a -> (SomeException -> m a) -> m a
catchNonAsync a onerr = a catches
 [ M.Handler ( (e :: SomeException) -> onerr e)
 ]
alanz commented 8 years ago

It seems it is the EViewPat with an enclosed ExprWithTySig that is the problem, it uses mkHsWithBndrs which initialises with panic values

data HsWithBndrs thing
  = HsWB { hswb_cts :: thing         -- Main payload (type or list of types)
         , hswb_kvs :: [Name]        -- Kind vars
         , hswb_tvs :: [Name]        -- Type vars
    }                  
  deriving (Data, Typeable)

mkHsWithBndrs :: thing -> HsWithBndrs thing
mkHsWithBndrs x = HsWB { hswb_cts = x, hswb_kvs = panic "mkHsTyWithBndrs:kvs"
                                     , hswb_tvs = panic "mkHsTyWithBndrs:tvs" }
alanz commented 8 years ago

@rubik Please try install ghc-syb-utils from my repo to see if my attempt does anything for you.

https://github.com/alanz/ghc-syb

rubik commented 8 years ago

Awesome! Thank you for your quick response and fix. It works perfectly now. Can you push a new version to Hackage?

alanz commented 8 years ago

I will have to put in a pull request, the repo/package belong to @nominolo

On Fri, Oct 30, 2015 at 8:46 PM, Michele Lacchia notifications@github.com wrote:

Closed #13 https://github.com/nominolo/ghc-syb/issues/13.

— Reply to this email directly or view it on GitHub https://github.com/nominolo/ghc-syb/issues/13#event-450718868.

nominolo commented 8 years ago

Since you have a test program, how hard would it be to add it as a test case? Right now the acceptance criterion is probably just "doesn't crash", but still.

The GHC API is annoyingly unstable and full of those silly potholes. Would be nice to start catching regressions when GHC 8.0 comes along.

rubik commented 8 years ago

I can add it very easily to Argon tests. But it's only possible if a new version is pushed to Hackage, because Stack pulls packages from there or from Stackage. I already have quite a few tests that cover multiple cases.

alanz commented 8 years ago

@nominolo I am about to update for the Coercion failure, but I see that the github version of https://github.com/nominolo/ghc-syb does not have any tests, although there is a target for it in the makefile.

Please clarify what tests you are requesting to be updated

On Fri, Oct 30, 2015 at 10:36 PM, Thomas Schilling <notifications@github.com

wrote:

Since you have a test program, how hard would it be to add it as a test case? Right now the acceptance criterion is probably just "doesn't crash", but still.

The GHC API is annoyingly unstable and full of those silly potholes. Would be nice to start catching regressions when GHC 8.0 comes along.

— Reply to this email directly or view it on GitHub https://github.com/nominolo/ghc-syb/issues/13#issuecomment-152645340.

rubik commented 8 years ago

I think @nominolo was referring to my program Argon. I already added the relevant test cases and confirmed that your changes solve the issues. Now it's just a matter of publishing a new version of ghc-syb-utils.