Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Unified Diff: runtime/vm/object.cc

Issue 2761933002: Add Genericity enum in VM to distinguish how a type is uninstantiated. (Closed)
Patch Set: sync Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 0c3cdba4b2b28511728297bc395ce6f389c8eb6b..2d3c83ab2eb83d883532866c406f0d7ba9cea8df 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -4800,6 +4800,7 @@ bool TypeArguments::IsResolved() const {
bool TypeArguments::IsSubvectorInstantiated(intptr_t from_index,
intptr_t len,
+ Genericity genericity,
TrailPtr trail) const {
ASSERT(!IsNull());
AbstractType& type = AbstractType::Handle();
@@ -4807,7 +4808,7 @@ bool TypeArguments::IsSubvectorInstantiated(intptr_t from_index,
type = TypeAt(from_index + i);
// If the type argument is null, the type parameterized with this type
// argument is still being finalized. Skip this null type argument.
- if (!type.IsNull() && !type.IsInstantiated(trail)) {
+ if (!type.IsNull() && !type.IsInstantiated(genericity, trail)) {
return false;
}
}
@@ -4826,7 +4827,7 @@ bool TypeArguments::IsUninstantiatedIdentity() const {
}
const TypeParameter& type_param = TypeParameter::Cast(type);
ASSERT(type_param.IsFinalized());
- if ((type_param.index() != i)) {
+ if ((type_param.index() != i) || type_param.IsFunctionTypeParameter()) {
return false;
}
// If this type parameter specifies an upper bound, then the type argument
@@ -4885,7 +4886,7 @@ bool TypeArguments::CanShareInstantiatorTypeArguments(
}
const TypeParameter& type_param = TypeParameter::Cast(type_arg);
ASSERT(type_param.IsFinalized());
- if ((type_param.index() != i)) {
+ if ((type_param.index() != i) || type_param.IsFunctionTypeParameter()) {
return false;
}
}
@@ -5550,6 +5551,18 @@ void Function::set_parent_function(const Function& value) const {
}
+bool Function::HasGenericParent() const {
+ Function& parent = Function::Handle(parent_function());
+ while (!parent.IsNull()) {
+ if (parent.IsGeneric()) {
+ return true;
+ }
+ parent = parent.parent_function();
+ }
+ return false;
+}
+
+
RawFunction* Function::implicit_closure_function() const {
if (IsClosureFunction() || IsSignatureFunction() || IsFactory()) {
return Function::null();
@@ -16049,7 +16062,7 @@ TokenPosition AbstractType::token_pos() const {
}
-bool AbstractType::IsInstantiated(TrailPtr trail) const {
+bool AbstractType::IsInstantiated(Genericity genericity, TrailPtr trail) const {
// AbstractType is an abstract class.
UNREACHABLE();
return false;
@@ -16855,11 +16868,12 @@ RawUnresolvedClass* Type::unresolved_class() const {
}
-bool Type::IsInstantiated(TrailPtr trail) const {
+bool Type::IsInstantiated(Genericity genericity, TrailPtr trail) const {
if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) {
return true;
}
- if (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated) {
+ if ((genericity == kAny) &&
+ (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated)) {
return false;
}
if (arguments() == TypeArguments::null()) {
@@ -16879,7 +16893,8 @@ bool Type::IsInstantiated(TrailPtr trail) const {
len = cls.NumTypeParameters(); // Check the type parameters only.
}
return (len == 0) ||
- args.IsSubvectorInstantiated(num_type_args - len, len, trail);
+ args.IsSubvectorInstantiated(num_type_args - len, len, genericity,
+ trail);
}
@@ -17567,11 +17582,11 @@ const char* Type::ToCString() const {
}
-bool TypeRef::IsInstantiated(TrailPtr trail) const {
+bool TypeRef::IsInstantiated(Genericity genericity, TrailPtr trail) const {
if (TestAndAddToTrail(&trail)) {
return true;
}
- return AbstractType::Handle(type()).IsInstantiated(trail);
+ return AbstractType::Handle(type()).IsInstantiated(genericity, trail);
}
@@ -17732,6 +17747,26 @@ void TypeParameter::SetIsFinalized() const {
}
+bool TypeParameter::IsInstantiated(Genericity genericity,
+ TrailPtr trail) const {
+ switch (genericity) {
+ case kAny:
+ return false;
+ case kClass:
+ return IsFunctionTypeParameter();
+ case kFunctions:
+ return IsClassTypeParameter();
+ case kCurrentFunction:
+ return IsClassTypeParameter() || (parent_level() > 0);
+ case kParentFunctions:
+ return IsClassTypeParameter() || (parent_level() == 0);
+ default:
+ UNREACHABLE();
+ }
+ return false;
+}
+
+
bool TypeParameter::IsEquivalent(const Instance& other, TrailPtr trail) const {
if (raw() == other.raw()) {
return true;
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698