Skip to content
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: Eliminate CoveredFoo SDOs #2350

Merged
merged 5 commits into from
Mar 24, 2021
Merged

Conversation

jmdyck
Copy link
Collaborator

@jmdyck jmdyck commented Mar 17, 2021

When the first two of these were introduced (in ES6), they were useful because they encapsulated a sizeable amount of pseudocode. But after successive rewordings (in PRs #692, #971, #890), the underlying pseudocode is almost as brief as invoking the SDO. So I think their benefit (in terms of conciseness or encapsulation) is now outweighed by their cost (in terms of indirection); eliminating them will make it slightly easier to understand how the spec uses cover grammars.

(For comparison, note that we don't bother to define similar SDOs for:
the |AssignmentPattern| that is covered by |LeftHandSideExpression|
or
the |AssignmentPattern| that is covered by |DestructuringAssignmentTarget|
We just use those phrases directly in algorithms.)

This PR undefines the following ids, because there didn't seem to be a good place to make them oldids:

  • sec-primary-expression-semantics
  • sec-static-semantics-coveredparenthesizedexpression
  • sec-left-hand-side-expressions-static-semantics-coveredcallexpression
  • sec-async-arrow-function-definitions-static-semantics-CoveredAsyncArrowHead
  • sec-static-semantics-coveredformalslist

Copy link
Contributor

@bakkot bakkot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice simplification, thanks.

spec.html Outdated
@@ -19896,8 +19853,7 @@ <h1>Runtime Semantics: InstantiateArrowFunctionExpression</h1>
1. If _name_ is not present, set _name_ to *""*.
1. Let _scope_ be the LexicalEnvironment of the running execution context.
1. Let _sourceText_ be the source text matched by |ArrowFunction|.
1. Let _parameters_ be CoveredFormalsList of |ArrowParameters|.
1. [id="step-arrowfunction-evaluation-functioncreate"] Let _closure_ be OrdinaryFunctionCreate(%Function.prototype%, _sourceText_, _parameters_, |ConciseBody|, ~lexical-this~, _scope_).
1. [id="step-arrowfunction-evaluation-functioncreate"] Let _closure_ be OrdinaryFunctionCreate(%Function.prototype%, _sourceText_, |ArrowParameters|, |ConciseBody|, ~lexical-this~, _scope_).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change which is suspicious, but as far as I can tell it all works: although this has the effect of changing the [[FormalParameters]] slot of arrow functions from containing an |ArrowFormalParameters| to containing a |CoverParenthesizedExpressionAndArrowParameterList|, it appears to be the case that all consumers of [[FormalParameters]] are already equipped to handle |CoverParenthesizedExpressionAndArrowParameterList| correctly.

@bakkot bakkot added the ready to merge Editors believe this PR needs no further reviews, and is ready to land. label Mar 24, 2021
jmdyck added 5 commits March 24, 2021 15:58
Here in InstantiateArrowFunctionExpression,
I assert that we can replace the status quo's
    CoveredFormalsList of |ArrowParameters|
with just
    |ArrowParameters|
(and then eliminate the _parameters_ alias).

case analysis on the 2 forms of |ArrowParameters|:

case 1:
When |ArrowParameters| is an instance of
    ArrowParameters : BindingIdentifier
then CoveredFormalsList simply returns |ArrowParameters| itself,
so the above replacement is obviously correct.

case 2:
When |ArrowParameters| is an instance of
    ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
then CoveredFormalsList will return an instance of
    ArrowFormalParameters
(whose particulars are not important here),
which then gets passed to OrdinaryFunctionCreate's ParameterList.

But if you go to OrdinaryFunctionCreate and follow what happens
to ParameterList, you find that, ultimately, it's submitted to:
    - ExpectedArgumentCount
    - BoundNames
    - IsSimpleParameterList
    - ContainsExpression
    - IteratorBindingInitialization

And all of these have an explicit definition for:
    ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
of roughly the form:
    1. Let _formals_ be the CoveredFormalsList of |CoverParenthesizedExpressionAndArrowParameterList|.
    1. Return <SDO> of _formals_.

That is, with respect to the OrdinaryFunctionCreate's call-tree,
if you don't call CoveredFormalsList near the root,
it will be called near the leaves.

So in this case too, it's okay to perform the given replacement.
@ljharb ljharb merged commit 7cea37d into tc39:master Mar 24, 2021
@jmdyck jmdyck deleted the Covered_SDOs branch March 25, 2021 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editorial change ready to merge Editors believe this PR needs no further reviews, and is ready to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants