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

Side by Side Diff: pkg/compiler/lib/src/universe/world_builder.dart

Issue 2609063002: Further reduce use of Element in codegen. (Closed)
Patch Set: Created 3 years, 11 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 | « pkg/compiler/lib/src/universe/use.dart ('k') | tests/compiler/dart2js/patch_test.dart » ('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 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';
11 import '../common/backend_api.dart' show Backend; 11 import '../common/backend_api.dart' show Backend;
12 import '../common/names.dart' show Identifiers; 12 import '../common/names.dart' show Identifiers;
13 import '../common/resolution.dart' show Resolution; 13 import '../common/resolution.dart' show Resolution;
14 import '../compiler.dart' show Compiler; 14 import '../compiler.dart' show Compiler;
15 import '../core_types.dart'; 15 import '../core_types.dart';
16 import '../dart_types.dart'; 16 import '../dart_types.dart';
17 import '../elements/elements.dart'; 17 import '../elements/elements.dart';
18 import '../elements/entities.dart'; 18 import '../elements/entities.dart';
19 import '../universe/class_set.dart'; 19 import '../universe/class_set.dart';
20 import '../universe/function_set.dart' show FunctionSetBuilder; 20 import '../universe/function_set.dart' show FunctionSetBuilder;
21 import '../util/enumset.dart'; 21 import '../util/enumset.dart';
22 import '../util/util.dart'; 22 import '../util/util.dart';
23 import '../world.dart' show World, ClosedWorld, ClosedWorldImpl, OpenWorld; 23 import '../world.dart' show World, ClosedWorld, ClosedWorldImpl, OpenWorld;
24 import 'call_structure.dart' show CallStructure;
24 import 'selector.dart' show Selector; 25 import 'selector.dart' show Selector;
25 import 'use.dart' show DynamicUse, DynamicUseKind, StaticUse, StaticUseKind; 26 import 'use.dart' show DynamicUse, DynamicUseKind, StaticUse, StaticUseKind;
26 27
27 /// The known constraint on receiver for a dynamic call site. 28 /// The known constraint on receiver for a dynamic call site.
28 /// 29 ///
29 /// This can for instance be used to constrain this dynamic call to `foo` to 30 /// This can for instance be used to constrain this dynamic call to `foo` to
30 /// 'receivers of the exact instance `Bar`': 31 /// 'receivers of the exact instance `Bar`':
31 /// 32 ///
32 /// class Bar { 33 /// class Bar {
33 /// void foo() {} 34 /// void foo() {}
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 ClosedWorld get closedWorldCache { 1097 ClosedWorld get closedWorldCache {
1097 assert(isClosed); 1098 assert(isClosed);
1098 return _closedWorldCache; 1099 return _closedWorldCache;
1099 } 1100 }
1100 } 1101 }
1101 1102
1102 /// World builder specific to codegen. 1103 /// World builder specific to codegen.
1103 /// 1104 ///
1104 /// This adds additional access to liveness of selectors and elements. 1105 /// This adds additional access to liveness of selectors and elements.
1105 abstract class CodegenWorldBuilder implements WorldBuilder { 1106 abstract class CodegenWorldBuilder implements WorldBuilder {
1107 /// Calls [f] with every instance field, together with its declarer, in an
1108 /// instance of [cls].
1109 void forEachInstanceField(
Siggi Cherem (dart-lang) 2017/01/03 17:39:37 I like the move of this out of the entities. Coup
Johnni Winther 2017/01/04 10:39:49 Currently all, in time it should be at the world b
1110 ClassEntity cls, void f(ClassEntity declarer, FieldEntity field));
1111
1106 void forEachInvokedName( 1112 void forEachInvokedName(
1107 f(String name, Map<Selector, SelectorConstraints> selectors)); 1113 f(String name, Map<Selector, SelectorConstraints> selectors));
1108 1114
1109 void forEachInvokedGetter( 1115 void forEachInvokedGetter(
1110 f(String name, Map<Selector, SelectorConstraints> selectors)); 1116 f(String name, Map<Selector, SelectorConstraints> selectors));
1111 1117
1112 void forEachInvokedSetter( 1118 void forEachInvokedSetter(
1113 f(String name, Map<Selector, SelectorConstraints> selectors)); 1119 f(String name, Map<Selector, SelectorConstraints> selectors));
1114 1120
1115 /// Returns `true` if [member] is invoked as a setter. 1121 /// Returns `true` if [member] is invoked as a setter.
1116 bool hasInvokedSetter(Element member, ClosedWorld world); 1122 bool hasInvokedSetter(Element member, ClosedWorld world);
1117 1123
1118 bool hasInvokedGetter(Element member, ClosedWorld world); 1124 bool hasInvokedGetter(Element member, ClosedWorld world);
1119 1125
1120 Map<Selector, SelectorConstraints> invocationsByName(String name); 1126 Map<Selector, SelectorConstraints> invocationsByName(String name);
1121 1127
1122 Map<Selector, SelectorConstraints> getterInvocationsByName(String name); 1128 Map<Selector, SelectorConstraints> getterInvocationsByName(String name);
1123 1129
1124 Map<Selector, SelectorConstraints> setterInvocationsByName(String name); 1130 Map<Selector, SelectorConstraints> setterInvocationsByName(String name);
1125 1131
1126 Iterable<FunctionElement> get staticFunctionsNeedingGetter; 1132 Iterable<FunctionElement> get staticFunctionsNeedingGetter;
1127 Iterable<FunctionElement> get methodsNeedingSuperGetter; 1133 Iterable<FunctionElement> get methodsNeedingSuperGetter;
1128 1134
1129 /// The set of all referenced static fields. 1135 /// The set of all referenced static fields.
1130 /// 1136 ///
1131 /// Invariant: Elements are declaration elements. 1137 /// Invariant: Elements are declaration elements.
1132 Iterable<FieldElement> get allReferencedStaticFields; 1138 Iterable<FieldElement> get allReferencedStaticFields;
1139
1140 CallStructure getCallStructureFor(FunctionEntity entity);
1133 } 1141 }
1134 1142
1135 class CodegenWorldBuilderImpl implements CodegenWorldBuilder { 1143 class CodegenWorldBuilderImpl implements CodegenWorldBuilder {
1136 final Backend _backend; 1144 final Backend _backend;
1137 1145
1138 /// The set of all directly instantiated classes, that is, classes with a 1146 /// The set of all directly instantiated classes, that is, classes with a
1139 /// generative constructor that has been called directly and not only through 1147 /// generative constructor that has been called directly and not only through
1140 /// a super-call. 1148 /// a super-call.
1141 /// 1149 ///
1142 /// Invariant: Elements are declaration elements. 1150 /// Invariant: Elements are declaration elements.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 /// closurized. 1203 /// closurized.
1196 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName = 1204 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName =
1197 <String, Set<_MemberUsage>>{}; 1205 <String, Set<_MemberUsage>>{};
1198 1206
1199 final Set<DartType> isChecks = new Set<DartType>(); 1207 final Set<DartType> isChecks = new Set<DartType>();
1200 1208
1201 final SelectorConstraintsStrategy selectorConstraintsStrategy; 1209 final SelectorConstraintsStrategy selectorConstraintsStrategy;
1202 1210
1203 CodegenWorldBuilderImpl(this._backend, this.selectorConstraintsStrategy); 1211 CodegenWorldBuilderImpl(this._backend, this.selectorConstraintsStrategy);
1204 1212
1213 /// Calls [f] with every instance field, together with its declarer, in an
1214 /// instance of [cls].
1215 void forEachInstanceField(
1216 ClassElement cls, void f(ClassEntity declarer, FieldEntity field)) {
1217 cls.implementation
1218 .forEachInstanceField(f, includeSuperAndInjectedMembers: true);
1219 }
1220
1221 CallStructure getCallStructureFor(MethodElement element) {
1222 return new CallStructure.unnamed(element.parameters.length);
1223 }
1224
1205 // TODO(johnniwinther): Remove this hack: 1225 // TODO(johnniwinther): Remove this hack:
1206 ClosedWorld get _world => 1226 ClosedWorld get _world =>
1207 _backend.compiler.resolverWorld.closedWorldForTesting; 1227 _backend.compiler.resolverWorld.closedWorldForTesting;
1208 1228
1209 Iterable<ClassElement> get processedClasses => _processedClasses.keys 1229 Iterable<ClassElement> get processedClasses => _processedClasses.keys
1210 .where((cls) => _processedClasses[cls].isInstantiated); 1230 .where((cls) => _processedClasses[cls].isInstantiated);
1211 1231
1212 /// All directly instantiated classes, that is, classes with a generative 1232 /// All directly instantiated classes, that is, classes with a generative
1213 /// constructor that has been called directly and not only through a 1233 /// constructor that has been called directly and not only through a
1214 /// super-call. 1234 /// super-call.
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1939 @override 1959 @override
1940 EnumSet<MemberUse> get _originalUse => MemberUses.ALL_STATIC; 1960 EnumSet<MemberUse> get _originalUse => MemberUses.ALL_STATIC;
1941 } 1961 }
1942 1962
1943 void removeFromSet(Map<String, Set<_MemberUsage>> map, Element element) { 1963 void removeFromSet(Map<String, Set<_MemberUsage>> map, Element element) {
1944 Set<_MemberUsage> set = map[element.name]; 1964 Set<_MemberUsage> set = map[element.name];
1945 if (set == null) return; 1965 if (set == null) return;
1946 set.removeAll( 1966 set.removeAll(
1947 set.where((_MemberUsage usage) => usage.entity == element).toList()); 1967 set.where((_MemberUsage usage) => usage.entity == element).toList());
1948 } 1968 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/universe/use.dart ('k') | tests/compiler/dart2js/patch_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698