Skip to content

Commit

Permalink
[VM] Ensure we use the most specific types for fields
Browse files Browse the repository at this point in the history
The VM uses normally strong mode types for LoadField instructions.
Though for certain fields we have known class-ids which we attach to the
Field instructions.

Before we had a case where the strong mode type was dynamic, but we had
a very specific cid for the Field.  Though when using the [CompileType]
afterwards via [CompileType()->ToAbstractType()] it was returning
`dynamic`.

We should use CompileType::ComputeRefineType() to get the most specific
one of those two.

Issue #31798

Change-Id: Ib0b7a596449cba0bc53e118ee603b2039aa312b3
Reviewed-on: https://dart-review.googlesource.com/43422
Commit-Queue: Martin Kustermann <[email protected]>
Reviewed-by: Vyacheslav Egorov <[email protected]>
  • Loading branch information
mkustermann authored and [email protected] committed Mar 1, 2018
1 parent 9104b5d commit 52bc1ac
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions runtime/vm/compiler/backend/type_propagator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -714,15 +714,17 @@ const AbstractType* CompileType::ToAbstractType() {
return type_;
}

const Class& type_class =
Class::Handle(Isolate::Current()->class_table()->At(cid_));

Isolate* I = Isolate::Current();
const Class& type_class = Class::Handle(I->class_table()->At(cid_));
if (type_class.NumTypeArguments() > 0) {
type_ = &Object::dynamic_type();
return type_;
if (I->strong()) {
type_ = &AbstractType::ZoneHandle(type_class.RareType());
} else {
type_ = &Object::dynamic_type();
}
} else {
type_ = &Type::ZoneHandle(Type::NewNonParameterizedType(type_class));
}

type_ = &Type::ZoneHandle(Type::NewNonParameterizedType(type_class));
}

return type_;
Expand Down Expand Up @@ -1254,21 +1256,27 @@ CompileType LoadFieldInstr::ComputeType() const {
}

const Isolate* isolate = Isolate::Current();
const AbstractType* abstract_type = NULL;
CompileType compile_type_annotation = CompileType::None();
if ((isolate->strong() && FLAG_use_strong_mode_types) ||
(isolate->type_checks() &&
(type().IsFunctionType() || type().HasResolvedTypeClass()))) {
abstract_type = &type();
const AbstractType* abstract_type = abstract_type = &type();
TraceStrongModeType(this, *abstract_type);
compile_type_annotation = CompileType::FromAbstractType(*abstract_type);
}

CompileType compile_type_cid = CompileType::None();
if ((field_ != NULL) && (field_->guarded_cid() != kIllegalCid)) {
bool is_nullable = field_->is_nullable();
intptr_t field_cid = field_->guarded_cid();
return CompileType(is_nullable, field_cid, abstract_type);

compile_type_cid = CompileType(is_nullable, field_cid, NULL);
} else {
compile_type_cid = CompileType::FromCid(result_cid_);
}

return CompileType::Create(result_cid_, *abstract_type);
return *CompileType::ComputeRefinedType(&compile_type_cid,
&compile_type_annotation);
}

CompileType LoadCodeUnitsInstr::ComputeType() const {
Expand Down

0 comments on commit 52bc1ac

Please sign in to comment.