[GHC] #3467: GHC HEAD panics trying to splice a type

GHC trac at galois.com
Fri Sep 11 06:41:26 EDT 2009


#3467: GHC HEAD panics trying to splice a type
---------------------------------+------------------------------------------
    Reporter:  awson             |        Owner:                  
        Type:  bug               |       Status:  closed          
    Priority:  normal            |    Milestone:                  
   Component:  Compiler          |      Version:  6.11            
    Severity:  normal            |   Resolution:  fixed           
    Keywords:                    |   Difficulty:  Unknown         
    Testcase:  th/T3467          |           Os:  Unknown/Multiple
Architecture:  Unknown/Multiple  |  
---------------------------------+------------------------------------------
Changes (by simonpj):

  * testcase:  => th/T3467
  * difficulty:  => Unknown
  * status:  new => closed
  * resolution:  => fixed

Comment:

 Excellent point, thank you for the report.
 It appears that when I added the ability to splice types in TH
 programs, I failed to pay attention to non-top-level splices -- that
 is, splices inside quotatation brackets.

 Fixed in HEAD, and hence in 6.12.  I took the opportunity to do other
 stuff too.
 {{{
 Thu Sep 10 13:58:48 BST 2009  simonpj at microsoft.com
   * Three improvements to Template Haskell (fixes #3467)

   This patch implements three significant improvements to Template
 Haskell.

   Declaration-level splices with no "$"
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   This change simply allows you to omit the "$(...)" wrapper for
   declaration-level TH splices.  An expression all by itself is
   not legal, so we now treat it as a TH splice.  Thus you can now
   say
         data T = T1 | T2
         deriveMyStuff ''T

   where deriveMyStuff :: Name -> Q [Dec]
   This makes a much nicer interface for clients of libraries that use
   TH: no scary $(deriveMyStuff ''T).

   Nested top-level splices
   ~~~~~~~~~~~~~~~~~~~~~~~~
   Previously TH would reject this, saying that splices cannot be nested:
         f x = $(g $(h 'x))
   But there is no reason for this not to work.  First $(h 'x) is run,
   yielding code <blah> that is spliced instead of the $(h 'x). Then (g
   <blah>) is typechecked and run, yielding code that replaces the
   $(g ...) splice.

   So this simply lifts the restriction.

   Fix Trac #3467: non-top-level type splices
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   It appears that when I added the ability to splice types in TH
   programs, I failed to pay attention to non-top-level splices -- that
   is, splices inside quotatation brackets.

   This patch fixes the problem.  I had to modify HsType, so there's a
   knock-on change to Haddock.

   Its seems that a lot of lines of code has changed, but almost all the
   new lines are comments!

   General tidying up
   ~~~~~~~~~~~~~~~~~~
   As a result of thinking all this out I re-jigged the data type ThStage,
   which had far too many values before.  And I wrote a nice state
 transition
   diagram to make it all precise;
      see Note [Template Haskell state diagram] in TcSplice

   Lots more refactoring in TcSplice, resulting in significantly less code.
   (A few more lines, but actually less code -- the rest is comments.)

   I think the result is significantly cleaner.


     M ./compiler/deSugar/DsMeta.hs -44 +54
     M ./compiler/hsSyn/HsTypes.lhs -11 +15
     M ./compiler/parser/Lexer.x -1 +1
     M ./compiler/parser/Parser.y.pp -8 +8
     M ./compiler/parser/RdrHsSyn.lhs -2 +17
     M ./compiler/rename/RnHsSyn.lhs -1 +2
     M ./compiler/rename/RnTypes.lhs +2
     M ./compiler/typecheck/Inst.lhs -1 +1
     M ./compiler/typecheck/TcEnv.lhs -33 +7
     M ./compiler/typecheck/TcExpr.lhs -18 +30
     M ./compiler/typecheck/TcHsType.lhs -3 +9
     M ./compiler/typecheck/TcRnTypes.lhs -17 +35
     M ./compiler/typecheck/TcSimplify.lhs -21
     M ./compiler/typecheck/TcSplice.lhs -191 +276
     M ./docs/users_guide/glasgow_exts.xml -5 +23
 }}}
 Simon

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3467#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list