Immediate closing of iterators

Chris Hansen renselp at gmail.com
Thu Dec 21 12:04:14 PST 2006


In C#, as I understand it, they sidestep this problem by (I'll try to
formulate this in terms of ES4) simply not allowing you to iterate
over generators. You can iterate over objects with an iterator::get
method but the returned object is owned by the loop and if it is a
generator it will be closed on loop exit whether or not others have
references to it.  Also, a generator doesn't have an iterator::get
method since that would complicate the question of who "owns" it.

That only "solves" Jeff's problem by disallowing it (ta-daa! ;-) but
it does away with the need for  any kind of finalization, prompt or
not.  In my experience (from java) GC finalization is something you
want to steer well clear of.

What do you think?


-- Chris

On 12/21/06, Brendan Eich <brendan at mozilla.org> wrote:
> 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