[squeak-dev] to:do: optimization is wrong when the block modifies the limit

nicolas cellier ncellier at ifrance.com
Fri Jun 13 01:28:25 UTC 2008


While browsing #to:do: optimization implementation i noticed this:

| n |
n := 2.
1 to: n do: [:i | (n := n+1)>10 ifTrue: [self halt: 'Should I get here?']].
^n

When you think in term of message send, well NO, YOU SHOULD NOT GET HERE.

Optimization is such a subtle thing that:

| n |
1 to: (n := 2) do: [:i | n := n+1. n>10 ifTrue: [self halt: 'You won''t 
get there']].
^n

Ha Ha, it's really fun!
Of course, if one corrects this bug, there is a pending Decompiler issue:

testDecompileToDoWithMovingLimit
	| n i |
	n := 4.
	i := 1.
	[i <= n] whileTrue: [
		n := n - 1.
		i := i + 1].

would decompile into:
	| n |
	n := 4.
	1
		to: n
		do: [:i | n := n - 1]

This is worth a http://bugs.squeak.org/view.php?id=7093
Ah i wonder what would a NewCompiler do to to:do:

Nicolas




More information about the Squeak-dev mailing list