-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Move complex parameter lists of async function into downlevel generator body #56296
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
Conversation
…el generator body
Just to understand, is this backwards compatible for |
That's correct. No change needs to be made to the helpers, so this is backwards compatible with existing |
@typescript-bot perf test |
Heya @rbuckton, I've started to run the regular perf test suite on this PR at b783f61. You can monitor the build here. Update: The results are in! |
@typescript-bot test this |
Heya @rbuckton, I've started to run the diff-based user code test suite on this PR at b783f61. You can monitor the build here. Update: The results are in! |
@rbuckton Here are the results of running the user test suite comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Everything looks good! |
@rbuckton Here they are:
CompilerComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
tsserverComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
StartupComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
This modifies our down-level emit for async functions when they contain non-trivial parameter lists that may potentially throw when bound. Prior to this change, the following would throw immediately when it should instead produce a rejected promise:
The reason for this is that we eagerly evaluate the parameter list in the down-level emit:
To address this, this PR repurposes the second parameter to
__awaiter
, which was previously only used to bind a lexically-capturedarguments
, to instead be used to forward arguments for the function to the down-level generator body, producing the following emit instead:When the transformed function is not an arrow function, we merely forward the function's
arguments
and emit placeholders for each fixed parameter to preserve the function'slength
, as can be seen withx_1
above.Arrow functions, however, do not have their own
arguments
. In that case, we instead capture all fixed arguments, followed by a rest parameter that holds any additional arguments.Thus,
now transforms to
This change means that we can no longer rely on the previous mechanism for lexical
arguments
capturing (i.e., just passing it along as the second parameter to__awaiter
), and instead must manually capture a lexicalarguments
binding.Thus,
now transforms to
Aside from the change to lexical
arguments
capturing, a function with a trivial parameter list does not undergo this transformation.Thus,
still transforms to
in an effort to limit the complexity of the down-level emit when it is unwarranted.
It should also be noted that this PR applies a similar change to async generators as well.
Fixes #40410