diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-28 09:43:32 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-29 06:54:02 +0000 |
commit | a7fc82e2e95657e048e43fe438d07b63349c38cd (patch) | |
tree | 48dfcfc88fb60cdb89efaabed53fcc6b82634e1a /src/qml/compiler/qv4codegen.cpp | |
parent | 2d1a50228571a82ab7a098a64ef04b4ccfe7ee15 (diff) | |
download | qtdeclarative-a7fc82e2e95657e048e43fe438d07b63349c38cd.tar.gz |
Optimize access to lexically scoped variables
If we access a lexically scoped variable after the initializer, then we
know it's either initialized or at least undefined, so we don't need to
do the TDZ check anymore.
The ES tests ensure that we don't optimize too much and the newly
revived tst_v4misc test ensures that we do not generate the TDZ check
instruction for certain scenarios.
Change-Id: I6706d1feb22217f323124ee698ebadb70324693b
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 5d16494c1b..f39f941cc6 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -523,7 +523,7 @@ void Codegen::variableDeclarationList(VariableDeclarationList *ast) Codegen::Reference Codegen::targetForPatternElement(AST::PatternElement *p) { if (!p->bindingIdentifier.isNull()) - return referenceForName(p->bindingIdentifier.toString(), true); + return referenceForName(p->bindingIdentifier.toString(), true, p->firstSourceLocation()); if (!p->bindingTarget || p->destructuringPattern()) return Codegen::Reference::fromStackSlot(this); Reference lhs = expression(p->bindingTarget); @@ -2242,9 +2242,9 @@ bool Codegen::visit(FunctionExpression *ast) return false; } -Codegen::Reference Codegen::referenceForName(const QString &name, bool isLhs) +Codegen::Reference Codegen::referenceForName(const QString &name, bool isLhs, const SourceLocation &accessLocation) { - Context::ResolvedName resolved = _context->resolveName(name); + Context::ResolvedName resolved = _context->resolveName(name, accessLocation); if (resolved.type == Context::ResolvedName::Local || resolved.type == Context::ResolvedName::Stack || resolved.type == Context::ResolvedName::Import) { @@ -2302,7 +2302,7 @@ bool Codegen::visit(IdentifierExpression *ast) if (hasError) return false; - _expr.setResult(referenceForName(ast->name.toString(), false)); + _expr.setResult(referenceForName(ast->name.toString(), false, ast->firstSourceLocation())); return false; } @@ -3111,7 +3111,7 @@ bool Codegen::visit(ForEachStatement *ast) Reference lhsValue = Reference::fromStackSlot(this); // There should be a temporal block, so that variables declared in lhs shadow outside vars. - // This block should define a temporal dead zone for those variables, which is not yet implemented. + // This block should define a temporal dead zone for those variables. { RegisterScope innerScope(this); ControlFlowBlock controlFlow(this, ast); |