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

Unified Diff: runtime/vm/code_generator.cc

Issue 163683006: Simplify generated code for object allocation with type arguments. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: addressed comments Created 6 years, 10 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 | « no previous file | runtime/vm/flow_graph_builder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/code_generator.cc
===================================================================
--- runtime/vm/code_generator.cc (revision 32653)
+++ runtime/vm/code_generator.cc (working copy)
@@ -114,9 +114,8 @@
// Allocate a new object.
// Arg0: class of the object that needs to be allocated.
// Arg1: type arguments of the object that needs to be allocated.
-// Arg2: type arguments of the instantiator or kNoInstantiator.
// Return value: newly allocated object.
-DEFINE_RUNTIME_ENTRY(AllocateObject, 3) {
+DEFINE_RUNTIME_ENTRY(AllocateObject, 2) {
const Class& cls = Class::CheckedHandle(arguments.ArgAt(0));
const Instance& instance = Instance::Handle(Instance::New(cls));
arguments.SetReturn(instance);
@@ -127,48 +126,12 @@
}
TypeArguments& type_arguments =
TypeArguments::CheckedHandle(arguments.ArgAt(1));
- // If no instantiator is provided, set the type arguments and return.
- if (Object::Handle(arguments.ArgAt(2)).IsSmi()) {
- ASSERT(Smi::CheckedHandle(arguments.ArgAt(2)).Value() ==
- StubCode::kNoInstantiator);
- // Unless null (for a raw type), the type argument vector may be longer than
- // necessary due to a type optimization reusing the type argument vector of
- // the instantiator.
- ASSERT(type_arguments.IsNull() ||
- (type_arguments.IsInstantiated() &&
- (type_arguments.Length() >= cls.NumTypeArguments())));
- instance.SetTypeArguments(type_arguments); // May be null.
- return;
- }
- // A still uninstantiated type argument vector must have the correct length.
- ASSERT(!type_arguments.IsInstantiated() &&
- (type_arguments.Length() == cls.NumTypeArguments()));
- const TypeArguments& instantiator =
- TypeArguments::CheckedHandle(arguments.ArgAt(2));
- ASSERT(instantiator.IsNull() || instantiator.IsInstantiated());
- // Code inlined in the caller should have optimized the case where the
- // instantiator can be reused as type argument vector.
- ASSERT(instantiator.IsNull() || !type_arguments.IsUninstantiatedIdentity());
- if (FLAG_enable_type_checks) {
- Error& bound_error = Error::Handle();
- type_arguments =
- type_arguments.InstantiateAndCanonicalizeFrom(instantiator,
- &bound_error);
- if (!bound_error.IsNull()) {
- // Throw a dynamic type error.
- const intptr_t location = GetCallerLocation();
- String& bound_error_message = String::Handle(
- String::New(bound_error.ToErrorCString()));
- Exceptions::CreateAndThrowTypeError(
- location, Symbols::Empty(), Symbols::Empty(),
- Symbols::Empty(), bound_error_message);
- UNREACHABLE();
- }
- } else {
- type_arguments =
- type_arguments.InstantiateAndCanonicalizeFrom(instantiator, NULL);
- }
- ASSERT(type_arguments.IsNull() || type_arguments.IsInstantiated());
+ // Unless null (for a raw type), the type argument vector may be longer than
+ // necessary due to a type optimization reusing the type argument vector of
+ // the instantiator.
+ ASSERT(type_arguments.IsNull() ||
+ (type_arguments.IsInstantiated() &&
+ (type_arguments.Length() >= cls.NumTypeArguments())));
instance.SetTypeArguments(type_arguments);
}
@@ -219,8 +182,25 @@
// Code inlined in the caller should have optimized the case where the
// instantiator can be reused as type argument vector.
ASSERT(instantiator.IsNull() || !type_arguments.IsUninstantiatedIdentity());
- type_arguments =
- type_arguments.InstantiateAndCanonicalizeFrom(instantiator, NULL);
+ if (FLAG_enable_type_checks) {
+ Error& bound_error = Error::Handle();
+ type_arguments =
+ type_arguments.InstantiateAndCanonicalizeFrom(instantiator,
+ &bound_error);
+ if (!bound_error.IsNull()) {
+ // Throw a dynamic type error.
+ const intptr_t location = GetCallerLocation();
+ String& bound_error_message = String::Handle(
+ String::New(bound_error.ToErrorCString()));
+ Exceptions::CreateAndThrowTypeError(
+ location, Symbols::Empty(), Symbols::Empty(),
+ Symbols::Empty(), bound_error_message);
+ UNREACHABLE();
+ }
+ } else {
+ type_arguments =
+ type_arguments.InstantiateAndCanonicalizeFrom(instantiator, NULL);
+ }
ASSERT(type_arguments.IsInstantiated());
arguments.SetReturn(type_arguments);
}
« no previous file with comments | « no previous file | runtime/vm/flow_graph_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698