Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(901)

Unified Diff: runtime/vm/kernel_to_il.cc

Issue 2772963003: VM [KERNEL] Avoid emitting :expr_temp and capturing :iterator (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/scopes.cc » ('j') | runtime/vm/scopes.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/kernel_to_il.cc
diff --git a/runtime/vm/kernel_to_il.cc b/runtime/vm/kernel_to_il.cc
index 40c1cd1fd326c2e9b143e2d75375a447d40675bf..1653061c07ab9624fefbdc97806cd57e696198ac 100644
--- a/runtime/vm/kernel_to_il.cc
+++ b/runtime/vm/kernel_to_il.cc
@@ -31,6 +31,32 @@ namespace kernel {
#define I Isolate::Current()
+class NeedExprTempVisitor : public RecursiveVisitor {
+ public:
+ NeedExprTempVisitor() : need_expr_temp_(false) {}
+
+ virtual void VisitConditionalExpression(ConditionalExpression* node) {
+ need_expr_temp_ = true;
+ }
+
+ virtual void VisitLogicalExpression(LogicalExpression* node) {
+ need_expr_temp_ = true;
+ }
+
+ bool NeedTemp() const { return need_expr_temp_; }
Vyacheslav Egorov (Google) 2017/03/27 14:31:46 nit: style guide suggests naming simple getters li
+
+ private:
+ bool need_expr_temp_;
Vyacheslav Egorov (Google) 2017/03/27 14:31:46 better name is needs_expr_temp_.
+};
+
+
+bool NeedExprTemp(TreeNode* node) {
Vyacheslav Egorov (Google) 2017/03/27 14:31:46 static bool NeedsExprTemp(...)
+ NeedExprTempVisitor visitor;
+ node->AcceptVisitor(&visitor);
+ return visitor.NeedTemp();
+}
+
+
static void DiscoverEnclosingElements(Zone* zone,
const Function& function,
Function* outermost_function,
@@ -300,7 +326,11 @@ ScopeBuildingResult* ScopeBuilder::BuildScopes() {
LocalVariable* context_var = parsed_function->current_context_var();
context_var->set_is_forced_stack();
scope_->AddVariable(context_var);
- scope_->AddVariable(parsed_function->EnsureExpressionTemp());
+ bool has_expr_temp = false;
+ if (node_ != NULL && NeedExprTemp(node_)) {
+ scope_->AddVariable(parsed_function->EnsureExpressionTemp());
+ has_expr_temp = true;
+ }
parsed_function->SetNodeSequence(
new SequenceNode(TokenPosition::kNoSource, scope_));
@@ -348,6 +378,10 @@ ScopeBuildingResult* ScopeBuilder::BuildScopes() {
Field* field = klass->fields()[i];
if (!field->IsStatic() && (field->initializer() != NULL)) {
EnterScope(field, field->position());
+ if (!has_expr_temp && NeedExprTemp(field->initializer())) {
+ scope_->AddVariable(parsed_function->EnsureExpressionTemp());
+ has_expr_temp = true;
+ }
field->initializer()->AcceptExpressionVisitor(this);
ExitScope(field->end_position());
}
« no previous file with comments | « no previous file | runtime/vm/scopes.cc » ('j') | runtime/vm/scopes.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698