[vm] Cleanup UntaggedTypeParameter::parameterized_class_id_

For class type parameters 'parameterized_class_id' duplicates
a recently added 'owner' and can be removed.
'owner' is changed to hold class reference as a class id (Smi).

TEST=ci

Change-Id: I93fc11e6bcfcc00058a5281b497f59c5c5847ea6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/299160
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
Alexander Markov 2023-04-28 19:37:10 +00:00 committed by Commit Queue
parent 2ee6fcf514
commit e46b97e1b7
12 changed files with 161 additions and 178 deletions

View file

@ -4475,7 +4475,6 @@ class TypeParameterSerializationCluster
void WriteTypeParameter(Serializer* s, TypeParameterPtr type) {
AutoTraceObject(type);
WriteFromTo(type);
s->Write<int32_t>(type->untag()->parameterized_class_id_);
s->Write<uint16_t>(type->untag()->base_);
s->Write<uint16_t>(type->untag()->index_);
ASSERT(Utils::IsUint(8, type->untag()->flags()));
@ -4509,7 +4508,6 @@ class TypeParameterDeserializationCluster
TypeParameter::InstanceSize(),
mark_canonical);
d.ReadFromTo(type);
type->untag()->parameterized_class_id_ = d.Read<int32_t>();
type->untag()->base_ = d.Read<uint16_t>();
type->untag()->index_ = d.Read<uint16_t>();
type->untag()->set_flags(d.Read<uint8_t>());

View file

@ -398,8 +398,8 @@ AbstractTypePtr ClassFinalizer::FinalizeType(const AbstractType& type,
// The base and index of a function type parameter are eagerly calculated
// upon loading and do not require adjustment here.
if (type_parameter.IsClassTypeParameter()) {
const Class& parameterized_class =
Class::Cast(Object::Handle(zone, type_parameter.owner()));
const Class& parameterized_class = Class::Cast(
Object::Handle(zone, type_parameter.parameterized_class()));
ASSERT(!parameterized_class.IsNull());
// The index must reflect the position of this type parameter in the type
// arguments vector of its parameterized class. The offset to add is the
@ -422,7 +422,7 @@ AbstractTypePtr ClassFinalizer::FinalizeType(const AbstractType& type,
// canonicalize common class type parameters
// with 'Object?' bound and same indices to the same
// instances.
type_parameter.set_owner(Object::null_object());
type_parameter.set_parameterized_class_id(kIllegalCid);
}
}
@ -1117,8 +1117,11 @@ class CidRewriteVisitor : public ObjectVisitor {
field->untag()->is_nullable_ = Map(field->untag()->is_nullable_);
} else if (obj->IsTypeParameter()) {
TypeParameterPtr param = TypeParameter::RawCast(obj);
param->untag()->parameterized_class_id_ =
Map(param->untag()->parameterized_class_id_);
if (!UntaggedTypeParameter::IsFunctionTypeParameter::decode(
param->untag()->flags())) {
param->untag()->set_owner(
Smi::New(Map(Smi::Value(Smi::RawCast(param->untag()->owner())))));
}
} else if (obj->IsType()) {
TypePtr type = Type::RawCast(obj);
type->untag()->set_type_class_id(Map(type->untag()->type_class_id()));
@ -1178,7 +1181,7 @@ void ClassFinalizer::RemapClassIds(intptr_t* old_to_new_cid) {
// computation of canonical hash codes:
//
// * TypePtr (due to UntaggedType::type_class_id)
// * TypeParameterPtr (due to UntaggedTypeParameter::parameterized_class_id_)
// * TypeParameterPtr (due to UntaggedTypeParameter::owner_)
//
// The following instances use cids for the computation of canonical hash codes
// indirectly:

View file

@ -1161,13 +1161,10 @@ void Precompiler::AddType(const AbstractType& abstype) {
if (typeparams_to_retain_.HasKey(&param)) return;
typeparams_to_retain_.Insert(&TypeParameter::ZoneHandle(Z, param.ptr()));
Object& owner = Object::Handle(Z, param.owner());
if (owner.IsClass()) {
AddTypesOf(Class::Cast(owner));
} else if (owner.IsFunctionType()) {
AddType(FunctionType::Cast(owner));
if (param.IsClassTypeParameter()) {
AddTypesOf(Class::Handle(Z, param.parameterized_class()));
} else {
RELEASE_ASSERT(owner.IsNull());
AddType(FunctionType::Handle(Z, param.parameterized_function_type()));
}
return;
}

View file

@ -1534,7 +1534,8 @@ void FlowGraphSerializer::WriteEnclosingTypes(
const auto& tp = TypeParameter::Cast(obj);
if (tp.IsFunctionTypeParameter() &&
(tp.index() < num_free_fun_type_params)) {
const auto& owner = FunctionType::Cast(Object::Handle(Z, tp.owner()));
const auto& owner =
FunctionType::Handle(Z, tp.parameterized_function_type());
if (!IsWritten(owner)) {
Write<bool>(true);
Write<const Object&>(owner);
@ -1792,9 +1793,13 @@ void FlowGraphSerializer::WriteObjectImpl(const Object& x,
Write<intptr_t>(tp.base());
Write<intptr_t>(tp.index());
Write<int8_t>(static_cast<int8_t>(tp.nullability()));
Write<classid_t>(tp.parameterized_class_id());
if (tp.IsFunctionTypeParameter()) {
Write<const Object&>(Object::Handle(Z, tp.owner()));
Write<bool>(true);
Write<const FunctionType&>(
FunctionType::Handle(Z, tp.parameterized_function_type()));
} else {
Write<bool>(false);
Write<const Class&>(Class::Handle(Z, tp.parameterized_class()));
}
break;
}
@ -2073,15 +2078,14 @@ const Object& FlowGraphDeserializer::ReadObjectImpl(intptr_t cid,
const intptr_t base = Read<intptr_t>();
const intptr_t index = Read<intptr_t>();
const Nullability nullability = static_cast<Nullability>(Read<int8_t>());
const classid_t parameterized_class_id = Read<classid_t>();
const Object& owner =
(parameterized_class_id == kObjectCid)
? Object::null_object()
: ((parameterized_class_id == kFunctionCid)
? Read<const Object&>()
: Class::Handle(Z, GetClassById(parameterized_class_id)));
const Object* owner = nullptr;
if (Read<bool>()) {
owner = &Read<const FunctionType&>();
} else {
owner = &Read<const Class&>();
}
auto& tp = TypeParameter::ZoneHandle(
Z, TypeParameter::New(owner, base, index, nullability));
Z, TypeParameter::New(*owner, base, index, nullability));
SetObjectAt(object_index, tp);
tp.SetIsFinalized();
tp ^= tp.Canonicalize(thread());

View file

@ -404,6 +404,9 @@ const word UntaggedAbstractType::kNullabilityMask =
const word UntaggedType::kTypeClassIdShift =
dart::UntaggedType::kTypeClassIdShift;
const word UntaggedTypeParameter::kIsFunctionTypeParameterBit =
dart::UntaggedTypeParameter::kIsFunctionTypeParameterBit;
const word UntaggedObject::kBarrierOverlapShift =
dart::UntaggedObject::kBarrierOverlapShift;

View file

@ -445,6 +445,11 @@ class UntaggedType : public AllStatic {
static const word kTypeClassIdShift;
};
class UntaggedTypeParameter : public AllStatic {
public:
static const word kIsFunctionTypeParameterBit;
};
class Object : public AllStatic {
public:
// Offset of the tags word.
@ -972,7 +977,6 @@ class TypeParameter : public AllStatic {
public:
static word InstanceSize();
FINAL_CLASS();
static word parameterized_class_id_offset();
static word index_offset();
};

View file

@ -555,9 +555,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 24;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 16;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 24;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 30;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 26;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 12;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 4;
@ -676,7 +674,7 @@ static constexpr dart::compiler::target::word LoadingUnit_InstanceSize = 20;
static constexpr dart::compiler::target::word
TransferableTypedData_InstanceSize = 4;
static constexpr dart::compiler::target::word Type_InstanceSize = 24;
static constexpr dart::compiler::target::word TypeParameter_InstanceSize = 32;
static constexpr dart::compiler::target::word TypeParameter_InstanceSize = 28;
static constexpr dart::compiler::target::word TypeParameters_InstanceSize = 20;
static constexpr dart::compiler::target::word TypedData_HeaderSize = 12;
static constexpr dart::compiler::target::word TypedDataBase_InstanceSize = 12;
@ -1239,9 +1237,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 48;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 32;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 48;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 54;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 50;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 24;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 8;
@ -1916,9 +1912,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 24;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 16;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 24;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 30;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 26;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 12;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 4;
@ -2037,7 +2031,7 @@ static constexpr dart::compiler::target::word LoadingUnit_InstanceSize = 20;
static constexpr dart::compiler::target::word
TransferableTypedData_InstanceSize = 4;
static constexpr dart::compiler::target::word Type_InstanceSize = 24;
static constexpr dart::compiler::target::word TypeParameter_InstanceSize = 32;
static constexpr dart::compiler::target::word TypeParameter_InstanceSize = 28;
static constexpr dart::compiler::target::word TypeParameters_InstanceSize = 20;
static constexpr dart::compiler::target::word TypedData_HeaderSize = 12;
static constexpr dart::compiler::target::word TypedDataBase_InstanceSize = 12;
@ -2600,9 +2594,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 48;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 32;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 48;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 54;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 50;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 24;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 8;
@ -3285,9 +3277,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 32;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 24;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 32;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 38;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 34;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 16;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 8;
@ -3969,9 +3959,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 32;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 24;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 32;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 38;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 34;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 16;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 8;
@ -4647,9 +4635,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 24;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 16;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 24;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 30;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 26;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 12;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 4;
@ -4770,7 +4756,7 @@ static constexpr dart::compiler::target::word LoadingUnit_InstanceSize = 20;
static constexpr dart::compiler::target::word
TransferableTypedData_InstanceSize = 4;
static constexpr dart::compiler::target::word Type_InstanceSize = 24;
static constexpr dart::compiler::target::word TypeParameter_InstanceSize = 32;
static constexpr dart::compiler::target::word TypeParameter_InstanceSize = 28;
static constexpr dart::compiler::target::word TypeParameters_InstanceSize = 20;
static constexpr dart::compiler::target::word TypedData_HeaderSize = 12;
static constexpr dart::compiler::target::word TypedDataBase_InstanceSize = 12;
@ -5333,9 +5319,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 48;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 32;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 48;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 54;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 50;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 24;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 8;
@ -6005,9 +5989,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 24;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 16;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 24;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 30;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 26;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 12;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 4;
@ -6126,7 +6108,7 @@ static constexpr dart::compiler::target::word LoadingUnit_InstanceSize = 20;
static constexpr dart::compiler::target::word
TransferableTypedData_InstanceSize = 4;
static constexpr dart::compiler::target::word Type_InstanceSize = 24;
static constexpr dart::compiler::target::word TypeParameter_InstanceSize = 32;
static constexpr dart::compiler::target::word TypeParameter_InstanceSize = 28;
static constexpr dart::compiler::target::word TypeParameters_InstanceSize = 20;
static constexpr dart::compiler::target::word TypedData_HeaderSize = 12;
static constexpr dart::compiler::target::word TypedDataBase_InstanceSize = 12;
@ -6681,9 +6663,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 48;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 32;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 48;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 54;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 50;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 24;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 8;
@ -7350,9 +7330,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 24;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 16;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 24;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 30;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 26;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 12;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 4;
@ -7471,7 +7449,7 @@ static constexpr dart::compiler::target::word LoadingUnit_InstanceSize = 20;
static constexpr dart::compiler::target::word
TransferableTypedData_InstanceSize = 4;
static constexpr dart::compiler::target::word Type_InstanceSize = 24;
static constexpr dart::compiler::target::word TypeParameter_InstanceSize = 32;
static constexpr dart::compiler::target::word TypeParameter_InstanceSize = 28;
static constexpr dart::compiler::target::word TypeParameters_InstanceSize = 20;
static constexpr dart::compiler::target::word TypedData_HeaderSize = 12;
static constexpr dart::compiler::target::word TypedDataBase_InstanceSize = 12;
@ -8026,9 +8004,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 48;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 32;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 48;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 54;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 50;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 24;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 8;
@ -8703,9 +8679,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 32;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 24;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 32;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 38;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 34;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 16;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 8;
@ -9379,9 +9353,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 32;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 24;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 32;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 38;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 34;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 16;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 8;
@ -10049,9 +10021,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 24;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 16;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 24;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 30;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 26;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 12;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 4;
@ -10172,7 +10142,7 @@ static constexpr dart::compiler::target::word LoadingUnit_InstanceSize = 20;
static constexpr dart::compiler::target::word
TransferableTypedData_InstanceSize = 4;
static constexpr dart::compiler::target::word Type_InstanceSize = 24;
static constexpr dart::compiler::target::word TypeParameter_InstanceSize = 32;
static constexpr dart::compiler::target::word TypeParameter_InstanceSize = 28;
static constexpr dart::compiler::target::word TypeParameters_InstanceSize = 20;
static constexpr dart::compiler::target::word TypedData_HeaderSize = 12;
static constexpr dart::compiler::target::word TypedDataBase_InstanceSize = 12;
@ -10727,9 +10697,7 @@ static constexpr dart::compiler::target::word
FunctionType_parameter_types_offset = 48;
static constexpr dart::compiler::target::word
FunctionType_type_parameters_offset = 32;
static constexpr dart::compiler::target::word
TypeParameter_parameterized_class_id_offset = 48;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 54;
static constexpr dart::compiler::target::word TypeParameter_index_offset = 50;
static constexpr dart::compiler::target::word TypeArguments_hash_offset = 24;
static constexpr dart::compiler::target::word
TypeArguments_instantiations_offset = 8;
@ -11459,10 +11427,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 24;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 16;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 24;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
30;
26;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
12;
static constexpr dart::compiler::target::word
@ -11601,7 +11567,7 @@ static constexpr dart::compiler::target::word
AOT_TransferableTypedData_InstanceSize = 4;
static constexpr dart::compiler::target::word AOT_Type_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_TypeParameter_InstanceSize =
32;
28;
static constexpr dart::compiler::target::word AOT_TypeParameters_InstanceSize =
20;
static constexpr dart::compiler::target::word AOT_TypedData_HeaderSize = 12;
@ -12214,10 +12180,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 48;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 32;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 48;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
54;
50;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
24;
static constexpr dart::compiler::target::word
@ -12974,10 +12938,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 48;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 32;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 48;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
54;
50;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
24;
static constexpr dart::compiler::target::word
@ -13733,10 +13695,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 32;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 24;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 32;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
38;
34;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
16;
static constexpr dart::compiler::target::word
@ -14491,10 +14451,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 32;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 24;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 32;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
38;
34;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
16;
static constexpr dart::compiler::target::word
@ -15246,10 +15204,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 24;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 16;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 24;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
30;
26;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
12;
static constexpr dart::compiler::target::word
@ -15390,7 +15346,7 @@ static constexpr dart::compiler::target::word
AOT_TransferableTypedData_InstanceSize = 4;
static constexpr dart::compiler::target::word AOT_Type_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_TypeParameter_InstanceSize =
32;
28;
static constexpr dart::compiler::target::word AOT_TypeParameters_InstanceSize =
20;
static constexpr dart::compiler::target::word AOT_TypedData_HeaderSize = 12;
@ -16003,10 +15959,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 48;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 32;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 48;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
54;
50;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
24;
static constexpr dart::compiler::target::word
@ -16751,10 +16705,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 24;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 16;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 24;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
30;
26;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
12;
static constexpr dart::compiler::target::word
@ -16893,7 +16845,7 @@ static constexpr dart::compiler::target::word
AOT_TransferableTypedData_InstanceSize = 4;
static constexpr dart::compiler::target::word AOT_Type_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_TypeParameter_InstanceSize =
32;
28;
static constexpr dart::compiler::target::word AOT_TypeParameters_InstanceSize =
20;
static constexpr dart::compiler::target::word AOT_TypedData_HeaderSize = 12;
@ -17497,10 +17449,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 48;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 32;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 48;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
54;
50;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
24;
static constexpr dart::compiler::target::word
@ -18248,10 +18198,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 48;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 32;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 48;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
54;
50;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
24;
static constexpr dart::compiler::target::word
@ -18998,10 +18946,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 32;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 24;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 32;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
38;
34;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
16;
static constexpr dart::compiler::target::word
@ -19747,10 +19693,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 32;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 24;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 32;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
38;
34;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
16;
static constexpr dart::compiler::target::word
@ -20493,10 +20437,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 24;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 16;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 24;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
30;
26;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
12;
static constexpr dart::compiler::target::word
@ -20637,7 +20579,7 @@ static constexpr dart::compiler::target::word
AOT_TransferableTypedData_InstanceSize = 4;
static constexpr dart::compiler::target::word AOT_Type_InstanceSize = 24;
static constexpr dart::compiler::target::word AOT_TypeParameter_InstanceSize =
32;
28;
static constexpr dart::compiler::target::word AOT_TypeParameters_InstanceSize =
20;
static constexpr dart::compiler::target::word AOT_TypedData_HeaderSize = 12;
@ -21241,10 +21183,8 @@ static constexpr dart::compiler::target::word
AOT_FunctionType_parameter_types_offset = 48;
static constexpr dart::compiler::target::word
AOT_FunctionType_type_parameters_offset = 32;
static constexpr dart::compiler::target::word
AOT_TypeParameter_parameterized_class_id_offset = 48;
static constexpr dart::compiler::target::word AOT_TypeParameter_index_offset =
54;
50;
static constexpr dart::compiler::target::word AOT_TypeArguments_hash_offset =
24;
static constexpr dart::compiler::target::word

View file

@ -374,7 +374,6 @@
FIELD(FunctionType, packed_type_parameter_counts_offset) \
FIELD(FunctionType, parameter_types_offset) \
FIELD(FunctionType, type_parameters_offset) \
FIELD(TypeParameter, parameterized_class_id_offset) \
FIELD(TypeParameter, index_offset) \
FIELD(TypeArguments, hash_offset) \
FIELD(TypeArguments, instantiations_offset) \

View file

@ -901,12 +901,11 @@ static void GenerateNullIsAssignableToType(Assembler* assembler,
};
Label function_type_param;
__ LoadFieldFromOffset(
kScratchReg, kCurrentTypeReg,
target::TypeParameter::parameterized_class_id_offset(),
kUnsignedFourBytes);
__ CompareImmediate(kScratchReg, kFunctionCid);
__ BranchIf(EQUAL, &function_type_param, Assembler::kNearJump);
__ LoadFieldFromOffset(kScratchReg, kCurrentTypeReg,
target::AbstractType::flags_offset(), kUnsignedByte);
__ BranchIfBit(kScratchReg,
target::UntaggedTypeParameter::kIsFunctionTypeParameterBit,
NOT_ZERO, &function_type_param, Assembler::kNearJump);
handle_case(TypeTestABI::kInstantiatorTypeArgumentsReg);
__ Bind(&function_type_param);
#if defined(TARGET_ARCH_IA32)
@ -1015,10 +1014,10 @@ static void BuildTypeParameterTypeTestStub(Assembler* assembler,
Label function_type_param;
__ LoadFieldFromOffset(TypeTestABI::kScratchReg, TypeTestABI::kDstTypeReg,
target::TypeParameter::parameterized_class_id_offset(),
kUnsignedFourBytes);
__ CompareImmediate(TypeTestABI::kScratchReg, kFunctionCid);
__ BranchIf(EQUAL, &function_type_param, Assembler::kNearJump);
target::AbstractType::flags_offset(), kUnsignedByte);
__ BranchIfBit(TypeTestABI::kScratchReg,
target::UntaggedTypeParameter::kIsFunctionTypeParameterBit,
NOT_ZERO, &function_type_param, Assembler::kNearJump);
handle_case(TypeTestABI::kInstantiatorTypeArgumentsReg);
__ Bind(&function_type_param);
handle_case(TypeTestABI::kFunctionTypeArgumentsReg);

View file

@ -6430,8 +6430,8 @@ class FunctionTypeMapping : public ValueObject {
TypeParameterPtr MapTypeParameter(const TypeParameter& type_param) const {
ASSERT(type_param.IsFunctionTypeParameter());
const FunctionType* new_owner =
Find(Object::Handle(zone_, type_param.owner()));
const FunctionType* new_owner = Find(
FunctionType::Handle(zone_, type_param.parameterized_function_type()));
if (new_owner != nullptr) {
return new_owner->TypeParameterAt(type_param.index() - type_param.base(),
type_param.nullability());
@ -6441,15 +6441,15 @@ class FunctionTypeMapping : public ValueObject {
bool ContainsOwnersOfTypeParameters(const TypeParameter& p1,
const TypeParameter& p2) const {
auto& from = Object::Handle(zone_, p1.owner());
auto& from = FunctionType::Handle(zone_, p1.parameterized_function_type());
const FunctionType* to = Find(from);
if (to != nullptr) {
return to->ptr() == p2.owner();
return to->ptr() == p2.parameterized_function_type();
}
from = p2.owner();
from = p2.parameterized_function_type();
to = Find(from);
if (to != nullptr) {
return to->ptr() == p1.owner();
return to->ptr() == p1.parameterized_function_type();
}
return false;
}
@ -22639,7 +22639,8 @@ bool TypeParameter::IsEquivalent(
" - result: false (other is not a function type parameter)\n");
return false;
}
if ((owner() != other_type_param.owner()) &&
if ((parameterized_function_type() !=
other_type_param.parameterized_function_type()) &&
((function_type_equivalence == nullptr) ||
!function_type_equivalence->ContainsOwnersOfTypeParameters(
*this, other_type_param))) {
@ -22673,20 +22674,36 @@ bool TypeParameter::IsEquivalent(
}
void TypeParameter::set_owner(const Object& value) const {
ASSERT(value.IsNull() || value.IsClass() || value.IsFunctionType());
ASSERT((IsFunctionTypeParameter() && value.IsFunctionType()) ||
(IsClassTypeParameter() && value.IsSmi()));
untag()->set_owner(value.ptr());
set_parameterized_class_id(
value.IsNull()
? kObjectCid
: (value.IsClass() ? Class::Cast(value).id() : kFunctionCid));
}
void TypeParameter::set_parameterized_class_id(classid_t value) const {
StoreNonPointer(&untag()->parameterized_class_id_, value);
}
classid_t TypeParameter::parameterized_class_id() const {
return untag()->parameterized_class_id_;
if (IsClassTypeParameter()) {
return Smi::Value(Smi::RawCast(untag()->owner()));
} else {
return kFunctionCid;
}
}
void TypeParameter::set_parameterized_class_id(classid_t value) const {
ASSERT(IsClassTypeParameter());
untag()->set_owner(Smi::New(value));
}
ClassPtr TypeParameter::parameterized_class() const {
if (IsClassTypeParameter()) {
const classid_t cid = parameterized_class_id();
if (cid != kIllegalCid) {
return IsolateGroup::Current()->class_table()->At(cid);
}
}
return Class::null();
}
FunctionTypePtr TypeParameter::parameterized_function_type() const {
ASSERT(IsFunctionTypeParameter());
return FunctionType::RawCast(untag()->owner());
}
void TypeParameter::set_base(intptr_t value) const {
@ -22702,14 +22719,20 @@ void TypeParameter::set_index(intptr_t value) const {
}
AbstractTypePtr TypeParameter::bound() const {
const auto& owner = Object::Handle(this->owner());
if (owner.IsNull()) {
return IsolateGroup::Current()->object_store()->nullable_object_type();
if (IsFunctionTypeParameter()) {
const auto& owner = FunctionType::Handle(parameterized_function_type());
const auto& type_parameters =
TypeParameters::Handle(owner.type_parameters());
return type_parameters.BoundAt(index() - base());
} else {
const auto& owner = Class::Handle(parameterized_class());
if (owner.IsNull()) {
return IsolateGroup::Current()->object_store()->nullable_object_type();
}
const auto& type_parameters =
TypeParameters::Handle(owner.type_parameters());
return type_parameters.BoundAt(index() - base());
}
const auto& type_parameters = TypeParameters::Handle(
owner.IsClass() ? Class::Cast(owner).type_parameters()
: FunctionType::Cast(owner).type_parameters());
return type_parameters.BoundAt(index() - base());
}
AbstractTypePtr TypeParameter::GetFromTypeArguments(
@ -22822,7 +22845,9 @@ AbstractTypePtr TypeParameter::Canonicalize(Thread* thread) const {
Zone* zone = thread->zone();
if (IsCanonical()) {
#ifdef DEBUG
ASSERT(Object::Handle(zone, owner()).IsOld());
if (IsFunctionTypeParameter()) {
ASSERT(FunctionType::Handle(zone, parameterized_function_type()).IsOld());
}
#endif
return this->ptr();
}
@ -22908,13 +22933,21 @@ TypeParameterPtr TypeParameter::New(const Object& owner,
intptr_t index,
Nullability nullability) {
ASSERT(owner.IsNull() || owner.IsClass() || owner.IsFunctionType());
const bool is_function_type_parameter = owner.IsFunctionType();
const uint32_t flags = UntaggedTypeParameter::IsFunctionTypeParameter::encode(
is_function_type_parameter);
Zone* Z = Thread::Current()->zone();
const TypeParameter& result = TypeParameter::Handle(Z, TypeParameter::New());
result.set_owner(owner);
result.set_flags(flags);
if (is_function_type_parameter) {
result.set_owner(owner);
} else {
result.set_parameterized_class_id(owner.IsNull() ? kIllegalCid
: Class::Cast(owner).id());
}
result.set_base(base);
result.set_index(index);
result.SetHash(0);
result.set_flags(0);
result.set_nullability(nullability);
result.set_type_state(UntaggedAbstractType::kAllocated);

View file

@ -9317,18 +9317,12 @@ class TypeParameter : public AbstractType {
TypeParameterPtr ToNullability(Nullability value, Heap::Space space) const;
virtual bool HasTypeClass() const { return false; }
virtual classid_t type_class_id() const { return kIllegalCid; }
classid_t parameterized_class_id() const;
void set_parameterized_class_id(classid_t value) const;
bool IsClassTypeParameter() const {
return parameterized_class_id() != kFunctionCid;
}
bool IsFunctionTypeParameter() const {
return parameterized_class_id() == kFunctionCid;
}
static intptr_t parameterized_class_id_offset() {
return OFFSET_OF(UntaggedTypeParameter, parameterized_class_id_);
bool IsFunctionTypeParameter() const {
return UntaggedTypeParameter::IsFunctionTypeParameter::decode(
untag()->flags());
}
bool IsClassTypeParameter() const { return !IsFunctionTypeParameter(); }
intptr_t base() const { return untag()->base_; }
void set_base(intptr_t value) const;
@ -9338,8 +9332,10 @@ class TypeParameter : public AbstractType {
return OFFSET_OF(UntaggedTypeParameter, index_);
}
ObjectPtr owner() const { return untag()->owner(); }
void set_owner(const Object& value) const;
classid_t parameterized_class_id() const;
void set_parameterized_class_id(classid_t value) const;
ClassPtr parameterized_class() const;
FunctionTypePtr parameterized_function_type() const;
AbstractTypePtr bound() const;
@ -9409,6 +9405,8 @@ class TypeParameter : public AbstractType {
uword ComputeHash() const;
void SetHash(intptr_t value) const;
void set_owner(const Object& value) const;
static TypeParameterPtr New();
FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType);

View file

@ -2764,14 +2764,19 @@ class UntaggedRecordType : public UntaggedAbstractType {
};
class UntaggedTypeParameter : public UntaggedAbstractType {
public:
static constexpr intptr_t kIsFunctionTypeParameterBit =
TypeStateBits::kNextBit;
using IsFunctionTypeParameter =
BitField<uint32_t, bool, kIsFunctionTypeParameterBit, 1>;
private:
RAW_HEAP_OBJECT_IMPLEMENTATION(TypeParameter);
COMPRESSED_POINTER_FIELD(SmiPtr, hash)
// Class or FunctionType.
// FunctionType or Smi (class id).
COMPRESSED_POINTER_FIELD(ObjectPtr, owner)
VISIT_TO(owner)
ClassIdTagType parameterized_class_id_; // Or kFunctionCid for function tp.
uint16_t base_; // Number of enclosing function type parameters.
uint16_t index_; // Keep size in sync with BuildTypeParameterTypeTestStub.