tc39 / ecma262

Status, process, and documents for ECMA-262
https://tc39.es/ecma262/
Other
15.09k stars 1.29k forks source link

What is an intrinsic? #1540

Open jmdyck opened 5 years ago

jmdyck commented 5 years ago

The spec doesn't really define the term "intrinsic".

It does define "well-known intrinsic":

built-in objects that are explicitly referenced by the algorithms of this specification

which suggests that "intrinsic" simply means "built-in object".

Alternatively, one could reasonably infer that an intrinsic is any object created by the CreateIntrinsics operation. I believe that all such objects are built-in objects, but the converse is not quite true. That is, the set of objects created by CreateIntrinsics is a subset of the built-in objects (for a given realm). For example, each invocation of MakeArgGetter creates a built-in function object, and that happens outside of CreateIntrinsics.

So: is a function created by MakeArgGetter an intrinsic? My guess is that it isn't, i.e. that the latter inference is the correct one. Not a big deal, but it would be nice to know.


While I'm in the neighborhood, 6.1.7.4 Well-Known Intrinsic Objects says:

Well-known intrinsics are built-in objects that are explicitly referenced by the algorithms of this specification and which usually have realm-specific identities. Unless otherwise specified each intrinsic object actually corresponds to a set of similar objects, one per realm.

I'm dubious about the "usually" and "Unless otherwise specified". Are there any (well-known) intrinsic objects that aren't tied to a specific realm? CreateIntrinsics doesn't seem to think so.

domenic commented 5 years ago

Perhaps it'd be good to first step back, and determine what normative impact any definition of "intrinsic" would have?

jmdyck commented 5 years ago

Oh, probably no impact that anyone would pay attention to.

allenwb commented 5 years ago

see related discussion WRT a PR to the Who We Work repository

https://github.com/tc39/how-we-work/pull/64

jmdyck commented 5 years ago

That link is a 404 for me. (I guess it's a private repo.)

ljharb commented 5 years ago

It is.

jmdyck commented 5 years ago

So could someone with access to that repo summarize (without violating whatever's private about it) how that PR relates to or informs this issue? (Or should I pretend it wasn't mentioned?)

erights commented 5 years ago

I'll just repost my own last contributions without quotations or names of other people:

Ok, I am satisfied that "intrinsics" should be defined such that includes all the primordials. "intrinsics" also includes the global object, which "primordials" excludes, but that's manageable.

Aside from the global object, does "intrinsics" exclude what "primordials" must exclude: objects provided by the host, like window, document, require, and all objects reachable (only) from them?

For example, if "intrinsic" might be taken to include elements of the "web platform" defined by whatwg/w3c, then we still need the separate term "primordial". If "intrinsic" clearly excludes these, then yes, I think we can drop "primordials" in favor of "intrinsics other than the global object".

"standard intrinsics apart from the global object" is a mouthful. But at this point I agree that some locution involving "intrinsic", if a good one can be found, is better than introducing "primordial" as a seemingly new term.

allenwb commented 5 years ago

Nothing particularly "private" there, it's just happened to be an issue attached to the private "How we work" repository.

Here is the essence of my part of the conversation (the preceded Mark's quote):

@erights Yes, All the objects that are created prior to execution of any code in a realm are "intrinsics".

See CreateIntrinsics() in particularly step 13 that says

Set fields of intrinsics with the values listed in Table 7 that have not already been handled above. The field names are the names listed in column one of the table. The value of each field is a new object value fully and recursively populated with property values as defined by the specification of each object in clauses 18-26. ...

The items listed in Table 7 are the Well Known Intrinsics that need to be directly referenced by the specification text. It includes among others all the objects that are specific as values of properties of the global object.

Other objects recursively specified in clauses 18-26 are also intrinsics, but are not "Well known" because there aren't any specification algorithms that need to directly refer to them.

The distinction between "intrinsic objects" and "well known intrinsic objects" probably should be clarified. Basically, the well known intrinics were always intended to be a subset of the intrinsics.