Skip to content
  • Simon Peyton Jones's avatar
    Make 'SPECIALISE instance' work again · 1ed04090
    Simon Peyton Jones authored
    This is a long-standing regression (Trac #7797), which meant that in
    particular the Eq [Char] instance does not get specialised.
    (The *methods* do, but the dictionary itself doesn't.)  So when you
    call a function
         f :: Eq a => blah
    on a string type (ie a=[Char]), 7.6 passes a dictionary of un-specialised
    methods.
    
    This only matters when calling an overloaded function from a
    specialised context, but that does matter in some programs.  I
    remember (though I cannot find the details) that Nick Frisby discovered
    this to be the source of some pretty solid performanc regresisons.
    
    Anyway it works now. The key change is that a DFunUnfolding now takes
    a form that is both simpler than before (the DFunArg type is eliminated)
    and more general:
    
    data Unfolding
      = ...
      | DFunUnfolding {     -- The Unfolding of a DFunId
        			-- See Note [DFun unfoldings]
          		  	--     df = /\a1..am. \d1..dn. MkD t1 .. tk
                            --                                 (op1 a1..am d1..dn)
         		      	--     	    	      	       	   (op2 a1..am d1..dn)
            df_bndrs :: [Var],      -- The bound variables [a1..m],[d1..dn]
            df_con   :: DataCon,    -- The dictionary data constructor (never a newtype datacon)
            df_args  :: [CoreExpr]  -- Args of the data con: types, superclasses and methods,
        }                           -- in positional order
    
    That in turn allowed me to re-enable the DFunUnfolding specialisation in
    DsBinds.  Lots of details here in TcInstDcls:
    	  Note [SPECIALISE instance pragmas]
    
    I also did some refactoring, in particular to pass the InScopeSet to
    exprIsConApp_maybe (which in turn means it has to go to a RuleFun).
    
    NB: Interface file format has changed!
    1ed04090