History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: BOO-137
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Cameron Kenneth Knight
Reporter: Rodrigo B. de Oliveira
Votes: 1
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Boo

optimize for item in array construct

Created: 01/Oct/04 10:34 AM   Updated: 21/Mar/06 07:01 PM
Component/s: Compiler
Affects Version/s: None
Fix Version/s: 0.7.6

Time Tracking:
Not Specified

File Attachments: 1. Text File OptimizeIterationStatements.cs (17 kb)

Issue Links:
Related
 


 Description  « Hide
The current progress in the generators front required deoptimizing the handling of "for item in array" constructs.

for item in array:
pass

should expand to:

i = 0
while i < len(array):
item = array[i]
++i

instead of today's:

iterator = array.GetEnumerator()
while iterator.MoveNext():
item = iterator.Current



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Sorin Ionescu - 22/Jul/05 04:03 PM
for index in range(0, 10):
pass

should expand to jump statements that would generate
for (int index = 0; index < 10, index++)
{
}


Cameron Kenneth Knight - 28/Sep/05 10:09 PM
This optimizes "for i in array" as well as "for i in range()"

It goes into the pipeline "ResolveExpressions" after ProcessMethodBodiesWithDuckTyping.


Cameron Kenneth Knight - 28/Sep/05 10:13 PM
The above comment refers to the attached file "OptimizeIterationStatements.cs"

now the iterators run just as fast as C#'s equivalents, while keeping Boo's shiny syntax.


Rodrigo B. de Oliveira - 29/Sep/05 09:07 AM
Great work!!

Cameron Kenneth Knight - 29/Sep/05 01:13 PM
Ok, Use this new file, it changes the order the loop expands to.

Before it did
__iter = 0
while __iter < 10:
i = __iter
<block>
_iter += 1

which would go on forever if <block> contained a continue statement.
__iter was moved above the <block>.


Rodrigo B. de Oliveira - 30/Sep/05 01:29 PM
Please make sure that all tests currently in the repository pass (I've just added some test cases regarding range runtime behavior).

Another thing, all the files in the boo code base must have the following header:

http://svn.boo.codehaus.org/boo/trunk/notice.txt?rev=1775&view=auto


Cameron Kenneth Knight - 05/Oct/05 12:24 AM
Alright, I have done all the tests and everything, and it's all peachy now with the new attachment.

Rodrigo B. de Oliveira - 05/Oct/05 12:49 PM
6 test cases are still failing after I apply the patch but I'll be giving a throughout review later after this release.

Thanks!


Cameron Kenneth Knight - 05/Oct/05 12:56 PM
Here's a version that makes it look like other Boo files, e.g. UTF-8 and proper indentation.

Please tell me what tests it failed on. I ran a lot of tests, and didn't have a problem.


Cameron Kenneth Knight - 05/Oct/05 03:26 PM
Alright, the file I attached fixed all the errors coming up from `nant test`
Now, it doesn't support multidimensional arrays (yet).
It also doesn't support callables, because it's in a hazy place in between when all the entities are declared, but before the callables are expanded.
I plan on making multidimensional arrays work.
If one were to have an array of callable types, one would generally not going to be dealing with large arrays that need strict optimization.

Cameron Kenneth Knight - 10/Oct/05 12:26 AM
Here's an updated patch.
When incrementing by step, it now uses add instead of add.ovf. The overflow checking is unnecessary in that case, because the max already exists.
Also, when available, it will replace num != end with num < end or num > end.
This gives it the same IL as C#'s.