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

Side by Side Diff: runtime/vm/intermediate_language.cc

Issue 10762003: Fix static type analysis of closure calls (issue 3959). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/language/closure_type_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/flow_graph_builder.h" 9 #include "vm/flow_graph_builder.h"
10 #include "vm/flow_graph_compiler.h" 10 #include "vm/flow_graph_compiler.h"
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 } 575 }
576 576
577 577
578 RawAbstractType* StoreContextComp::StaticType() const { 578 RawAbstractType* StoreContextComp::StaticType() const {
579 UNREACHABLE(); 579 UNREACHABLE();
580 return AbstractType::null(); 580 return AbstractType::null();
581 } 581 }
582 582
583 583
584 RawAbstractType* ClosureCallComp::StaticType() const { 584 RawAbstractType* ClosureCallComp::StaticType() const {
585 // The closure is the first argument to the call. 585 // Because of function subtyping rules, the static return type of a closure
586 const AbstractType& function_type = 586 // call cannot be relied upon for static type analysis. For example, a
587 AbstractType::Handle(ArgumentAt(0)->StaticType()); 587 // function returning Dynamic can be assigned to a closure variable declared
588 if (function_type.IsDynamicType() || function_type.IsFunctionInterface()) { 588 // to return int and may actually return a double at run-time.
589 // The function type is not statically known or simply Function. 589 return Type::DynamicType();
590 return Type::DynamicType();
591 }
592 const Class& signature_class = Class::Handle(function_type.type_class());
593 const Function& signature_function =
594 Function::Handle(signature_class.signature_function());
595 if (signature_function.IsNull()) {
596 // Attempting to invoke a non-closure object.
597 return Type::DynamicType();
598 }
599 // TODO(regis): The result type may be generic. Consider upper bounds.
600 return signature_function.result_type();
601 } 590 }
602 591
603 592
604 RawAbstractType* InstanceCallComp::StaticType() const { 593 RawAbstractType* InstanceCallComp::StaticType() const {
605 return Type::DynamicType(); 594 return Type::DynamicType();
606 } 595 }
607 596
608 597
609 RawAbstractType* PolymorphicInstanceCallComp::StaticType() const { 598 RawAbstractType* PolymorphicInstanceCallComp::StaticType() const {
610 return Type::DynamicType(); 599 return Type::DynamicType();
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 const ExternalLabel label(closure_function.ToCString(), stub.EntryPoint()); 1282 const ExternalLabel label(closure_function.ToCString(), stub.EntryPoint());
1294 compiler->GenerateCall(token_pos(), try_index(), &label, 1283 compiler->GenerateCall(token_pos(), try_index(), &label,
1295 PcDescriptors::kOther); 1284 PcDescriptors::kOther);
1296 __ Drop(2); // Discard type arguments and receiver. 1285 __ Drop(2); // Discard type arguments and receiver.
1297 } 1286 }
1298 1287
1299 1288
1300 #undef __ 1289 #undef __
1301 1290
1302 } // namespace dart 1291 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/closure_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698