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

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

Issue 12374024: Fix factory name to result cid mapping, run type propagation once more after constant propagation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/flow_graph_type_propagator.cc » ('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/flow_graph_builder.h" 5 #include "vm/flow_graph_builder.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/ast_printer.h" 8 #include "vm/ast_printer.h"
9 #include "vm/code_descriptors.h" 9 #include "vm/code_descriptors.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 1958 matching lines...) Expand 10 before | Expand all | Expand 10 after
1969 arguments->Add(push_ctor_arg); 1969 arguments->Add(push_ctor_arg);
1970 1970
1971 BuildPushArguments(*node->arguments(), arguments); 1971 BuildPushArguments(*node->arguments(), arguments);
1972 Do(new StaticCallInstr(node->token_pos(), 1972 Do(new StaticCallInstr(node->token_pos(),
1973 node->constructor(), 1973 node->constructor(),
1974 node->arguments()->names(), 1974 node->arguments()->names(),
1975 arguments)); 1975 arguments));
1976 } 1976 }
1977 1977
1978 1978
1979 static bool IsRecognizedConstructor(const Function& function, 1979 // List of recognized factories in core lib (factories with known result-cid):
1980 const String& expected) { 1980 // (factory-name-symbol, result-cid, fingerprint).
1981 const Class& clazz = Class::Handle(function.Owner()); 1981 #define RECOGNIZED_FACTORY_LIST(V) \
1982 const Library& lib = Library::Handle(clazz.library()); 1982 V(ObjectArrayDot, kArrayCid, 97987288) \
1983 V(GrowableObjectArrayWithData, kGrowableObjectArrayCid, 816132033) \
1984 V(GrowableObjectArrayDot, kGrowableObjectArrayCid, 1896741574) \
1983 1985
1984 const String& expected_class_name = 1986
1985 String::Handle(lib.PrivateName(expected)); 1987 // Class that recognizes factories and returns corresponding result cid.
1986 if (!String::Handle(clazz.Name()).Equals(expected_class_name)) { 1988 class FactoryRecognizer : public AllStatic {
1987 return false; 1989 public:
1990 // Return kDynamicCid if factory is not recognized.
1991 static intptr_t ResultCid(const Function& factory) {
1992 ASSERT(factory.IsFactory());
1993 const Class& function_class = Class::Handle(factory.Owner());
1994 const Library& lib = Library::Handle(function_class.library());
1995 if (lib.raw() != Library::CoreLibrary()) {
1996 // Only core library factories recognized.
1997 return kDynamicCid;
1998 }
1999 const String& factory_name = String::Handle(factory.name());
2000 #define RECOGNIZE_FACTORY(test_factory_symbol, cid, fp) \
2001 if (String::EqualsIgnoringPrivateKey( \
2002 factory_name, Symbols::test_factory_symbol())) { \
2003 ASSERT(factory.CheckSourceFingerprint(fp)); \
2004 return cid; \
2005 } \
2006
2007 RECOGNIZED_FACTORY_LIST(RECOGNIZE_FACTORY);
2008 #undef RECOGNIZE_FACTORY
2009
2010 return kDynamicCid;
1988 } 2011 }
1989 2012 };
1990 const String& function_name = String::Handle(function.name());
1991 const String& expected_function_name = String::Handle(
1992 String::Concat(expected_class_name, Symbols::Dot()));
1993 return function_name.Equals(expected_function_name);
1994 }
1995 2013
1996 2014
1997 static intptr_t GetResultCidOfConstructor(ConstructorCallNode* node) { 2015 static intptr_t GetResultCidOfConstructor(ConstructorCallNode* node) {
1998 const Function& function = node->constructor(); 2016 const Function& function = node->constructor();
1999 const Class& function_class = Class::Handle(function.Owner()); 2017 const Class& function_class = Class::Handle(function.Owner());
2000 const Library& core_lib = Library::Handle(Library::CoreLibrary()); 2018 const Library& core_lib = Library::Handle(Library::CoreLibrary());
2001 2019
2002 if (function_class.library() != core_lib.raw()) { 2020 if (function_class.library() != core_lib.raw()) {
2003 return kDynamicCid; 2021 return kDynamicCid;
2004 } 2022 }
2005 2023
2006 if (node->constructor().IsFactory()) { 2024 if (node->constructor().IsFactory()) {
2007 if ((function_class.Name() == Symbols::List().raw()) && 2025 if ((function_class.Name() == Symbols::List().raw()) &&
2008 (function.name() == Symbols::ListFactory().raw())) { 2026 (function.name() == Symbols::ListFactory().raw())) {
2027 // Special recognition of 'new List()' vs 'new List(n)'.
2009 if (node->arguments()->length() == 0) { 2028 if (node->arguments()->length() == 0) {
2010 return kGrowableObjectArrayCid; 2029 return kGrowableObjectArrayCid;
2011 } 2030 }
2012 return kArrayCid; 2031 return kArrayCid;
2013 } else {
2014 if (IsRecognizedConstructor(function, Symbols::ObjectArray()) &&
2015 (node->arguments()->length() == 1)) {
2016 return kArrayCid;
2017 } else if (IsRecognizedConstructor(function,
2018 Symbols::GrowableObjectArray()) &&
2019 (node->arguments()->length() == 0)) {
2020 return kGrowableObjectArrayCid;
2021 }
2022 } 2032 }
2033 return FactoryRecognizer::ResultCid(function);
2023 } 2034 }
2024 return kDynamicCid; // Result cid not known. 2035 return kDynamicCid; // Result cid not known.
2025 } 2036 }
2026 2037
2027 2038
2028 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { 2039 void EffectGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) {
2029 if (node->constructor().IsFactory()) { 2040 if (node->constructor().IsFactory()) {
2030 ZoneGrowableArray<PushArgumentInstr*>* arguments = 2041 ZoneGrowableArray<PushArgumentInstr*>* arguments =
2031 new ZoneGrowableArray<PushArgumentInstr*>(); 2042 new ZoneGrowableArray<PushArgumentInstr*>();
2032 PushArgumentInstr* push_type_arguments = PushArgument( 2043 PushArgumentInstr* push_type_arguments = PushArgument(
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after
3264 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; 3275 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1;
3265 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 3276 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
3266 OS::SNPrint(chars, len, kFormat, function_name, reason); 3277 OS::SNPrint(chars, len, kFormat, function_name, reason);
3267 const Error& error = Error::Handle( 3278 const Error& error = Error::Handle(
3268 LanguageError::New(String::Handle(String::New(chars)))); 3279 LanguageError::New(String::Handle(String::New(chars))));
3269 Isolate::Current()->long_jump_base()->Jump(1, error); 3280 Isolate::Current()->long_jump_base()->Jump(1, error);
3270 } 3281 }
3271 3282
3272 3283
3273 } // namespace dart 3284 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/flow_graph_type_propagator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698