Opened 3 years ago

Last modified 19 months ago

#5320 new bug

check_overlap panic (7.1 regression)

Reported by: mikhail.vorozhtsov Owned by: simonpj
Priority: normal Milestone: 7.6.2
Component: Compiler Version: 7.1
Keywords: Cc: dimitris@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

The attached program is rightfully rejected by GHC 7.0.4 (with "Could not deduce (HMapClass f l) ...") but makes GHC HEAD panic:

$ ghc-7.3.20110713 Overlap.hs 
[1 of 1] Compiling Overlap          ( Overlap.hs, Overlap.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 7.3.20110713 for x86_64-unknown-linux):
	check_overlap
    main:Overlap.HDropClass{tc raS}
      main:Overlap.PZero{tc raZ}
      (main:Overlap.HMap{tc raN} f{tv adi} [sk] l{tv adk} [sk])

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

Both versions are built with the devel2 BuildFlavour?.

Attachments (1)

Overlap.hs (1.7 KB) - added by mikhail.vorozhtsov 3 years ago.

Download all attachments as: .zip

Change History (13)

Changed 3 years ago by mikhail.vorozhtsov

comment:1 Changed 3 years ago by simonpj

  • Cc dimitris@… added

comment:2 Changed 3 years ago by simonpj

Harump. I'll fix the crash, but it does expose a little problem. Consider this program

{-# LANGUAGE FlexibleInstances, FlexibleContexts, 
             ScopedTypeVariables, MultiParamTypeClasses, TypeFamilies #-}

module Foo where

class C a b where op :: a -> b
instance C Int b
type family F a

f :: forall w. C Int w => Int -> w -> F Int
f x y = op x :: F Int

The call of op gives rise to a wanted constraint (C Int (F Int)) which you would think would be satisfied from the (C Int b) instance declaration. But actually we get this:

Foo.hs:10:9:
    Overlapping instances for C Int (F Int)
      arising from a use of `op'
    Matching instances: instance C Int b -- Defined at Foo.hs:6:10-16
    There exists a (perhaps superclass) match:
      from the context (C Int w)
        bound by the type signature for f :: C Int w => Int -> w -> F Int
        at Foo.hs:10:1-21

GHC is saying (a bit stupidly) that (C Int (F Int)) might ultimately reduce, by evaluating the call to F, to (C Int w), which could be satisfied from the constraint in the signature rather than the instance declaration. Of course, it can't. But it wouldn't have been so stupid if the program had been

g :: forall w. C Int w => Int -> w -> F [w]
g x y = op x :: F [w]

Now it's not so stupid; (F [w]) might indeed reduce to w.

But it's delicate, and may end up rejecdting a program that really should be accepted (like f). Not sure what to do here.

comment:3 Changed 3 years ago by mikhail.vorozhtsov

Can we safely ignore an overlap in case of "wildcard" (in the parameter(s) in question) instances like C Int b?

comment:4 Changed 3 years ago by mikhail.vorozhtsov

If yes, then the instance C Int (B b) could be considered a "wildcard" for resolving the potential overlap between C Int (B w) and C Int (B (F [w])). And so on.

comment:5 Changed 3 years ago by simonpj@…

commit 7689e56641423b818fbd19fe2128cd6eec2ec212
Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Fri Jul 15 14:46:13 2011 +0100

    Fix error reporting for overlapping instances in type checker
    
    See #5320 and discussion there.  This patch only removes
    a bogus assertion failure and refactors the code slightly.
    There's still an underlying delicate point, described in #5320.

comment:6 Changed 3 years ago by simonpj

Ian: can you merge the change to 7.2 anyway, pls?

comment:7 Changed 3 years ago by mikhail.vorozhtsov

Now I'm getting

ghc: panic! (the 'impossible' happened)
  (GHC version 7.3.20110718 for x86_64-unknown-linux):
	ASSERT failed! file compiler/typecheck/TcErrors.lhs, line 590

after the "Overlapping instances ..." message.

comment:8 Changed 3 years ago by simonpj

Ah, sorry. I've pushed a fix

commit f272d03a64329abdc28613a24f193bef7080db5a
Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Mon Jul 18 13:54:00 2011 +0100

    Remove bogus ASSERT

 compiler/typecheck/TcErrors.lhs |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

comment:9 Changed 3 years ago by igloo

  • Status changed from new to merge

comment:10 Changed 3 years ago by igloo

  • Status changed from merge to new

Merged as changeset:b72f0df964f4c52d0e0a4ca68ea8b5e58d5dea5b and changeset:2648e205f8d9c2d148c19f6df987c6b21fab0526

I'll leave the ticket open for the "underlying delicate point".

comment:11 Changed 2 years ago by igloo

  • Milestone set to 7.6.1
  • Owner set to simonpj

comment:12 Changed 19 months ago by igloo

  • Milestone changed from 7.6.1 to 7.6.2
Note: See TracTickets for help on using tickets.