Skip to content

Commit

Permalink
Revert "[VM/runtime] Refactor the representation of type parameters i…
Browse files Browse the repository at this point in the history
…n the VM."

This reverts commit 8a21ab1.

Reason for revert: Test failure: http://b/187227619

Original change's description:
> [VM/runtime] Refactor the representation of type parameters in the VM.
>
> This introduces a new VM internal class 'TypeParameters' representing the declaration of a list of type parameters, either in a class or function.
> The reference to (or use of) a type parameter is still represented by the existing 'TypeParameter' class.
>
> Fixes #43901
> Fixes #45763
>
> TEST=existing ones and a regression test
>
> Change-Id: I1fde808bf753cc1cb829f2c4383c1836651cee80
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/189942
> Commit-Queue: Régis Crelier <regis@google.com>
> Reviewed-by: Alexander Markov <alexmarkov@google.com>

TBR=rmacnak@google.com,alexmarkov@google.com,regis@google.com,sstrickl@google.com

Change-Id: If12caa1a84cb6d1c1b8225589f3c994d25abb120
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/198282
Reviewed-by: Michal Terepeta <michalt@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Michal Terepeta <michalt@google.com>
  • Loading branch information
michalt authored and commit-bot@chromium.org committed May 5, 2021
1 parent 08faf7b commit c6bffaf
Show file tree
Hide file tree
Showing 64 changed files with 1,519 additions and 1,733 deletions.
15 changes: 8 additions & 7 deletions runtime/lib/mirrors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,26 @@ static InstancePtr CreateTypeVariableMirror(const TypeParameter& param,
const Instance& owner_mirror) {
const Array& args = Array::Handle(Array::New(3));
args.SetAt(0, param);
args.SetAt(1, String::Handle(param.UserVisibleName()));
args.SetAt(1, String::Handle(param.name()));
args.SetAt(2, owner_mirror);
return CreateMirror(Symbols::_TypeVariableMirror(), args);
}

// We create a list in native code and let Dart code create the type mirror
// object and the ordered map.
static InstancePtr CreateTypeVariableList(const Class& cls) {
const intptr_t num_type_params = cls.NumTypeParameters();
if (num_type_params == 0) {
const TypeArguments& args = TypeArguments::Handle(cls.type_parameters());
if (args.IsNull()) {
return Object::empty_array().ptr();
}
const Array& result = Array::Handle(Array::New(num_type_params * 2));
const Array& result = Array::Handle(Array::New(args.Length() * 2));
TypeParameter& type = TypeParameter::Handle();
String& name = String::Handle();
for (intptr_t i = 0; i < num_type_params; i++) {
type = cls.TypeParameterAt(i, Nullability::kLegacy);
for (intptr_t i = 0; i < args.Length(); i++) {
type ^= args.TypeAt(i);
ASSERT(type.IsTypeParameter());
ASSERT(type.IsFinalized());
name = type.UserVisibleName();
name = type.name();
result.SetAt(2 * i, name);
result.SetAt(2 * i + 1, type);
}
Expand Down
21 changes: 11 additions & 10 deletions runtime/lib/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -449,19 +449,18 @@ DEFINE_NATIVE_ENTRY(Internal_boundsCheckForPartialInstantiation, 0, 2) {
const Closure& closure =
Closure::CheckedHandle(zone, arguments->NativeArgAt(0));
const Function& target = Function::Handle(zone, closure.function());
const TypeParameters& type_params =
TypeParameters::Handle(zone, target.type_parameters());
if (type_params.IsNull() || type_params.AllDynamicBounds()) {
// The function is not generic or the bounds are all dynamic.
return Object::null();
}
const TypeArguments& bounds =
TypeArguments::Handle(zone, target.type_parameters());

// Either the bounds are all-dynamic or the function is not generic.
if (bounds.IsNull()) return Object::null();

const TypeArguments& type_args_to_check =
TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1));

// This should be guaranteed by the front-end.
ASSERT(type_args_to_check.IsNull() ||
type_params.Length() <= type_args_to_check.Length());
bounds.Length() <= type_args_to_check.Length());

// The bounds on the closure may need instantiation.
const TypeArguments& instantiator_type_args =
Expand All @@ -471,8 +470,10 @@ DEFINE_NATIVE_ENTRY(Internal_boundsCheckForPartialInstantiation, 0, 2) {

AbstractType& supertype = AbstractType::Handle(zone);
AbstractType& subtype = AbstractType::Handle(zone);
for (intptr_t i = 0; i < type_params.Length(); ++i) {
supertype = type_params.BoundAt(i);
TypeParameter& parameter = TypeParameter::Handle(zone);
for (intptr_t i = 0; i < bounds.Length(); ++i) {
parameter ^= bounds.TypeAt(i);
supertype = parameter.bound();
subtype = type_args_to_check.IsNull() ? Object::dynamic_type().ptr()
: type_args_to_check.TypeAt(i);

Expand All @@ -491,7 +492,7 @@ DEFINE_NATIVE_ENTRY(Internal_boundsCheckForPartialInstantiation, 0, 2) {
ASSERT(caller_frame != NULL);
location = caller_frame->GetTokenPos();
}
const auto& parameter_name = String::Handle(zone, type_params.NameAt(i));
String& parameter_name = String::Handle(zone, parameter.Name());
Exceptions::CreateAndThrowTypeError(location, subtype, supertype,
parameter_name);
UNREACHABLE();
Expand Down
5 changes: 5 additions & 0 deletions runtime/vm/canonical_tables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ bool MetadataMapTraits::IsMatch(const Object& a, const Object& b) {
const Object& owner_b = Object::Handle(Field::Cast(b).Owner());
return IsMatch(owner_a, owner_b);
} else if (a.IsTypeParameter() && b.IsTypeParameter()) {
const String& name_a = String::Handle(TypeParameter::Cast(a).name());
const String& name_b = String::Handle(TypeParameter::Cast(b).name());
if (!name_a.Equals(name_b)) {
return false;
}
if (TypeParameter::Cast(a).index() != TypeParameter::Cast(b).index() ||
TypeParameter::Cast(a).base() != TypeParameter::Cast(b).base()) {
return false;
Expand Down
Loading

0 comments on commit c6bffaf

Please sign in to comment.