Skip to content

Cross-module SpecConstr

Type-class specialisation now happens flawlessly across modules. That is, if I define

module DefineF where
   f :: Num a => a -> a
   {-# INLINEABLE f #-}
   f x = ...f x'....

then modules that import DefineF and call f at some particular type (say Int) will generate a specialised copy of f's code.

But this does not happen for SpecConstr; we only specialise a function for calls made in the same module. For example:

module M where
  {-# INLINABLE foo #-}
  foo True  y     = y
  foo False (a,b) = foo True (a+b,b)

module X where
  import M
  bar = ...(foo (x,y))...

Here foo is called with an explicit (x,y) argument in module X, and we'd like to !SpecConstr it, as it would be if the call was in module M.

All the infrastructure is in place to allow cross-module SpecConstr; it just hasn't been done yet. This ticket is to record the idea.

Edited by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information