Files
sdk/runtime/lib/async.cc
T
Alexander Markov 2ee6fcf514 [vm] Remove TypeRef
TypeRef type wraps around another type and it was used to represent
a graph of recursive types. After [0], the only use of TypeRef is
for TypeParameter.bound which may indirectly reference the same
TypeParameter.

This change replaces TypeParameter.bound with TypeParameter.owner and
removes TypeRef entirely. Various parts of the VM no longer need to
handle and support TypeRefs.

TypeParameter.owner can reference a FunctionType, Class,
or, as an optimization, it can be set to null in order to share
class type parameters among different classes.

With the exception of the 'TypeParameter.owner' back pointer,
VM types are now not recursive and can be visited without
additional tracking.

Caveats:

* Generic FunctionType cannot be cloned in a shallow way:
  when copying a FunctionType, type parameters should be cloned too
  and their owners should be updated. For that reason,
  a mapping between 'from' and 'to' function types
  (FunctionTypeMapping) is maintained during type transformations
  such as InstantiateFrom.
  FunctionType::Clone is used instead of Object::Clone where
  appropriate.

* When testing types for subtyping and equivalence, mapping
  between function types is passed to make sure
  type parameters belong to the equivalent function types.

* IL serializer needs to serialize function types as a whole before
  serializing any types potentially pointing into the middle of a
  function type (such as return type 'List<Y0>' pointing into
  the middle of a function type 'List<Y0> Function<Y0>()').

[0] https://dart-review.googlesource.com/c/sdk/+/296300

TEST=ci

Change-Id: I67c2fd0117c6183a45e183919a7847fd1af70b3e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294165
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-04-28 19:29:36 +00:00

60 lines
2.1 KiB
C++

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/bootstrap_natives.h"
#include "vm/debugger.h"
#include "vm/exceptions.h"
#include "vm/native_entry.h"
#include "vm/object_store.h"
#include "vm/runtime_entry.h"
namespace dart {
DEFINE_NATIVE_ENTRY(AsyncStarMoveNext_debuggerStepCheck, 0, 1) {
#if !defined(PRODUCT)
GET_NON_NULL_NATIVE_ARGUMENT(Closure, async_op, arguments->NativeArgAt(0));
Debugger* debugger = isolate->debugger();
if (debugger != nullptr) {
debugger->MaybeAsyncStepInto(async_op);
}
#endif
return Object::null();
}
// Instantiate generic [closure] using the type argument T
// corresponding to Future<T> in the given [future] instance
// (which may extend or implement Future).
DEFINE_NATIVE_ENTRY(SuspendState_instantiateClosureWithFutureTypeArgument,
0,
2) {
GET_NON_NULL_NATIVE_ARGUMENT(Closure, closure, arguments->NativeArgAt(0));
GET_NON_NULL_NATIVE_ARGUMENT(Instance, future, arguments->NativeArgAt(1));
IsolateGroup* isolate_group = thread->isolate_group();
const auto& future_class =
Class::Handle(zone, isolate_group->object_store()->future_class());
ASSERT(future_class.NumTypeArguments() == 1);
const auto& cls = Class::Handle(zone, future.clazz());
auto& type = Type::Handle(zone, cls.GetInstantiationOf(zone, future_class));
ASSERT(!type.IsNull());
if (!type.IsInstantiated()) {
const auto& instance_type_args =
TypeArguments::Handle(zone, future.GetTypeArguments());
type ^=
type.InstantiateFrom(instance_type_args, Object::null_type_arguments(),
kNoneFree, Heap::kOld);
}
auto& type_args = TypeArguments::Handle(zone, type.arguments());
ASSERT(type_args.IsNull() || type_args.Length() == 1);
type_args = type_args.Canonicalize(thread);
ASSERT(closure.delayed_type_arguments() ==
Object::empty_type_arguments().ptr());
closure.set_delayed_type_arguments(type_args);
return closure.ptr();
}
} // namespace dart