Commit d98ef522 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[compiler] Replace type->IsInhabited() by !type->IsNone().

They have been meaning the same thing for a while now.

R=jarin@chromium.org

Bug: 
Change-Id: Ie5988e6429b795babfa1e1f79841a9f03b8362dc
Reviewed-on: https://chromium-review.googlesource.com/758268
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49228}
parent df15c60e
...@@ -35,7 +35,7 @@ bool NoReturn(Node* node) { ...@@ -35,7 +35,7 @@ bool NoReturn(Node* node) {
return node->opcode() == IrOpcode::kDead || return node->opcode() == IrOpcode::kDead ||
node->opcode() == IrOpcode::kUnreachable || node->opcode() == IrOpcode::kUnreachable ||
node->opcode() == IrOpcode::kDeadValue || node->opcode() == IrOpcode::kDeadValue ||
!NodeProperties::GetTypeOrAny(node)->IsInhabited(); NodeProperties::GetTypeOrAny(node)->IsNone();
} }
bool HasDeadInput(Node* node) { bool HasDeadInput(Node* node) {
...@@ -210,7 +210,7 @@ Reduction DeadCodeElimination::ReducePhi(Node* node) { ...@@ -210,7 +210,7 @@ Reduction DeadCodeElimination::ReducePhi(Node* node) {
Reduction reduction = PropagateDeadControl(node); Reduction reduction = PropagateDeadControl(node);
if (reduction.Changed()) return reduction; if (reduction.Changed()) return reduction;
if (PhiRepresentationOf(node->op()) == MachineRepresentation::kNone || if (PhiRepresentationOf(node->op()) == MachineRepresentation::kNone ||
!NodeProperties::GetTypeOrAny(node)->IsInhabited()) { NodeProperties::GetTypeOrAny(node)->IsNone()) {
return Replace(dead_value()); return Replace(dead_value());
} }
return NoChange(); return NoChange();
......
...@@ -641,8 +641,8 @@ void ReduceNode(const Operator* op, EscapeAnalysisTracker::Scope* current, ...@@ -641,8 +641,8 @@ void ReduceNode(const Operator* op, EscapeAnalysisTracker::Scope* current,
// types (which might confuse representation selection). We get // types (which might confuse representation selection). We get
// around this by refusing to constant-fold and escape-analyze // around this by refusing to constant-fold and escape-analyze
// if the type is not inhabited. // if the type is not inhabited.
if (NodeProperties::GetType(left)->IsInhabited() && if (!NodeProperties::GetType(left)->IsNone() &&
NodeProperties::GetType(right)->IsInhabited()) { !NodeProperties::GetType(right)->IsNone()) {
current->SetReplacement(replacement); current->SetReplacement(replacement);
} else { } else {
current->SetEscaped(left); current->SetEscaped(left);
......
...@@ -282,13 +282,10 @@ Type* OperationTyper::ToNumber(Type* type) { ...@@ -282,13 +282,10 @@ Type* OperationTyper::ToNumber(Type* type) {
Type* OperationTyper::NumberAbs(Type* type) { Type* OperationTyper::NumberAbs(Type* type) {
DCHECK(type->Is(Type::Number())); DCHECK(type->Is(Type::Number()));
if (type->IsNone()) return type;
if (!type->IsInhabited()) {
return Type::None();
}
type = Type::Intersect(type, Type::PlainNumber(), zone()); type = Type::Intersect(type, Type::PlainNumber(), zone());
if (type->IsInhabited()) { if (!type->IsNone()) {
double const max = type->Max(); double const max = type->Max();
double const min = type->Min(); double const min = type->Min();
if (min < 0) { if (min < 0) {
...@@ -473,7 +470,7 @@ Type* OperationTyper::NumberTrunc(Type* type) { ...@@ -473,7 +470,7 @@ Type* OperationTyper::NumberTrunc(Type* type) {
Type* OperationTyper::NumberToBoolean(Type* type) { Type* OperationTyper::NumberToBoolean(Type* type) {
DCHECK(type->Is(Type::Number())); DCHECK(type->Is(Type::Number()));
if (!type->IsInhabited()) return Type::None(); if (type->IsNone()) return type;
if (type->Is(cache_.kZeroish)) return singleton_false_; if (type->Is(cache_.kZeroish)) return singleton_false_;
if (type->Is(Type::PlainNumber()) && (type->Max() < 0 || 0 < type->Min())) { if (type->Is(Type::PlainNumber()) && (type->Max() < 0 || 0 < type->Min())) {
return singleton_true_; // Ruled out nan, -0 and +0. return singleton_true_; // Ruled out nan, -0 and +0.
...@@ -525,9 +522,7 @@ Type* OperationTyper::NumberAdd(Type* lhs, Type* rhs) { ...@@ -525,9 +522,7 @@ Type* OperationTyper::NumberAdd(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number())); DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number())); DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) { if (lhs->IsNone() || rhs->IsNone()) return Type::None();
return Type::None();
}
// Addition can return NaN if either input can be NaN or we try to compute // Addition can return NaN if either input can be NaN or we try to compute
// the sum of two infinities of opposite sign. // the sum of two infinities of opposite sign.
...@@ -550,7 +545,7 @@ Type* OperationTyper::NumberAdd(Type* lhs, Type* rhs) { ...@@ -550,7 +545,7 @@ Type* OperationTyper::NumberAdd(Type* lhs, Type* rhs) {
Type* type = Type::None(); Type* type = Type::None();
lhs = Type::Intersect(lhs, Type::PlainNumber(), zone()); lhs = Type::Intersect(lhs, Type::PlainNumber(), zone());
rhs = Type::Intersect(rhs, Type::PlainNumber(), zone()); rhs = Type::Intersect(rhs, Type::PlainNumber(), zone());
if (lhs->IsInhabited() && rhs->IsInhabited()) { if (!lhs->IsNone() && !rhs->IsNone()) {
if (lhs->Is(cache_.kInteger) && rhs->Is(cache_.kInteger)) { if (lhs->Is(cache_.kInteger) && rhs->Is(cache_.kInteger)) {
type = AddRanger(lhs->Min(), lhs->Max(), rhs->Min(), rhs->Max()); type = AddRanger(lhs->Min(), lhs->Max(), rhs->Min(), rhs->Max());
} else { } else {
...@@ -572,9 +567,7 @@ Type* OperationTyper::NumberSubtract(Type* lhs, Type* rhs) { ...@@ -572,9 +567,7 @@ Type* OperationTyper::NumberSubtract(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number())); DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number())); DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) { if (lhs->IsNone() || rhs->IsNone()) return Type::None();
return Type::None();
}
// Subtraction can return NaN if either input can be NaN or we try to // Subtraction can return NaN if either input can be NaN or we try to
// compute the sum of two infinities of opposite sign. // compute the sum of two infinities of opposite sign.
...@@ -595,7 +588,7 @@ Type* OperationTyper::NumberSubtract(Type* lhs, Type* rhs) { ...@@ -595,7 +588,7 @@ Type* OperationTyper::NumberSubtract(Type* lhs, Type* rhs) {
Type* type = Type::None(); Type* type = Type::None();
lhs = Type::Intersect(lhs, Type::PlainNumber(), zone()); lhs = Type::Intersect(lhs, Type::PlainNumber(), zone());
rhs = Type::Intersect(rhs, Type::PlainNumber(), zone()); rhs = Type::Intersect(rhs, Type::PlainNumber(), zone());
if (lhs->IsInhabited() && rhs->IsInhabited()) { if (!lhs->IsNone() && !rhs->IsNone()) {
if (lhs->Is(cache_.kInteger) && rhs->Is(cache_.kInteger)) { if (lhs->Is(cache_.kInteger) && rhs->Is(cache_.kInteger)) {
type = SubtractRanger(lhs->Min(), lhs->Max(), rhs->Min(), rhs->Max()); type = SubtractRanger(lhs->Min(), lhs->Max(), rhs->Min(), rhs->Max());
} else { } else {
...@@ -637,9 +630,7 @@ Type* OperationTyper::NumberMultiply(Type* lhs, Type* rhs) { ...@@ -637,9 +630,7 @@ Type* OperationTyper::NumberMultiply(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number())); DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number())); DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) { if (lhs->IsNone() || rhs->IsNone()) return Type::None();
return Type::None();
}
lhs = Rangify(lhs); lhs = Rangify(lhs);
rhs = Rangify(rhs); rhs = Rangify(rhs);
...@@ -654,10 +645,7 @@ Type* OperationTyper::NumberDivide(Type* lhs, Type* rhs) { ...@@ -654,10 +645,7 @@ Type* OperationTyper::NumberDivide(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number())); DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number())); DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) { if (lhs->IsNone() || rhs->IsNone()) return Type::None();
return Type::None();
}
if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN(); if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN();
// Division is tricky, so all we do is try ruling out -0 and NaN. // Division is tricky, so all we do is try ruling out -0 and NaN.
...@@ -685,7 +673,7 @@ Type* OperationTyper::NumberModulus(Type* lhs, Type* rhs) { ...@@ -685,7 +673,7 @@ Type* OperationTyper::NumberModulus(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number())); DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number())); DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) return Type::None(); if (lhs->IsNone() || rhs->IsNone()) return Type::None();
// Modulus can yield NaN if either {lhs} or {rhs} are NaN, or // Modulus can yield NaN if either {lhs} or {rhs} are NaN, or
// {lhs} is not finite, or the {rhs} is a zero value. // {lhs} is not finite, or the {rhs} is a zero value.
...@@ -709,7 +697,7 @@ Type* OperationTyper::NumberModulus(Type* lhs, Type* rhs) { ...@@ -709,7 +697,7 @@ Type* OperationTyper::NumberModulus(Type* lhs, Type* rhs) {
// We can only derive a meaningful type if both {lhs} and {rhs} are inhabited, // We can only derive a meaningful type if both {lhs} and {rhs} are inhabited,
// and the {rhs} is not 0, otherwise the result is NaN independent of {lhs}. // and the {rhs} is not 0, otherwise the result is NaN independent of {lhs}.
if (lhs->IsInhabited() && !rhs->Is(cache_.kSingletonZero)) { if (!lhs->IsNone() && !rhs->Is(cache_.kSingletonZero)) {
// Determine the bounds of {lhs} and {rhs}. // Determine the bounds of {lhs} and {rhs}.
double const lmin = lhs->Min(); double const lmin = lhs->Min();
double const lmax = lhs->Max(); double const lmax = lhs->Max();
...@@ -754,7 +742,7 @@ Type* OperationTyper::NumberBitwiseOr(Type* lhs, Type* rhs) { ...@@ -754,7 +742,7 @@ Type* OperationTyper::NumberBitwiseOr(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number())); DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number())); DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) return Type::None(); if (lhs->IsNone() || rhs->IsNone()) return Type::None();
lhs = NumberToInt32(lhs); lhs = NumberToInt32(lhs);
rhs = NumberToInt32(rhs); rhs = NumberToInt32(rhs);
...@@ -791,7 +779,7 @@ Type* OperationTyper::NumberBitwiseAnd(Type* lhs, Type* rhs) { ...@@ -791,7 +779,7 @@ Type* OperationTyper::NumberBitwiseAnd(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number())); DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number())); DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) return Type::None(); if (lhs->IsNone() || rhs->IsNone()) return Type::None();
lhs = NumberToInt32(lhs); lhs = NumberToInt32(lhs);
rhs = NumberToInt32(rhs); rhs = NumberToInt32(rhs);
...@@ -822,7 +810,7 @@ Type* OperationTyper::NumberBitwiseXor(Type* lhs, Type* rhs) { ...@@ -822,7 +810,7 @@ Type* OperationTyper::NumberBitwiseXor(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number())); DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number())); DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) return Type::None(); if (lhs->IsNone() || rhs->IsNone()) return Type::None();
lhs = NumberToInt32(lhs); lhs = NumberToInt32(lhs);
rhs = NumberToInt32(rhs); rhs = NumberToInt32(rhs);
...@@ -847,7 +835,7 @@ Type* OperationTyper::NumberShiftLeft(Type* lhs, Type* rhs) { ...@@ -847,7 +835,7 @@ Type* OperationTyper::NumberShiftLeft(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number())); DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number())); DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) return Type::None(); if (lhs->IsNone() || rhs->IsNone()) return Type::None();
lhs = NumberToInt32(lhs); lhs = NumberToInt32(lhs);
rhs = NumberToUint32(rhs); rhs = NumberToUint32(rhs);
...@@ -882,7 +870,7 @@ Type* OperationTyper::NumberShiftRight(Type* lhs, Type* rhs) { ...@@ -882,7 +870,7 @@ Type* OperationTyper::NumberShiftRight(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number())); DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number())); DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) return Type::None(); if (lhs->IsNone() || rhs->IsNone()) return Type::None();
lhs = NumberToInt32(lhs); lhs = NumberToInt32(lhs);
rhs = NumberToUint32(rhs); rhs = NumberToUint32(rhs);
...@@ -907,7 +895,7 @@ Type* OperationTyper::NumberShiftRightLogical(Type* lhs, Type* rhs) { ...@@ -907,7 +895,7 @@ Type* OperationTyper::NumberShiftRightLogical(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number())); DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number())); DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) return Type::None(); if (lhs->IsNone() || rhs->IsNone()) return Type::None();
lhs = NumberToUint32(lhs); lhs = NumberToUint32(lhs);
rhs = NumberToUint32(rhs); rhs = NumberToUint32(rhs);
...@@ -948,12 +936,10 @@ Type* OperationTyper::NumberImul(Type* lhs, Type* rhs) { ...@@ -948,12 +936,10 @@ Type* OperationTyper::NumberImul(Type* lhs, Type* rhs) {
Type* OperationTyper::NumberMax(Type* lhs, Type* rhs) { Type* OperationTyper::NumberMax(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number())); DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number())); DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) {
return Type::None(); if (lhs->IsNone() || rhs->IsNone()) return Type::None();
} if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN();
if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) {
return Type::NaN();
}
Type* type = Type::None(); Type* type = Type::None();
// TODO(turbofan): Improve minus zero handling here. // TODO(turbofan): Improve minus zero handling here.
if (lhs->Maybe(Type::NaN()) || rhs->Maybe(Type::NaN())) { if (lhs->Maybe(Type::NaN()) || rhs->Maybe(Type::NaN())) {
...@@ -974,12 +960,10 @@ Type* OperationTyper::NumberMax(Type* lhs, Type* rhs) { ...@@ -974,12 +960,10 @@ Type* OperationTyper::NumberMax(Type* lhs, Type* rhs) {
Type* OperationTyper::NumberMin(Type* lhs, Type* rhs) { Type* OperationTyper::NumberMin(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number())); DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number())); DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) {
return Type::None(); if (lhs->IsNone() || rhs->IsNone()) return Type::None();
} if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN();
if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) {
return Type::NaN();
}
Type* type = Type::None(); Type* type = Type::None();
// TODO(turbofan): Improve minus zero handling here. // TODO(turbofan): Improve minus zero handling here.
if (lhs->Maybe(Type::NaN()) || rhs->Maybe(Type::NaN())) { if (lhs->Maybe(Type::NaN()) || rhs->Maybe(Type::NaN())) {
...@@ -1036,7 +1020,7 @@ Type* OperationTyper::ToPrimitive(Type* type) { ...@@ -1036,7 +1020,7 @@ Type* OperationTyper::ToPrimitive(Type* type) {
Type* OperationTyper::Invert(Type* type) { Type* OperationTyper::Invert(Type* type) {
DCHECK(type->Is(Type::Boolean())); DCHECK(type->Is(Type::Boolean()));
DCHECK(type->IsInhabited()); DCHECK(!type->IsNone());
if (type->Is(singleton_false())) return singleton_true(); if (type->Is(singleton_false())) return singleton_true();
if (type->Is(singleton_true())) return singleton_false(); if (type->Is(singleton_true())) return singleton_false();
return type; return type;
......
...@@ -137,8 +137,7 @@ bool IsWord(MachineRepresentation rep) { ...@@ -137,8 +137,7 @@ bool IsWord(MachineRepresentation rep) {
Node* RepresentationChanger::GetRepresentationFor( Node* RepresentationChanger::GetRepresentationFor(
Node* node, MachineRepresentation output_rep, Type* output_type, Node* node, MachineRepresentation output_rep, Type* output_type,
Node* use_node, UseInfo use_info) { Node* use_node, UseInfo use_info) {
if (output_rep == MachineRepresentation::kNone && if (output_rep == MachineRepresentation::kNone && !output_type->IsNone()) {
output_type->IsInhabited()) {
// The output representation should be set if the type is inhabited (i.e., // The output representation should be set if the type is inhabited (i.e.,
// if the value is possible). // if the value is possible).
return TypeError(node, output_rep, output_type, use_info.representation()); return TypeError(node, output_rep, output_type, use_info.representation());
......
...@@ -213,7 +213,7 @@ bool CanOverflowSigned32(const Operator* op, Type* left, Type* right, ...@@ -213,7 +213,7 @@ bool CanOverflowSigned32(const Operator* op, Type* left, Type* right,
// that cannot cause overflow. // that cannot cause overflow.
left = Type::Intersect(left, Type::Signed32(), type_zone); left = Type::Intersect(left, Type::Signed32(), type_zone);
right = Type::Intersect(right, Type::Signed32(), type_zone); right = Type::Intersect(right, Type::Signed32(), type_zone);
if (!left->IsInhabited() || !right->IsInhabited()) return false; if (left->IsNone() || right->IsNone()) return false;
switch (op->opcode()) { switch (op->opcode()) {
case IrOpcode::kSpeculativeSafeIntegerAdd: case IrOpcode::kSpeculativeSafeIntegerAdd:
return (left->Max() + right->Max() > kMaxInt) || return (left->Max() + right->Max() > kMaxInt) ||
...@@ -1052,7 +1052,7 @@ class RepresentationSelector { ...@@ -1052,7 +1052,7 @@ class RepresentationSelector {
} }
static MachineType DeoptMachineTypeOf(MachineRepresentation rep, Type* type) { static MachineType DeoptMachineTypeOf(MachineRepresentation rep, Type* type) {
if (!type->IsInhabited()) { if (type->IsNone()) {
return MachineType::None(); return MachineType::None();
} }
// TODO(turbofan): Special treatment for ExternalPointer here, // TODO(turbofan): Special treatment for ExternalPointer here,
...@@ -1587,7 +1587,7 @@ class RepresentationSelector { ...@@ -1587,7 +1587,7 @@ class RepresentationSelector {
node->AppendInput(jsgraph_->zone(), jsgraph_->FalseConstant()); node->AppendInput(jsgraph_->zone(), jsgraph_->FalseConstant());
NodeProperties::ChangeOp(node, lowering->machine()->WordEqual()); NodeProperties::ChangeOp(node, lowering->machine()->WordEqual());
} else { } else {
DCHECK(!TypeOf(node->InputAt(0))->IsInhabited()); DCHECK(TypeOf(node->InputAt(0))->IsNone());
DeferReplacement(node, lowering->jsgraph()->Int32Constant(0)); DeferReplacement(node, lowering->jsgraph()->Int32Constant(0));
} }
} else { } else {
......
...@@ -42,7 +42,7 @@ Reduction TypedOptimization::Reduce(Node* node) { ...@@ -42,7 +42,7 @@ Reduction TypedOptimization::Reduce(Node* node) {
// eager deoptimization exit (i.e. {node} has an operator that doesn't have // eager deoptimization exit (i.e. {node} has an operator that doesn't have
// the Operator::kNoDeopt property). // the Operator::kNoDeopt property).
Type* upper = NodeProperties::GetType(node); Type* upper = NodeProperties::GetType(node);
if (upper->IsInhabited()) { if (!upper->IsNone()) {
if (upper->IsHeapConstant()) { if (upper->IsHeapConstant()) {
Node* replacement = Node* replacement =
jsgraph()->Constant(upper->AsHeapConstant()->Value()); jsgraph()->Constant(upper->AsHeapConstant()->Value());
......
...@@ -389,15 +389,15 @@ void Typer::Decorator::Decorate(Node* node) { ...@@ -389,15 +389,15 @@ void Typer::Decorator::Decorate(Node* node) {
Type* Typer::Visitor::TypeUnaryOp(Node* node, UnaryTyperFun f) { Type* Typer::Visitor::TypeUnaryOp(Node* node, UnaryTyperFun f) {
Type* input = Operand(node, 0); Type* input = Operand(node, 0);
return input->IsInhabited() ? f(input, typer_) : Type::None(); return input->IsNone() ? Type::None() : f(input, typer_);
} }
Type* Typer::Visitor::TypeBinaryOp(Node* node, BinaryTyperFun f) { Type* Typer::Visitor::TypeBinaryOp(Node* node, BinaryTyperFun f) {
Type* left = Operand(node, 0); Type* left = Operand(node, 0);
Type* right = Operand(node, 1); Type* right = Operand(node, 1);
return left->IsInhabited() && right->IsInhabited() ? f(left, right, typer_) return left->IsNone() || right->IsNone() ? Type::None()
: Type::None(); : f(left, right, typer_);
} }
...@@ -461,7 +461,7 @@ Type* Typer::Visitor::ToInteger(Type* type, Typer* t) { ...@@ -461,7 +461,7 @@ Type* Typer::Visitor::ToInteger(Type* type, Typer* t) {
Type* Typer::Visitor::ToLength(Type* type, Typer* t) { Type* Typer::Visitor::ToLength(Type* type, Typer* t) {
// ES6 section 7.1.15 ToLength ( argument ) // ES6 section 7.1.15 ToLength ( argument )
type = ToInteger(type, t); type = ToInteger(type, t);
if (!type->IsInhabited()) return Type::None(); if (type->IsNone()) return type;
double min = type->Min(); double min = type->Min();
double max = type->Max(); double max = type->Max();
if (max <= 0.0) { if (max <= 0.0) {
...@@ -722,7 +722,7 @@ Type* Typer::Visitor::TypeInductionVariablePhi(Node* node) { ...@@ -722,7 +722,7 @@ Type* Typer::Visitor::TypeInductionVariablePhi(Node* node) {
} }
// If we do not have enough type information for the initial value or // If we do not have enough type information for the initial value or
// the increment, just return the initial value's type. // the increment, just return the initial value's type.
if (!initial_type->IsInhabited() || if (initial_type->IsNone() ||
increment_type->Is(typer_->cache_.kSingletonZero)) { increment_type->Is(typer_->cache_.kSingletonZero)) {
return initial_type; return initial_type;
} }
...@@ -756,7 +756,7 @@ Type* Typer::Visitor::TypeInductionVariablePhi(Node* node) { ...@@ -756,7 +756,7 @@ Type* Typer::Visitor::TypeInductionVariablePhi(Node* node) {
// If the type is not an integer, just skip the bound. // If the type is not an integer, just skip the bound.
if (!bound_type->Is(typer_->cache_.kInteger)) continue; if (!bound_type->Is(typer_->cache_.kInteger)) continue;
// If the type is not inhabited, then we can take the initial value. // If the type is not inhabited, then we can take the initial value.
if (!bound_type->IsInhabited()) { if (bound_type->IsNone()) {
max = initial_type->Max(); max = initial_type->Max();
break; break;
} }
...@@ -776,7 +776,7 @@ Type* Typer::Visitor::TypeInductionVariablePhi(Node* node) { ...@@ -776,7 +776,7 @@ Type* Typer::Visitor::TypeInductionVariablePhi(Node* node) {
// If the type is not an integer, just skip the bound. // If the type is not an integer, just skip the bound.
if (!bound_type->Is(typer_->cache_.kInteger)) continue; if (!bound_type->Is(typer_->cache_.kInteger)) continue;
// If the type is not inhabited, then we can take the initial value. // If the type is not inhabited, then we can take the initial value.
if (!bound_type->IsInhabited()) { if (bound_type->IsNone()) {
min = initial_type->Min(); min = initial_type->Min();
break; break;
} }
...@@ -1856,7 +1856,7 @@ Type* Typer::Visitor::TypeCheckBounds(Node* node) { ...@@ -1856,7 +1856,7 @@ Type* Typer::Visitor::TypeCheckBounds(Node* node) {
index = Type::Union(index, typer_->cache_.kSingletonZero, zone()); index = Type::Union(index, typer_->cache_.kSingletonZero, zone());
} }
index = Type::Intersect(index, Type::Integral32(), zone()); index = Type::Intersect(index, Type::Integral32(), zone());
if (!index->IsInhabited() || !length->IsInhabited()) return Type::None(); if (index->IsNone() || length->IsNone()) return Type::None();
double min = std::max(index->Min(), 0.0); double min = std::max(index->Min(), 0.0);
double max = std::min(index->Max(), length->Max() - 1); double max = std::min(index->Max(), length->Max() - 1);
if (max < min) return Type::None(); if (max < min) return Type::None();
......
...@@ -67,8 +67,8 @@ bool Type::Contains(RangeType* range, i::Object* val) { ...@@ -67,8 +67,8 @@ bool Type::Contains(RangeType* range, i::Object* val) {
// Min and Max computation. // Min and Max computation.
double Type::Min() { double Type::Min() {
DCHECK(this->IsInhabited());
DCHECK(this->Is(Number())); DCHECK(this->Is(Number()));
DCHECK(!this->IsNone());
if (this->IsBitset()) return BitsetType::Min(this->AsBitset()); if (this->IsBitset()) return BitsetType::Min(this->AsBitset());
if (this->IsUnion()) { if (this->IsUnion()) {
double min = +V8_INFINITY; double min = +V8_INFINITY;
...@@ -76,7 +76,7 @@ double Type::Min() { ...@@ -76,7 +76,7 @@ double Type::Min() {
min = std::min(min, this->AsUnion()->Get(i)->Min()); min = std::min(min, this->AsUnion()->Get(i)->Min());
} }
Type* bitset = this->AsUnion()->Get(0); Type* bitset = this->AsUnion()->Get(0);
if (bitset->IsInhabited()) min = std::min(min, bitset->Min()); if (!bitset->IsNone()) min = std::min(min, bitset->Min());
return min; return min;
} }
if (this->IsRange()) return this->AsRange()->Min(); if (this->IsRange()) return this->AsRange()->Min();
...@@ -86,8 +86,8 @@ double Type::Min() { ...@@ -86,8 +86,8 @@ double Type::Min() {
} }
double Type::Max() { double Type::Max() {
DCHECK(this->IsInhabited());
DCHECK(this->Is(Number())); DCHECK(this->Is(Number()));
DCHECK(!this->IsNone());
if (this->IsBitset()) return BitsetType::Max(this->AsBitset()); if (this->IsBitset()) return BitsetType::Max(this->AsBitset());
if (this->IsUnion()) { if (this->IsUnion()) {
double max = -V8_INFINITY; double max = -V8_INFINITY;
...@@ -95,7 +95,7 @@ double Type::Max() { ...@@ -95,7 +95,7 @@ double Type::Max() {
max = std::max(max, this->AsUnion()->Get(i)->Max()); max = std::max(max, this->AsUnion()->Get(i)->Max());
} }
Type* bitset = this->AsUnion()->Get(0); Type* bitset = this->AsUnion()->Get(0);
if (bitset->IsInhabited()) max = std::max(max, bitset->Max()); if (!bitset->IsNone()) max = std::max(max, bitset->Max());
return max; return max;
} }
if (this->IsRange()) return this->AsRange()->Max(); if (this->IsRange()) return this->AsRange()->Max();
...@@ -523,8 +523,7 @@ bool Type::SlowIs(Type* that) { ...@@ -523,8 +523,7 @@ bool Type::SlowIs(Type* that) {
bool Type::Maybe(Type* that) { bool Type::Maybe(Type* that) {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
if (!BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub())) if (BitsetType::IsNone(this->BitsetLub() & that->BitsetLub())) return false;
return false;
// (T1 \/ ... \/ Tn) overlaps T if (T1 overlaps T) \/ ... \/ (Tn overlaps T) // (T1 \/ ... \/ Tn) overlaps T if (T1 overlaps T) \/ ... \/ (Tn overlaps T)
if (this->IsUnion()) { if (this->IsUnion()) {
...@@ -721,9 +720,7 @@ int Type::IntersectAux(Type* lhs, Type* rhs, UnionType* result, int size, ...@@ -721,9 +720,7 @@ int Type::IntersectAux(Type* lhs, Type* rhs, UnionType* result, int size,
return size; return size;
} }
if (!BitsetType::IsInhabited(lhs->BitsetLub() & rhs->BitsetLub())) { if (BitsetType::IsNone(lhs->BitsetLub() & rhs->BitsetLub())) return size;
return size;
}
if (lhs->IsRange()) { if (lhs->IsRange()) {
if (rhs->IsBitset()) { if (rhs->IsBitset()) {
......
...@@ -246,7 +246,7 @@ class V8_EXPORT_PRIVATE BitsetType { ...@@ -246,7 +246,7 @@ class V8_EXPORT_PRIVATE BitsetType {
return static_cast<bitset>(reinterpret_cast<uintptr_t>(this) ^ 1u); return static_cast<bitset>(reinterpret_cast<uintptr_t>(this) ^ 1u);
} }
static bool IsInhabited(bitset bits) { return bits != kNone; } static bool IsNone(bitset bits) { return bits == kNone; }
static bool Is(bitset bits1, bitset bits2) { static bool Is(bitset bits1, bitset bits2) {
return (bits1 | bits2) == bits2; return (bits1 | bits2) == bits2;
...@@ -581,7 +581,7 @@ class V8_EXPORT_PRIVATE Type { ...@@ -581,7 +581,7 @@ class V8_EXPORT_PRIVATE Type {
static Type* For(i::Handle<i::Map> map) { return For(*map); } static Type* For(i::Handle<i::Map> map) { return For(*map); }
// Predicates. // Predicates.
bool IsInhabited() { return BitsetType::IsInhabited(this->BitsetLub()); } bool IsNone() { return this == None(); }
bool Is(Type* that) { return this == that || this->SlowIs(that); } bool Is(Type* that) { return this == that || this->SlowIs(that); }
bool Maybe(Type* that); bool Maybe(Type* that);
...@@ -644,7 +644,6 @@ class V8_EXPORT_PRIVATE Type { ...@@ -644,7 +644,6 @@ class V8_EXPORT_PRIVATE Type {
// Internal inspection. // Internal inspection.
bool IsKind(TypeBase::Kind kind) { return TypeBase::IsKind(this, kind); } bool IsKind(TypeBase::Kind kind) { return TypeBase::IsKind(this, kind); }
bool IsNone() { return this == None(); }
bool IsAny() { return this == Any(); } bool IsAny() { return this == Any(); }
bool IsBitset() { return BitsetType::IsBitset(this); } bool IsBitset() { return BitsetType::IsBitset(this); }
bool IsUnion() { return IsKind(TypeBase::kUnion); } bool IsUnion() { return IsKind(TypeBase::kUnion); }
......
...@@ -413,7 +413,7 @@ struct Tests { ...@@ -413,7 +413,7 @@ struct Tests {
// T->Is(Range(T->Min(), T->Max())). // T->Is(Range(T->Min(), T->Max())).
for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
Type* type = *it; Type* type = *it;
CHECK(!type->Is(T.Integer) || !type->IsInhabited() || CHECK(!type->Is(T.Integer) || type->IsNone() ||
type->Is(T.Range(type->Min(), type->Max()))); type->Is(T.Range(type->Min(), type->Max())));
} }
} }
...@@ -542,7 +542,7 @@ struct Tests { ...@@ -542,7 +542,7 @@ struct Tests {
(type1->IsRange() && type2->IsRange()) || (type1->IsRange() && type2->IsRange()) ||
(type1->IsOtherNumberConstant() && (type1->IsOtherNumberConstant() &&
type2->IsOtherNumberConstant()) || type2->IsOtherNumberConstant()) ||
!type1->IsInhabited()); type1->IsNone());
} }
} }
} }
...@@ -666,7 +666,7 @@ struct Tests { ...@@ -666,7 +666,7 @@ struct Tests {
// T->Maybe(Any) iff T inhabited // T->Maybe(Any) iff T inhabited
for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
Type* type = *it; Type* type = *it;
CHECK(type->Maybe(T.Any) == type->IsInhabited()); CHECK(type->Maybe(T.Any) == !type->IsNone());
} }
// T->Maybe(None) never // T->Maybe(None) never
...@@ -678,7 +678,7 @@ struct Tests { ...@@ -678,7 +678,7 @@ struct Tests {
// Reflexivity upto Inhabitation: T->Maybe(T) iff T inhabited // Reflexivity upto Inhabitation: T->Maybe(T) iff T inhabited
for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
Type* type = *it; Type* type = *it;
CHECK(type->Maybe(type) == type->IsInhabited()); CHECK(type->Maybe(type) == !type->IsNone());
} }
// Symmetry: T1->Maybe(T2) iff T2->Maybe(T1) // Symmetry: T1->Maybe(T2) iff T2->Maybe(T1)
...@@ -695,8 +695,7 @@ struct Tests { ...@@ -695,8 +695,7 @@ struct Tests {
for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
Type* type1 = *it1; Type* type1 = *it1;
Type* type2 = *it2; Type* type2 = *it2;
CHECK(!type1->Maybe(type2) || CHECK(!type1->Maybe(type2) || (!type1->IsNone() && !type2->IsNone()));
(type1->IsInhabited() && type2->IsInhabited()));
} }
} }
...@@ -706,7 +705,7 @@ struct Tests { ...@@ -706,7 +705,7 @@ struct Tests {
Type* type1 = *it1; Type* type1 = *it1;
Type* type2 = *it2; Type* type2 = *it2;
Type* intersect12 = T.Intersect(type1, type2); Type* intersect12 = T.Intersect(type1, type2);
CHECK(!type1->Maybe(type2) || intersect12->IsInhabited()); CHECK(!type1->Maybe(type2) || !intersect12->IsNone());
} }
} }
...@@ -715,8 +714,7 @@ struct Tests { ...@@ -715,8 +714,7 @@ struct Tests {
for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
Type* type1 = *it1; Type* type1 = *it1;
Type* type2 = *it2; Type* type2 = *it2;
CHECK(!(type1->Is(type2) && type1->IsInhabited()) || CHECK(!(type1->Is(type2) && !type1->IsNone()) || type1->Maybe(type2));
type1->Maybe(type2));
} }
} }
......
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