#14732 closed bug (fixed)

-fdefer-typed-holes breaks a correct program

Reported by: MitchellSalad Owned by:
Priority: normal Milestone: 8.4.1
Component: Compiler Version: 8.2.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: typecheck/should_compile/T14732
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by MitchellSalad)

Here's a bug I discovered in vector that Ryan Scott identified as a regression from 7.10.3:

https://github.com/haskell/vector/issues/200

Here is Ryan's minimal example:

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Bug where

import Prelude hiding (zip, zipWith)

zipWith :: (a -> b -> c)
        -> Bundle v a
        -> Bundle v b
        -> Bundle v c
zipWith = undefined

class GVector (v :: * -> *) a
instance GVector Vector a

data Bundle (v :: * -> *) a
data Vector a
class Unbox a

stream :: GVector v a => v a -> Bundle v a
{-# INLINE [1] stream #-}
stream = undefined

zip :: (Unbox a, Unbox b) => Vector a -> Vector b -> Vector (a, b)
{-# INLINE [1] zip #-}
zip = undefined
{-# RULES "stream/zip [Vector.Unboxed]" forall as bs .
  stream (zip as bs) = zipWith (,) (stream as)
                                   (stream bs)   #-}

Output (8.2.2):

Bug.hs:29:11: error:
    • Could not deduce (Unbox a) arising from a use of ‘zip’
      from the context: GVector Vector (a, b)
        bound by the RULE "stream/zip [Vector.Unboxed]"
        at Bug.hs:(28,11)-(30,46)
      Possible fix:
        add (Unbox a) to the context of
          the RULE "stream/zip [Vector.Unboxed]"
    • In the first argument of ‘stream’, namely ‘(zip as bs)’
      In the expression: stream (zip as bs)
      When checking the transformation rule "stream/zip [Vector.Unboxed]"
   |
29 |   stream (zip as bs) = zipWith (,) (stream as)
   |           ^^^^^^^^^

Similar output in 8.0.1, 8.0.2, 8.2.1

Change History (8)

comment:1 Changed 23 months ago by MitchellSalad

Description: modified (diff)

comment:2 Changed 23 months ago by MitchellSalad

Summary: -fdefer-type-holes breaks a correct program-fdefer-typed-holes breaks a correct program

comment:3 Changed 23 months ago by simonpj

What exactly is the bug here, and how can I reproduce it? What has it got to do with -fdefer-type-errors?

I compiled the program above with -O; I got a Lint failure (but not a type error) with GHC-8.0; all other GHCs succeeded.

Last edited 23 months ago by simonpj (previous) (diff)

comment:4 Changed 23 months ago by RyanGlScott

You need to compile the program with -fdefer-typed-holes to trigger the error:

$ /opt/ghc/8.2.2/bin/ghc -fdefer-typed-holes Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

Bug.hs:29:11: error:
    • Could not deduce (Unbox a) arising from a use of ‘zip’
      from the context: GVector Vector (a, b)
        bound by the RULE "stream/zip [Vector.Unboxed]"
        at Bug.hs:(28,11)-(30,46)
      Possible fix:
        add (Unbox a) to the context of
          the RULE "stream/zip [Vector.Unboxed]"
    • In the first argument of ‘stream’, namely ‘(zip as bs)’
      In the expression: stream (zip as bs)
      When checking the transformation rule "stream/zip [Vector.Unboxed]"
   |
29 |   stream (zip as bs) = zipWith (,) (stream as)
   |           ^^^^^^^^^

This regression was introduced in 6746549772c5cc0ac66c0fce562f297f4d4b80a2 (Add kind equalities to GHC.).

comment:5 Changed 23 months ago by Simon Peyton Jones <simonpj@…>

In e9ae0ca/ghc:

Look inside implications in simplifyRule

Trac #14732 was a perpelexing bug in which -fdefer-typed-holes
caused a mysterious type error in a RULE.  This turned out to
be because we are more aggressive about creating implications
when deferring (see TcUnify.implicationNeeded), and the rule
mechanism hadn't caught up.

This fixes it.

comment:6 Changed 23 months ago by simonpj

Status: newmerge
Test Case: typecheck/should_compile/T14732

comment:7 Changed 23 months ago by bgamari

Milestone: 8.4.1

comment:8 Changed 23 months ago by bgamari

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.