[compiler] Don't call Type::Min/Max on the empty type.

This is a cleanup.

R=jarin@chromium.org

Bug: 
Change-Id: I1621fde3f2a7da03ceca781b96d5ffec44eb8168
Reviewed-on: https://chromium-review.googlesource.com/758373
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49225}
This commit is contained in:
Georg Neis 2017-11-08 15:15:09 +01:00 committed by Commit Bot
parent 7223024658
commit 9d557e0ec4
3 changed files with 24 additions and 13 deletions

View File

@ -287,22 +287,24 @@ Type* OperationTyper::NumberAbs(Type* type) {
return Type::None();
}
bool const maybe_nan = type->Maybe(Type::NaN());
bool const maybe_minuszero = type->Maybe(Type::MinusZero());
type = Type::Intersect(type, Type::PlainNumber(), zone());
if (type->IsInhabited()) {
double const max = type->Max();
double const min = type->Min();
if (min < 0) {
if (type->Is(cache_.kInteger)) {
type = Type::Range(0.0, std::max(std::fabs(min), std::fabs(max)), zone());
type =
Type::Range(0.0, std::max(std::fabs(min), std::fabs(max)), zone());
} else {
type = Type::PlainNumber();
}
}
if (maybe_minuszero) {
}
if (type->Maybe(Type::NaN())) {
type = Type::Union(type, cache_.kSingletonZero, zone());
}
if (maybe_nan) {
if (type->Maybe(Type::MinusZero())) {
type = Type::Union(type, Type::NaN(), zone());
}
return type;
@ -683,6 +685,8 @@ Type* OperationTyper::NumberModulus(Type* lhs, Type* rhs) {
DCHECK(lhs->Is(Type::Number()));
DCHECK(rhs->Is(Type::Number()));
if (!lhs->IsInhabited() || !rhs->IsInhabited()) return Type::None();
// Modulus can yield NaN if either {lhs} or {rhs} are NaN, or
// {lhs} is not finite, or the {rhs} is a zero value.
bool maybe_nan = lhs->Maybe(Type::NaN()) || rhs->Maybe(cache_.kZeroish) ||

View File

@ -461,6 +461,7 @@ Type* Typer::Visitor::ToInteger(Type* type, Typer* t) {
Type* Typer::Visitor::ToLength(Type* type, Typer* t) {
// ES6 section 7.1.15 ToLength ( argument )
type = ToInteger(type, t);
if (!type->IsInhabited()) return Type::None();
double min = type->Min();
double max = type->Max();
if (max <= 0.0) {

View File

@ -67,13 +67,16 @@ bool Type::Contains(RangeType* range, i::Object* val) {
// Min and Max computation.
double Type::Min() {
DCHECK(this->IsInhabited());
DCHECK(this->Is(Number()));
if (this->IsBitset()) return BitsetType::Min(this->AsBitset());
if (this->IsUnion()) {
double min = +V8_INFINITY;
for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
for (int i = 1, n = this->AsUnion()->Length(); i < n; ++i) {
min = std::min(min, this->AsUnion()->Get(i)->Min());
}
Type* bitset = this->AsUnion()->Get(0);
if (bitset->IsInhabited()) min = std::min(min, bitset->Min());
return min;
}
if (this->IsRange()) return this->AsRange()->Min();
@ -83,13 +86,16 @@ double Type::Min() {
}
double Type::Max() {
DCHECK(this->IsInhabited());
DCHECK(this->Is(Number()));
if (this->IsBitset()) return BitsetType::Max(this->AsBitset());
if (this->IsUnion()) {
double max = -V8_INFINITY;
for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
for (int i = 1, n = this->AsUnion()->Length(); i < n; ++i) {
max = std::max(max, this->AsUnion()->Get(i)->Max());
}
Type* bitset = this->AsUnion()->Get(0);
if (bitset->IsInhabited()) max = std::max(max, bitset->Max());
return max;
}
if (this->IsRange()) return this->AsRange()->Max();