-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editorial: enable built-in async and sync generator functions to be specified #1665
Editorial: enable built-in async and sync generator functions to be specified #1665
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be perhaps helpful in demonstrating the change to refactor the matchAll iterator algorithm steps to be a built-in generator function?
@ljharb here's what i think
|
Actually, we might need to add a |
Why couldn't we do it now? The only observable part is the toString's |
@ljharb because RegExpStringIteratorPrototype is observable, we can't stop having the function return it. |
ahhh right, so to make this PR maximally useful, we'd have to have a way to control the [[Prototype]] of the returned iterator (since we'd want to use this approach on all the iterators in the spec, i'd think) |
I am not convinced this is an improvement in clarity, personally. |
To me the pros are:
And the cons are:
|
Since this is strictly editorial, how could it impact optimizability or memory usage? |
@bakkot because without this we create additional visible methods and prototypes for every iterator method we add (22 in the current proposal), every one of which takes up a non-zero amount of memory and which requires its own checks to make sure its safe to be optimized and lowered in whatever implementation-specific way it will be. Since its also come up twice, i'm also going to rename this pr to normative, even though the diff has no normative changes. |
@devsnek If you want to discuss whether the iterators added by your proposal should be specified as creating generator functions in a user-observable way, that's something which should be discussed on your proposal, since it's about the normative details of your proposal. If you want to discuss whether it's clearer to write iterators in the current style or with a |
I think there's conceptually two parts here:
There is not necessarily any dependency between the two, and the first makes sense now while the second only makes sense if we actually add a built-in generator function later. Is it possible change this PR to define (Talked about this with @ljharb, @syg, and @michaelficarra, and I believe this is their position as well.) |
@bakkot my plan is to make this pr a commit that is part of merging iterator methods into the spec. are you saying you want a separate pr that just refactors yield? |
@devsnek I would like the |
@bakkot you mean use |
There is no primitive "yield operation". Built-in iterators and the iterators returned by generators are both just a combination of an object which stores some state and a |
@bakkot yielding is suspending a context to be resumed later. The iterators currently in the spec are just normal functions. I don't understand how those could be combined. |
It is not observable that (e.g.) string iterators keep track of state by keeping a |
@bakkot so you're saying, make an internal generator and then do That would depend on the built-in generators in this pr, so i couldn't really separate out just the |
Something like that, I guess, except that it would just call Of course, I'm not sure that capturing an entire execution context is actually clearer than the current approach of just being explicit about the state being tracked. But if that's true, we should not introduce a |
I'm really not sure what you're trying to say, and I'm not planning to address how our current iterators are written (at least not right now, maybe after iterator helpers is merged I'll look at ways to simplify them). |
imo the current iterator-producing functions should be written in the same way as the new iterator helpers - whether that's the current style, or an alternative style. |
I guess that would be the hidden built-in generator approach? I wouldn't object to anyone doing such a refactoring. |
@devsnek We talked about this in the editor call yesterday. Since this PR includes observable changes, we will need committee consensus before it can be incorporated. The observable changes would need to be rationalised on their own merit, regardless of the impact they would have on spec authorship/readability. Alternatively, you could make this PR strictly editorial. |
@michaelficarra the editor team also said this change was purely editorial before and made me rename it. can you expand specifically on what makes it normative so we're on the same page. |
@devsnek The PR as-is is editorial because it doesn't do anything, because, per discussion above, it can't be used for anything currently in the spec without making observable changes. Using built-in generators for iterator helpers, rather than specifying the helpers the way the spec currently describes all iterators, would also be observable. So either
|
got it. the intention here is to be merged with iterator helpers anyway so it seems like we're in a good place. |
This has been superseded by #2045, which uses Abstract Closures for this. |
This is a precursor to https://github.com/tc39/proposal-iterator-helpers, and probably can be integrated into that proposal at some point, but I wanted to get some feedback on this approach before then. I think this change is definitely worth exploring for the purpose of the clarity and maintainability of the specification. You can compare the current iterator methods (https://tc39.es/proposal-iterator-helpers) with what the spec text looks like with this change: