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: refer to numeric methods as we do other AOs #2546

Merged
merged 1 commit into from
Oct 20, 2021

Conversation

michaelficarra
Copy link
Member

This leaves the :: in the names for now to make the diff a little easier. We can rename the AOs in a follow-up if we think it's worth it.

spec.html Outdated
@@ -19322,7 +19478,11 @@ <h1>Runtime Semantics: Evaluation</h1>
<emu-alg>
1. Let _lhs_ be the result of evaluating |LeftHandSideExpression|.
1. Let _oldValue_ be ? ToNumeric(? GetValue(_lhs_)).
1. Let _newValue_ be ! Type(_oldValue_)::add(_oldValue_, Type(_oldValue_)::unit).
1. If Type(_oldValue_) is Number, then
1. Let _newValue_ be ! Number::add(_oldValue_, *1*<sub>𝔽</sub>).
Copy link
Member Author

Choose a reason for hiding this comment

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

I inlined and removed the ::unit constants, since they were described as the multiplicative identity, but only ever used in additive positions. Plus, it just makes sense to use 1 literally in the increment/decrement algorithms.

@michaelficarra
Copy link
Member Author

@bakkot Comments addressed.

@michaelficarra michaelficarra requested review from a team and bakkot October 11, 2021 17:09
spec.html Outdated
<tr><td> `&amp;` </td><td> _T_::bitwiseAND </td></tr>
<tr><td> `^` </td><td> _T_::bitwiseXOR </td></tr>
<tr><td> `|` </td><td> _T_::bitwiseOR </td></tr>
<tr><th> _opText_ </th><th> Type(_lnum_) </th><th> _operation_ </th></tr>
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't love having these duplicated - it would maybe be better to have rowspan=2?

Copy link
Member Author

Choose a reason for hiding this comment

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

since the lightweight table doesn't have cell borders, that would render confusingly

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.

LGTM other than comments.

I think having these automatically link is well worth the slight overhead in amount of prose.

@michaelficarra
Copy link
Member Author

@bakkot Comments addressed.

@bakkot bakkot added the ready to merge Editors believe this PR needs no further reviews, and is ready to land. label Oct 15, 2021
@jmdyck
Copy link
Collaborator

jmdyck commented Oct 16, 2021

I think having these automatically link is well worth the slight overhead in amount of prose.

Is that the rationale for this PR? The initial comment didn't really say.

@bakkot
Copy link
Contributor

bakkot commented Oct 16, 2021

The original motivation for the PR was to more precisely capture the return types for these operations - to talk sensibly about the return type of e.g. T::unsignedRightShift you have to say it can return either a normal completion of a Number or a throw completion of a TypeError, which obscures what's actually happening - namely, that Number::unsignedRightShift always returns a Number and never throws, and BigInt::unsignedRightShift always throws.

This matters more with #2547, which is where the issue came up.

However, separately, I think having these automatically link is enough motivation on its own.

@jmdyck
Copy link
Collaborator

jmdyck commented Oct 16, 2021

The original motivation for the PR was to more precisely capture the return types for these operations - to talk sensibly about the return type of e.g. T::unsignedRightShift you have to say it can return either a normal completion of a Number or a throw completion of a TypeError, which obscures what's actually happening - namely, that Number::unsignedRightShift always returns a Number and never throws, and BigInt::unsignedRightShift always throws.

