Skip to content

Commit

Permalink
Editorial: Split identity into spec and language identity
Browse files Browse the repository at this point in the history
This 2-level stratification of identity is needed rigor for Symbols as
WeakMap keys (tc39#2777) to capture the reason for why Symbol.for symbols
cannot be used as weak targets.
  • Loading branch information
syg committed Mar 9, 2023
1 parent c4a8bd4 commit fdebad9
Showing 1 changed file with 113 additions and 9 deletions.
122 changes: 113 additions & 9 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -1085,10 +1085,114 @@ <h1>Value Notation</h1>

<emu-clause id="sec-identity">
<h1>Identity</h1>
<p>In this specification, the word “is” is used to compare two values through equality, as in “If _bool_ is *true*, then”. For the purposes of this equality comparison, all values within this specification fall into one of the following two categories.</p>
<p><dfn variants="values without identity,value without identity">Values without identity</dfn> are equal to other values without identity if all of their innate characteristics are the same — characteristics such as the magnitude of an integer or the length of a sequence. Because of this, values without identity may be manifest anywhere simply by fully describing their characteristics. It is not meaningful to change the characteristics of a value that does not have identity. Examples of values without identity include, but are not limited to: <emu-xref href="#sec-ecmascript-language-types-boolean-type">Booleans</emu-xref>; mathematical values and extended mathematical values; <emu-xref href="#sec-ecmascript-language-types-number-type">Numbers</emu-xref>; <emu-xref href="#sec-ecmascript-language-types-bigint-type">BigInts</emu-xref>; *null*; *undefined*; sequences, including <emu-xref href="#sec-ecmascript-language-types-string-type">Strings</emu-xref>, ECMAScript source text, surrogate pairs, Directive Prologues, etc; UTF-16 code units; Unicode code points; enums; abstract operations, including syntax-directed operations, host hooks, etc; and ordered pairs. The preceding list is exhaustive for ECMAScript language values.</p>
<p>In contrast, each <dfn variants="values with identity">value with identity</dfn> is unique and therefore only equal to itself. Values with identity are like values without identity but with an additional unguessable, unchangeable, universally-unique characteristic called <em>identity</em>. References to existing values with identity cannot be manifest simply by describing them, as the identity itself is indescribable; instead, references to these values must be explicitly passed from one place to another. Some values with identity are mutable and therefore can have their characteristics (except their identity) changed in-place, causing all holders of the value to observe the new characteristics. Examples of values with identity include, but are not limited to: <emu-xref href="#sec-object-type">Objects</emu-xref>, including function objects, exotic objects, etc; any kind of Records, including Property Descriptors, PrivateElements, etc; <emu-xref href="#sec-ecmascript-language-types-symbol-type">symbols</emu-xref>; Parse Nodes; Lists; <emu-xref href="#sec-set-and-relation-specification-type">Sets</emu-xref> and Relations; Abstract Closures; Data Blocks; Private Names; execution contexts and execution context stacks; agent signifiers; and WaiterLists. The preceding list is exhaustive for ECMAScript language values.</p>
<p>A value without identity is never equal to a value with identity.</p>
<p>In this specification, both specification values and ECMAScript language values are compared to each other for equality. When comparing equality, values fall into one of two categories. <dfn variants="values without identity,value without identity">Values without identity</dfn> are equal to other values without identity if all of their innate characteristics are the same — characteristics such as the magnitude of an integer or the length of a sequence. Values without identity may be manifest without prior reference by fully describing their characteristics. In contrast, each <dfn variants="values with identity">value with identity</dfn> is unique and therefore only equal to itself. Values with identity are like values without identity but with an additional unguessable, unchangeable, universally-unique characteristic called <em>identity</em>. References to existing values with identity cannot be manifest simply by describing them, as the identity itself is indescribable; instead, references to these values must be explicitly passed from one place to another. Some values with identity are mutable and therefore can have their characteristics (except their identity) changed in-place, causing all holders of the value to observe the new characteristics. A value without identity is never equal to a value with identity.</p>
<p>This specification uses the word “is” to compare two values through equality, as in “If _bool_ is *true*, then ...”, and uses the word “contains” to search for a value inside lists using equality comparisons, as in "If _list_ contains a Record _r_ such that _r_.[[Foo]] is *true*, then ...". For the purposes of these equality comparisons, <dfn>specification identity</dfn> of the values determines the result. Both specification values and ECMAScript language values have specification identity. Specification identity is not observable by ECMAScript programs.</p>
<p>Additionally, ECMAScript language values are compared using SameValue and the abstract operations SameValue transitively calls. The algorithms of these comparison abstract operations determine the <dfn>language identity</dfn> of the ECMAScript language values. Only ECMAScript language values have language identity. The language identity of ECMAScript language values is observable by ECMAScript programs.</p>
<p>For specification values, examples of values without specification identity include, but are not limited to: mathematical values and extended mathematical values; ECMAScript source text, surrogate pairs, Directive Prologues, etc; UTF-16 code units; Unicode code points; enums; abstract operations, including syntax-directed operations, host hooks, etc; and ordered pairs. Examples of specification values with specification identity include, but are not limited to: any kind of Records, including Property Descriptors, PrivateElements, etc; Parse Nodes; Lists; <emu-xref href="#sec-set-and-relation-specification-type">Sets</emu-xref> and Relations; Abstract Closures; Data Blocks; Private Names; execution contexts and execution context stacks; agent signifiers; and WaiterLists. These lists are not exhaustive.</p>
<p>For ECMAScript language values, the following table exhaustively lists whether they have specification identity and language identity.</p>
<emu-table id="table-language-values-identity" caption="Identity of ECMAScript Language Values">
<table>
<tr>
<th>
ECMAScript Language Type
</th>
<th>
Has specification identity
</th>
<th>
Has language identity
</th>
</tr>
<tr>
<td>
<emu-xref href="#sec-ecmascript-language-types-undefined-type">Undefined</emu-xref>
</td>
<td>
No
</td>
<td>
No
</td>
</tr>
<tr>
<td>
<emu-xref href="#sec-ecmascript-language-types-null-type">Null</emu-xref>
</td>
<td>
No
</td>
<td>
No
</td>
</tr>
<tr>
<td>
<emu-xref href="#sec-ecmascript-language-types-boolean-type">Boolean</emu-xref>
</td>
<td>
No
</td>
<td>
No
</td>
</tr>
<tr>
<td>
<emu-xref href="#sec-ecmascript-language-types-string-type">String</emu-xref>
</td>
<td>
No
</td>
<td>
No
</td>
</tr>
<tr>
<td>
<emu-xref href="#sec-ecmascript-language-types-symbol-type">Symbol</emu-xref>
</td>
<td>
Yes
</td>
<td>
If and only if it is not contained in the <emu-xref href="#sec-symbol.for">GlobalSymbolRegistry</emu-xref> List
</td>
</tr>
<tr>
<td>
<emu-xref href="#sec-ecmascript-language-types-number-type">Number</emu-xref>
</td>
<td>
No
</td>
<td>
No
</td>
</tr>
<tr>
<td>
<emu-xref href="#sec-ecmascript-language-types-bigint-type">BigInt</emu-xref>
</td>
<td>
No
</td>
<td>
No
</td>
</tr>
<tr>
<td>
<emu-xref href="#sec-object-type">Object</emu-xref>
</td>
<td>
Yes
</td>
<td>
Yes
</td>
</tr>
</table>
</emu-table>
</emu-clause>
</emu-clause>
</emu-clause>
Expand Down Expand Up @@ -4471,7 +4575,7 @@ <h1>The Abstract Closure Specification Type</h1>
<h1>Data Blocks</h1>
<p>The <dfn variants="Data Blocks">Data Block</dfn> specification type is used to describe a distinct and mutable sequence of byte-sized (8 bit) numeric values. A <dfn variants="byte values">byte value</dfn> is an integer in the inclusive interval from 0 to 255. A Data Block value is created with a fixed number of bytes that each have the initial value 0.</p>
<p>For notational convenience within this specification, an array-like syntax can be used to access the individual bytes of a Data Block value. This notation presents a Data Block value as a 0-origined integer-indexed sequence of bytes. For example, if _db_ is a 5 byte Data Block value then _db_[2] can be used to access its 3<sup>rd</sup> byte.</p>
<p>A data block that resides in memory that can be referenced from multiple agents concurrently is designated a <dfn variants="Shared Data Blocks">Shared Data Block</dfn>. A Shared Data Block has an identity (for the purposes of equality testing Shared Data Block values) that is <em>address-free</em>: it is tied not to the virtual addresses the block is mapped to in any process, but to the set of locations in memory that the block represents. Two data blocks are equal only if the sets of the locations they contain are equal; otherwise, they are not equal and the intersection of the sets of locations they contain is empty. Finally, Shared Data Blocks can be distinguished from Data Blocks.</p>
<p>A data block that resides in memory that can be referenced from multiple agents concurrently is designated a <dfn variants="Shared Data Blocks">Shared Data Block</dfn>. A Shared Data Block has a specification identity (for the purposes of equality testing Shared Data Block values) that is <em>address-free</em>: it is tied not to the virtual addresses the block is mapped to in any process, but to the set of locations in memory that the block represents. Two data blocks are equal only if the sets of the locations they contain are equal; otherwise, they are not equal and the intersection of the sets of locations they contain is empty. Finally, Shared Data Blocks can be distinguished from Data Blocks.</p>
<p>The semantics of Shared Data Blocks is defined using Shared Data Block events by the memory model. Abstract operations below introduce Shared Data Block events and act as the interface between evaluation semantics and the event semantics of the memory model. The events form a candidate execution, on which the memory model acts as a filter. Please consult the memory model for full semantics.</p>
<p>Shared Data Block events are modeled by Records, defined in the memory model.</p>
<p>The following abstract operations are used in this specification to operate upon Data Block values:</p>
Expand Down Expand Up @@ -5858,7 +5962,7 @@ <h1>
1. If _x_ and _y_ have the same length and the same code units in the same positions, return *true*; otherwise, return *false*.
1. If _x_ is a Boolean, then
1. If _x_ and _y_ are both *true* or both *false*, return *true*; otherwise, return *false*.
1. NOTE: All other ECMAScript language values are compared by identity.
1. NOTE: All other ECMAScript language values are compared by specification identity.
1. If _x_ is _y_, return *true*; otherwise, return *false*.
</emu-alg>
<emu-note>
Expand Down Expand Up @@ -12177,7 +12281,7 @@ <h1>Liveness</h1>
</li>
</ul>
<emu-note>
The second condition above intends to capture the intuition that an object is live if its identity is observable via non-WeakRef means. An object's identity may be observed by observing a strict equality comparison between objects or observing the object being used as key in a Map.
The second condition above intends to capture the intuition that an object is live if its language identity is observable via non-WeakRef means. An object's language identity may be observed by observing a strict equality comparison between objects or observing the object being used as key in a Map.
</emu-note>
<emu-note>
<p>Presence of an object in a field, an internal slot, or a property does not imply that the object is live. For example if the object in question is never passed back to the program, then it cannot be observed.</p>
Expand Down Expand Up @@ -12213,9 +12317,9 @@ <h1>Execution</h1>
<emu-note>
<p>Together with the definition of liveness, this clause prescribes optimizations that an implementation may apply regarding WeakRefs.</p>

<p>It is possible to access an object without observing its identity. Optimizations such as dead variable elimination and scalar replacement on properties of non-escaping objects whose identity is not observed are allowed. These optimizations are thus allowed to observably empty WeakRefs that point to such objects.</p>
<p>It is possible to access an object without observing its language identity. Optimizations such as dead variable elimination and scalar replacement on properties of non-escaping objects whose language identity is not observed are allowed. These optimizations are thus allowed to observably empty WeakRefs that point to such objects.</p>

<p>On the other hand, if an object's identity is observable, and that object is in the [[WeakRefTarget]] internal slot of a WeakRef, optimizations such as rematerialization that observably empty the WeakRef are prohibited.</p>
<p>On the other hand, if an object's language identity is observable, and that object is in the [[WeakRefTarget]] internal slot of a WeakRef, optimizations such as rematerialization that observably empty the WeakRef are prohibited.</p>

<p>Because calling HostEnqueueFinalizationRegistryCleanupJob is optional, registered objects in a FinalizationRegistry do not necessarily hold that FinalizationRegistry live. Implementations may omit FinalizationRegistry callbacks for any reason, e.g., if the FinalizationRegistry itself becomes dead, or if the application is shutting down.</p>
</emu-note>
Expand Down

0 comments on commit fdebad9

Please sign in to comment.