OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library analyzer.src.generated.type_system; | 5 library analyzer.src.generated.type_system; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
9 | 9 |
10 import 'package:analyzer/dart/ast/token.dart' show TokenType; | 10 import 'package:analyzer/dart/ast/token.dart' show TokenType; |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 * 2. If the first type is a type parameter, replace it with its bound, | 745 * 2. If the first type is a type parameter, replace it with its bound, |
746 * with recursive occurrences of itself replaced with Object. | 746 * with recursive occurrences of itself replaced with Object. |
747 * The second part of this should ensure termination. Informally, | 747 * The second part of this should ensure termination. Informally, |
748 * each type variable instantiation in one of the arguments to the | 748 * each type variable instantiation in one of the arguments to the |
749 * least upper bound algorithm now strictly reduces the number | 749 * least upper bound algorithm now strictly reduces the number |
750 * of bound variables in scope in that argument position. | 750 * of bound variables in scope in that argument position. |
751 * 3. If the second type is a type parameter, do the symmetric operation | 751 * 3. If the second type is a type parameter, do the symmetric operation |
752 * to #2. | 752 * to #2. |
753 * | 753 * |
754 * It's not immediately obvious why this is symmetric in the case that both | 754 * It's not immediately obvious why this is symmetric in the case that both |
755 * of the them are type parameters. For #1, symmetry holds since subtype | 755 * of them are type parameters. For #1, symmetry holds since subtype |
756 * is antisymmetric. For #2, it's clearly not symmetric if upper bounds of | 756 * is antisymmetric. For #2, it's clearly not symmetric if upper bounds of |
757 * bottom are allowed. Ignoring this (for various reasons, not least | 757 * bottom are allowed. Ignoring this (for various reasons, not least |
758 * of which that there's no way to write it), there's an informal | 758 * of which that there's no way to write it), there's an informal |
759 * argument (that might even be right) that you will always either | 759 * argument (that might even be right) that you will always either |
760 * end up expanding both of them or else returning the same result no matter | 760 * end up expanding both of them or else returning the same result no matter |
761 * which order you expand them in. A key observation is that | 761 * which order you expand them in. A key observation is that |
762 * identical(expand(type1), type2) => subtype(type1, type2) | 762 * identical(expand(type1), type2) => subtype(type1, type2) |
763 * and hence the contra-positive. | 763 * and hence the contra-positive. |
764 * | 764 * |
765 * TODO(leafp): Think this through and figure out what's the right | 765 * TODO(leafp): Think this through and figure out what's the right |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1423 /// Func<TIn> method<TIn>(TIn t); | 1423 /// Func<TIn> method<TIn>(TIn t); |
1424 bool passedIn = false; | 1424 bool passedIn = false; |
1425 | 1425 |
1426 _TypeParameterVariance.from(TypeParameterType typeParam, DartType type) { | 1426 _TypeParameterVariance.from(TypeParameterType typeParam, DartType type) { |
1427 _visitType(typeParam, type, false); | 1427 _visitType(typeParam, type, false); |
1428 } | 1428 } |
1429 | 1429 |
1430 void _visitFunctionType( | 1430 void _visitFunctionType( |
1431 TypeParameterType typeParam, FunctionType type, bool paramIn) { | 1431 TypeParameterType typeParam, FunctionType type, bool paramIn) { |
1432 for (ParameterElement p in type.parameters) { | 1432 for (ParameterElement p in type.parameters) { |
1433 // If a lambda L is passed in to a function F, the the parameters are | 1433 // If a lambda L is passed in to a function F, the parameters are |
1434 // "passed out" of F into L. Thus we invert the "passedIn" state. | 1434 // "passed out" of F into L. Thus we invert the "passedIn" state. |
1435 _visitType(typeParam, p.type, !paramIn); | 1435 _visitType(typeParam, p.type, !paramIn); |
1436 } | 1436 } |
1437 // If a lambda L is passed in to a function F, and we call L, the result of | 1437 // If a lambda L is passed in to a function F, and we call L, the result of |
1438 // L is then "passed in" to F. So we keep the "passedIn" state. | 1438 // L is then "passed in" to F. So we keep the "passedIn" state. |
1439 _visitType(typeParam, type.returnType, paramIn); | 1439 _visitType(typeParam, type.returnType, paramIn); |
1440 } | 1440 } |
1441 | 1441 |
1442 void _visitInterfaceType( | 1442 void _visitInterfaceType( |
1443 TypeParameterType typeParam, InterfaceType type, bool paramIn) { | 1443 TypeParameterType typeParam, InterfaceType type, bool paramIn) { |
(...skipping 17 matching lines...) Expand all Loading... |
1461 } else { | 1461 } else { |
1462 passedOut = true; | 1462 passedOut = true; |
1463 } | 1463 } |
1464 } else if (type is FunctionType) { | 1464 } else if (type is FunctionType) { |
1465 _visitFunctionType(typeParam, type, paramIn); | 1465 _visitFunctionType(typeParam, type, paramIn); |
1466 } else if (type is InterfaceType) { | 1466 } else if (type is InterfaceType) { |
1467 _visitInterfaceType(typeParam, type, paramIn); | 1467 _visitInterfaceType(typeParam, type, paramIn); |
1468 } | 1468 } |
1469 } | 1469 } |
1470 } | 1470 } |
OLD | NEW |