Skip to content

eliminate Lexical Environment? #1473

@jmdyck

Description

@jmdyck

I'm thinking the spec might be better off if we eliminated the 'Lexical Environment' structure.

"A Lexical Environment consists of an Environment Record and a possibly null reference to an outer Lexical Environment."

Instead, we could make [[Outer]] a field common to all Environment Records, and then replace every Lexical Environment with the Environment Record that it refers to.

Reasons to eliminate:

  1. The name similarity between "Lexical Environment" and "Environment Record" is a possible source of confusion.

  2. A Lexical Environment is a thing with two components, rather than a record with two fields. Thus, we can't use dot-notation to express "the EnvironmentRecord component of ". We could redefine it as a record, but then we'd have a Lexical Environment record which isn't a kind of Environment Record, an even greater source of confusion.

  3. It's an extra level of indirection. Whenever we want to do something with a Lexical Environment, we typically have to add another step to extract its Environment Record component.

(Note that, due to 2 and 3, there's already the temptation to pretend it doesn't exist. E.g., PRs #702 and #1463 are considering using the phrase realm.[[GlobalEnv]].[[GlobalThisValue]]. Technically, this is incorrect, because realm.[[GlobalEnv]] is a Lexical Environment, and you have to get its Environment Record (a global ER) before you can then get the latter's [[GlobalThisValue]] field.)

Reasons to keep:

I can't see any. Layering? Tradition? Nobody wants to perform the necessary edits?

(As far as I can tell, a Lexical Environment's EnvironmentRecord component is only ever set once, when the Lexical Environment is created. Had that not been the case, that might have been a reason to keep the extra level of indirection.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions