-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: Use abstract closures instead of semantic functions #1907
Editorial: Use abstract closures instead of semantic functions #1907
Conversation
990730d
to
a810c60
Compare
1. Let _x_ be RawBytesToNumeric(_type_, _xBytes_, _isLittleEndian_). | ||
1. Let _y_ be RawBytesToNumeric(_type_, _yBytes_, _isLittleEndian_). | ||
1. Let _T_ be Type(_x_). | ||
1. Let _sum_ be _T_::add(_x_, _y_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Let _sum_ be _T_::add(_x_, _y_). | |
1. Let _sum_ be ! _T_::add(_x_, _y_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one isn't an abstract closure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, that's worth a note saying none of the steps performed by ::add here are observable because x and y are guaranteed to be numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which means that "doesn't call other abstract operations" isn't actually necessary to indicate or guarantee that something is "pure" - so why is that part of the definition of these functions?
spec.html
Outdated
<p>The following steps are taken:</p> | ||
<emu-alg> | ||
1. Return ? AtomicReadModifyWrite(_typedArray_, _index_, _value_, `or`). | ||
1. Let _or_ be a new read-modify-write modification function with parameters (_xBytes_, _yBytes_) that captures nothing and performs the following steps atomically when called: | ||
1. Return ByteListBitwiseOp(`|`, _xBytes_, _yBytes_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Return ByteListBitwiseOp(`|`, _xBytes_, _yBytes_). | |
1. Return ! ByteListBitwiseOp(`|`, _xBytes_, _yBytes_). |
1. Let _subtract_ be a new read-modify-write modification function with parameters (_xBytes_, _yBytes_) that captures _type_ and _isLittleEndian_ and performs the following steps atomically when called: | ||
1. Assert: _xBytes_ and _yBytes_ have equal length. | ||
1. Let _x_ be RawBytesToNumeric(_type_, _xBytes_, _isLittleEndian_). | ||
1. Let _y_ be RawBytesToNumeric(_type_, _yBytes_, _isLittleEndian_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Let _y_ be RawBytesToNumeric(_type_, _yBytes_, _isLittleEndian_). | |
1. Let _y_ be ! RawBytesToNumeric(_type_, _yBytes_, _isLittleEndian_). |
1. Return ? AtomicReadModifyWrite(_typedArray_, _index_, _value_, `subtract`). | ||
1. Let _subtract_ be a new read-modify-write modification function with parameters (_xBytes_, _yBytes_) that captures _type_ and _isLittleEndian_ and performs the following steps atomically when called: | ||
1. Assert: _xBytes_ and _yBytes_ have equal length. | ||
1. Let _x_ be RawBytesToNumeric(_type_, _xBytes_, _isLittleEndian_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Let _x_ be RawBytesToNumeric(_type_, _xBytes_, _isLittleEndian_). | |
1. Let _x_ be ! RawBytesToNumeric(_type_, _xBytes_, _isLittleEndian_). |
spec.html
Outdated
1. Let _y_ be RawBytesToNumeric(_type_, _yBytes_, _isLittleEndian_). | ||
1. Let _T_ be Type(_x_). | ||
1. Let _difference_ be _T_::subtract(_x_, _y_). | ||
1. Return NumericToRawBytes(_type_, _differenceBytes_, _isLittleEndian_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Return NumericToRawBytes(_type_, _differenceBytes_, _isLittleEndian_). | |
1. Return ! NumericToRawBytes(_type_, _differenceBytes_, _isLittleEndian_). |
spec.html
Outdated
<p>The following steps are taken:</p> | ||
<emu-alg> | ||
1. Return ? AtomicReadModifyWrite(_typedArray_, _index_, _value_, `xor`). | ||
1. Let _xor_ be a new read-modify-write modification function with parameters (_xBytes_, _yBytes_) that captures nothing and performs the following steps atomically when called: | ||
1. Return ByteListBitwiseOp(`^`, _xBytes_, _yBytes_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Return ByteListBitwiseOp(`^`, _xBytes_, _yBytes_). | |
1. Return ! ByteListBitwiseOp(`^`, _xBytes_, _yBytes_). |
My preference is also to avoid |
Prior to #1796, the reigning approach is to always use the |
The current state is not consistent, as we've discussed at length before, and besides @bakkot will PR that.
This is the wrong intuition and this confusion is precisely why @bakkot, @michaelficarra, and I want to do the reform. Completion Records are about reifying control in observable program evaluation, with
1 and 3 really should not be conflated. 3 tells me a lot about no observability on control flow, which is a necessary (but not sufficient) condition for an operation being observable at all. 1 doesn't tell me that. Edit: That's what ?/! should mean post-reform. For now we just have an inconsistent state, but I prefer to not perpetuate what I consider a wrong intuition by having ! in the newer parts of the spec that are meant to not have observable effects on control flow. |
1. Let _x_ be RawBytesToNumeric(_type_, _xBytes_, _isLittleEndian_). | ||
1. Let _y_ be RawBytesToNumeric(_type_, _yBytes_, _isLittleEndian_). | ||
1. Let _T_ be Type(_x_). | ||
1. Let _sum_ be _T_::add(_x_, _y_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one isn't an abstract closure.
The problem I see is that step 2 is one that's easy to forget, and the omnipresence of |
a19a3eb
to
40dbfb4
Compare
<li>Their individual algorithm steps are not observable.</li> | ||
</ul> | ||
<emu-note> | ||
<p>To aid verifying that a read-modify-write modification function's algorithm steps constitute a pure, mathematical function, the following editorial conventions are recommended:</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, this is much clearer to me.
40dbfb4
to
6fa3b1a
Compare
Addressed review, squashed, rebased. |
spec.html
Outdated
<emu-clause id="sec-arraybuffer-notation"> | ||
<h1>Notation</h1> | ||
<p>The descriptions below in this section, <emu-xref href="#sec-atomics-object"></emu-xref>, and <emu-xref href="#sec-memory-model"></emu-xref> use the read-modify-write modification function internal data structure.</p> | ||
<p>A <dfn>read-modify-write modification function</dfn> is a mathematical function that is notationally represented as an abstract closure that takes two Lists of bytes as arguments and returns a List of bytes. These abstract closures satisfy all of the following properties:</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<p>A <dfn>read-modify-write modification function</dfn> is a mathematical function that is notationally represented as an abstract closure that takes two Lists of bytes as arguments and returns a List of bytes. These abstract closures satisfy all of the following properties:</p> | |
<p>A <dfn>read-modify-write modification function</dfn> is a mathematical function that is notationally represented as an abstract closure that takes two Lists of byte values as arguments and returns a List of byte values. These abstract closures satisfy all of the following properties:</p> |
6fa3b1a
to
ca1fb57
Compare
Rebased; PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still LGTM.
…1907) Refactor semantic functions as used by atomic RMW operations to be a subclass of abstract closures that are pure. The remaining use of "semantic function" for reads-bytes-from is changed to say "mathematical function". It is used in the axiomatic event semantics and do not have algorithm steps. Fixes tc39#1895.
56bd5fc
to
5370c6c
Compare
…1907) Refactor semantic functions as used by atomic RMW operations to be a subclass of abstract closures that are pure. The remaining use of "semantic function" for reads-bytes-from is changed to say "mathematical function". It is used in the axiomatic event semantics and do not have algorithm steps. Fixes tc39#1895.
Refactor semantic functions as used by atomic RMW operations to be
a subclass of abstract closures that are pure.
The remaining use of "semantic function" for reads-bytes-from is
changed to say "mathematical function". It is used in the axiomatic
event semantics and do not have algorithm steps.
Fixes #1895.