Editorial: Model execution context as a record - #2246
Conversation
|
Nice! I'll give this a more thorough review soon, but while I'm thinking of it:
For now, I think we should stick with the existing format. I would like to address #2095 eventually, at which point I think it might make sense to switch to the literal syntax. But we'd need to find a way to express the |
Yup.
Yeah, I maybe should have raised that as another bullet. I mean, it's no less clear than in the status quo, but it does stick out more when we model things this way. The points where |
In the memory model, the following step is often repeated:
Analogously here, how do you feel about
|
85251e6 to
36f5402
Compare
|
(force-pushed to resolve merge conflicts) |
36f5402 to
1e28eeb
Compare
|
(force-pushed to rebase to master) |
I guess I'm okay with it. |
1e28eeb to
2b46387
Compare
|
(force-pushed to use the phrase "the [[Something]] field of the running execution context") |
|
@michaelficarra You should probably rename #1742 to make it clear it's tracking more stuff than its title currently claims. |
|
@bakkot Okay, changed it to match the project card. |
2b46387 to
2843c22
Compare
|
force-pushed to:
|
2843c22 to
de3eb5a
Compare
|
(force-pushed to resolve merge conflicts) |
de3eb5a to
0e8d49f
Compare
0e8d49f to
8959226
Compare
|
force-pushed to:
|
3d0c24c to
7a79833
Compare
9d9e403 to
9ae108b
Compare
9ae108b to
076766e
Compare
076766e to
847cc36
Compare
|
(force-pushed to rebase to master + resolve merge conflicts from #2408) |
847cc36 to
c02e1b4
Compare
2d22f7d to
5b234c3
Compare
5b234c3 to
ef79dbc
Compare
|
The rendered spec for this PR is available at https://tc39.es/ecma262/pr/2246. |
ef79dbc to
6859c77
Compare
|
The rendered spec for this PR is available at https://tc39.es/ecma262/pr/2246. |
6859c77 to
29234b3
Compare
|
The rendered spec for this PR is available as a single page at https://tc39.es/ecma262/pr/2246 and as multiple pages at https://tc39.es/ecma262/pr/2246/multipage . |
| [[CodeEvaluationState]] | ||
| </td> | ||
| <td> | ||
| implementation-specific |
There was a problem hiding this comment.
In a bunch of other places where we have fields whose contents are not managed by us (e.g. Module Record's [[HostDefined]]) we use "anything" instead.
There was a problem hiding this comment.
Right, but we do actually manage code evaluation state to some extent: there are 3 steps where we set it.
Note that PR #2962 has a commit to make 'code evaluation state' less vague. (It doesn't update the type in this table, but it could.)
| <p>An execution context contains whatever implementation specific state is necessary to track the execution progress of its associated code. Each execution context has at least the state components listed in <emu-xref href="#table-state-components-for-all-execution-contexts"></emu-xref>.</p> | ||
| <emu-table id="table-state-components-for-all-execution-contexts" caption="State Components for All Execution Contexts" oldids="table-22"> | ||
| <p>Each execution context is represented as an ExecutionContext Record, with at least the fields listed in <emu-xref href="#table-state-components-for-all-execution-contexts"></emu-xref>.</p> | ||
| <emu-table id="table-state-components-for-all-execution-contexts" caption="ExecutionContext Record Fields" oldids="table-22"> |
There was a problem hiding this comment.
For the other editors: do you prefer to keep this table's id as-is, or change it to something like table-executioncontex-record-fields and moving the current ID to oldids?
I have a very slight preference for giving it an ID that is more similar to the other record definition tables, but I'm happy either way.
There was a problem hiding this comment.
I don't think it matters.
| 1. Assert: _generator_.[[GeneratorState]] is ~suspended-start~. | ||
| 1. Let _genContext_ be the running execution context. | ||
| 1. Set the Generator component of _genContext_ to _generator_. | ||
| 1. Set _genContext_.[[Generator]] to _generator_. |
There was a problem hiding this comment.
(also in the async version)
What is happening here is that _genContext_ did not have yet a [[Generator]] field, and we are creating the extra field now effectively transforming the ExecutionContext Record into a Generator ExecutionContext Record?
If that's the case, I'd prefer either one of these options:
- Add a note explaining what's happening. I don't think we dynamically add extra fields on existing records anywhere else?
- Create a new Generator ExecutionContext Record here, copying all the other fields from the running execution context, and swap the running execution context record with this new one.
- Give the
[[Generator]]field to all execution contexts, and allow it to be~empty~.<dfn>Generator ExecutionContext Record as "an ExecutionContext Record whose[[Generator]]field is not~empty~".
Can an ExecutionContext Record be a Generator ExecutionContext Record withuot being an ECMAScript code ExecutionContext Record? (EDIT: The answer here is yes, when using CreateIteratorFromClosure. In principle I'd be fine with some sort of dyamond inheritance between these records and define an ECMAScript Code Generator ExecutionContext Record that implements both interfaces. We don't have methods on ExecutionContext Records anyway)
There was a problem hiding this comment.
What is happening here is that
_genContext_did not have yet a[[Generator]]field, and we are creating the extra field now effectively transforming the ExecutionContext Record into a Generator ExecutionContext Record?
Yup, I think that's what's happening.
If that's the case, I'd prefer either one of these options:
- Add a note explaining what's happening. I don't think we dynamically add extra fields on existing records anywhere else?
Well, there's ToPropertyDescriptor, which dynamically adds fields to a Property Descriptor record that was created with no fields. Moreover, some of those additions can change the 'type' of the PD from a generic PD to a data PD or an accessor PD. However, all of that is happening right after the record is created, so it kind of gets a pass. I think this is the only case where a component/field is created well after the thing/record is created (but I'm not positive).
- Create a new Generator ExecutionContext Record here, copying all the other fields from the running execution context, and swap the running execution context record with this new one.
Note that the caption of this table is the only place that the spec mentions Generator Execution Contexts, so it doesn't seem to care about them as a type. (In places where it might ask "is this a Generator Execution Context?", it instead asks "does this have a Generator component?".)
- Give the
[[Generator]]field to all execution contexts, and allow it to be~empty~.<dfn>Generator ExecutionContext Record as "an ExecutionContext Record whose[[Generator]]field is not~empty~".
I'd be inclined to go with this one, but maybe not even bother mentioning "Generator ExecutionContext Record".
| @@ -50459,10 +50491,10 @@ <h1> | |||
| <emu-alg> | |||
| 1. Let _genContext_ be the running execution context. | |||
| 1. Assert: _genContext_ is the execution context of a generator. | |||
There was a problem hiding this comment.
(also in the async version)
Can we have a more "mechanical" assertion? One of:
_genContext_.[[Function]] is a generator_genContext_ is a Generator ExecutionContext Record_genContext_ has a [[Generator]] field
The first one is probably too loose, as it does not always imply that there is a [[Generator]] field (e.g. while evaluating the default parameters of a generator function).
There was a problem hiding this comment.
I'd go for 3, I think.
| an Object | ||
| </td> | ||
| <td> | ||
| The Generator that this execution context is evaluating. |
There was a problem hiding this comment.
Not in this PR, but it'd be helpful to eventually <dfn> what a Generator is. Many people think of the generator as the function itself, rather than the object it returns.
| 1. Set the ScriptOrModule of _moduleContext_ to _module_. | ||
| 1. Set the VariableEnvironment of _moduleContext_ to _module_.[[Environment]]. | ||
| 1. Set the LexicalEnvironment of _moduleContext_ to _module_.[[Environment]]. | ||
| 1. Let _moduleContext_ be a new ECMAScript code ExecutionContext Record. |
There was a problem hiding this comment.
(this was already the same before, but while we are touching this code...) This should really be just an ExecutionContext Record. We are not evaluating JavaScript code in here.
There was a problem hiding this comment.
I think you're right, but I'm not sure. If there's agreement, I can add a separate commit to that effect.
29234b3 to
af3bb02
Compare
|
The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/2246 and as multiple pages at https://tc39.es/ecma262/pr/2246/multipage . |
af3bb02 to
b73c3f7
Compare
|
The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/2246 and as multiple pages at https://tc39.es/ecma262/pr/2246/multipage . |
b73c3f7 to
72bb574
Compare
|
The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/2246 and as multiple pages at https://tc39.es/ecma262/pr/2246/multipage . |
72bb574 to
e1c4b5b
Compare
|
The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/2246 and as multiple pages at https://tc39.es/ecma262/pr/2246/multipage . |
e1c4b5b to
d33009b
Compare
|
The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/2246 and as multiple pages at https://tc39.es/ecma262/pr/2246/multipage . |
|
Note that the "cleanup" section of #2962 is sort of a prerequisite for this PR, as it removes wording that treats execution context as anything other than a data structure. (Arguably, that cleanup should have been part of this PR instead of that one, but probably that won't matter much.) |
d33009b to
169ceb8
Compare
|
The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/2246 and as multiple pages at https://tc39.es/ecma262/pr/2246/multipage . |
169ceb8 to
c336c61
Compare
|
The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/2246 and as multiple pages at https://tc39.es/ecma262/pr/2246/multipage . |
|
The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/2246 and as multiple pages at https://tc39.es/ecma262/pr/2246/multipage . |
Resolves the first comment in issue #1742
I believe this PR is complete in the sense that it would leave the spec in a consistent state. However, there are various further changes you might want,
so it's currently a Draft PR.I introduced the term
ExecutionContext Record, but left some occurrences ofexecution context. You might prefer to get rid ofexecution contextentirely.I changed the caption text of the three
Fieldstables, but not theiridattributes.The status quo creates the context and then separately sets each of its components. I kept that format, but you might prefer the use of a record "literal" to define it all in one step.
[Later: @bakkot prefers it as-is.]
Where the status quo refers to
the running execution context's SomethingOrOther, I introduced a stepLet _runningContext_ be the running execution contextand then referred to_runningContext_.[[SomethingOrOther]]. You might prefer to introduce a compact way to say "the running execution context". (About the only precedent for this is the use ofNewTargetin algorithms.)[Later: @syg suggests "the [[SomethingOrOther]] field of the running execution context"]
[Even later: settle on "the running execution context's [[SomethingOrOther]]"]
When we define Additional Fields elsewhere in the spec (for Environment Records and Module Records), they're aligned with a (quasi) subtype hierarchy. This sort of works for
ExecutionContext RecordandECMAScript code ExecutionContext Record, but not forGenerator ExecutionContext Record: it's difficult to see the latter as a subtype. AnExecutionContext Recordthat represents the evaluation of a generator object is created as anECMAScript code ExecutionContext Record(not aGenerator ExecutionContext Record) and then later (after it's already been made the running execution context), it has a[[Generator]]field attached to it.The execution context stack could conceivably be modeled by giving each ExecutionContext Record something like a [[CallerContext]] field .
Downstream effects:
The HTML spec has some references to an execution context's "Realm component", which would be changed to its "[[Realm]] field" after this PR.