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

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

Issue 2696783002: Properly resolve upper bounds of generic function's type parameters. (Closed)
Patch Set: Created 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | runtime/vm/kernel_reader.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/class_finalizer.h" 5 #include "vm/class_finalizer.h"
6 6
7 #include "vm/code_generator.h" 7 #include "vm/code_generator.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/heap.h" 9 #include "vm/heap.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 } 1248 }
1249 return type.Canonicalize(); 1249 return type.Canonicalize();
1250 } else { 1250 } else {
1251 return type.raw(); 1251 return type.raw();
1252 } 1252 }
1253 } 1253 }
1254 1254
1255 1255
1256 void ClassFinalizer::ResolveSignature(const Class& cls, 1256 void ClassFinalizer::ResolveSignature(const Class& cls,
1257 const Function& function) { 1257 const Function& function) {
1258 AbstractType& type = AbstractType::Handle();
1259 // Resolve upper bounds of function type parameters.
1260 const intptr_t num_type_params = function.NumTypeParameters();
1261 if (num_type_params > 0) {
1262 TypeParameter& type_param = TypeParameter::Handle();
1263 const TypeArguments& type_params =
1264 TypeArguments::Handle(function.type_parameters());
1265 for (intptr_t i = 0; i < num_type_params; i++) {
1266 type_param ^= type_params.TypeAt(i);
1267 type = type_param.bound();
1268 ResolveType(cls, type);
1269 }
1270 }
1258 // Resolve result type. 1271 // Resolve result type.
1259 AbstractType& type = AbstractType::Handle(function.result_type()); 1272 type = function.result_type();
1260 // It is not a compile time error if this name does not resolve to a class or 1273 // It is not a compile time error if this name does not resolve to a class or
1261 // interface. 1274 // interface.
1262 ResolveType(cls, type); 1275 ResolveType(cls, type);
1263 // Resolve formal parameter types. 1276 // Resolve formal parameter types.
1264 const intptr_t num_parameters = function.NumParameters(); 1277 const intptr_t num_parameters = function.NumParameters();
1265 for (intptr_t i = 0; i < num_parameters; i++) { 1278 for (intptr_t i = 0; i < num_parameters; i++) {
1266 type = function.ParameterTypeAt(i); 1279 type = function.ParameterTypeAt(i);
1267 ResolveType(cls, type); 1280 ResolveType(cls, type);
1268 } 1281 }
1269 } 1282 }
1270 1283
1271 1284
1272 void ClassFinalizer::FinalizeSignature(const Class& cls, 1285 void ClassFinalizer::FinalizeSignature(const Class& cls,
1273 const Function& function) { 1286 const Function& function) {
1287 AbstractType& type = AbstractType::Handle();
1288 AbstractType& finalized_type = AbstractType::Handle();
1289 // Finalize upper bounds of function type parameters.
1290 const intptr_t num_type_params = function.NumTypeParameters();
1291 if (num_type_params > 0) {
1292 TypeParameter& type_param = TypeParameter::Handle();
1293 const TypeArguments& type_params =
1294 TypeArguments::Handle(function.type_parameters());
1295 for (intptr_t i = 0; i < num_type_params; i++) {
1296 type_param ^= type_params.TypeAt(i);
1297 type = type_param.bound();
1298 finalized_type = FinalizeType(cls, type, kCanonicalize);
1299 if (finalized_type.raw() != type.raw()) {
1300 type_param.set_bound(finalized_type);
1301 }
1302 }
1303 }
1274 // Finalize result type. 1304 // Finalize result type.
1275 AbstractType& type = AbstractType::Handle(function.result_type()); 1305 type = function.result_type();
1276 // It is not a compile time error if this name does not resolve to a class or 1306 finalized_type = FinalizeType(cls, type, kCanonicalize);
1277 // interface.
1278 AbstractType& finalized_type =
1279 AbstractType::Handle(FinalizeType(cls, type, kCanonicalize));
1280 // The result type may be malformed or malbounded. 1307 // The result type may be malformed or malbounded.
1281 if (finalized_type.raw() != type.raw()) { 1308 if (finalized_type.raw() != type.raw()) {
1282 function.set_result_type(finalized_type); 1309 function.set_result_type(finalized_type);
1283 } 1310 }
1284 // Finalize formal parameter types. 1311 // Finalize formal parameter types.
1285 const intptr_t num_parameters = function.NumParameters(); 1312 const intptr_t num_parameters = function.NumParameters();
1286 for (intptr_t i = 0; i < num_parameters; i++) { 1313 for (intptr_t i = 0; i < num_parameters; i++) {
1287 type = function.ParameterTypeAt(i); 1314 type = function.ParameterTypeAt(i);
1288 finalized_type = FinalizeType(cls, type, kCanonicalize); 1315 finalized_type = FinalizeType(cls, type, kCanonicalize);
1289 // The parameter type may be malformed or malbounded. 1316 // The parameter type may be malformed or malbounded.
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1729 // the super class of its mixin. Note also that the other mixin 1756 // the super class of its mixin. Note also that the other mixin
1730 // application will only mixin the last mixin type listed in the first 1757 // application will only mixin the last mixin type listed in the first
1731 // mixin application it is mixing in. 1758 // mixin application it is mixing in.
1732 param_bound = thread->isolate()->object_store()->object_type(); 1759 param_bound = thread->isolate()->object_store()->object_type();
1733 for (intptr_t i = 0; i < num_super_type_params; i++) { 1760 for (intptr_t i = 0; i < num_super_type_params; i++) {
1734 param ^= super_type_params.TypeAt(i); 1761 param ^= super_type_params.TypeAt(i);
1735 param_name = param.name(); 1762 param_name = param.name();
1736 param_name = 1763 param_name =
1737 Symbols::FromConcat(thread, param_name, Symbols::Backtick()); 1764 Symbols::FromConcat(thread, param_name, Symbols::Backtick());
1738 cloned_param = 1765 cloned_param =
1739 TypeParameter::New(mixin_app_class, null_function, cloned_index, 1766 TypeParameter::New(mixin_app_class, null_function, cloned_index, 0,
1740 param_name, param_bound, param.token_pos()); 1767 param_name, param_bound, param.token_pos());
1741 cloned_type_params.SetTypeAt(cloned_index, cloned_param); 1768 cloned_type_params.SetTypeAt(cloned_index, cloned_param);
1742 // Change the type arguments of the super type to refer to the 1769 // Change the type arguments of the super type to refer to the
1743 // cloned type parameters of the mixin application class. 1770 // cloned type parameters of the mixin application class.
1744 super_type_args.SetTypeAt(cloned_index, cloned_param); 1771 super_type_args.SetTypeAt(cloned_index, cloned_param);
1745 cloned_index++; 1772 cloned_index++;
1746 } 1773 }
1747 // The super type may have a BoundedType as type argument, but cannot be 1774 // The super type may have a BoundedType as type argument, but cannot be
1748 // a BoundedType itself. 1775 // a BoundedType itself.
1749 Type::Cast(super_type).set_arguments(super_type_args); 1776 Type::Cast(super_type).set_arguments(super_type_args);
(...skipping 17 matching lines...) Expand all
1767 for (intptr_t i = 0; i < num_mixin_type_params; i++) { 1794 for (intptr_t i = 0; i < num_mixin_type_params; i++) {
1768 param ^= mixin_params.TypeAt(i); 1795 param ^= mixin_params.TypeAt(i);
1769 param_name = param.name(); 1796 param_name = param.name();
1770 param_bound = param.bound(); // The bound will be adjusted below. 1797 param_bound = param.bound(); // The bound will be adjusted below.
1771 if (!param_bound.IsInstantiated()) { 1798 if (!param_bound.IsInstantiated()) {
1772 has_uninstantiated_bounds = true; 1799 has_uninstantiated_bounds = true;
1773 } 1800 }
1774 cloned_param = 1801 cloned_param =
1775 TypeParameter::New(mixin_app_class, null_function, 1802 TypeParameter::New(mixin_app_class, null_function,
1776 cloned_index, // Unfinalized index. 1803 cloned_index, // Unfinalized index.
1777 param_name, param_bound, param.token_pos()); 1804 0, param_name, param_bound, param.token_pos());
1778 cloned_type_params.SetTypeAt(cloned_index, cloned_param); 1805 cloned_type_params.SetTypeAt(cloned_index, cloned_param);
1779 mixin_type_args.SetTypeAt(i, cloned_param); // Unfinalized length. 1806 mixin_type_args.SetTypeAt(i, cloned_param); // Unfinalized length.
1780 instantiator.SetTypeAt(offset + i, cloned_param); // Finalized length. 1807 instantiator.SetTypeAt(offset + i, cloned_param); // Finalized length.
1781 cloned_index++; 1808 cloned_index++;
1782 } 1809 }
1783 1810
1784 // Third, replace the type parameters appearing in the bounds of the mixin 1811 // Third, replace the type parameters appearing in the bounds of the mixin
1785 // type parameters, if any, by the cloned type parameters. This can be 1812 // type parameters, if any, by the cloned type parameters. This can be
1786 // done by instantiating each bound using the instantiator built above. 1813 // done by instantiating each bound using the instantiator built above.
1787 // If the mixin class extends a generic super class, its first finalized 1814 // If the mixin class extends a generic super class, its first finalized
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after
3408 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); 3435 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields());
3409 field ^= fields_array.At(0); 3436 field ^= fields_array.At(0);
3410 ASSERT(field.Offset() == ByteBuffer::data_offset()); 3437 ASSERT(field.Offset() == ByteBuffer::data_offset());
3411 name ^= field.name(); 3438 name ^= field.name();
3412 expected_name ^= String::New("_data"); 3439 expected_name ^= String::New("_data");
3413 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); 3440 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name));
3414 #endif 3441 #endif
3415 } 3442 }
3416 3443
3417 } // namespace dart 3444 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/kernel_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698