Inlining instance dictionary functions
Marcin 'Qrczak' Kowalczyk
qrczak@knm.org.pl
4 May 2001 10:27:32 GMT
Fri, 4 May 2001 01:04:12 -0700, Simon Peyton-Jones <simonpj@microsoft.com> pisze:
> a) arranged that all dictionary-construction functions are inlined
Marked as InlineMe to be precise: they are not inlined in the presence
of some polymorphic recursion (or without -O of course).
> b) arranged that INLINE doesn't get in the way of expr_isConApp
>
> Those two things have more or less solved your problem, right?
Right.
> (1) You'd like to be able to say "specialise this f once for each call
> pattern in each calling module". That's a good idea; I'll think on it.
Thanks. The syntax could be {-# SPECIALIZE f #-}
> {-# SPECIALISE g :: Int -> Int #-}
> {-# INLINE g #-}
> g y = ... f...
>
> Here, the INLINE makes things worse because we don't
> generate specialised versions of f.
>
> I agree that's odd, but the rationale is this: inlining is like per-call-site
> specialisation, so you should't need SPECIALISE pragmas if you are
> going to INLINE. Instead put your SPECIALISE on f. Does that make sense?
Hmm, yes. But...
Currently all SPECIALIZE instance pragmas are ignored (because they
get attached to an inlined entity). You are saying that I should write
SPECIALIZE pragmas on methods instead. First, ghc doesn't allow this,
with a bogus error:
module Test where
newtype F a = F a
instance Eq a => Eq (F a) where
{-# SPECIALIZE (==) :: F Int -> F Int -> Bool #-}
F x == F y = x == y
Test.hs:3:
Inferred type is less polymorphic than expected
Quantified type variable `a' is unified with `Int'
Signature type: forall a. (Eq a) => F a -> F a -> Bool
Type to generalise: F Int -> F Int -> Bool
When checking the expected type for class method ==
In the instance declaration for `Eq (F a)'
Second, SPECIALIZE instance should still work I assume? so if ghc is
unable to cope with SpecSig pragmas it generated for the dictionary
function, it should attach appropriate SpecSig pragmas to methods
instead.
> Are there an other things you've tripped over?
I think not.
> | Note that (==)::Int->Int->Bool is still being extracted from
> | a constant dictionary of 'Eq Int'!
>
> That is wierd, but I assume it was fixed by (b) above, correct?
Yes.
--
__("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZASTĘPCZA
QRCZAK