Immediate closing of iterators

Brendan Eich brendan at mozilla.org
Thu Dec 21 10:42:42 PST 2006


On Dec 21, 2006, at 9:55 AM, Chris Hansen wrote:

>> You're right, the case 2 analysis I wrote up in my last message was
>> too restrictive.  If you put a type annotation on function gen, then
>> the guarantee should hold:
>>
>> class CollectionWrapper {
>>   var collection = ...some collection...;
>>   function gen():Generator.<*,*,*> {
>>     return this.collection.gen();
>>   }
>> }
>
> But if the rule is less restrictive I would claim that my original
> objection applies: you need to run a full gc whenever a loop exits
> abruptly to determine whether or not the generator is reachable:

Sorry, caffeinated now.  The outcomes to avoid are:

1. Requiring a full gc on loop exit, obviously a non-starter for  
performance reasons.
2. Requiring reference counting of all implementations.
3. Requiring static escape analysis of all implementations.

What I was groping for with the revision to case 2 is this: a way for  
the type system to promise no escape, and for all implementations to  
trivially check it, when a delegate returns the result of a generator- 
function call.  This type-checking can't require 3, so the form of  
the delegate would have to be restricted to linear flow, if not  
return of generator call.

Given the constraints, what's better: simple rules for direct  
generator calls, or special-casing in the type system just to allow  
delegation with guarantee of prompt close?

/be



More information about the Es4-discuss mailing list