Constant fold strict comparison based on incoming types: different (exact) types means that the result is false. LoadStaticField computes type for final fields. Make a temporary buffer final.

R=kmillikin@google.com

Review URL: https://codereview.chromium.org//57703004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@30119 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
srdjan@google.com 2013-11-08 17:42:45 +00:00
parent 3eb8d59184
commit 16f4e5c690
3 changed files with 30 additions and 4 deletions

View file

@ -289,7 +289,7 @@ class _Smi extends _IntegerImplementation implements int {
}
// Reusable buffer used by smi.toString.
List _toStringBuffer = new Uint8List(20);
final List _toStringBuffer = new Uint8List(20);
// Represents integers that cannot be represented by Smi but fit into 64bits.
class _Mint extends _IntegerImplementation implements int {

View file

@ -6313,14 +6313,28 @@ void ConstantPropagator::VisitStrictCompare(StrictCompareInstr* instr) {
(right.IsNull() && instr->left()->Type()->HasDecidableNullability())) {
bool result = left.IsNull() ? instr->right()->Type()->IsNull()
: instr->left()->Type()->IsNull();
if (instr->kind() == Token::kNE_STRICT) result = !result;
if (instr->kind() == Token::kNE_STRICT) {
result = !result;
}
SetValue(instr, Bool::Get(result));
} else {
SetValue(instr, non_constant_);
const intptr_t left_cid = instr->left()->Type()->ToCid();
const intptr_t right_cid = instr->right()->Type()->ToCid();
// If exact classes (cids) are known and they differ, the result
// of strict compare can be computed.
if ((left_cid != kDynamicCid) && (right_cid != kDynamicCid) &&
(left_cid != right_cid)) {
const bool result = (instr->kind() != Token::kEQ_STRICT);
SetValue(instr, Bool::Get(result));
} else {
SetValue(instr, non_constant_);
}
}
} else if (IsConstant(left) && IsConstant(right)) {
bool result = (left.raw() == right.raw());
if (instr->kind() == Token::kNE_STRICT) result = !result;
if (instr->kind() == Token::kNE_STRICT) {
result = !result;
}
SetValue(instr, Bool::Get(result));
}
}

View file

@ -894,6 +894,18 @@ CompileType LoadStaticFieldInstr::ComputeType() const {
return CompileType::FromAbstractType(
AbstractType::ZoneHandle(StaticField().type()));
}
const Field& field = this->StaticField();
ASSERT(field.is_static());
if (field.is_final()) {
Instance& obj = Instance::Handle(field.value());
if ((obj.raw() != Object::sentinel().raw()) &&
(obj.raw() != Object::transition_sentinel().raw()) &&
!obj.IsNull()) {
return CompileType(CompileType::kNonNullable,
Class::Handle(obj.clazz()).id(),
NULL);
}
}
return CompileType::Dynamic();
}