Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#4120 closed bug (fixed)

Iface type variable out of scope in cast

Reported by: benl Owned by:
Priority: high Milestone: 7.0.1
Component: Compiler (Type checker) Version: 6.13
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case: indexed-types/should_compile/T4120
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Compiling the following module against vector-0.6 or 0.7:

module Thing where
import Data.Vector.Unboxed
import Data.Vector.Unboxed.Mutable	as MV

thing :: Vector Int
thing = create (MV.new 5)

Complains about:

desire:tmp benl$ ghc -O -c -fglasgow-exts Thing.hs -fforce-recomp
/Users/benl/.cabal/lib/vector-0.7/ghc-6.13.20100607/Data/Vector/Unboxed.hi
Declaration for create
Unfolding of Data.Vector.Unboxed.create:
  Iface type variable out of scope:  s

Looking in the interface file we have:

  create :: forall a.
            Data.Vector.Unboxed.Base.Unbox a =>
            (forall s. GHC.ST.ST s (Data.Vector.Unboxed.Base.MVector s a))
            -> Data.Vector.Unboxed.Base.Vector a
    {- Arity: 2, Strictness: U(SA)C(U(LL)),
       Inline: INLINE (sat-args=0),
       Unfolding: InlineRule (1, False, False)
                  (\ @ a
                     $dUnbox :: Data.Vector.Unboxed.Base.Unbox a
                     eta :: forall s.
                            GHC.ST.ST
                                s
                                (Data.Vector.Generic.Base.Mutable
                                     Data.Vector.Unboxed.Base.Vector s a) ->
                   Data.Vector.Generic.new
                     @ Data.Vector.Unboxed.Base.Vector
                     @ a
                     (Data.Vector.Unboxed.Base.$p1Unbox @ a $dUnbox)
                     (Data.Vector.Generic.New.New
                        @ Data.Vector.Unboxed.Base.Vector
                        @ a
                        eta))
                    `cast`
                  (forall a.
                   Data.Vector.Unboxed.Base.Unbox a =>
                   GHC.ST.ST s (Data.Vector.Unboxed.Base.TFCo:R:MutableVector s a)
                   -> Data.Vector.Unboxed.Base.Vector a) -}

The variable s in the right of the cast is indeed not in scope.

This prevents create being inlined into client modules, which kills performance for benchmarks that create lots of small vectors (like a version of quickhull in DPH).

Change History (3)

comment:1 Changed 9 years ago by igloo

Milestone: 6.14.1
Priority: normalhigh

comment:2 Changed 9 years ago by simonpj

Resolution: fixed
Status: newclosed

Fixed by

Mon Jun 14 14:43:11 BST 2010  simonpj@microsoft.com
  * Fix Trac #4120: generate a proper coercion when unifying forall types
  
  This was just a blatant omission, which hasn't come up before.
  Easily fixed, happily.

    M ./compiler/typecheck/TcUnify.lhs -3 +8

Simon

comment:3 Changed 9 years ago by simonpj

Test Case: indexed-types/should_compile/T4120
Note: See TracTickets for help on using tickets.