Ticket #5792 (closed bug: fixed)

Opened 4 months ago

Last modified 4 months ago

PolyKinds and recompilation causes internal error

Reported by: reinerp Owned by: simonpj
Priority: high Milestone: 7.4.2
Component: Compiler (Type checker) Version: 7.4.1-rc1
Keywords: PolyKinds Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Difficulty: Unknown
Test Case: typecheck/should_compile/T5792 Blocked By:
Blocking: Related Tickets:

Description

Given these two files:

module A where
-- empty

and

{-# LANGUAGE PolyKinds, TypeFamilies, UndecidableInstances #-}
module B where

import A

data T = TT

type family Compare (m :: T) :: Ordering
type instance Compare TT = Compare TT

type Compare' a = Compare a

We can cause an internal GHC error as follows:

$ rm *.o *.hi
$ ghc B.hs
[1 of 2] Compiling A                ( A.hs, A.o )
[2 of 2] Compiling B                ( B.hs, B.o )
$ sleep 1
$ touch B.hs
$ ghc B.hs
[2 of 2] Compiling B                ( B.hs, B.o )

B.hs:11:19:
    GHC internal error: `Compare' is not in scope during type checking, but it passed the renamer
    tcl_env of environment: [(a9R, AThing k_a9U)]
    In the type `Compare a'
    In the type synonym declaration for Compare'

Change History

Changed 4 months ago by dreixel

  • keywords PolyKinds added

Changed 4 months ago by igloo

  • priority changed from normal to high
  • difficulty set to Unknown
  • os changed from MacOS X to Unknown/Multiple
  • milestone set to 7.4.2

Reproducible in HEAD and 7.4 branch.

Changed 4 months ago by simonpj

  • owner set to simonpj

I know what is going on here.

Changed 4 months ago by simonpj

I've fixed the 7.4 branch, thus:

commit bd0ce7d72a62100157355e3bab50bee3c953ee62
Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Thu Feb 2 13:21:46 2012 +0000

    Fix dependency-analysis of type/class decls
    
    Family instances don't define a new type, but we were bogusly
    pretending they bound the family tycon.  The led to incorrect
    dependencies with strange results; it showed up as Trac #5792.
    
    This slightly hacky fix is on the branch only; I am doing a more
    substantial refactoring on HEAD.

 compiler/rename/RnSource.lhs |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

I'll make a separate fix for HEAD.

Simon

Changed 4 months ago by simonpj

  • status changed from new to closed
  • testcase set to typecheck/should_compile/T5792
  • resolution set to fixed

And I fixed the HEAD thus:

commit f92591defcb5c4803c301558d51e3f8c9c92a985
Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Mon Feb 6 08:38:59 2012 +0000

    Refactor HsDecls again, to put family instances in InstDecl
    
    This continues the clean up of the front end.  Since they
    were first invented, type and data family *instance* decls
    have been in the TyClDecl data type, even though they always
    treated separately.
    
    This patch takes a step in the right direction
      * The InstDecl type now includes both class instances and
        type/data family instances
    
      * The hs_tyclds field of HsGroup now never has any family
        instance declarations in it
    
    However a family instance is still a TyClDecl.  It should really
    be a separate type, but that's the next step.
    
    All this was provoked by fixing Trac #5792 in the HEAD.
    (I did a less invasive fix on the branch.)

 compiler/deSugar/DsMeta.hs          |   16 ++++++---
 compiler/hsSyn/Convert.lhs          |   20 ++++++-----
 compiler/hsSyn/HsDecls.lhs          |   61 +++++++++++++++++++++++------------
 compiler/hsSyn/HsUtils.lhs          |   24 ++++++++------
 compiler/main/HscStats.lhs          |   13 ++++---
 compiler/parser/Parser.y.pp         |   33 +++++++++++--------
 compiler/rename/RnNames.lhs         |   29 ++++++++--------
 compiler/rename/RnSource.lhs        |   23 +++++++++----
 compiler/typecheck/TcDeriv.lhs      |    2 +-
 compiler/typecheck/TcInstDcls.lhs   |   35 ++++++++++----------
 compiler/typecheck/TcTyClsDecls.lhs |   11 ++----
 utils/ghctags/Main.hs               |    2 +-
 12 files changed, 156 insertions(+), 113 deletions(-)

Plus a regression test. Done!

Simon

Note: See TracTickets for help on using tickets.