infra icon indicating copy to clipboard operation
infra copied to clipboard

Introduce a shorthand for ECMA262 abstract ops

Open jugglinmike opened this issue 2 years ago • 7 comments

This patch is in service of gh-518.

I've implemented this using the definition name "throw-if-abrupt" because I can't get Bikeshed to use ? (U+003F) as a name. If we think this might limit adoption, I can inquire about modifying Bikeshed.

The new text (which I've largely copied from ECMA262) reduces ambiguity, but it does not eliminate it. There are ways of applying ? which do not match the example, even within Infra itself:

1. Return ? Call(%JSON.parse%, undefined, « string »).

...is not "otherwise equivalent to":

1. Let |result| be ? AbstractOperation().

For what it's worth, ECMA262 suffers from the same deficiency, though some folks have been trying to address it. @annevk do you feel that the ambiguity undermines the goal of this patch?


Preview | Diff

jugglinmike avatar Feb 16 '23 03:02 jugglinmike

Would be interested in feedback from @jmdyck on this.

annevk avatar Feb 16 '23 09:02 annevk

As for the problems with defining ?, I probably don't have anything to say here beyond what I've said in https://github.com/tc39/ecma262/pull/1573

jmdyck avatar Feb 16 '23 20:02 jmdyck

Thank you, @jmdyck! I appreciate your encouragement to explain this more holistically. I couldn't find a way to expand the reasoning exactly according to the points you've outlined, but I hope the prose I've pushed up is sufficiently coherent, anyway.

Completion records aren't just for modelling exceptions-based flow; even if ECMAScript didn't have exceptions, it would still need completion records (or something like them) to model break+continue+return control flow.

Fair point. Those details don't seem necessary to explain the motivation or usage of this shorthand, though, so I've true to accommodate them simply by writing in less sweeping terms ("to model control flow interruptions such as thrown exceptions.")

As for the problems with defining ?, I probably don't have anything to say here beyond what I've said in tc39/ecma262#1573

After some more thought, I'm feeling like replicating 262's current (though imprecise) language still represents a meaningful step forward here. That said, I've also added a note to surface this consideration and help folks recognize when an improvement is available.

jugglinmike avatar Feb 17 '23 01:02 jugglinmike

Those details don't seem necessary to explain the motivation or usage of this shorthand, though, so I've true to accommodate them simply by writing in less sweeping terms ("to model control flow interruptions such as thrown exceptions.")

Sounds good.

jmdyck avatar Feb 17 '23 03:02 jmdyck

@annevk I think this is ready for another look!

jugglinmike avatar Feb 23 '23 23:02 jugglinmike

The difference is in the way that an abrupt completion is handled. In ECMAScript, it's simply returned (i.e., the algorithm using ? returns an abrupt completion), whereas here, its [[Value]] is thrown (i.e., the algorithm using ? throws an Infra-exception). Issue #518 explains the significance of that distinction.

jmdyck avatar Feb 24 '23 13:02 jmdyck

Thanks for the refresher. So I think what needs to happen is that we state that normatively. And then have an example that illustrates it. And not have the normative requirements be made through examples.

annevk avatar Feb 24 '23 13:02 annevk