Skip to content

Editorial: Merge FunctionAllocate and FunctionInitialize#1562

Merged
ljharb merged 5 commits intotc39:masterfrom
jmdyck:OrdinaryFunctionCreate
Nov 14, 2019
Merged

Editorial: Merge FunctionAllocate and FunctionInitialize#1562
ljharb merged 5 commits intotc39:masterfrom
jmdyck:OrdinaryFunctionCreate

Conversation

@jmdyck
Copy link
Collaborator

@jmdyck jmdyck commented May 31, 2019

FunctionAllocate and FunctionInitialize are always invoked in tandem. Moreover, the division between them seems somewhat arbitrary. So, merge the two operations into one, called OrdinaryFunctionCreate.

(Yeah, it's got 7 parameters, but I'm pretty sure we can eliminate one of them in a future refactoring.)

The second commit is the main one; the others are prep and cleanup.

(Web IDL and HTML do not reference FunctionAllocate or FunctionInitialize.)

spec.html Outdated
1. Else, let _allocKind_ be `"normal"`.
1. Let _F_ be FunctionAllocate(_prototype_, _Strict_, _allocKind_).
1. Return FunctionInitialize(_F_, _kind_, _ParameterList_, _Body_, _Scope_).
1. Return ! OrdinaryFunctionCreate(_prototype_, _ParameterList_, _Body_, _allocKind_, _kind_, _Strict_, _Scope_).
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you didn’t keep the same param order - prototype, strict, allocKind, and then the initialize args?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The resulting order didn't make sense to me.

Copy link
Member

Choose a reason for hiding this comment

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

At the least, strict seems to me like it should come before body and parameter list, since it determines how it’s parsed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe in the real world, but not in spec-world. In general, the spec can't even ask whether some code is strict until after it's been parsed. And anyhow, parsing is well in the past by the time this operation is called. A function's [[Strict]] value is only used to affect the creation of an "arguments" object, and how 'this' gets bound. (I think.)