Okay, but Number::uRS and BigInt::uRS are defined separately, so (with tc39/ecmarkup#363) we can precisely convey each one's return type. Wouldn't that be enough to address the original motivation?

This matters more with #2547, which is where the issue came up.

That one says "not ready for review", so I'm trying not to look at it.

However, separately, I think having these automatically link is enough motivation on its own.

Yup, could be.

@bakkot
Copy link
Contributor

bakkot commented Oct 16, 2021

Okay, but Number::uRS and BigInt::uRS are defined separately, so (with tc39/ecmarkup#363) we can precisely convey each one's return type.

Yes, but you have to know which you're calling for that to be useful at the call site. Otherwise you end up with exactly the same lack of precision - you don't know if your value is a completion record or not. Hence this PR.

@jmdyck
Copy link
Collaborator

jmdyck commented Oct 17, 2021

Okay, but Number::uRS and BigInt::uRS are defined separately, so (with tc39/ecmarkup#363) we can precisely convey each one's return type.

Yes, but you have to know which you're calling for that to be useful at the call site. Otherwise you end up with exactly the same lack of precision - you don't know if your value is a completion record or not.

Right! But if you don't know which you're calling in the status quo, how do you think this PR improves that?

E.g., if the status quo has Type(x)::uRS(x,y) and this PR splits that into (roughly)
if x is a Number then Number::uRS(x,y) else if x is a BigInt then BigInt::uRS(x,y)
then sure, you know that the type of Number::uRS(x,y) is Number and the type of BigInt::uRS(x,y) is throw(TypeError), but the type of the whole expression is still exactly the same as for Type(x)::uRS(x,y).

@ljharb
Copy link
Member

ljharb commented Oct 17, 2021

Sure, but then you don't have a mixed return type at an individual callsite.

@michaelficarra
Copy link
Member Author

In particular, mixed between a completion record and a non completion record.

@jmdyck
Copy link
Collaborator

jmdyck commented Oct 20, 2021

Sure, but then you don't have a mixed return type at an individual callsite.

Well, you don't have a mixed return type at the callsites of Number::uRS and BigInt::uRS, but you do still have a mixed return type at the callsites of ApplyStringOrNumericBinaryOperator.

Looking at this example more realistically, this PR doesn't actually unfold/inline any invocation of ::unsignedRightShift. The only invocation is in ApplyStringOrNumericBinaryOperator, where all the numeric operations are invoked via ? _operation_(_lnum_, _rnum_). This PR doesn't avoid a mixed return type at that callsite.

In particular, mixed between a completion record and a non completion record.

This PR unfolds calls to:

  • _T_::equal
  • _T_::sameValue
  • _T_::sameValueZero

where the return type is Boolean regardless of _T_, and

  • _T_::unaryMinus
  • _T_::bitwiseNOT
  • _T_::add
  • _T_::subtract
  • _T_::lessThan

where the result type does depend on _T_, but never involves an abrupt completion.

So I don't think this PR changes any callsite where the return type mixes a completion record and a non completion record.

@bakkot
Copy link
Contributor

bakkot commented Oct 20, 2021

@jmdyck Oh, right. The plan is for #2547 to modify ApplyStringOrNumericBinaryOperator to distinguish between the throwing and non-throwing AOs, like so, but I agree it doesn't affect any callsites in that way right now.

@ljharb ljharb merged commit a714cfd into master Oct 20, 2021
@ljharb ljharb deleted the numeric-methods branch October 20, 2021 23:18
@jmdyck
Copy link
Collaborator

jmdyck commented Oct 21, 2021

The plan is for #2547 to modify ApplyStringOrNumericBinaryOperator to distinguish between the throwing and non-throwing AOs, like so, but I agree it doesn't affect any callsites in that way right now.

Hm, interesting.

Still, that doesn't explain why this PR unfolds _T_::foo() when the return type isn't 'mixed', and in some cases isn't even dependent on _T_.

@bakkot
Copy link
Contributor

bakkot commented Oct 21, 2021

If we're not going to use _T_::foo() consistently, it's simpler to just not have such a mechanism at all, so that readers don't need to learn what that syntax means.

@jmdyck
Copy link
Collaborator

jmdyck commented Oct 21, 2021

And we're not going to use it consistently because in some cases it has a 'mixed' return type?

@bakkot
Copy link
Contributor

bakkot commented Oct 21, 2021

Yup.

@jmdyck
Copy link
Collaborator

jmdyck commented Oct 21, 2021

Okay. I'm not sure I agree it's an improvement, but at least the rationale is clearer now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editorial change establishes editorial conventions 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.

4 participants