Opened 2 years ago

Closed 2 years ago

Last modified 6 months ago

#9880 closed bug (fixed)

ghc crashes on th splices in instance context

Reported by: Philonous Owned by:
Priority: normal Milestone:
Component: Documentation Version: 7.8.3
Keywords: Cc: goldfire
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Given Class.hs:

module Class where

class Foo a where
    bar :: a -> Int

TH.hs

{-# LANGUAGE TemplateHaskell #-}
module TH where

import Class
import Language.Haskell.TH

mkFun :: Q [Dec]
mkFun = return [FunD 'bar [Clause [WildP] (NormalB (LitE (IntegerL 0)))
                                     []]]

and Instance.hs

{-# LANGUAGE TemplateHaskell #-}
module Instance where

import TH
import Class

instance Foo Bool where
    $(mkFun)

compiling the project crashes ghc with

#ghc --make Instance.hs
[2 of 3] Compiling TH               ( TH.hs, TH.o )
[3 of 3] Compiling Instance         ( Instance.hs, Instance.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 7.8.3 for x86_64-unknown-linux):
        cvBindsAndSigs $[splice{v}]mkFun{v}

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug


Change History (7)

comment:1 Changed 2 years ago by simonpj

Cc: goldfire added

HEAD says

T9880.hs:5:3:
    Declaration splices are allowed only at the top level: $mkFun

which is a lot better than crashing.

Richard is this supposed to work now? I recall that you largely made splices in local declarations work.

Simon

comment:2 Changed 2 years ago by goldfire

The behavior you see -- that error -- is what I'd expect.

I had a brief go at implementing local declaration splices but soon realized that implementing this involves quite a bit of replumbing. The splices would have to break up mutually-recursive groups within class, instance, and let declarations, and that would require changes to several bits of HsSyn. So, I settled for just fixing the panic and waiting for someone to scream loudly that they need this feature.

comment:3 Changed 2 years ago by simonpj

Is this behaviour documented in the user manual?

comment:4 Changed 2 years ago by goldfire

Doesn't seem to be. I'll fix that shortly.

comment:5 Changed 2 years ago by Richard Eisenberg <eir@…>

In 53599b3f515227f3407991913781fc8ea79d9638/ghc:

Clarify that declaration splices exist at top level only. (#9880)

comment:6 Changed 2 years ago by goldfire

Component: CompilerDocumentation
Resolution: fixed
Status: newclosed

comment:7 in reply to:  2 Changed 6 months ago by mentheta

Replying to goldfire:

The behavior you see -- that error -- is what I'd expect.

I had a brief go at implementing local declaration splices but soon realized that implementing this involves quite a bit of replumbing. The splices would have to break up mutually-recursive groups within class, instance, and let declarations, and that would require changes to several bits of HsSyn. So, I settled for just fixing the panic and waiting for someone to scream loudly that they need this feature.

goldfire,

I've just run into the situation where I hoped Q [Dec] would have worked in a let binding, and it did not. I don't yet intend to scream, however, I am curious; Is there any Trac ticket in particular I could subscribe to, where I can follow any potential development on the implementation for supporting declaration splices in let bindings?

Last edited 6 months ago by mentheta (previous) (diff)
Note: See TracTickets for help on using tickets.