(Moreover, #1563 eliminates the _Strict_ parameter, so its position in the parameter list may be a moot point.)

@jmdyck
Copy link
Collaborator Author

jmdyck commented Jun 17, 2019

(force-pushed to resolve merge conflicts)

@jmdyck jmdyck force-pushed the OrdinaryFunctionCreate branch from 1dc95e2 to b284baf Compare July 17, 2019 19:57
@jmdyck
Copy link
Collaborator Author

jmdyck commented Jul 17, 2019

(force-pushed to resolve merge conflicts again)

@ljharb ljharb requested a review from a team July 17, 2019 22:22
@jmdyck jmdyck force-pushed the OrdinaryFunctionCreate branch from b284baf to c28a7bb Compare September 14, 2019 14:32
@jmdyck
Copy link
Collaborator Author

jmdyck commented Sep 14, 2019

(force-pushed to resolve merge conflicts /3)

@ljharb ljharb self-assigned this Sep 14, 2019
@ljharb ljharb requested review from syg and removed request for a team and zenparsing October 9, 2019 22:16
@jmdyck jmdyck force-pushed the OrdinaryFunctionCreate branch from c28a7bb to a8cac86 Compare October 14, 2019 13:53
@jmdyck
Copy link
Collaborator Author

jmdyck commented Oct 14, 2019

(force-pushed to resolve merge conflicts /4)

spec.html Outdated
1. Let _realmF_ be the current Realm Record.
1. Let _scope_ be _realmF_.[[GlobalEnv]].
1. Perform FunctionInitialize(_F_, ~Normal~, _parameters_, _body_, _scope_).
1. Let _F_ be ! OrdinaryFunctionCreate(_proto_, _parameters_, _body_, _kind_, ~Normal~, _scope_).
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice cleanup here for _scope_.

spec.html Outdated
<h1>FunctionAllocate ( _functionPrototype_, _functionKind_ )</h1>
<p>The abstract operation FunctionAllocate requires the two arguments _functionPrototype_ and _functionKind_. FunctionAllocate performs the following steps:</p>
<emu-clause id="sec-ordinaryfunctioncreate" aoid="OrdinaryFunctionCreate" oldids="sec-functionallocate,sec-functioninitialize">
<h1>OrdinaryFunctionCreate ( _functionPrototype_, _ParameterList_, _Body_, _functionKind_, _kind_, _Scope_ )</h1>
Copy link
Contributor

Choose a reason for hiding this comment

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

It's unfortunate there's both a _kind_ and a _functionKind_. AFAICT the ~Method~ case of _kind_ doesn't do anything, and _kind_ is only used to determine the this scope lookup mode. I would prefer to pass that directly, i.e. a new _thisMode_ that's ~LexicalThis~ or ~NonLexicalThis~ and have the non-lexical case checked for strictness inside this AO.

@jmdyck WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, currently _kind_ is still used to determine the allocation kind for non-constructibles. It's all rather circuitous logic in there. Do you plan to layer this on top of #1546, after which my suggestion above makes more sense?

Copy link
Collaborator Author

@jmdyck jmdyck Oct 17, 2019

Choose a reason for hiding this comment

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

Do you plan to layer this on top of #1546?

Well, if #1546 is accepted, then I'll resolve the resulting merge conflicts here, if that's what you mean.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would prefer to pass that directly, i.e. a new _thisMode_ that's ~LexicalThis~ or ~NonLexicalThis~

Done! (modulo naming)

and have the non-lexical case checked for strictness inside this AO.

I wasn't sure what you meant by this.

jmdyck added a commit to jmdyck/ecma262 that referenced this pull request Oct 24, 2019
The only effect of OrdinaryFunctionCreate's _kind_ parameter
is on the [[ThisMode]] of the new function.
And although _kind_ has three possible values (~Normal~, ~Method~, ~Arrow~),
the only thing that matters is whether or not it's ~Arrow~.
So replace it with parameter _thisMode_ that has two possible values:
~lexical-this~ and ~nonlexical-this~.

Suggested by @syg in:
tc39#1562 (comment)
@jmdyck jmdyck force-pushed the OrdinaryFunctionCreate branch from a8cac86 to b30238b Compare October 24, 2019 19:46
@jmdyck
Copy link
Collaborator Author

jmdyck commented Oct 24, 2019

Force-pushed to resolve merge conflicts, and also to add 2 commits.

@ljharb ljharb requested a review from syg October 24, 2019 22:01
jmdyck added a commit to jmdyck/ecma262 that referenced this pull request Oct 24, 2019
The only effect of OrdinaryFunctionCreate's _kind_ parameter
is on the [[ThisMode]] of the new function.
And although _kind_ has three possible values (~Normal~, ~Method~, ~Arrow~),
the only thing that matters is whether or not it's ~Arrow~.
So replace it with parameter _thisMode_ that has two possible values:
~lexical-this~ and ~non-lexical-this~.

Suggested by @syg in:
tc39#1562 (comment)
@jmdyck jmdyck force-pushed the OrdinaryFunctionCreate branch from b30238b to 324cc1c Compare October 24, 2019 23:24
Copy link
Member

@michaelficarra michaelficarra left a comment

Choose a reason for hiding this comment

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

LGTM. This will probably have lots of variable renaming conflicts with #1477.

@michaelficarra michaelficarra requested a review from bakkot November 1, 2019 19:24
Copy link
Contributor

@syg syg left a comment

Choose a reason for hiding this comment

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

lgtm. Nice cleanup!

FunctionAllocate() always returns a function object
whose [[Realm]] is the current Realm Record.
FunctionAllocate and FunctionInitialize are always invoked in tandem.
Moreover, the division between them seems somewhat arbitrary.
So, merge the two operations into one, called OrdinaryFunctionCreate.
(This seems like a sensible order to me, at least.)
... specifically:
- FunctionCreate
- GeneratorFunctionCreate
- AsyncGeneratorFunctionCreate
- AsyncFunctionCreate

After the refactorings of PR tc39#1546 and the prior commits in this PR,
these have slimmed down to very thin wrappers around OrdinaryFunctionCreate.
The only thing they hide is the choice of prototype;
all their parameters are simply passed through.
I don't think they provide a useful abstraction layer any more.

In fact, I think they're kind of an obstacle.
Any change in the interface of OrdinaryFunctionCreate
would require a corresponding change to each of these operations,
an unnecessary complication and possible inhibitor.

Downstream specs:
- ES Intl doesn't use any of these operations.
- WebIDL doesn't use any of these operations.
- HTML has one call to FunctionCreate.
)

The only effect of OrdinaryFunctionCreate's _kind_ parameter
is on the [[ThisMode]] of the new function.
And although _kind_ has three possible values (~Normal~, ~Method~, ~Arrow~),
the only thing that matters is whether or not it's ~Arrow~.
So replace it with parameter _thisMode_ that has two possible values:
~lexical-this~ and ~non-lexical-this~.

Suggested in: tc39#1562 (comment)
@ljharb ljharb force-pushed the OrdinaryFunctionCreate branch from 324cc1c to 3899f59 Compare November 14, 2019 05:50
@ljharb ljharb merged commit 3899f59 into tc39:master Nov 14, 2019
@jmdyck
Copy link
Collaborator Author

jmdyck commented Nov 14, 2019

Yay! Thanks for the merge.

@jmdyck jmdyck deleted the OrdinaryFunctionCreate branch November 14, 2019 21:13
jmdyck added a commit to jmdyck/html that referenced this pull request Nov 15, 2019
In the ECMAScript spec, the recently merged [PR whatwg#1562](tc39/ecma262#1562)
replaced the `FunctionCreate` operation (and some others)
with the new operation `OrdinaryFunctionCreate`.

This commit makes the necessary changes to HTML's only call to `FunctionCreate`.
domenic pushed a commit to whatwg/html that referenced this pull request Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants