Skip to content

Commit 52bc1ac

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[VM] Ensure we use the most specific types for fields
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]>
1 parent 9104b5d commit 52bc1ac

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

runtime/vm/compiler/backend/type_propagator.cc

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -714,15 +714,17 @@ const AbstractType* CompileType::ToAbstractType() {
714714
return type_;
715715
}
716716

717-
const Class& type_class =
718-
Class::Handle(Isolate::Current()->class_table()->At(cid_));
719-
717+
Isolate* I = Isolate::Current();
718+
const Class& type_class = Class::Handle(I->class_table()->At(cid_));
720719
if (type_class.NumTypeArguments() > 0) {
721-
type_ = &Object::dynamic_type();
722-
return type_;
720+
if (I->strong()) {
721+
type_ = &AbstractType::ZoneHandle(type_class.RareType());
722+
} else {
723+
type_ = &Object::dynamic_type();
724+
}
725+
} else {
726+
type_ = &Type::ZoneHandle(Type::NewNonParameterizedType(type_class));
723727
}
724-
725-
type_ = &Type::ZoneHandle(Type::NewNonParameterizedType(type_class));
726728
}
727729

728730
return type_;
@@ -1254,21 +1256,27 @@ CompileType LoadFieldInstr::ComputeType() const {
12541256
}
12551257

12561258
const Isolate* isolate = Isolate::Current();
1257-
const AbstractType* abstract_type = NULL;
1259+
CompileType compile_type_annotation = CompileType::None();
12581260
if ((isolate->strong() && FLAG_use_strong_mode_types) ||
12591261
(isolate->type_checks() &&
12601262
(type().IsFunctionType() || type().HasResolvedTypeClass()))) {
1261-
abstract_type = &type();
1263+
const AbstractType* abstract_type = abstract_type = &type();
12621264
TraceStrongModeType(this, *abstract_type);
1265+
compile_type_annotation = CompileType::FromAbstractType(*abstract_type);
12631266
}
12641267

1268+
CompileType compile_type_cid = CompileType::None();
12651269
if ((field_ != NULL) && (field_->guarded_cid() != kIllegalCid)) {
12661270
bool is_nullable = field_->is_nullable();
12671271
intptr_t field_cid = field_->guarded_cid();
1268-
return CompileType(is_nullable, field_cid, abstract_type);
1272+
1273+
compile_type_cid = CompileType(is_nullable, field_cid, NULL);
1274+
} else {
1275+
compile_type_cid = CompileType::FromCid(result_cid_);
12691276
}
12701277

1271-
return CompileType::Create(result_cid_, *abstract_type);
1278+
return *CompileType::ComputeRefinedType(&compile_type_cid,
1279+
&compile_type_annotation);
12721280
}
12731281

12741282
CompileType LoadCodeUnitsInstr::ComputeType() const {

0 commit comments

Comments
 (0)