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

Side by Side Diff: src/scopes.cc

Issue 791603003: WIP context-allocation for “this” in arrow functions Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: WIP v3 Created 5 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/scopes.h" 7 #include "src/scopes.h"
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 602
603 // Collect internals which are always allocated on the heap. 603 // Collect internals which are always allocated on the heap.
604 for (int i = 0; i < internals_.length(); i++) { 604 for (int i = 0; i < internals_.length(); i++) {
605 Variable* var = internals_[i]; 605 Variable* var = internals_[i];
606 if (var->is_used()) { 606 if (var->is_used()) {
607 DCHECK(var->IsContextSlot()); 607 DCHECK(var->IsContextSlot());
608 context_locals->Add(var, zone()); 608 context_locals->Add(var, zone());
609 } 609 }
610 } 610 }
611 611
612 // Arrow functions can cause the receiver to be collected in the context.
wingo 2015/01/15 10:09:06 "allocated". And really it's "copied to" the cont
aperez 2015/01/15 16:58:03 Done.
613 if (receiver_ && receiver_->has_forced_context_allocation()) {
614 DCHECK(receiver_->IsContextSlot());
615 context_locals->Add(receiver_, zone());
616 }
617
612 // Collect temporaries which are always allocated on the stack, unless the 618 // Collect temporaries which are always allocated on the stack, unless the
613 // context as a whole has forced context allocation. 619 // context as a whole has forced context allocation.
614 for (int i = 0; i < temps_.length(); i++) { 620 for (int i = 0; i < temps_.length(); i++) {
615 Variable* var = temps_[i]; 621 Variable* var = temps_[i];
616 if (var->is_used()) { 622 if (var->is_used()) {
617 if (var->IsContextSlot()) { 623 if (var->IsContextSlot()) {
618 DCHECK(has_forced_context_allocation()); 624 DCHECK(has_forced_context_allocation());
619 context_locals->Add(var, zone()); 625 context_locals->Add(var, zone());
620 } else { 626 } else {
621 DCHECK(var->IsStackLocal()); 627 DCHECK(var->IsStackLocal());
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_; 1180 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_;
1175 for (int i = 0; i < inner_scopes_.length(); i++) { 1181 for (int i = 0; i < inner_scopes_.length(); i++) {
1176 Scope* inner = inner_scopes_[i]; 1182 Scope* inner = inner_scopes_[i];
1177 inner->PropagateScopeInfo(calls_sloppy_eval); 1183 inner->PropagateScopeInfo(calls_sloppy_eval);
1178 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { 1184 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) {
1179 inner_scope_calls_eval_ = true; 1185 inner_scope_calls_eval_ = true;
1180 } 1186 }
1181 // If the inner scope is an arrow function, propagate the flags tracking 1187 // If the inner scope is an arrow function, propagate the flags tracking
1182 // usage of arguments/super/this, but do not propagate them out from normal 1188 // usage of arguments/super/this, but do not propagate them out from normal
1183 // functions. 1189 // functions.
1184 if (!inner->is_function_scope() || inner->is_arrow_scope()) { 1190 if (inner->is_arrow_scope()) {
1185 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) { 1191 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) {
1186 inner_scope_uses_arguments_ = true; 1192 inner_scope_uses_arguments_ = true;
1187 } 1193 }
1188 if (inner->scope_uses_super_property_ || 1194 if (inner->scope_uses_super_property_ ||
1189 inner->inner_scope_uses_super_property_) { 1195 inner->inner_scope_uses_super_property_) {
1190 inner_scope_uses_super_property_ = true; 1196 inner_scope_uses_super_property_ = true;
1191 } 1197 }
1192 if (inner->uses_super_constructor_call() || 1198 if (inner->uses_super_constructor_call() ||
1193 inner->inner_scope_uses_super_constructor_call_) { 1199 inner->inner_scope_uses_super_constructor_call_) {
1194 inner_scope_uses_super_constructor_call_ = true; 1200 inner_scope_uses_super_constructor_call_ = true;
1195 } 1201 }
1196 if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) { 1202 if (inner->scope_uses_this_ || inner->inner_scope_uses_this_) {
1197 inner_scope_uses_this_ = true; 1203 inner_scope_uses_this_ = true;
1198 } 1204 }
1199 } 1205 } else if (inner->is_block_scope()) {
1200 if (inner->force_eager_compilation_) { 1206 if (inner->scope_uses_this_) {
wingo 2015/01/15 10:09:06 Why do we need the whole list of these? At some p
aperez 2015/01/15 16:58:03 I have been trying to factor out the flag propagat
1201 force_eager_compilation_ = true; 1207 scope_uses_this_ = true;
1202 } 1208 }
1203 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { 1209 if (inner->scope_uses_arguments_) {
1204 inner->asm_function_ = true; 1210 scope_uses_arguments_ = true;
1211 }
1212 if (inner->scope_uses_super_property_) {
1213 scope_uses_super_property_ = true;
1214 }
1215 if (inner->scope_uses_super_constructor_call_) {
1216 scope_uses_super_constructor_call_ = true;
1217 }
1218 if (inner->inner_scope_uses_arguments_) {
1219 inner_scope_uses_arguments_ = true;
1220 }
1221 if (inner->inner_scope_uses_super_property_) {
1222 inner_scope_uses_super_property_ = true;
1223 }
1224 if (inner->inner_scope_uses_super_constructor_call_) {
1225 inner_scope_uses_super_constructor_call_ = true;
1226 }
1227 if (inner->inner_scope_uses_this_) {
1228 inner_scope_uses_this_ = true;
1229 }
1230 } else if (!inner->is_function_scope() || inner->is_arrow_scope()) {
1231 if (inner->force_eager_compilation_) {
1232 force_eager_compilation_ = true;
1233 }
wingo 2015/01/15 10:09:05 These propagations should run for all scopes
aperez 2015/01/15 16:58:03 Done.
1234 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) {
1235 inner->asm_function_ = true;
1236 }
1205 } 1237 }
1206 } 1238 }
1207 } 1239 }
1208 1240
1209 1241
1210 bool Scope::MustAllocate(Variable* var) { 1242 bool Scope::MustAllocate(Variable* var) {
1211 // Give var a read/write use if there is a chance it might be accessed 1243 // Give var a read/write use if there is a chance it might be accessed
1212 // via an eval() call. This is only possible if the variable has a 1244 // via an eval() call. This is only possible if the variable has a
1213 // visible name. 1245 // visible name.
1214 if ((var->is_this() || !var->raw_name()->IsEmpty()) && 1246 if ((var->is_this() || !var->raw_name()->IsEmpty()) &&
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 AllocateHeapSlot(var); 1349 AllocateHeapSlot(var);
1318 } 1350 }
1319 } else { 1351 } else {
1320 DCHECK(var->IsUnallocated() || var->IsParameter()); 1352 DCHECK(var->IsUnallocated() || var->IsParameter());
1321 if (var->IsUnallocated()) { 1353 if (var->IsUnallocated()) {
1322 var->AllocateTo(Variable::PARAMETER, i); 1354 var->AllocateTo(Variable::PARAMETER, i);
1323 } 1355 }
1324 } 1356 }
1325 } 1357 }
1326 } 1358 }
1359
1360 // If the scope contains at least one inner arrow function which uses
1361 // "this", it must be copied in the context, from where it will be looked
wingo 2015/01/15 10:09:06 s/it must be copied in/the receiver must be copied
aperez 2015/01/15 16:58:03 Done.
1362 // up by code emitted in the prologues of arrow functions.
1363 if (inner_scope_uses_this_) {
1364 DCHECK(receiver_);
1365 if (receiver_->IsUnallocated() || !receiver_->IsContextSlot()) {
1366 receiver_->ForceContextAllocation();
1367 AllocateHeapSlot(receiver_);
1368 }
1369 DCHECK(MustAllocateInContext(receiver_));
1370 }
1327 } 1371 }
1328 1372
1329 1373
1330 void Scope::AllocateNonParameterLocal(Variable* var) { 1374 void Scope::AllocateNonParameterLocal(Variable* var) {
1331 DCHECK(var->scope() == this); 1375 DCHECK(var->scope() == this);
1332 DCHECK(!var->IsVariable(isolate_->factory()->dot_result_string()) || 1376 DCHECK(!var->IsVariable(isolate_->factory()->dot_result_string()) ||
1333 !var->IsStackLocal()); 1377 !var->IsStackLocal());
1334 if (var->IsUnallocated() && MustAllocate(var)) { 1378 if (var->IsUnallocated() && MustAllocate(var)) {
1335 if (MustAllocateInContext(var)) { 1379 if (MustAllocateInContext(var)) {
1336 AllocateHeapSlot(var); 1380 AllocateHeapSlot(var);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 } 1477 }
1434 1478
1435 1479
1436 int Scope::ContextLocalCount() const { 1480 int Scope::ContextLocalCount() const {
1437 if (num_heap_slots() == 0) return 0; 1481 if (num_heap_slots() == 0) return 0;
1438 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1482 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1439 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1483 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1440 } 1484 }
1441 1485
1442 } } // namespace v8::internal 1486 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698