Commit 17e9e2f4 authored by mvstanton's avatar mvstanton Committed by Commit bot

Forking the type system between Crankshaft & Turbofan.

Our Type class has a semantic and representational dimension.
Much code in src/ast, Crankshaft and Turbofan is based on it.
Going forward in Turbofan we'd like to remove representational information
entirely. To that end, new type AstType has been created to preserve
existing behavior for the benefit of Crankshaft and the AST.

BUG=

Review-Url: https://codereview.chromium.org/2302283002
Cr-Commit-Position: refs/heads/master@{#39135}
parent 6ef6d902
......@@ -857,6 +857,8 @@ v8_source_set("v8_base") {
"src/ast/ast-numbering.h",
"src/ast/ast-traversal-visitor.h",
"src/ast/ast-type-bounds.h",
"src/ast/ast-types.cc",
"src/ast/ast-types.h",
"src/ast/ast-value-factory.cc",
"src/ast/ast-value-factory.h",
"src/ast/ast.cc",
......
......@@ -12,10 +12,10 @@
#include "src/allocation.h"
#include "src/asmjs/asm-types.h"
#include "src/ast/ast-type-bounds.h"
#include "src/ast/ast-types.h"
#include "src/ast/ast.h"
#include "src/effects.h"
#include "src/type-info.h"
#include "src/types.h"
#include "src/zone-containers.h"
#include "src/zone.h"
......
......@@ -7,7 +7,7 @@
#ifndef V8_AST_AST_TYPE_BOUNDS_H_
#define V8_AST_AST_TYPE_BOUNDS_H_
#include "src/types.h"
#include "src/ast/ast-types.h"
#include "src/zone-containers.h"
namespace v8 {
......@@ -20,18 +20,18 @@ class AstTypeBounds {
explicit AstTypeBounds(Zone* zone) : bounds_map_(zone) {}
~AstTypeBounds() {}
Bounds get(Expression* expression) const {
ZoneMap<Expression*, Bounds>::const_iterator i =
AstBounds get(Expression* expression) const {
ZoneMap<Expression*, AstBounds>::const_iterator i =
bounds_map_.find(expression);
return (i != bounds_map_.end()) ? i->second : Bounds::Unbounded();
return (i != bounds_map_.end()) ? i->second : AstBounds::Unbounded();
}
void set(Expression* expression, Bounds bounds) {
void set(Expression* expression, AstBounds bounds) {
bounds_map_[expression] = bounds;
}
private:
ZoneMap<Expression*, Bounds> bounds_map_;
ZoneMap<Expression*, AstBounds> bounds_map_;
};
} // namespace internal
......
This diff is collapsed.
This diff is collapsed.
......@@ -950,7 +950,7 @@ CaseClause::CaseClause(Expression* label, ZoneList<Statement*>* statements,
: Expression(pos, kCaseClause),
label_(label),
statements_(statements),
compare_type_(Type::None()) {}
compare_type_(AstType::None()) {}
void CaseClause::AssignFeedbackVectorSlots(Isolate* isolate,
FeedbackVectorSpec* spec,
......
......@@ -5,6 +5,7 @@
#ifndef V8_AST_AST_H_
#define V8_AST_AST_H_
#include "src/ast/ast-types.h"
#include "src/ast/ast-value-factory.h"
#include "src/ast/modules.h"
#include "src/ast/variables.h"
......@@ -17,7 +18,6 @@
#include "src/parsing/token.h"
#include "src/runtime/runtime.h"
#include "src/small-pointer-list.h"
#include "src/types.h"
#include "src/utils.h"
namespace v8 {
......@@ -939,8 +939,8 @@ class CaseClause final : public Expression {
BailoutId EntryId() const { return BailoutId(local_id(0)); }
TypeFeedbackId CompareId() { return TypeFeedbackId(local_id(1)); }
Type* compare_type() { return compare_type_; }
void set_compare_type(Type* type) { compare_type_ = type; }
AstType* compare_type() { return compare_type_; }
void set_compare_type(AstType* type) { compare_type_ = type; }
// CaseClause will have both a slot in the feedback vector and the
// TypeFeedbackId to record the type information. TypeFeedbackId is used by
......@@ -962,7 +962,7 @@ class CaseClause final : public Expression {
Expression* label_;
Label body_target_;
ZoneList<Statement*>* statements_;
Type* compare_type_;
AstType* compare_type_;
FeedbackVectorSlot type_feedback_slot_;
};
......@@ -2135,14 +2135,14 @@ class CountOperation final : public Expression {
KeyedAccessStoreMode GetStoreMode() const {
return StoreModeField::decode(bit_field_);
}
Type* type() const { return type_; }
AstType* type() const { return type_; }
void set_key_type(IcCheckType type) {
bit_field_ = KeyTypeField::update(bit_field_, type);
}
void set_store_mode(KeyedAccessStoreMode mode) {
bit_field_ = StoreModeField::update(bit_field_, mode);
}
void set_type(Type* type) { type_ = type; }
void set_type(AstType* type) { type_ = type; }
static int num_ids() { return parent_num_ids() + 4; }
BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
......@@ -2187,7 +2187,7 @@ class CountOperation final : public Expression {
uint16_t bit_field_;
FeedbackVectorSlot slot_;
FeedbackVectorSlot binary_operation_slot_;
Type* type_;
AstType* type_;
Expression* expression_;
SmallMapList receiver_types_;
};
......@@ -2207,8 +2207,8 @@ class CompareOperation final : public Expression {
TypeFeedbackId CompareOperationFeedbackId() const {
return TypeFeedbackId(local_id(0));
}
Type* combined_type() const { return combined_type_; }
void set_combined_type(Type* type) { combined_type_ = type; }
AstType* combined_type() const { return combined_type_; }
void set_combined_type(AstType* type) { combined_type_ = type; }
// CompareOperation will have both a slot in the feedback vector and the
// TypeFeedbackId to record the type information. TypeFeedbackId is used
......@@ -2234,7 +2234,7 @@ class CompareOperation final : public Expression {
op_(op),
left_(left),
right_(right),
combined_type_(Type::None()) {
combined_type_(AstType::None()) {
DCHECK(Token::IsCompareOp(op));
}
......@@ -2245,7 +2245,7 @@ class CompareOperation final : public Expression {
Expression* left_;
Expression* right_;
Type* combined_type_;
AstType* combined_type_;
FeedbackVectorSlot type_feedback_slot_;
};
......
......@@ -335,7 +335,7 @@ template <>
HValue* CodeStubGraphBuilder<NumberToStringStub>::BuildCodeStub() {
info()->MarkAsSavesCallerDoubles();
HValue* number = GetParameter(Descriptor::kArgument);
return BuildNumberToString(number, Type::Number());
return BuildNumberToString(number, AstType::Number());
}
......@@ -1263,26 +1263,26 @@ HValue* CodeStubGraphBuilder<BinaryOpICStub>::BuildCodeInitializedStub() {
HValue* left = GetParameter(Descriptor::kLeft);
HValue* right = GetParameter(Descriptor::kRight);
Type* left_type = state.GetLeftType();
Type* right_type = state.GetRightType();
Type* result_type = state.GetResultType();
AstType* left_type = state.GetLeftType();
AstType* right_type = state.GetRightType();
AstType* result_type = state.GetResultType();
DCHECK(!left_type->Is(Type::None()) && !right_type->Is(Type::None()) &&
(state.HasSideEffects() || !result_type->Is(Type::None())));
DCHECK(!left_type->Is(AstType::None()) && !right_type->Is(AstType::None()) &&
(state.HasSideEffects() || !result_type->Is(AstType::None())));
HValue* result = NULL;
HAllocationMode allocation_mode(NOT_TENURED);
if (state.op() == Token::ADD &&
(left_type->Maybe(Type::String()) || right_type->Maybe(Type::String())) &&
!left_type->Is(Type::String()) && !right_type->Is(Type::String())) {
if (state.op() == Token::ADD && (left_type->Maybe(AstType::String()) ||
right_type->Maybe(AstType::String())) &&
!left_type->Is(AstType::String()) && !right_type->Is(AstType::String())) {
// For the generic add stub a fast case for string addition is performance
// critical.
if (left_type->Maybe(Type::String())) {
if (left_type->Maybe(AstType::String())) {
IfBuilder if_leftisstring(this);
if_leftisstring.If<HIsStringAndBranch>(left);
if_leftisstring.Then();
{
Push(BuildBinaryOperation(state.op(), left, right, Type::String(),
Push(BuildBinaryOperation(state.op(), left, right, AstType::String(),
right_type, result_type,
state.fixed_right_arg(), allocation_mode));
}
......@@ -1300,7 +1300,7 @@ HValue* CodeStubGraphBuilder<BinaryOpICStub>::BuildCodeInitializedStub() {
if_rightisstring.Then();
{
Push(BuildBinaryOperation(state.op(), left, right, left_type,
Type::String(), result_type,
AstType::String(), result_type,
state.fixed_right_arg(), allocation_mode));
}
if_rightisstring.Else();
......@@ -1341,9 +1341,9 @@ HValue* CodeStubGraphBuilder<BinaryOpWithAllocationSiteStub>::BuildCodeStub() {
HValue* left = GetParameter(Descriptor::kLeft);
HValue* right = GetParameter(Descriptor::kRight);
Type* left_type = state.GetLeftType();
Type* right_type = state.GetRightType();
Type* result_type = state.GetResultType();
AstType* left_type = state.GetLeftType();
AstType* right_type = state.GetRightType();
AstType* result_type = state.GetResultType();
HAllocationMode allocation_mode(allocation_site);
return BuildBinaryOperation(state.op(), left, right, left_type, right_type,
......@@ -1364,7 +1364,7 @@ HValue* CodeStubGraphBuilderBase::BuildToString(HValue* input, bool convert) {
if_inputissmi.Then();
{
// Convert the input smi to a string.
Push(BuildNumberToString(input, Type::SignedSmall()));
Push(BuildNumberToString(input, AstType::SignedSmall()));
}
if_inputissmi.Else();
{
......
......@@ -5837,20 +5837,20 @@ ArrayConstructorStub::ArrayConstructorStub(Isolate* isolate,
InternalArrayConstructorStub::InternalArrayConstructorStub(Isolate* isolate)
: PlatformCodeStub(isolate) {}
Representation RepresentationFromType(Type* type) {
if (type->Is(Type::UntaggedIntegral())) {
Representation RepresentationFromType(AstType* type) {
if (type->Is(AstType::UntaggedIntegral())) {
return Representation::Integer32();
}
if (type->Is(Type::TaggedSigned())) {
if (type->Is(AstType::TaggedSigned())) {
return Representation::Smi();
}
if (type->Is(Type::UntaggedPointer())) {
if (type->Is(AstType::UntaggedPointer())) {
return Representation::External();
}
DCHECK(!type->Is(Type::Untagged()));
DCHECK(!type->Is(AstType::Untagged()));
return Representation::Tagged();
}
......
......@@ -12,17 +12,17 @@ namespace v8 {
namespace internal {
// static
HType HType::FromType(Type* type) {
if (Type::Any()->Is(type)) return HType::Any();
HType HType::FromType(AstType* type) {
if (AstType::Any()->Is(type)) return HType::Any();
if (!type->IsInhabited()) return HType::None();
if (type->Is(Type::SignedSmall())) return HType::Smi();
if (type->Is(Type::Number())) return HType::TaggedNumber();
if (type->Is(Type::Null())) return HType::Null();
if (type->Is(Type::String())) return HType::String();
if (type->Is(Type::Boolean())) return HType::Boolean();
if (type->Is(Type::Undefined())) return HType::Undefined();
if (type->Is(Type::Object())) return HType::JSObject();
if (type->Is(Type::DetectableReceiver())) return HType::JSReceiver();
if (type->Is(AstType::SignedSmall())) return HType::Smi();
if (type->Is(AstType::Number())) return HType::TaggedNumber();
if (type->Is(AstType::Null())) return HType::Null();
if (type->Is(AstType::String())) return HType::String();
if (type->Is(AstType::Boolean())) return HType::Boolean();
if (type->Is(AstType::Undefined())) return HType::Undefined();
if (type->Is(AstType::Object())) return HType::JSObject();
if (type->Is(AstType::DetectableReceiver())) return HType::JSReceiver();
return HType::Tagged();
}
......
......@@ -8,8 +8,8 @@
#include <climits>
#include <iosfwd>
#include "src/ast/ast-types.h"
#include "src/base/macros.h"
#include "src/types.h"
namespace v8 {
namespace internal {
......@@ -64,7 +64,7 @@ class HType final {
HTYPE_LIST(DECLARE_IS_TYPE)
#undef DECLARE_IS_TYPE
static HType FromType(Type* type) WARN_UNUSED_RESULT;
static HType FromType(AstType* type) WARN_UNUSED_RESULT;
static HType FromFieldType(Handle<FieldType> type,
Zone* temp_zone) WARN_UNUSED_RESULT;
static HType FromValue(Handle<Object> value) WARN_UNUSED_RESULT;
......
This diff is collapsed.
......@@ -1396,7 +1396,7 @@ class HGraphBuilder {
ElementsKind to_kind,
bool is_jsarray);
HValue* BuildNumberToString(HValue* object, Type* type);
HValue* BuildNumberToString(HValue* object, AstType* type);
HValue* BuildToNumber(HValue* input);
HValue* BuildToObject(HValue* receiver);
......@@ -1500,8 +1500,8 @@ class HGraphBuilder {
HValue** shift_amount);
HValue* BuildBinaryOperation(Token::Value op, HValue* left, HValue* right,
Type* left_type, Type* right_type,
Type* result_type, Maybe<int> fixed_right_arg,
AstType* left_type, AstType* right_type,
AstType* result_type, Maybe<int> fixed_right_arg,
HAllocationMode allocation_mode,
BailoutId opt_id = BailoutId::None());
......@@ -1514,8 +1514,8 @@ class HGraphBuilder {
HValue* AddLoadJSBuiltin(int context_index);
HValue* EnforceNumberType(HValue* number, Type* expected);
HValue* TruncateToNumber(HValue* value, Type** expected);
HValue* EnforceNumberType(HValue* number, AstType* expected);
HValue* TruncateToNumber(HValue* value, AstType** expected);
void FinishExitWithHardDeoptimization(DeoptimizeReason reason);
......@@ -2707,8 +2707,8 @@ class HOptimizedGraphBuilder : public HGraphBuilder,
};
HControlInstruction* BuildCompareInstruction(
Token::Value op, HValue* left, HValue* right, Type* left_type,
Type* right_type, Type* combined_type, SourcePosition left_position,
Token::Value op, HValue* left, HValue* right, AstType* left_type,
AstType* right_type, AstType* combined_type, SourcePosition left_position,
SourcePosition right_position, PushBeforeSimulateBehavior push_sim_result,
BailoutId bailout_id);
......
......@@ -33,7 +33,7 @@ AstTyper::AstTyper(Isolate* isolate, Zone* zone, Handle<JSFunction> closure,
#ifdef OBJECT_PRINT
static void PrintObserved(Variable* var, Object* value, Type* type) {
static void PrintObserved(Variable* var, Object* value, AstType* type) {
OFStream os(stdout);
os << " observed " << (var->IsParameter() ? "param" : "local") << " ";
var->name()->Print(os);
......@@ -45,8 +45,8 @@ AstTyper::AstTyper(Isolate* isolate, Zone* zone, Handle<JSFunction> closure,
Effect AstTyper::ObservedOnStack(Object* value) {
Type* lower = Type::NowOf(value, zone());
return Effect(Bounds(lower, Type::Any()));
AstType* lower = AstType::NowOf(value, zone());
return Effect(AstBounds(lower, AstType::Any()));
}
......@@ -206,9 +206,9 @@ void AstTyper::VisitSwitchStatement(SwitchStatement* stmt) {
if (!clause->is_default()) {
Expression* label = clause->label();
// Collect type feedback.
Type* tag_type;
Type* label_type;
Type* combined_type;
AstType* tag_type;
AstType* label_type;
AstType* combined_type;
oracle()->CompareType(clause->CompareId(),
&tag_type, &label_type, &combined_type);
NarrowLowerType(stmt->tag(), tag_type);
......@@ -367,7 +367,7 @@ void AstTyper::VisitConditional(Conditional* expr) {
store_.Seq(then_effects);
NarrowType(expr,
Bounds::Either(bounds_->get(expr->then_expression()),
AstBounds::Either(bounds_->get(expr->then_expression()),
bounds_->get(expr->else_expression()), zone()));
}
......@@ -381,14 +381,14 @@ void AstTyper::VisitVariableProxy(VariableProxy* expr) {
void AstTyper::VisitLiteral(Literal* expr) {
Type* type = Type::Constant(expr->value(), zone());
NarrowType(expr, Bounds(type));
AstType* type = AstType::Constant(expr->value(), zone());
NarrowType(expr, AstBounds(type));
}
void AstTyper::VisitRegExpLiteral(RegExpLiteral* expr) {
// TODO(rossberg): Reintroduce RegExp type.
NarrowType(expr, Bounds(Type::Object()));
NarrowType(expr, AstBounds(AstType::Object()));
}
......@@ -416,7 +416,7 @@ void AstTyper::VisitObjectLiteral(ObjectLiteral* expr) {
RECURSE(Visit(prop->value()));
}
NarrowType(expr, Bounds(Type::Object()));
NarrowType(expr, AstBounds(AstType::Object()));
}
......@@ -427,7 +427,7 @@ void AstTyper::VisitArrayLiteral(ArrayLiteral* expr) {
RECURSE(Visit(value));
}
NarrowType(expr, Bounds(Type::Object()));
NarrowType(expr, AstBounds(AstType::Object()));
}
......@@ -480,7 +480,7 @@ void AstTyper::VisitThrow(Throw* expr) {
RECURSE(Visit(expr->exception()));
// TODO(rossberg): is it worth having a non-termination effect?
NarrowType(expr, Bounds(Type::None()));
NarrowType(expr, AstBounds(AstType::None()));
}
......@@ -563,7 +563,7 @@ void AstTyper::VisitCallNew(CallNew* expr) {
RECURSE(Visit(arg));
}
NarrowType(expr, Bounds(Type::None(), Type::Receiver()));
NarrowType(expr, AstBounds(AstType::None(), AstType::Receiver()));
}
......@@ -590,13 +590,13 @@ void AstTyper::VisitUnaryOperation(UnaryOperation* expr) {
switch (expr->op()) {
case Token::NOT:
case Token::DELETE:
NarrowType(expr, Bounds(Type::Boolean()));
NarrowType(expr, AstBounds(AstType::Boolean()));
break;
case Token::VOID:
NarrowType(expr, Bounds(Type::Undefined()));
NarrowType(expr, AstBounds(AstType::Undefined()));
break;
case Token::TYPEOF:
NarrowType(expr, Bounds(Type::InternalizedString()));
NarrowType(expr, AstBounds(AstType::InternalizedString()));
break;
default:
UNREACHABLE();
......@@ -618,7 +618,7 @@ void AstTyper::VisitCountOperation(CountOperation* expr) {
RECURSE(Visit(expr->expression()));
NarrowType(expr, Bounds(Type::SignedSmall(), Type::Number()));
NarrowType(expr, AstBounds(AstType::SignedSmall(), AstType::Number()));
VariableProxy* proxy = expr->expression()->AsVariableProxy();
if (proxy != NULL && proxy->var()->IsStackAllocated()) {
......@@ -629,9 +629,9 @@ void AstTyper::VisitCountOperation(CountOperation* expr) {
void AstTyper::VisitBinaryOperation(BinaryOperation* expr) {
// Collect type feedback.
Type* type;
Type* left_type;
Type* right_type;
AstType* type;
AstType* left_type;
AstType* right_type;
Maybe<int> fixed_right_arg = Nothing<int>();
Handle<AllocationSite> allocation_site;
oracle()->BinaryType(expr->BinaryOperationFeedbackId(),
......@@ -663,7 +663,7 @@ void AstTyper::VisitBinaryOperation(BinaryOperation* expr) {
left_effects.Alt(right_effects);
store_.Seq(left_effects);
NarrowType(expr, Bounds::Either(bounds_->get(expr->left()),
NarrowType(expr, AstBounds::Either(bounds_->get(expr->left()),
bounds_->get(expr->right()), zone()));
break;
}
......@@ -671,11 +671,13 @@ void AstTyper::VisitBinaryOperation(BinaryOperation* expr) {
case Token::BIT_AND: {
RECURSE(Visit(expr->left()));
RECURSE(Visit(expr->right()));
Type* upper = Type::Union(bounds_->get(expr->left()).upper,
AstType* upper =
AstType::Union(bounds_->get(expr->left()).upper,
bounds_->get(expr->right()).upper, zone());
if (!upper->Is(Type::Signed32())) upper = Type::Signed32();
Type* lower = Type::Intersect(Type::SignedSmall(), upper, zone());
NarrowType(expr, Bounds(lower, upper));
if (!upper->Is(AstType::Signed32())) upper = AstType::Signed32();
AstType* lower =
AstType::Intersect(AstType::SignedSmall(), upper, zone());
NarrowType(expr, AstBounds(lower, upper));
break;
}
case Token::BIT_XOR:
......@@ -683,7 +685,7 @@ void AstTyper::VisitBinaryOperation(BinaryOperation* expr) {
case Token::SAR:
RECURSE(Visit(expr->left()));
RECURSE(Visit(expr->right()));
NarrowType(expr, Bounds(Type::SignedSmall(), Type::Signed32()));
NarrowType(expr, AstBounds(AstType::SignedSmall(), AstType::Signed32()));
break;
case Token::SHR:
RECURSE(Visit(expr->left()));
......@@ -691,28 +693,29 @@ void AstTyper::VisitBinaryOperation(BinaryOperation* expr) {
// TODO(rossberg): The upper bound would be Unsigned32, but since there
// is no 'positive Smi' type for the lower bound, we use the smallest
// union of Smi and Unsigned32 as upper bound instead.
NarrowType(expr, Bounds(Type::SignedSmall(), Type::Number()));
NarrowType(expr, AstBounds(AstType::SignedSmall(), AstType::Number()));
break;
case Token::ADD: {
RECURSE(Visit(expr->left()));
RECURSE(Visit(expr->right()));
Bounds l = bounds_->get(expr->left());
Bounds r = bounds_->get(expr->right());
Type* lower =
AstBounds l = bounds_->get(expr->left());
AstBounds r = bounds_->get(expr->right());
AstType* lower =
!l.lower->IsInhabited() || !r.lower->IsInhabited()
? Type::None()
: l.lower->Is(Type::String()) || r.lower->Is(Type::String())
? Type::String()
: l.lower->Is(Type::Number()) && r.lower->Is(Type::Number())
? Type::SignedSmall()
: Type::None();
Type* upper =
l.upper->Is(Type::String()) || r.upper->Is(Type::String())
? Type::String()
: l.upper->Is(Type::Number()) && r.upper->Is(Type::Number())
? Type::Number()
: Type::NumberOrString();
NarrowType(expr, Bounds(lower, upper));
? AstType::None()
: l.lower->Is(AstType::String()) || r.lower->Is(AstType::String())
? AstType::String()
: l.lower->Is(AstType::Number()) &&
r.lower->Is(AstType::Number())
? AstType::SignedSmall()
: AstType::None();
AstType* upper =
l.upper->Is(AstType::String()) || r.upper->Is(AstType::String())
? AstType::String()
: l.upper->Is(AstType::Number()) && r.upper->Is(AstType::Number())
? AstType::Number()
: AstType::NumberOrString();
NarrowType(expr, AstBounds(lower, upper));
break;
}
case Token::SUB:
......@@ -721,7 +724,7 @@ void AstTyper::VisitBinaryOperation(BinaryOperation* expr) {
case Token::MOD:
RECURSE(Visit(expr->left()));
RECURSE(Visit(expr->right()));
NarrowType(expr, Bounds(Type::SignedSmall(), Type::Number()));
NarrowType(expr, AstBounds(AstType::SignedSmall(), AstType::Number()));
break;
default:
UNREACHABLE();
......@@ -731,9 +734,9 @@ void AstTyper::VisitBinaryOperation(BinaryOperation* expr) {
void AstTyper::VisitCompareOperation(CompareOperation* expr) {
// Collect type feedback.
Type* left_type;
Type* right_type;
Type* combined_type;
AstType* left_type;
AstType* right_type;
AstType* combined_type;
oracle()->CompareType(expr->CompareOperationFeedbackId(),
&left_type, &right_type, &combined_type);
NarrowLowerType(expr->left(), left_type);
......@@ -743,7 +746,7 @@ void AstTyper::VisitCompareOperation(CompareOperation* expr) {
RECURSE(Visit(expr->left()));
RECURSE(Visit(expr->right()));
NarrowType(expr, Bounds(Type::Boolean()));
NarrowType(expr, AstBounds(AstType::Boolean()));
}
......
......@@ -7,11 +7,11 @@
#include "src/allocation.h"
#include "src/ast/ast-type-bounds.h"
#include "src/ast/ast-types.h"
#include "src/ast/scopes.h"
#include "src/ast/variables.h"
#include "src/effects.h"
#include "src/type-info.h"
#include "src/types.h"
#include "src/zone.h"
namespace v8 {
......@@ -49,11 +49,11 @@ class AstTyper final : public AstVisitor<AstTyper> {
Zone* zone() const { return zone_; }
TypeFeedbackOracle* oracle() { return &oracle_; }
void NarrowType(Expression* e, Bounds b) {
bounds_->set(e, Bounds::Both(bounds_->get(e), b, zone()));
void NarrowType(Expression* e, AstBounds b) {
bounds_->set(e, AstBounds::Both(bounds_->get(e), b, zone()));
}
void NarrowLowerType(Expression* e, Type* t) {
bounds_->set(e, Bounds::NarrowLower(bounds_->get(e), t, zone()));
void NarrowLowerType(Expression* e, AstType* t) {
bounds_->set(e, AstBounds::NarrowLower(bounds_->get(e), t, zone()));
}
Effects EnterEffects() {
......
......@@ -5,7 +5,7 @@
#ifndef V8_EFFECTS_H_
#define V8_EFFECTS_H_
#include "src/types.h"
#include "src/ast/ast-types.h"
namespace v8 {
namespace internal {
......@@ -28,30 +28,30 @@ struct Effect {
enum Modality { POSSIBLE, DEFINITE };
Modality modality;
Bounds bounds;
AstBounds bounds;
Effect() : modality(DEFINITE) {}
explicit Effect(Bounds b, Modality m = DEFINITE) : modality(m), bounds(b) {}
explicit Effect(AstBounds b, Modality m = DEFINITE)
: modality(m), bounds(b) {}
// The unknown effect.
static Effect Unknown(Zone* zone) {
return Effect(Bounds::Unbounded(), POSSIBLE);
return Effect(AstBounds::Unbounded(), POSSIBLE);
}
static Effect Forget(Zone* zone) {
return Effect(Bounds::Unbounded(), DEFINITE);
return Effect(AstBounds::Unbounded(), DEFINITE);
}
// Sequential composition, as in 'e1; e2'.
static Effect Seq(Effect e1, Effect e2, Zone* zone) {
if (e2.modality == DEFINITE) return e2;
return Effect(Bounds::Either(e1.bounds, e2.bounds, zone), e1.modality);
return Effect(AstBounds::Either(e1.bounds, e2.bounds, zone), e1.modality);
}
// Alternative composition, as in 'cond ? e1 : e2'.
static Effect Alt(Effect e1, Effect e2, Zone* zone) {
return Effect(
Bounds::Either(e1.bounds, e2.bounds, zone),
return Effect(AstBounds::Either(e1.bounds, e2.bounds, zone),
e1.modality == POSSIBLE ? POSSIBLE : e2.modality);
}
};
......@@ -84,10 +84,10 @@ class EffectsMixin: public Base {
? locator.value() : Effect::Unknown(Base::zone());
}
Bounds LookupBounds(Var var) {
AstBounds LookupBounds(Var var) {
Effect effect = Lookup(var);
return effect.modality == Effect::DEFINITE
? effect.bounds : Bounds::Unbounded();
return effect.modality == Effect::DEFINITE ? effect.bounds
: AstBounds::Unbounded();
}
// Sequential composition.
......
......@@ -4,9 +4,9 @@
#include "src/field-type.h"
#include "src/ast/ast-types.h"
#include "src/handles-inl.h"
#include "src/ostreams.h"
#include "src/types.h"
namespace v8 {
namespace internal {
......@@ -71,11 +71,11 @@ bool FieldType::NowIs(FieldType* other) {
bool FieldType::NowIs(Handle<FieldType> other) { return NowIs(*other); }
Type* FieldType::Convert(Zone* zone) {
if (IsAny()) return Type::NonInternal();
if (IsNone()) return Type::None();
AstType* FieldType::Convert(Zone* zone) {
if (IsAny()) return AstType::NonInternal();
if (IsNone()) return AstType::None();
DCHECK(IsClass());
return Type::Class(AsClass(), zone);
return AstType::Class(AsClass(), zone);
}
void FieldType::PrintTo(std::ostream& os) {
......
......@@ -5,6 +5,7 @@
#ifndef V8_FIELD_TYPE_H_
#define V8_FIELD_TYPE_H_
#include "src/ast/ast-types.h"
#include "src/handles.h"
#include "src/objects.h"
#include "src/ostreams.h"
......@@ -38,7 +39,7 @@ class FieldType : public Object {
bool NowStable();
bool NowIs(FieldType* other);
bool NowIs(Handle<FieldType> other);
Type* Convert(Zone* zone);
AstType* Convert(Zone* zone);
void PrintTo(std::ostream& os);
};
......
......@@ -189,15 +189,14 @@ void BinaryOpICState::GenerateAheadOfTime(
#undef GENERATE
}
Type* BinaryOpICState::GetResultType() const {
AstType* BinaryOpICState::GetResultType() const {
Kind result_kind = result_kind_;
if (HasSideEffects()) {
result_kind = NONE;
} else if (result_kind == GENERIC && op_ == Token::ADD) {
return Type::NumberOrString();
return AstType::NumberOrString();
} else if (result_kind == NUMBER && op_ == Token::SHR) {
return Type::Unsigned32();
return AstType::Unsigned32();
}
DCHECK_NE(GENERIC, result_kind);
return KindToType(result_kind);
......@@ -318,20 +317,20 @@ const char* BinaryOpICState::KindToString(Kind kind) {
// static
Type* BinaryOpICState::KindToType(Kind kind) {
AstType* BinaryOpICState::KindToType(Kind kind) {
switch (kind) {
case NONE:
return Type::None();
return AstType::None();
case SMI:
return Type::SignedSmall();
return AstType::SignedSmall();
case INT32:
return Type::Signed32();
return AstType::Signed32();
case NUMBER:
return Type::Number();
return AstType::Number();
case STRING:
return Type::String();
return AstType::String();
case GENERIC:
return Type::Any();
return AstType::Any();
}
UNREACHABLE();
return NULL;
......@@ -365,29 +364,28 @@ const char* CompareICState::GetStateName(State state) {
return NULL;
}
Type* CompareICState::StateToType(Zone* zone, State state, Handle<Map> map) {
AstType* CompareICState::StateToType(Zone* zone, State state, Handle<Map> map) {
switch (state) {
case UNINITIALIZED:
return Type::None();
return AstType::None();
case BOOLEAN:
return Type::Boolean();
return AstType::Boolean();
case SMI:
return Type::SignedSmall();
return AstType::SignedSmall();
case NUMBER:
return Type::Number();
return AstType::Number();
case STRING:
return Type::String();
return AstType::String();
case INTERNALIZED_STRING:
return Type::InternalizedString();
return AstType::InternalizedString();
case UNIQUE_NAME:
return Type::UniqueName();
return AstType::UniqueName();
case RECEIVER:
return Type::Receiver();
return AstType::Receiver();
case KNOWN_RECEIVER:
return map.is_null() ? Type::Receiver() : Type::Class(map, zone);
return map.is_null() ? AstType::Receiver() : AstType::Class(map, zone);
case GENERIC:
return Type::Any();
return AstType::Any();
}
UNREACHABLE();
return NULL;
......
......@@ -120,9 +120,9 @@ class BinaryOpICState final BASE_EMBEDDED {
Token::Value op() const { return op_; }
Maybe<int> fixed_right_arg() const { return fixed_right_arg_; }
Type* GetLeftType() const { return KindToType(left_kind_); }
Type* GetRightType() const { return KindToType(right_kind_); }
Type* GetResultType() const;
AstType* GetLeftType() const { return KindToType(left_kind_); }
AstType* GetRightType() const { return KindToType(right_kind_); }
AstType* GetResultType() const;
void Update(Handle<Object> left, Handle<Object> right, Handle<Object> result);
......@@ -140,7 +140,7 @@ class BinaryOpICState final BASE_EMBEDDED {
Kind UpdateKind(Handle<Object> object, Kind kind) const;
static const char* KindToString(Kind kind);
static Type* KindToType(Kind kind);
static AstType* KindToType(Kind kind);
static bool KindMaybeSmi(Kind kind) {
return (kind >= SMI && kind <= NUMBER) || kind == GENERIC;
}
......@@ -202,7 +202,7 @@ class CompareICState {
GENERIC
};
static Type* StateToType(Zone* zone, State state,
static AstType* StateToType(Zone* zone, State state,
Handle<Map> map = Handle<Map>());
static State NewInputState(State old_state, Handle<Object> value);
......
......@@ -5,7 +5,7 @@
#ifndef V8_PARSING_PARAMETER_EXPRESSION_REWRITER_H_
#define V8_PARSING_PARAMETER_EXPRESSION_REWRITER_H_
#include "src/types.h"
#include "src/ast/ast-types.h"
namespace v8 {
namespace internal {
......
......@@ -191,15 +191,13 @@ Handle<AllocationSite> TypeFeedbackOracle::GetCallNewAllocationSite(
return Handle<AllocationSite>::null();
}
void TypeFeedbackOracle::CompareType(TypeFeedbackId id,
Type** left_type,
Type** right_type,
Type** combined_type) {
void TypeFeedbackOracle::CompareType(TypeFeedbackId id, AstType** left_type,
AstType** right_type,
AstType** combined_type) {
Handle<Object> info = GetInfo(id);
if (!info->IsCode()) {
// For some comparisons we don't have ICs, e.g. LiteralCompareTypeof.
*left_type = *right_type = *combined_type = Type::None();
*left_type = *right_type = *combined_type = AstType::None();
return;
}
Handle<Code> code = Handle<Code>::cast(info);
......@@ -216,11 +214,8 @@ void TypeFeedbackOracle::CompareType(TypeFeedbackId id,
}
}
void TypeFeedbackOracle::BinaryType(TypeFeedbackId id,
Type** left,
Type** right,
Type** result,
void TypeFeedbackOracle::BinaryType(TypeFeedbackId id, AstType** left,
AstType** right, AstType** result,
Maybe<int>* fixed_right_arg,
Handle<AllocationSite>* allocation_site,
Token::Value op) {
......@@ -230,7 +225,7 @@ void TypeFeedbackOracle::BinaryType(TypeFeedbackId id,
// operations covered by the BinaryOpIC we should always have them.
DCHECK(op < BinaryOpICState::FIRST_TOKEN ||
op > BinaryOpICState::LAST_TOKEN);
*left = *right = *result = Type::None();
*left = *right = *result = AstType::None();
*fixed_right_arg = Nothing<int>();
*allocation_site = Handle<AllocationSite>::null();
return;
......@@ -253,10 +248,9 @@ void TypeFeedbackOracle::BinaryType(TypeFeedbackId id,
}
}
Type* TypeFeedbackOracle::CountType(TypeFeedbackId id) {
AstType* TypeFeedbackOracle::CountType(TypeFeedbackId id) {
Handle<Object> object = GetInfo(id);
if (!object->IsCode()) return Type::None();
if (!object->IsCode()) return AstType::None();
Handle<Code> code = Handle<Code>::cast(object);
DCHECK_EQ(Code::BINARY_OP_IC, code->kind());
BinaryOpICState state(isolate(), code->extra_ic_state());
......
......@@ -6,10 +6,10 @@
#define V8_TYPE_INFO_H_
#include "src/allocation.h"
#include "src/ast/ast-types.h"
#include "src/contexts.h"
#include "src/globals.h"
#include "src/parsing/token.h"
#include "src/types.h"
#include "src/zone.h"
namespace v8 {
......@@ -77,20 +77,15 @@ class TypeFeedbackOracle: public ZoneObject {
uint16_t ToBooleanTypes(TypeFeedbackId id);
// Get type information for arithmetic operations and compares.
void BinaryType(TypeFeedbackId id,
Type** left,
Type** right,
Type** result,
Maybe<int>* fixed_right_arg,
void BinaryType(TypeFeedbackId id, AstType** left, AstType** right,
AstType** result, Maybe<int>* fixed_right_arg,
Handle<AllocationSite>* allocation_site,
Token::Value operation);
void CompareType(TypeFeedbackId id,
Type** left,
Type** right,
Type** combined);
void CompareType(TypeFeedbackId id, AstType** left, AstType** right,
AstType** combined);
Type* CountType(TypeFeedbackId id);
AstType* CountType(TypeFeedbackId id);
Zone* zone() const { return zone_; }
Isolate* isolate() const { return isolate_; }
......
......@@ -980,7 +980,6 @@ struct Bounds {
return that.lower->Is(this->lower) && this->upper->Is(that.upper);
}
};
} // namespace internal
} // namespace v8
......
......@@ -451,6 +451,8 @@
'ast/ast-numbering.h',
'ast/ast-traversal-visitor.h',
'ast/ast-type-bounds.h',
'ast/ast-types.cc',
'ast/ast-types.h',
'ast/ast-value-factory.cc',
'ast/ast-value-factory.h',
'ast/ast.cc',
......
This diff is collapsed.
......@@ -174,6 +174,7 @@
'test-trace-event.cc',
'test-transitions.cc',
'test-typedarrays.cc',
'test-ast-types.cc',
'test-types.cc',
'test-unbound-queue.cc',
'test-unboxed-doubles.cc',
......
......@@ -66,6 +66,7 @@
# This tests only the type system, no point in running several variants.
'test-hydrogen-types/*': [PASS, NO_VARIANTS],
'test-types/*': [PASS, NO_VARIANTS],
'test-ast-types/*': [PASS, NO_VARIANTS],
# This tests API threading, no point in running several variants.
'test-api/Threading*': [PASS, NO_VARIANTS],
......
This diff is collapsed.
......@@ -2419,8 +2419,8 @@ TEST(FieldTypeConvertSimple) {
Zone zone(isolate->allocator());
CHECK_EQ(FieldType::Any()->Convert(&zone), Type::NonInternal());
CHECK_EQ(FieldType::None()->Convert(&zone), Type::None());
CHECK_EQ(FieldType::Any()->Convert(&zone), AstType::NonInternal());
CHECK_EQ(FieldType::None()->Convert(&zone), AstType::None());
}
// TODO(ishell): add this test once IS_ACCESSOR_FIELD_SUPPORTED is supported.
......
......@@ -1866,18 +1866,6 @@ struct Tests {
}
}
}
void HTypeFromType() {
for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
Type* type1 = *it1;
Type* type2 = *it2;
HType htype1 = HType::FromType(type1);
HType htype2 = HType::FromType(type2);
CHECK(!type1->Is(type2) || htype1.IsSubtypeOf(htype2));
}
}
}
};
TEST(IsSomeType_zone) { Tests().IsSomeType(); }
......@@ -1931,5 +1919,3 @@ TEST(Intersect_zone) { Tests().Intersect(); }
TEST(Distributivity_zone) { Tests().Distributivity(); }
TEST(GetRange_zone) { Tests().GetRange(); }
TEST(HTypeFromType_zone) { Tests().HTypeFromType(); }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment