tc39 / proposal-symbol-predicates

A proposal to introduce ways to differentiate symbols
https://tc39.es/proposal-symbol-predicates/
MIT License
19 stars 3 forks source link

Question: Classification of `%Intl%.[[FallbackSymbol]]` #4

Closed rricard closed 2 years ago

rricard commented 2 years ago

As discussed in https://github.com/rricard/proposal-symbol-predicates/pull/2#discussion_r917245590 - We need to know if %Intl%.[[FallbackSymbol]] is going to be considered by this predicate as a Well-known symbol or not.

rricard commented 2 years ago

Reporting @ljharb (co-champion) opinion on this from https://github.com/rricard/proposal-symbol-predicates/pull/2#discussion_r917281399:

I believe the overwhelming preference is for FallbackSymbol to not be well-known, as the spec currently requires, and for v8 to fix it to not be cross-realm.

If it becomes well-known, 402 would need to add it to the table.

I agree that this should be settled out of this proposal, either by inclusion in the table or by keeping it as a unique symbol. This will probably need to be settled before we go to Stage 3 in order to avoid future behaviour change from the predicate once landed.

rricard commented 2 years ago

Per the decision today in plenary: the current spec will be kept for a per-realm FallbackSymbol, so not a Well-known symbol. The current spec text for this proposal is therefore still correct.

bathos commented 1 year ago

The current definitions of well-known-ness for both intrinsic objects and intrinsic symbols only seem to concern the status of the intrinsic having a name defined in the spec for referencing it. It doesn’t seem to have anything to do with whether the intrinsic being named describes a “pan-realm instance” or a “set of per-realm instances” — it just happens to be the case that all well-known symbols fall in the former group presently. In other words, nothing in the spec seems to have forbidden ECMA-402 from making %Intl%.[[FallbackSymbol]]% “@@fallback” with the per-realm semantics. In fact...

Unless otherwise specified, well-known symbols values are shared by all realms [...]

...appears to make it explicit that they could have.

Perhaps another name should be chosen (e.g. isUniversal) rather than one that exposes previously spec-internal terminology to authors. However if isWellKnown is preferred (or even if it isn’t, I think?), it would be good for the current definition of well-known symbols to be updated at the same time so that the informal conflation of well-known & pan-realm can be a formal truth going forward.

ljharb commented 1 year ago

What forbids them is that non-registry Symbols do not have cross-realm semantics, so it is a violation for any of them TO have it - except the ones that 262 anoints, which are the well-known ones.

bathos commented 1 year ago

I agree that the concept of a spec-annointed pan-realm symbol exists. I don’t agree that the term “well-known symbol” is currently defined in a way that makes it synonymous with that concept. But I do agree that it ought to be defined that way!

ljharb commented 1 year ago

I don't think it is synonymous inherently; but non-registry cross-realm symbols are forbidden, except where 262 allows them; and 262 only allows them for well-known symbols (which are symbols listed in the table). I agree the definitions could be rewritten to make that reality less circuitous, but I disagree that it's currently defined incorrectly.

bathos commented 1 year ago

This was a quote from the ECMA-262 definition:

Unless otherwise specified, well-known symbols values are shared by all realms [...]

That pretty explicitly says that a well-known symbol could be introduced that isn’t cross-realm. Given the current definition only concerns the status of an intrinsic symbol as having a name in a particular table, this doesn’t seem super weird to me — I don’t follow what’s indirectly forbidding it. In any case:

Either way, I believe “unless otherwise specified” should be removed as part of this proposal’s spec update (or beforehand).

ljharb commented 1 year ago

Yes, it could be - and Intl didn't introduce one because they didn't add it to the table. Had they, it would have been both properly cross-realm and well-known.

There's nothing forbidding other specs from adding to the table - only from having a cross-realm symbol that isn't in the table.

bathos commented 1 year ago

Had they, it would have been both properly cross-realm and well-known.

I’m afraid I still don’t follow. The definition says members of the table are cross-realm unless otherwise specified. What would have stopped them from specifying otherwise?

There's nothing forbidding other specs from adding to the table - only from having a cross-realm symbol that isn't in the table.

Right. Adding cross-realm symbols that aren’t in the table isn’t the issue I’m describing. I’m talking about adding non-cross-realm symbols to the table, which the spec’s definition expressly states is possible and (afaict) there doesn’t seem to be anything indirectly forbidding it somewhere else.

To be clear, I’m making a case that the definition should be updated to provide the guarantee that all table members are cross-realm; I’m not disagreeing with the premise of isWellKnown or its intended semantics.

ljharb commented 1 year ago

