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: add PromiseCapability Record assertions #2050

Merged
merged 1 commit into from
Jul 2, 2020

Conversation

ljharb
Copy link
Member

@ljharb ljharb commented Jun 15, 2020

I didn't bother to add an assertion after every callsite of NewPromiseCapability.

@bakkot
Copy link
Contributor

bakkot commented Jun 15, 2020

We should also add a dfn for "PromiseCapability Record" (and maybe also capitalize the word "record" in Table 75, and also say "the PromiseCapability Record {" instead of "the PromiseCapability {" in step 3 of NewPromiseCapability).

Doesn't need to be done in this PR if you're not inclined to, though.

ljharb added a commit to ljharb/ecma262 that referenced this pull request Jun 15, 2020
ljharb added a commit to ljharb/ecma262 that referenced this pull request Jun 15, 2020
@ljharb
Copy link
Member Author

ljharb commented Jun 15, 2020

all updated

ljharb added a commit to ljharb/ecma262 that referenced this pull request Jun 15, 2020
spec.html Outdated
@@ -39528,6 +39528,7 @@ <h1>AsyncGeneratorResolve ( _generator_, _value_, _done_ )</h1>
1. Assert: _queue_ is not an empty List.
1. Remove the first element from _queue_ and let _next_ be the value of that element.
1. Let _promiseCapability_ be _next_.[[Capability]].
1. Assert: _promiseCapability_ is a PromiseCapability Record.
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not convinced it's good to assert on the type of an internal slot which is described as holding a value of the type in question. From reading this assertion I would assume that it's possible for the slot to hold some other type, so that it's meaningful to assert that it does not happen to in this particular case - but that's not so; the slot only ever holds a PromiseCapability.

Copy link
Member Author

Choose a reason for hiding this comment

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

Without these assertions tho, that's only the case "accidentally" - iow, there's nothing anywhere else that ensures it's always one in the event of a spec authoring error.

If that's not a concern, I can remove these, but I'm not sure what the downside would be of keeping them?

Copy link
Contributor

Choose a reason for hiding this comment

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

An assertion also would not ensure the type is correct. It just asserts it, exactly the same way the description of the field does. I don't see what the value of the assertion is given that the field is described as containing a PromiseCapability Record.

I'm not sure what the downside would be of keeping them?

The downside is as I said in the previous comment: from reading this assertion I would assume that it's possible for the slot to hold some other type, so that it's meaningful to assert that it does not happen to in this particular case. Which would be incorrect.

Copy link
Member Author

Choose a reason for hiding this comment

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

an implementation can alter internal slots at any time; without the assertion somewhere then it already can be any possible type.

Copy link
Contributor

Choose a reason for hiding this comment

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

an implementation can alter internal slots at any time

... Why do you believe this to be true? I don't think this is true.

without the assertion somewhere then it already can be any possible type.

Again, assertions have no normative force. They are just comments for clarity to the reader.

Copy link
Member Author

Choose a reason for hiding this comment

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

They're normative in the sense that an implementation doesn't have any observable action to take, and can thus ignore them, but if the assertion is violated, it's either a spec bug or an implementation bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

if the assertion is violated, it's either a spec bug or an implementation bug.

If an assertion is violated, it's a spec bug, yes. (I'm not really sure what it would mean for an implementation to violate an assertion.) But it would be exactly as much of a bug to put a non-PromiseCapability Record value in a slot which is described as holding a PromiseCapability Record. And it would similarly be a bug to treat a non-PromiseCapability Record value as a PromiseCapability Record. It does not somehow become more of a spec bug just because there's an assertion.

Assertions in the context of the spec are just comments. I think it is a mistake to add a comment for any reason other than because we think it will aid clarity for readers.

(I don't really know what you mean by "normative" in this context.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair - I do think this change adds clarity for readers, because I don't have to go elsewhere to figure out what kind of thing is held in the slot.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair - I do think this change adds clarity for readers, because I don't have to go elsewhere to figure out what kind of thing is held in the slot.

We could achieve that by naming the slot more precisely, e.g. [[PromiseCapability]] (or, if that's still not enough, [[PromiseCapabilityRecord]]).

Copy link
Member Author

Choose a reason for hiding this comment

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

That still wouldn't make it auto-link to "PromiseCapability Record", though.

ljharb added a commit to ljharb/ecma262 that referenced this pull request Jun 19, 2020
@ljharb
Copy link
Member Author

ljharb commented Jun 19, 2020

Removed the assertions immediately following a slot extraction.

@ljharb ljharb requested review from michaelficarra and jmdyck June 19, 2020 20:30
Copy link
Collaborator

@jmdyck jmdyck left a comment

Choose a reason for hiding this comment

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

Other than that one thing, looks okay to me.

ljharb added a commit to ljharb/ecma262 that referenced this pull request Jun 21, 2020
@ljharb ljharb requested review from jmdyck, bakkot and a team June 21, 2020 05:27
@ljharb ljharb added the editor call to be discussed in the next editor call label Jun 24, 2020
@ljharb ljharb removed the editor call to be discussed in the next editor call label Jul 1, 2020
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

@ljharb ljharb self-assigned this Jul 1, 2020
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.

6 participants