Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 library universe; | 5 library universe; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import '../cache_strategy.dart'; | 9 import '../cache_strategy.dart'; |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 this.cacheStrategy = cacheStrategy, | 491 this.cacheStrategy = cacheStrategy, |
| 492 alreadyPopulated = cacheStrategy.newSet() { | 492 alreadyPopulated = cacheStrategy.newSet() { |
| 493 _allFunctions = new FunctionSetBuilder(); | 493 _allFunctions = new FunctionSetBuilder(); |
| 494 } | 494 } |
| 495 | 495 |
| 496 Iterable<ClassElement> get processedClasses => _processedClasses.keys | 496 Iterable<ClassElement> get processedClasses => _processedClasses.keys |
| 497 .where((cls) => _processedClasses[cls].isInstantiated); | 497 .where((cls) => _processedClasses[cls].isInstantiated); |
| 498 | 498 |
| 499 CommonElements get commonElements => _resolution.commonElements; | 499 CommonElements get commonElements => _resolution.commonElements; |
| 500 | 500 |
| 501 ClosedWorld get closedWorldForTesting { | 501 ClosedWorld get closedWorldForTesting { |
|
Siggi Cherem (dart-lang)
2017/01/03 17:46:08
do we still need this for testing, or should we be
Johnni Winther
2017/01/04 09:11:20
We still need it (kernel/closed_world_test). The C
| |
| 502 if (!_closed) { | 502 if (!_closed) { |
| 503 throw new SpannableAssertionFailure( | 503 throw new SpannableAssertionFailure( |
| 504 NO_LOCATION_SPANNABLE, "The world builder has not yet been closed."); | 504 NO_LOCATION_SPANNABLE, "The world builder has not yet been closed."); |
| 505 } | 505 } |
| 506 return _closedWorldCache; | 506 return _closedWorldCache; |
| 507 } | 507 } |
| 508 | 508 |
| 509 /// All directly instantiated classes, that is, classes with a generative | 509 /// All directly instantiated classes, that is, classes with a generative |
| 510 /// constructor that has been called directly and not only through a | 510 /// constructor that has been called directly and not only through a |
| 511 /// super-call. | 511 /// super-call. |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1096 ClosedWorld get closedWorldCache { | 1096 ClosedWorld get closedWorldCache { |
| 1097 assert(isClosed); | 1097 assert(isClosed); |
| 1098 return _closedWorldCache; | 1098 return _closedWorldCache; |
| 1099 } | 1099 } |
| 1100 } | 1100 } |
| 1101 | 1101 |
| 1102 /// World builder specific to codegen. | 1102 /// World builder specific to codegen. |
| 1103 /// | 1103 /// |
| 1104 /// This adds additional access to liveness of selectors and elements. | 1104 /// This adds additional access to liveness of selectors and elements. |
| 1105 abstract class CodegenWorldBuilder implements WorldBuilder { | 1105 abstract class CodegenWorldBuilder implements WorldBuilder { |
| 1106 /// Opens this world builder using [closedWorld] as the known superset of | |
| 1107 /// possible runtime entities. | |
| 1108 void open(ClosedWorld closedWorld); | |
| 1109 | |
| 1106 void forEachInvokedName( | 1110 void forEachInvokedName( |
| 1107 f(String name, Map<Selector, SelectorConstraints> selectors)); | 1111 f(String name, Map<Selector, SelectorConstraints> selectors)); |
| 1108 | 1112 |
| 1109 void forEachInvokedGetter( | 1113 void forEachInvokedGetter( |
| 1110 f(String name, Map<Selector, SelectorConstraints> selectors)); | 1114 f(String name, Map<Selector, SelectorConstraints> selectors)); |
| 1111 | 1115 |
| 1112 void forEachInvokedSetter( | 1116 void forEachInvokedSetter( |
| 1113 f(String name, Map<Selector, SelectorConstraints> selectors)); | 1117 f(String name, Map<Selector, SelectorConstraints> selectors)); |
| 1114 | 1118 |
| 1115 /// Returns `true` if [member] is invoked as a setter. | 1119 /// Returns `true` if [member] is invoked as a setter. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1127 Iterable<FunctionElement> get methodsNeedingSuperGetter; | 1131 Iterable<FunctionElement> get methodsNeedingSuperGetter; |
| 1128 | 1132 |
| 1129 /// The set of all referenced static fields. | 1133 /// The set of all referenced static fields. |
| 1130 /// | 1134 /// |
| 1131 /// Invariant: Elements are declaration elements. | 1135 /// Invariant: Elements are declaration elements. |
| 1132 Iterable<FieldElement> get allReferencedStaticFields; | 1136 Iterable<FieldElement> get allReferencedStaticFields; |
| 1133 } | 1137 } |
| 1134 | 1138 |
| 1135 class CodegenWorldBuilderImpl implements CodegenWorldBuilder { | 1139 class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
| 1136 final Backend _backend; | 1140 final Backend _backend; |
| 1141 ClosedWorld __world; | |
|
Siggi Cherem (dart-lang)
2017/01/03 17:46:08
I guess this is really really private ;-)
| |
| 1137 | 1142 |
| 1138 /// The set of all directly instantiated classes, that is, classes with a | 1143 /// The set of all directly instantiated classes, that is, classes with a |
| 1139 /// generative constructor that has been called directly and not only through | 1144 /// generative constructor that has been called directly and not only through |
| 1140 /// a super-call. | 1145 /// a super-call. |
| 1141 /// | 1146 /// |
| 1142 /// Invariant: Elements are declaration elements. | 1147 /// Invariant: Elements are declaration elements. |
| 1143 // TODO(johnniwinther): [_directlyInstantiatedClasses] and | 1148 // TODO(johnniwinther): [_directlyInstantiatedClasses] and |
| 1144 // [_instantiatedTypes] sets should be merged. | 1149 // [_instantiatedTypes] sets should be merged. |
| 1145 final Set<ClassElement> _directlyInstantiatedClasses = | 1150 final Set<ClassElement> _directlyInstantiatedClasses = |
| 1146 new Set<ClassElement>(); | 1151 new Set<ClassElement>(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1195 /// closurized. | 1200 /// closurized. |
| 1196 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName = | 1201 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName = |
| 1197 <String, Set<_MemberUsage>>{}; | 1202 <String, Set<_MemberUsage>>{}; |
| 1198 | 1203 |
| 1199 final Set<DartType> isChecks = new Set<DartType>(); | 1204 final Set<DartType> isChecks = new Set<DartType>(); |
| 1200 | 1205 |
| 1201 final SelectorConstraintsStrategy selectorConstraintsStrategy; | 1206 final SelectorConstraintsStrategy selectorConstraintsStrategy; |
| 1202 | 1207 |
| 1203 CodegenWorldBuilderImpl(this._backend, this.selectorConstraintsStrategy); | 1208 CodegenWorldBuilderImpl(this._backend, this.selectorConstraintsStrategy); |
| 1204 | 1209 |
| 1205 // TODO(johnniwinther): Remove this hack: | 1210 void open(ClosedWorld closedWorld) { |
| 1206 ClosedWorld get _world => | 1211 assert(invariant(NO_LOCATION_SPANNABLE, __world == null, |
| 1207 _backend.compiler.resolverWorld.closedWorldForTesting; | 1212 message: "CodegenWorldBuilder has already been opened.")); |
| 1213 __world = closedWorld; | |
| 1214 } | |
| 1215 | |
| 1216 ClosedWorld get _world { | |
| 1217 assert(invariant(NO_LOCATION_SPANNABLE, __world != null, | |
| 1218 message: "CodegenWorldBuilder has not been opened.")); | |
| 1219 return __world; | |
| 1220 } | |
| 1208 | 1221 |
| 1209 Iterable<ClassElement> get processedClasses => _processedClasses.keys | 1222 Iterable<ClassElement> get processedClasses => _processedClasses.keys |
| 1210 .where((cls) => _processedClasses[cls].isInstantiated); | 1223 .where((cls) => _processedClasses[cls].isInstantiated); |
| 1211 | 1224 |
| 1212 /// All directly instantiated classes, that is, classes with a generative | 1225 /// All directly instantiated classes, that is, classes with a generative |
| 1213 /// constructor that has been called directly and not only through a | 1226 /// constructor that has been called directly and not only through a |
| 1214 /// super-call. | 1227 /// super-call. |
| 1215 // TODO(johnniwinther): Improve semantic precision. | 1228 // TODO(johnniwinther): Improve semantic precision. |
| 1216 Iterable<ClassElement> get directlyInstantiatedClasses { | 1229 Iterable<ClassElement> get directlyInstantiatedClasses { |
| 1217 return _directlyInstantiatedClasses; | 1230 return _directlyInstantiatedClasses; |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1939 @override | 1952 @override |
| 1940 EnumSet<MemberUse> get _originalUse => MemberUses.ALL_STATIC; | 1953 EnumSet<MemberUse> get _originalUse => MemberUses.ALL_STATIC; |
| 1941 } | 1954 } |
| 1942 | 1955 |
| 1943 void removeFromSet(Map<String, Set<_MemberUsage>> map, Element element) { | 1956 void removeFromSet(Map<String, Set<_MemberUsage>> map, Element element) { |
| 1944 Set<_MemberUsage> set = map[element.name]; | 1957 Set<_MemberUsage> set = map[element.name]; |
| 1945 if (set == null) return; | 1958 if (set == null) return; |
| 1946 set.removeAll( | 1959 set.removeAll( |
| 1947 set.where((_MemberUsage usage) => usage.entity == element).toList()); | 1960 set.where((_MemberUsage usage) => usage.entity == element).toList()); |
| 1948 } | 1961 } |
| OLD | NEW |