Comments (9)
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.
(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.
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.
The intention of the AssertedScope
s 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 class
es 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.
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.
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.
@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.
Thanks!
Filed https://bugzilla.mozilla.org/show_bug.cgi?id=1467052 to think about "var" vs "function".
from proposal-binary-ast.
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)
- Subresource Integrity integration HOT 16
- .length property should be available for lazy function HOT 3
- Can we have `AssertedPositionalParameterName` interface which contains index? HOT 5
- Can we put more information into AssertedParameterScope ? HOT 2
- Why do some interfaces not inherit from Node? HOT 8
- (Optional) type information HOT 2
- Add comments to length field of functions. HOT 1
- Transfer repo to TC39 org HOT 5
- Add verification of property names vs identifiers
- What should be put into AssertedParameterScope for duplicate parameters? HOT 6
- Consider merging LiteralInfinityExpression into LiteralNumericExpression HOT 3
- Could the binary AST be...a bit more binary? HOT 1
- Consider splitting `LiteralNumericExpression` to `LiteralInt32Expression` + `LiteralFloatExpression`
- Could the AST be based on a reduced subset of productions? HOT 1
- Consider a compressed file format with pre-shared dictionary.
- Function.prototype.toString() HOT 12
- Modify IDL order if all JS engines benefit
- [question] I have a question that Binary AST file can be translated directly to bytecode or it should be translated to standard AST and then translated to bytecode in browser? HOT 2
- What is the current status of this proposal? HOT 12
- Solved by W3C EXI? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-binary-ast.