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

Side by Side Diff: src/ast/ast.cc

Issue 2479123002: Compiling an array literal should be context-independent. (Closed)
Patch Set: rebase Created 4 years, 1 month 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
« no previous file with comments | « no previous file | src/elements.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ast/ast.h" 5 #include "src/ast/ast.h"
6 6
7 #include <cmath> // For isfinite. 7 #include <cmath> // For isfinite.
8 8
9 #include "src/ast/compile-time-value.h" 9 #include "src/ast/compile-time-value.h"
10 #include "src/ast/prettyprinter.h" 10 #include "src/ast/prettyprinter.h"
11 #include "src/ast/scopes.h" 11 #include "src/ast/scopes.h"
12 #include "src/base/hashmap.h" 12 #include "src/base/hashmap.h"
13 #include "src/builtins/builtins.h" 13 #include "src/builtins/builtins.h"
14 #include "src/code-stubs.h" 14 #include "src/code-stubs.h"
15 #include "src/contexts.h" 15 #include "src/contexts.h"
16 #include "src/conversions.h" 16 #include "src/conversions.h"
17 #include "src/elements.h"
17 #include "src/property-details.h" 18 #include "src/property-details.h"
18 #include "src/property.h" 19 #include "src/property.h"
19 #include "src/string-stream.h" 20 #include "src/string-stream.h"
20 #include "src/type-info.h" 21 #include "src/type-info.h"
21 22
22 namespace v8 { 23 namespace v8 {
23 namespace internal { 24 namespace internal {
24 25
25 // ---------------------------------------------------------------------------- 26 // ----------------------------------------------------------------------------
26 // Implementation of other node functionality. 27 // Implementation of other node functionality.
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 set_depth(depth_acc); 574 set_depth(depth_acc);
574 } 575 }
575 576
576 577
577 void ArrayLiteral::BuildConstantElements(Isolate* isolate) { 578 void ArrayLiteral::BuildConstantElements(Isolate* isolate) {
578 DCHECK_LT(first_spread_index_, 0); 579 DCHECK_LT(first_spread_index_, 0);
579 580
580 if (!constant_elements_.is_null()) return; 581 if (!constant_elements_.is_null()) return;
581 582
582 int constants_length = values()->length(); 583 int constants_length = values()->length();
583 584 ElementsKind kind = FIRST_FAST_ELEMENTS_KIND;
584 // Allocate a fixed array to hold all the object literals. 585 Handle<FixedArray> fixed_array =
585 Handle<JSArray> array = isolate->factory()->NewJSArray( 586 isolate->factory()->NewFixedArrayWithHoles(constants_length);
586 FAST_HOLEY_SMI_ELEMENTS, constants_length, constants_length,
587 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
588 587
589 // Fill in the literals. 588 // Fill in the literals.
590 bool is_simple = true; 589 bool is_simple = true;
591 int depth_acc = 1; 590 int depth_acc = 1;
592 bool is_holey = false; 591 bool is_holey = false;
593 int array_index = 0; 592 int array_index = 0;
594 for (; array_index < constants_length; array_index++) { 593 for (; array_index < constants_length; array_index++) {
595 Expression* element = values()->at(array_index); 594 Expression* element = values()->at(array_index);
596 DCHECK(!element->IsSpread()); 595 DCHECK(!element->IsSpread());
597 MaterializedLiteral* m_literal = element->AsMaterializedLiteral(); 596 MaterializedLiteral* m_literal = element->AsMaterializedLiteral();
(...skipping 10 matching lines...) Expand all
608 if (boilerplate_value->IsTheHole(isolate)) { 607 if (boilerplate_value->IsTheHole(isolate)) {
609 is_holey = true; 608 is_holey = true;
610 continue; 609 continue;
611 } 610 }
612 611
613 if (boilerplate_value->IsUninitialized(isolate)) { 612 if (boilerplate_value->IsUninitialized(isolate)) {
614 boilerplate_value = handle(Smi::kZero, isolate); 613 boilerplate_value = handle(Smi::kZero, isolate);
615 is_simple = false; 614 is_simple = false;
616 } 615 }
617 616
618 JSObject::AddDataElement(array, array_index, boilerplate_value, NONE) 617 kind = GetMoreGeneralElementsKind(kind,
619 .Assert(); 618 boilerplate_value->OptimalElementsKind());
619 fixed_array->set(array_index, *boilerplate_value);
620 } 620 }
621 621
622 JSObject::ValidateElements(array); 622 if (is_holey) kind = GetHoleyElementsKind(kind);
623 Handle<FixedArrayBase> element_values(array->elements());
624 623
625 // Simple and shallow arrays can be lazily copied, we transform the 624 // Simple and shallow arrays can be lazily copied, we transform the
626 // elements array to a copy-on-write array. 625 // elements array to a copy-on-write array.
627 if (is_simple && depth_acc == 1 && array_index > 0 && 626 if (is_simple && depth_acc == 1 && array_index > 0 &&
628 array->HasFastSmiOrObjectElements()) { 627 IsFastSmiOrObjectElementsKind(kind)) {
629 element_values->set_map(isolate->heap()->fixed_cow_array_map()); 628 fixed_array->set_map(isolate->heap()->fixed_cow_array_map());
629 }
630
631 Handle<FixedArrayBase> elements = fixed_array;
632 if (IsFastDoubleElementsKind(kind)) {
633 ElementsAccessor* accessor = ElementsAccessor::ForKind(kind);
634 elements = isolate->factory()->NewFixedDoubleArray(constants_length);
635 // We are copying from non-fast-double to fast-double.
636 ElementsKind from_kind = TERMINAL_FAST_ELEMENTS_KIND;
637 accessor->CopyElements(fixed_array, from_kind, elements, constants_length);
630 } 638 }
631 639
632 // Remember both the literal's constant values as well as the ElementsKind 640 // Remember both the literal's constant values as well as the ElementsKind
633 // in a 2-element FixedArray. 641 // in a 2-element FixedArray.
634 Handle<FixedArray> literals = isolate->factory()->NewFixedArray(2, TENURED); 642 Handle<FixedArray> literals = isolate->factory()->NewFixedArray(2, TENURED);
635
636 ElementsKind kind = array->GetElementsKind();
637 kind = is_holey ? GetHoleyElementsKind(kind) : GetPackedElementsKind(kind);
638
639 literals->set(0, Smi::FromInt(kind)); 643 literals->set(0, Smi::FromInt(kind));
640 literals->set(1, *element_values); 644 literals->set(1, *elements);
641 645
642 constant_elements_ = literals; 646 constant_elements_ = literals;
643 set_is_simple(is_simple); 647 set_is_simple(is_simple);
644 set_depth(depth_acc); 648 set_depth(depth_acc);
645 } 649 }
646 650
647 651
648 void ArrayLiteral::AssignFeedbackVectorSlots(Isolate* isolate, 652 void ArrayLiteral::AssignFeedbackVectorSlots(Isolate* isolate,
649 FeedbackVectorSpec* spec, 653 FeedbackVectorSpec* spec,
650 FeedbackVectorSlotCache* cache) { 654 FeedbackVectorSlotCache* cache) {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 // static 947 // static
944 bool Literal::Match(void* literal1, void* literal2) { 948 bool Literal::Match(void* literal1, void* literal2) {
945 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); 949 const AstValue* x = static_cast<Literal*>(literal1)->raw_value();
946 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); 950 const AstValue* y = static_cast<Literal*>(literal2)->raw_value();
947 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || 951 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) ||
948 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); 952 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber());
949 } 953 }
950 954
951 } // namespace internal 955 } // namespace internal
952 } // namespace v8 956 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/elements.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698