On Thu, 2007-02-15 at 14:55 -0500, Chris King wrote:

> > I can certainly fix the bug by simply not inlining functions
> > that return closures .. but that would include the trivial
> > case of 'f' above: the performance hit isn't acceptable.
> 
> Perhaps leave the decision up to the coder: by default, don't inline
> functions which return closures

Nah, we can't have that: that would make curried functions unusable:

val x = f 1 2;

is actually

val x = (f 1) 2;

in other words, (f 1) is returning a function which accepts 2.
If f is given by

        fun f(x:int) (y:int) => x + y;

then this had better evaluate to

val x = 1 + 2;

or Felix is useless. The thing to note is that this closure (f 1)
is a temporary which is applied immediately and then becomes
unreachable by everyone.

The argument to, say, spawn_fthread, isn't lost: it's passed
to the driver. And if you made an array of closures,
they're not lost either.

So more or less if you write:

var z = 1;
var g = f z;

then f can't be inlined, because the closure this application
returns refers to x, which contains the value 1 it should
copy from z .. this fragment is safe to inline as written,
but not if g was stored in an array, and the calculation
was inside a loop that varied z. There has to be an 'x'
which is variable holding the value of z at the time
of g closure formation, and to which g's value is bound.

The inlining is just too aggressive. I made it that way
deliberately: performance first, correctness later :)

Otherwise we end up like GHC used to be only a very short
time ago: so slow as to be useless. Also we don't have the
luxury of a written down standard to conform to -- but that
also means we can define the semantics specifically to 
allow high performance.

EVERYONE: you, RF, me .. we all got bitten by this bug.
It is definitely a bug!


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to