Nothing is free in in life... [was: CALLER_SAVE/RESTORE in CCalls]

Sven Panne Sven.Panne@informatik.uni-muenchen.de
Wed, 28 Mar 2001 16:35:46 +0200


After some experiments I've recognized that the CALLER_{SAVE,RESTORE}
story isn't as easy as I thought first. But the good news are that it
doesn't do much harm on an architecture with such a poor register set as
the x86 family.  :-)  But in general, we shouldn't generate useless
CALLER_SAVE*/CALLER_RESTORE* pairs in the backend. This is not that
straightforward because PprsAbsC.pprCCall will need some context info
for that task, something which I don't want to change in a hurry just
before a release. Furthermore, I currently have very limited resources,
so if anybody volunteers...

But during my experiments I noticed that despite of some efforts in
hslibs, the newtypes in CTypes{,ISO} don't come for free.  :-(  The
problem is illustrated by the following example:

--------------------------------------------------
module Foo where

import CTypes

valFloat :: Float
valFloat = 1234.0

valCFloat :: CFloat
valCFloat = 5678.0

valInt :: Int
valInt = 1111

valCInt ::  CInt
valCInt = 2222
--------------------------------------------------

After type checking and desugaring the code looks basically like this:

--------------------------------------------------
valFloat :: Float
valFloat = F# __float 1234.0

valCFloat :: CFloat
valCFloat = (fromRational :: Rational -> CFloat) ((S# 5678) :% (S# 1))

valInt :: Int
valInt = I# 1111

valCInt :: CInt
valCInt = (fromInteger :: (Integer -> CInt)) (S# 2222)
--------------------------------------------------

valCInt is lucky enough to be transformed to I32# 2222 in the
simplifier, buf valCFloat isn't. The only thing which happens to the
latter is that fromRational is simplified to a specialised version of
fromRat, which doesn't help very much.

The problem for CFloat is Inst.lookupInst, which doesn't "look through"
newtypes (plus a re-wrapping/coercion to the right type afterwards), a
similar problem exists for CInt in Inst.newOverloadedLit. Could someone
fix this? Again, I don't have the time...

Another route would be a special rule in PrelRules.builtinRules for
fromRational, but that doesn't look right for me, it's a bit too late in
the compilation process IMHO.

Cheers,
   Sven