| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 kernel.tree_shaker; | 5 library kernel.tree_shaker; |
| 6 | 6 |
| 7 import '../ast.dart'; | 7 import '../ast.dart'; |
| 8 import '../class_hierarchy.dart'; | 8 import '../class_hierarchy.dart'; |
| 9 import '../core_types.dart'; | 9 import '../core_types.dart'; |
| 10 import '../type_environment.dart'; | 10 import '../type_environment.dart'; |
| (...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 // for external purposes. | 1049 // for external purposes. |
| 1050 // TODO(asgerf): Variance analysis might pay off for other external APIs. | 1050 // TODO(asgerf): Variance analysis might pay off for other external APIs. |
| 1051 if (isWhitelistedCovariant(node.classNode)) { | 1051 if (isWhitelistedCovariant(node.classNode)) { |
| 1052 visitCovariant(typeArgument); | 1052 visitCovariant(typeArgument); |
| 1053 } else { | 1053 } else { |
| 1054 visitInvariant(typeArgument); | 1054 visitInvariant(typeArgument); |
| 1055 } | 1055 } |
| 1056 } | 1056 } |
| 1057 } | 1057 } |
| 1058 | 1058 |
| 1059 visitTypedefType(TypedefType node) { |
| 1060 throw 'TypedefType is not implemented in tree shaker'; |
| 1061 } |
| 1062 |
| 1059 visitFunctionType(FunctionType node) { | 1063 visitFunctionType(FunctionType node) { |
| 1060 visit(node.returnType); | 1064 visit(node.returnType); |
| 1061 for (int i = 0; i < node.positionalParameters.length; ++i) { | 1065 for (int i = 0; i < node.positionalParameters.length; ++i) { |
| 1062 visitContravariant(node.positionalParameters[i]); | 1066 visitContravariant(node.positionalParameters[i]); |
| 1063 } | 1067 } |
| 1064 for (int i = 0; i < node.namedParameters.length; ++i) { | 1068 for (int i = 0; i < node.namedParameters.length; ++i) { |
| 1065 visitContravariant(node.namedParameters[i].type); | 1069 visitContravariant(node.namedParameters[i].type); |
| 1066 } | 1070 } |
| 1067 } | 1071 } |
| 1068 | 1072 |
| 1069 visitTypeParameterType(TypeParameterType node) {} | 1073 visitTypeParameterType(TypeParameterType node) {} |
| 1070 | 1074 |
| 1071 /// Just treat a couple of whitelisted classes as having covariant type | 1075 /// Just treat a couple of whitelisted classes as having covariant type |
| 1072 /// parameters. | 1076 /// parameters. |
| 1073 bool isWhitelistedCovariant(Class classNode) { | 1077 bool isWhitelistedCovariant(Class classNode) { |
| 1074 if (classNode.typeParameters.isEmpty) return false; | 1078 if (classNode.typeParameters.isEmpty) return false; |
| 1075 CoreTypes coreTypes = shaker.coreTypes; | 1079 CoreTypes coreTypes = shaker.coreTypes; |
| 1076 return classNode == coreTypes.iteratorClass || | 1080 return classNode == coreTypes.iteratorClass || |
| 1077 classNode == coreTypes.iterableClass || | 1081 classNode == coreTypes.iterableClass || |
| 1078 classNode == coreTypes.futureClass || | 1082 classNode == coreTypes.futureClass || |
| 1079 classNode == coreTypes.streamClass || | 1083 classNode == coreTypes.streamClass || |
| 1080 classNode == coreTypes.listClass || | 1084 classNode == coreTypes.listClass || |
| 1081 classNode == coreTypes.mapClass; | 1085 classNode == coreTypes.mapClass; |
| 1082 } | 1086 } |
| 1083 } | 1087 } |
| 1084 | 1088 |
| 1085 /// Exception that is thrown to stop the tree shaking analysis when a use | 1089 /// Exception that is thrown to stop the tree shaking analysis when a use |
| 1086 /// of `dart:mirrors` is found. | 1090 /// of `dart:mirrors` is found. |
| 1087 class _UsingMirrorsException {} | 1091 class _UsingMirrorsException {} |
| OLD | NEW |