On Sun, 2006-10-01 at 20:27 -0700, Erick Tryzelaar wrote:

> John, it does seem like it'd be a bug to optimize away calls that 
> involve external functions. 

External functions no. External procedures yes.
External generators .. probably yes, it's a bug.

> Since those calls could be state changing as 
> in this case, I don't think they can be safely optimized. Perhaps we 
> need another function attribute to mark that it's safe to optimize.

We have one: 'fun'.

We also have 'gen' which means the call must be lifted
out of an expression to avoid duplication or elision
in case inlining the expression is lazy.

The problem seems to be that the unused variable 
eliminator is in fact effectively implementing
lazy evaluation -- 'evaluate on demand'. And since
there's no demand for the variable, don't evaluate.

I think you are right, if you change 'external
function' to 'external generator'.

Note that the *variable* can still be elided,
saving stack or heap space: the function can be called like:

        (void)generator();

which casts away the return value (which isn't needed in C
but I exhibit it just to illustrate the point).

So the problem isn't that the variable isn't used,
but that this implies the initialiser isn't required.

Unfortunately this IS the case for some generators.
Rarely do we want 

        var x = malloc(99);

where x is unused, to actually do:

        (void)malloc(99);

and waste heap space. It is less clear with 'random()'.
With 'jseek()' there really are side effects .. but this
is a long way from the core idea of a generator, which
basically has internal state but no side-effects,
and tends to return something with 'identity' like
an object that can't be duplicated as if it were a
value like an int.

The problem here is that there are a lot of subtle
semantic distinctions to take into account, and we don't
want to clutter the language too much.



-- 
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