Opened 10 months ago

Closed 2 months ago

#9032 closed bug (fixed)

Panic with self-import

Reported by: jstolarek Owned by:
Priority: highest Milestone: 7.10.1
Component: Template Haskell Version: 7.8.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Test Case: rename/should_fail/T9032
Blocked By: Blocking:
Related Tickets: #1012 Differential Revisions:

Description (last modified by thomie)

A test in the singletons package leads to a panic when run:

ghc: panic! (the 'impossible' happened)
  (GHC version 7.8.2 for x86_64-unknown-linux):
        tcIfaceGlobal (local): not found:
    singletons-1.0:Singletons.Star.TFCo:R:DemoteRep*KProxy{tc r0}
    []

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

Edit: see comment:1 for a testcase.

Change History (10)

comment:1 Changed 9 months ago by monoidal

Here's a test case with no external dependencies, obtained from singletons and th-desugar; crashes 7.8.2 and HEAD. Put two files

CustomStar.hs

{-# LANGUAGE TypeFamilies, TemplateHaskell #-}

module CustomStar ( singletonStar ) where

import Language.Haskell.TH

data family Sing a

singFamilyName :: Name
singFamilyName = ''Sing

singletonStar :: Q [Dec]
singletonStar = do
  aName <- newName "z"
  return $ [DataInstD [] singFamilyName [SigT (VarT aName) StarT] [] []]

Star.hs

{-# LANGUAGE CPP, TemplateHaskell, TypeFamilies #-}

module Star where

import CustomStar

#ifdef ERR
import Star
#endif

$(singletonStar)

and execute

rm -f *.dyn_hi *.dyn_o *.hi *.o
ghc CustomStar.hs
ghc -c Star.hs
ghc -c Star.hs -DERR
Last edited 9 months ago by monoidal (previous) (diff)

comment:2 Changed 7 months ago by jstolarek

comment:3 Changed 4 months ago by thomie

  • Component changed from Compiler to Template Haskell
  • Description modified (diff)
  • Milestone set to 7.10.1

Still present in 7.9. I have cleaned up the description a bit.

comment:4 Changed 3 months ago by simonpj

  • Priority changed from normal to highest

I think a module should simply never import itself. I propose to make this an error. Does anyone object?

I'm increasing the priority to highest to make sure that we attend to this, not because it's terribly important. It's very easy to implement if we agree that it should be illegal.

Simon

comment:5 follow-up: Changed 3 months ago by monoidal

It's already an error (Module imports form a cycle: module 'X' imports itself), but in this case the self-import somehow gives a panic.

comment:6 in reply to: ↑ 5 Changed 3 months ago by simonpj

Replying to monoidal:

It's already an error (Module imports form a cycle: module 'X' imports itself), but in this case the self-import somehow gives a panic.

Good point. So it's already an error; albeit one that is only reported with --make. We should get a decent error in one-shot mode too.

Simon

comment:7 Changed 2 months ago by Simon Peyton Jones <simonpj@…>

In edd233acc19d269385c1a870829e0916a3df8e88/ghc:

Test earlier for self-import (Trac #9032)

This patch makes the renamer check for self-import, especially when
dependencies change, because the typechecker can fall over if that
happens.

I'm still uneasy about *indirect* self-import, but I'll leave that for
another day

comment:8 Changed 2 months ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to rename/should_fail/T9032

comment:9 Changed 2 months ago by hvr

  • Status changed from closed to merge

comment:10 Changed 2 months ago by hvr

  • Status changed from merge to closed

has been cherry-picked into ghc-7.10 branch

Note: See TracTickets for help on using tickets.