←back to thread

122 points phsilva | 3 comments | | HN request time: 0.001s | source
Show context
thunkingdeep ◴[] No.43110710[source]
This does NOT mean Python will get Tail Call Optimization, as Guido cannot be shown The Light, and has decided.
replies(4): >>43110815 #>>43110832 #>>43111490 #>>43112657 #
beagle3 ◴[] No.43111490[source]
It is not an optimization ; it changes program semantics - converts programs that will run out of stack eventually regardless of the amount of available memory (and raise exceptions an the process, for example, which a program might rely on. Either way, semantics are changed)

It should only be called Tail Call Elimination.

replies(2): >>43111684 #>>43111776 #
dragonwriter ◴[] No.43111776[source]
By that standard, any optimization that changes scaling in any dimension changes semantics, which, well, I’m not saying its wrong, but I would say it is exactly what people looking for optimization want.
replies(3): >>43111911 #>>43112365 #>>43119601 #
dataflow ◴[] No.43111911[source]
> By that standard, any optimization that changes scaling in any dimension changes semantics

That doesn't follow. This isn't like going from driving a car to flying an airplane. It's like going from driving a car to just teleporting instantly. (Except it's about space rather than time.)

It's a difference in degree (optimization), yes, but by a factor of infinity (O(n) overhead to 0 overhead). At that point it's not unreasonable to consider it a difference in kind (semantics).

replies(1): >>43111980 #
tomsmeding ◴[] No.43111980[source]
Modern C compilers are able to transform something like this:

for (int i = 0; i < n; i++) a += i;

To:

a += n * (n+1) / 2;

Is this an optimisation or a change in program semantics? I've never heard anyone call it anything slse than an optimisation.

replies(3): >>43112007 #>>43112065 #>>43121733 #
pinoy420 ◴[] No.43112007[source]
Amazing it can do that. How does it work?

That definitely does seem to change its semantics to me. I am not a c expert but this surely has problems the previous one doesn’t?

replies(1): >>43112454 #
1. hathawsh ◴[] No.43112454{3}[source]
It does change the semantics if n is negative or large enough to cause an overflow. The challenge for the compiler is to somehow prove that neither of those things can happen.
replies(1): >>43112571 #
2. kryptiskt ◴[] No.43112571[source]
It doesn't have to prove absence of overflow since that is undefined behavior in C and thus modern compilers assume it can never happen.
replies(1): >>43119703 #
3. hathawsh ◴[] No.43119703[source]
Great point.