GithubHelp home page GithubHelp logo

Comments (9)

arai-a avatar arai-a commented on May 22, 2024

AssertedBlockScope also needs to distinguish between let and const:

interface AssertedBlockScope {
  // checked eagerly during transformation
  attribute FrozenArray<IdentifierName> lexicallyDeclaredNames;

  // checked lazily as inner functions are invoked
  attribute FrozenArray<IdentifierName> capturedNames;
  attribute boolean hasDirectEval;
};

from proposal-binary-ast.

Yoric avatar Yoric commented on May 22, 2024

(first post on microsoft github, odd)

Yeah, that would make sense. We could have an

interface ScopeNames {
  attribute FrozenArray<IdentifierName> declaredNames;
  attribute FrozenArray<IdentifierName> capturedNames;
}

and then rewrite

interface AssertedBlockScope {
   attribute ScopeNames? letNames;
   attribute ScopeNames? constNames; 
   attribute boolean hasDirectEval;
}

etc.

from proposal-binary-ast.

arai-a avatar arai-a commented on May 22, 2024

also, adding class separately from let might be nice.
SpiderMonkey currently doesn't distinguish between them, but adding class will help showing better error message for redeclaration across 2 files or from eval.

from proposal-binary-ast.

syg avatar syg commented on May 22, 2024

The intention of the AssertedScopes is to have the minimal amount of information needed to enable computing binding locations (i.e. frame or environment slots) and accesses to those binding locations ahead of time.

Distinguishing non-const from const is strictly not needed, because any access to the const before the actual declaration is encountered is a TDZ error, and thus do not need to distinguish const from non-const. That said, non-const vs const seems useful to know ahead of time since an implementation could reasonably choose to put consts elsewhere than other lexical bindings.

Also, I'll probably rename let names to nonConstLexical or something, in that there are other lexical bindings that aren't let forms.

Distinguishing classes and top-level functions are harder to justify. For better error messages with classes in SM, you can add a new DeclarationKind for classes.

from proposal-binary-ast.

arai-a avatar arai-a commented on May 22, 2024

The intention of the AssertedScopes is to have the minimal amount of information needed to enable computing binding locations (i.e. frame or environment slots) and accesses to those binding locations ahead of time.

I'm not sure how other implementations handle slot and declaration kind tho,
for SpiderMonkey, slot offset implies the declaration kind (including let/const/var/function),
so simply using the index in the AssertdScope's array doesn't work, but we'll need to reorder bindings based on declaration kind,
either at the beginning of the compilation (which is not possible without lookahead),
or gradually create the scope object while compiling the file, and fixup each bytecode's slot data once the actual slot offset is known (which could be done, but costs).

For better error messages with classes in SM, you can add a new DeclarationKind for classes.

it's already added, and works when we hit redeclaration in the single compilation unit.
https://searchfox.org/mozilla-central/rev/292d295d6b084b43b70de26a42e68513bb7b36a3/js/src/frontend/NameAnalysisTypes.h#84

what I intended is the case that redeclaration happens across 2 compilation unit.
(https://bugzilla.mozilla.org/show_bug.cgi?id=1428672 for non-binjs case, which I guess is going to add class range to the offset)
what we have at that point is only Scope object
(of course, this restriction would also be too SpiderMonkey-specific)

from proposal-binary-ast.

syg avatar syg commented on May 22, 2024

I'm not sure how other implementations handle slot and declaration kind tho,
for SpiderMonkey, slot offset implies the declaration kind

Right, I originally designed it that way as a packed representation. At the cost of memory, you can imagine a scope having an array of pairs of (name, kind). The only real constraints at the time when I originally designed it was that all lexical bindings should be in a contiguous range, so that we can TDZ an entire range instead of one slot at a time.

I agree fixing up would be really gross. I'm fine with adding the let/const distinction since it's pretty fundamental to the language. Other additions you want to add to Scope::Data would need to be fixed up somehow. Perhaps we can come up with a better packed Scope::Data representation that can keep slot location logic separate from slot type logic in SM?

from proposal-binary-ast.

syg avatar syg commented on May 22, 2024

@arai-a I have pushed a refactoring of asserted scoeps to https://binast.github.io/ecmascript-binary-ast/

Search for "AssertedDeclaredKind", and check out the updated CheckAssertedScope Abstract Operation. I've also added an isSimpleParameterList to AssertedParameterScope to distinguish when its bindings are in TDZ.

Let me know if you think this'll work for you.

from proposal-binary-ast.

arai-a avatar arai-a commented on May 22, 2024

Thanks!
Filed https://bugzilla.mozilla.org/show_bug.cgi?id=1467052 to think about "var" vs "function".

from proposal-binary-ast.

arai-a avatar arai-a commented on May 22, 2024

Fortunately, the var vs function can be represented without extra memory cost in SpiderMonkey, thanks to whoever invented tagged pointer.
Given that let vs const is handled in the spec, what we should handle in the impl is only var vs function, and let vs class, so 1 bit is sufficient.

So, I think the change works :)

from proposal-binary-ast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.