The definition already provides the guarantee; it sounds like you want the guarantee that things not in the table are not cross-realm, which I'm claiming is already the case, despite "otherwise specified".

bathos commented 1 year ago

it sounds like you want the guarantee that things not in the table are not cross-realm

No. I understand that that’s covered elsewhere.

The definition already provides the guarantee [that the table only includes cross-realm symbols]

I’m not sure how I can communicate more clearly that the definition explicitly states that this is not guaranteed. As that allowance has never been taken advantage of in practice, it can be removed, but right now it’s there.

(Thanks for bearing with me — I’m confident we’ll end up on the same page sooner or later 😄.)

ljharb commented 1 year ago

While I don't agree that's what it says, even if you're right, that's fine, because it's not being taken advantage of. To make that change is something that'd be up to the editors and would be entirely unrelated to any proposal.

bathos commented 1 year ago

I’m interested in understanding alternative interpretations of the quoted text (“shared by all realms unless otherwise specified”) that allow it to constitute or be compatible with a guarantee that well-known symbols are shared by all realms.

That said, I also won’t bug you about it further :)

If you’re curious: I’ve included notes below on what I suspect explains why the text in question is there and what it originally intended to allow for, archaeologically & speculatively pieced together by digging through old ES spec texts/discussions/ephemera. Don’t know how accurate the analysis is, but perhaps it will be entertaining...

Open for Archeological Explorations ⛏️🏺🦖 The text in question seems to have been left unchanged since symbols were introduced in 2015 apart from “Code Realms” becoming “realms”. In fact it dates to the December 21, 2012 Harmony draft, which introduced both of the well-known tables: ![screenshot of 2015 draft text](https://github.com/tc39/proposal-symbol-predicates/assets/6257356/25ab0b91-7f6b-482f-adb5-3c1222ab92f0) _btw ... the “well-known symbols [plural] values” typo is still in the spec 11 years later 😄_ At the time, it seems to have been conceived of very similarly to the WKIO section that followed it. Each had an “unless otherwise specified” clause declaring _default_ value-vs-values semantics followed by (relatively rudimentary, compared to now) explanations of the associated spec notation. But of course a WKIO has to represent a value set and not a single cross-realm value, so how could their per-realmness merely be _default?_ > Unless otherwise specific _[sic]_ each intrinsic object actually corresponds to a set of similar objects, one per Code Realm [...] That original WKIO text [is _also_ still with us now](https://tc39.es/ecma262/#sec-well-known-intrinsic-objects:~:text=Unless%20otherwise%20specified%20each%20intrinsic%20object%20actually%20corresponds%20to%20a%20set%20of%20similar%20objects%2C%20one%20per%20realm.). It reads as mysterious hedging today — but Harmony drafts from this period make both statements a lot more intelligible, because... In this era, it turns out, **cross-realm intrinsic objects**(!!) were on the table! In fact, not long after both tables were introduced, Symbol was (briefly) rewritten as an exotic object type — without the well-known symbols losing their cross-realm singleton semantics. Discussions at the time hint at the understanding that these two “defaults” formed a logical pair. An intrinsic of whatever type might describe _either_ a single pan-realm value _or_ a set of per-realm values, with one being the norm for intrinsic symbols and one being the norm for intrinsic objects, but neither being definitional to either term or to their status as well-known ones in particular. Though not made explicit, documents at the time do suggest a generalized understanding that a hypothetical per-realm intrinsic `@@symbol` might have been referenceable by its well-known name in the same realm-contextualized manner used for `%object%` (and perhaps vice versa!). Note that when both “well-known” groups were defined, WKIO notation wasn’t yet fully defined and wasn’t specified in terms of `realm.[[Intrinsics]]` (though there was already one single reference to that field). It never came to pass that anyone made use of either “unless otherwise specified” clauses. The idea of a cross-realm WKIO became strictly impossible, as far as I know. The idea of a per-realm WKS never likewise became impossible per its _original_ definition, but the phrase “well-known symbol” itself underwent semantic drift among editors years ago owing to the enduring 1:1-ness of “well-known symbols” and “pan-realm intrinsic values”, which became _intrinsic_ [hehe] to its meaning “as spoken”. With this definition — the one we’re all most familiar with now and the one that this proposal concerns — “per-realm WKS” is an oxymoron. However the original “well-known !== cross-realm” text was never updated to reflect the change in our understanding of the term. The _“unless otherwise specified”_ clause is the last vestige of the old model. I’m sure there are folks around who were involved in authoring that text and introducing the WKS table who could say for sure if any of this sleuthing was accurate, tho I realize it’s not important enough to ping em. In any case ... thanks fer chattin’!