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

Unified Diff: runtime/vm/constant_propagator.cc

Issue 877163002: Upstream folding instanceof on a constant. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/constant_propagator.cc
diff --git a/runtime/vm/constant_propagator.cc b/runtime/vm/constant_propagator.cc
index 7662e8bb2320844825e375a3c7f3bc09fba4747f..8cbb12d2480cbd59db596ff84f3764831d91aa71 100644
--- a/runtime/vm/constant_propagator.cc
+++ b/runtime/vm/constant_propagator.cc
@@ -740,7 +740,23 @@ void ConstantPropagator::VisitInstanceOf(InstanceOfInstr* instr) {
SetValue(instr, non_constant_);
}
} else if (IsConstant(value)) {
- // TODO(kmillikin): Handle instanceof on constants.
+ if (value.IsInstance()) {
+ const Instance& instance = Instance::Cast(value);
+ const AbstractType& checked_type = instr->type();
+ if (instr->instantiator()->BindsToConstantNull() &&
+ instr->instantiator_type_arguments()->BindsToConstantNull()) {
+ const TypeArguments& checked_type_arguments = TypeArguments::Handle();
+ Error& bound_error = Error::Handle();
+ bool is_instance = instance.IsInstanceOf(checked_type,
+ checked_type_arguments,
+ &bound_error);
+ // Can only have bound error with generics.
+ ASSERT(bound_error.IsNull());
+ SetValue(instr, Bool::Get(instr->negate_result()
+ ? !is_instance : is_instance));
+ return;
+ }
+ }
SetValue(instr, non_constant_);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698