On 18/08/2012, at 6:33 AM, Dobes Vandermeer wrote:
> 
> Can't you see how wrong it is that this behaves differently than the one 
> without noinline?

I see that you have expectations not matching reality.
You're used to "inline is an optimisation hint it doesn't impact semantics".
You expect C++ specification to apply in Felix. It doesn't.

> Does the spec guarantee that a procedure without noinline will be inlined, 
> that its vals will be passed by value?

Nope. Don't use vals if you want eager evaluation. That's what vars do (at the 
moment).

vars are optimised away too, but it is done conservatively.
vals are optimised away aggressively.

A val names a value. You should not expect a named value to work the
same as a variable, which names a storage location.

> I don't think I have ever encountered a feature of C or C++ where its 
> behavior depended on whether a function was inlined or not.  Such a variance 
> would be considered a compiler bug.

That's the C++ specification, with one exception: copy constructors.
Consequently C++ is slow and cannot be easily optimised.

Semantics matters. People still use Fortran because it is up to 30% faster
than C doing the same calculations, because of rules you'd be horrified by!

        x = calc (y,y) 

ILLEGAL IN FORTRAN! You cannot pass overlapping arrays to functions.

This is such a major problem the C committee totally screwed up C with
a "no alias" feature so they could compete with Fortran. They messed it
up totally. It got replaced later by "restrict" which actually works.

Anyhow the fundamental problem is this:

How do we mix functional and imperative programming in a 
comprehensible way?

No one knows! There are two approaches, neither works:

(a) Algol like language (meaning has variables)

(b) ML like language (meaning has references)
technical name ISWIM language.

ML is purely functional, but throws in just one extra thing:
references. The functional system treats them as if they're
just ordinary values. It total ignores side-effects. This means
to predict what an ML program using references does you have
to know implementation details. generally programmers avoid
situations where you need to know them in detail, and just rely
on a few obvious rules.

But in Ocaml some of the details surprised people. One of them
is that a function call like:

                f a b c d

evaluates arguments from right to left not left to right. In particular
record evaluations:

        { a = x; b = y; c = z; }

are also in reverse order, which surprises people if the initialising
expressions have side effects like incrementing a counter.
One has to fix this by using

        let x = ... in

which forces the ordering. It only matters if you depart from
functional programming though.

Felix is both an algol like language (with variables) and an ISWIM
like language (because it has pointers). It make a lot of things
indeterminate (unspecified behaviour) because that is how you
get optimisations. A completely determinate system is almost
impossible to optimise. Note that C/C++ are far from being 
determinate!

The closest thing to a determinate language is Python,
and that is impossible to optimise because the author
Guido van Rossum doesn't know anything about language design.
In Python, you cannot make an error. So a compiler cannot make
assumptions and optimise things.

you may be surprised that EVERY sequence of characters 
is a valid Python program. It's true! The specification requires
that if a program tries to import a file with "syntax errors" in it
then an exception is thrown. This is utter stupidity but you have
to understand how compilers work to see why. the compiler cannot
reject a string of rubbish. It has to implement code that throws
an exception at run time. Because the programmer is ALLOWED
to catch the exception and do something. Its deterministic.

Same with "type errors". You cannot graft static typing and optimisations
based on it into Python because type errors have a deterministic behaviour:
an exception must be thrown and the programmer is allowed to catch it.
So the compiler cannot assume that adding two values cannot be
an addition of an integer to a string (for example) (unless it does
sophisticated control flow analysis, which is likely to fail to produce
a result anyhow due to separate compilation of modules). 

Felix has some surprises as a consequence of radical semantics.
It's an experimental language. You shouldn't be surprised that there
are a few surprises :)

--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to