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

Side by Side Diff: pkg/compiler/lib/src/world.dart

Issue 2860733002: Remove ClosedWorld.allFunctions (Closed)
Patch Set: Created 3 years, 7 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
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 dart2js.world; 5 library dart2js.world;
6 6
7 import 'closure.dart' show ClosureClassElement, SynthesizedCallMethodElementX; 7 import 'closure.dart' show ClosureClassElement, SynthesizedCallMethodElementX;
8 import 'common.dart'; 8 import 'common.dart';
9 import 'constants/constant_system.dart'; 9 import 'constants/constant_system.dart';
10 import 'common_elements.dart' show CommonElements; 10 import 'common_elements.dart' show CommonElements;
11 import 'elements/entities.dart'; 11 import 'elements/entities.dart';
12 import 'elements/elements.dart' 12 import 'elements/elements.dart'
13 show 13 show
14 ClassElement, 14 ClassElement,
15 Element, 15 Element,
16 MemberElement, 16 MemberElement,
17 MixinApplicationElement, 17 MixinApplicationElement,
18 TypedefElement; 18 TypedefElement;
19 import 'elements/resolution_types.dart'; 19 import 'elements/resolution_types.dart';
20 import 'elements/types.dart'; 20 import 'elements/types.dart';
21 import 'js_backend/backend_usage.dart' show BackendUsage; 21 import 'js_backend/backend_usage.dart' show BackendUsage;
22 import 'js_backend/interceptor_data.dart' show InterceptorData; 22 import 'js_backend/interceptor_data.dart' show InterceptorData;
23 import 'js_backend/native_data.dart' show NativeData; 23 import 'js_backend/native_data.dart' show NativeData;
24 import 'ordered_typeset.dart'; 24 import 'ordered_typeset.dart';
25 import 'types/masks.dart' show CommonMasks, FlatTypeMask, TypeMask; 25 import 'types/masks.dart' show CommonMasks, FlatTypeMask, TypeMask;
26 import 'universe/class_set.dart'; 26 import 'universe/class_set.dart';
27 import 'universe/function_set.dart' show FunctionSet, FunctionSetBuilder; 27 import 'universe/function_set.dart' show FunctionSet;
28 import 'universe/selector.dart' show Selector; 28 import 'universe/selector.dart' show Selector;
29 import 'universe/side_effects.dart' show SideEffects; 29 import 'universe/side_effects.dart' show SideEffects;
30 import 'universe/world_builder.dart' show ResolutionWorldBuilder; 30 import 'universe/world_builder.dart' show ResolutionWorldBuilder;
31 import 'util/util.dart' show Link; 31 import 'util/util.dart' show Link;
32 32
33 /// Common superinterface for [OpenWorld] and [ClosedWorld]. 33 /// Common superinterface for [OpenWorld] and [ClosedWorld].
34 abstract class World {} 34 abstract class World {}
35 35
36 /// The [ClosedWorld] represents the information known about a program when 36 /// The [ClosedWorld] represents the information known about a program when
37 /// compiling with closed-world semantics. 37 /// compiling with closed-world semantics.
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 /// 263 ///
264 /// This method is only provided for testing. For queries on classes, use the 264 /// This method is only provided for testing. For queries on classes, use the
265 /// methods defined in [ClosedWorld]. 265 /// methods defined in [ClosedWorld].
266 ClassSet getClassSet(ClassEntity cls); 266 ClassSet getClassSet(ClassEntity cls);
267 267
268 /// Return the cached mask for [base] with the given flags, or 268 /// Return the cached mask for [base] with the given flags, or
269 /// calls [createMask] to create the mask and cache it. 269 /// calls [createMask] to create the mask and cache it.
270 // TODO(johnniwinther): Find a better strategy for caching these? 270 // TODO(johnniwinther): Find a better strategy for caching these?
271 TypeMask getCachedMask(ClassEntity base, int flags, TypeMask createMask()); 271 TypeMask getCachedMask(ClassEntity base, int flags, TypeMask createMask());
272 272
273 /// Returns the [FunctionSet] containing all live functions in the closed
274 /// world.
275 FunctionSet get allFunctions;
276
277 /// Returns `true` if the field [element] is known to be effectively final. 273 /// Returns `true` if the field [element] is known to be effectively final.
278 bool fieldNeverChanges(MemberEntity element); 274 bool fieldNeverChanges(MemberEntity element);
279 275
280 /// Extends the receiver type [mask] for calling [selector] to take live 276 /// Extends the receiver type [mask] for calling [selector] to take live
281 /// `noSuchMethod` handlers into account. 277 /// `noSuchMethod` handlers into account.
282 TypeMask extendMaskIfReachesAll(Selector selector, TypeMask mask); 278 TypeMask extendMaskIfReachesAll(Selector selector, TypeMask mask);
283 279
284 /// Returns all resolved typedefs. 280 /// Returns all resolved typedefs.
285 Iterable<TypedefElement> get allTypedefs; 281 Iterable<TypedefElement> get allTypedefs;
286 282
287 /// Returns the single [Element] that matches a call to [selector] on a 283 /// Returns the mask for the potential receivers of a dynamic call to
284 /// [selector] on [mask].
285 ///
286 /// This will narrow the constraints of [mask] to a [TypeMask] of the
287 /// set of classes that actually implement the selected member or implement
288 /// the handling 'noSuchMethod' where the selected member is unimplemented.
289 TypeMask computeReceiverType(Selector selector, TypeMask mask);
290
291 /// Returns all the instance members that may be invoked with the
292 /// [selector] on a receiver with the given [mask]. The returned elements may
293 /// include noSuchMethod handlers that are potential targets indirectly
294 /// through the noSuchMethod mechanism.
295 Iterable<MemberEntity> locateMembers(Selector selector, TypeMask mask);
296
297 /// Returns the single [MemberEntity] that matches a call to [selector] on a
288 /// receiver of type [mask]. If multiple targets exist, `null` is returned. 298 /// receiver of type [mask]. If multiple targets exist, `null` is returned.
289 MemberEntity locateSingleElement(Selector selector, TypeMask mask); 299 MemberEntity locateSingleElement(Selector selector, TypeMask mask);
290 300
291 /// Returns the single field that matches a call to [selector] on a 301 /// Returns the single field that matches a call to [selector] on a
292 /// receiver of type [mask]. If multiple targets exist or the single target 302 /// receiver of type [mask]. If multiple targets exist or the single target
293 /// is not a field, `null` is returned. 303 /// is not a field, `null` is returned.
294 FieldEntity locateSingleField(Selector selector, TypeMask mask); 304 FieldEntity locateSingleField(Selector selector, TypeMask mask);
295 305
296 /// Returns the side effects of executing [element]. 306 /// Returns the side effects of executing [element].
297 SideEffects getSideEffectsOfElement(Entity element); 307 SideEffects getSideEffectsOfElement(Entity element);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 /// are included. 392 /// are included.
383 SUBTYPE, 393 SUBTYPE,
384 } 394 }
385 395
386 abstract class ClosedWorldBase implements ClosedWorld, ClosedWorldRefiner { 396 abstract class ClosedWorldBase implements ClosedWorld, ClosedWorldRefiner {
387 final ConstantSystem constantSystem; 397 final ConstantSystem constantSystem;
388 final NativeData nativeData; 398 final NativeData nativeData;
389 final InterceptorData interceptorData; 399 final InterceptorData interceptorData;
390 final BackendUsage _backendUsage; 400 final BackendUsage _backendUsage;
391 401
392 FunctionSet _allFunctions; 402 final FunctionSet _allFunctions;
393 403
394 final Iterable<TypedefElement> _allTypedefs; 404 final Iterable<TypedefElement> _allTypedefs;
395 405
396 final Map<ClassEntity, Set<ClassEntity>> _mixinUses; 406 final Map<ClassEntity, Set<ClassEntity>> _mixinUses;
397 Map<ClassEntity, List<ClassEntity>> _liveMixinUses; 407 Map<ClassEntity, List<ClassEntity>> _liveMixinUses;
398 408
399 final Map<ClassEntity, Set<ClassEntity>> _typesImplementedBySubclasses; 409 final Map<ClassEntity, Set<ClassEntity>> _typesImplementedBySubclasses;
400 410
401 // We keep track of subtype and subclass relationships in four 411 // We keep track of subtype and subclass relationships in four
402 // distinct sets to make class hierarchy analysis faster. 412 // distinct sets to make class hierarchy analysis faster.
(...skipping 18 matching lines...) Expand all
421 431
422 final ResolutionWorldBuilder _resolverWorld; 432 final ResolutionWorldBuilder _resolverWorld;
423 433
424 ClosedWorldBase( 434 ClosedWorldBase(
425 {this.commonElements, 435 {this.commonElements,
426 this.constantSystem, 436 this.constantSystem,
427 this.nativeData, 437 this.nativeData,
428 this.interceptorData, 438 this.interceptorData,
429 BackendUsage backendUsage, 439 BackendUsage backendUsage,
430 ResolutionWorldBuilder resolutionWorldBuilder, 440 ResolutionWorldBuilder resolutionWorldBuilder,
431 FunctionSetBuilder functionSetBuilder, 441 FunctionSet functionSet,
432 Iterable<TypedefElement> allTypedefs, 442 Iterable<TypedefElement> allTypedefs,
433 Map<ClassEntity, Set<ClassEntity>> mixinUses, 443 Map<ClassEntity, Set<ClassEntity>> mixinUses,
434 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses, 444 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses,
435 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes, 445 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes,
436 Map<ClassEntity, ClassSet> classSets}) 446 Map<ClassEntity, ClassSet> classSets})
437 : this._backendUsage = backendUsage, 447 : this._backendUsage = backendUsage,
438 this._resolverWorld = resolutionWorldBuilder, 448 this._resolverWorld = resolutionWorldBuilder,
449 this._allFunctions = functionSet,
439 this._allTypedefs = allTypedefs, 450 this._allTypedefs = allTypedefs,
440 this._mixinUses = mixinUses, 451 this._mixinUses = mixinUses,
441 this._typesImplementedBySubclasses = typesImplementedBySubclasses, 452 this._typesImplementedBySubclasses = typesImplementedBySubclasses,
442 this._classHierarchyNodes = classHierarchyNodes, 453 this._classHierarchyNodes = classHierarchyNodes,
443 this._classSets = classSets { 454 this._classSets = classSets {
444 _commonMasks = new CommonMasks(this); 455 _commonMasks = new CommonMasks(this);
445 _allFunctions = functionSetBuilder.close(this);
446 } 456 }
447 457
448 @override 458 @override
449 ClosedWorld get closedWorld => this; 459 ClosedWorld get closedWorld => this;
450 460
451 /// Cache of [FlatTypeMask]s grouped by the 8 possible values of the 461 /// Cache of [FlatTypeMask]s grouped by the 8 possible values of the
452 /// `FlatTypeMask.flags` property. 462 /// `FlatTypeMask.flags` property.
453 final List<Map<ClassEntity, TypeMask>> _canonicalizedTypeMasks = 463 final List<Map<ClassEntity, TypeMask>> _canonicalizedTypeMasks =
454 new List<Map<ClassEntity, TypeMask>>.filled(8, null); 464 new List<Map<ClassEntity, TypeMask>>.filled(8, null);
455 465
456 FunctionSet get allFunctions => _allFunctions;
457
458 CommonMasks get commonMasks { 466 CommonMasks get commonMasks {
459 return _commonMasks; 467 return _commonMasks;
460 } 468 }
461 469
462 TypeMask getCachedMask(ClassEntity base, int flags, TypeMask createMask()) { 470 TypeMask getCachedMask(ClassEntity base, int flags, TypeMask createMask()) {
463 Map<ClassEntity, TypeMask> cachedMasks = 471 Map<ClassEntity, TypeMask> cachedMasks =
464 _canonicalizedTypeMasks[flags] ??= <ClassEntity, TypeMask>{}; 472 _canonicalizedTypeMasks[flags] ??= <ClassEntity, TypeMask>{};
465 return cachedMasks.putIfAbsent(base, createMask); 473 return cachedMasks.putIfAbsent(base, createMask);
466 } 474 }
467 475
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 /// 970 ///
963 /// This method is only provided for testing. For queries on classes, use the 971 /// This method is only provided for testing. For queries on classes, use the
964 /// methods defined in [ClosedWorld]. 972 /// methods defined in [ClosedWorld].
965 ClassSet getClassSet(ClassEntity cls) { 973 ClassSet getClassSet(ClassEntity cls) {
966 assert(_checkClass(cls)); 974 assert(_checkClass(cls));
967 return _classSets[cls]; 975 return _classSets[cls];
968 } 976 }
969 977
970 Iterable<TypedefElement> get allTypedefs => _allTypedefs; 978 Iterable<TypedefElement> get allTypedefs => _allTypedefs;
971 979
980 TypeMask computeReceiverType(Selector selector, TypeMask mask) {
981 return _allFunctions.receiverType(selector, mask, this);
982 }
983
984 Iterable<MemberEntity> locateMembers(Selector selector, TypeMask mask) {
985 return _allFunctions.filter(selector, mask, this);
986 }
987
972 bool hasAnyUserDefinedGetter(Selector selector, TypeMask mask) { 988 bool hasAnyUserDefinedGetter(Selector selector, TypeMask mask) {
973 return allFunctions.filter(selector, mask).any((each) => each.isGetter); 989 return _allFunctions
990 .filter(selector, mask, this)
991 .any((each) => each.isGetter);
974 } 992 }
975 993
976 FieldEntity locateSingleField(Selector selector, TypeMask mask) { 994 FieldEntity locateSingleField(Selector selector, TypeMask mask) {
977 MemberEntity result = locateSingleElement(selector, mask); 995 MemberEntity result = locateSingleElement(selector, mask);
978 return (result != null && result.isField) ? result : null; 996 return (result != null && result.isField) ? result : null;
979 } 997 }
980 998
981 MemberEntity locateSingleElement(Selector selector, TypeMask mask) { 999 MemberEntity locateSingleElement(Selector selector, TypeMask mask) {
982 mask ??= commonMasks.dynamicType; 1000 mask ??= commonMasks.dynamicType;
983 return mask.locateSingleElement(selector, this); 1001 return mask.locateSingleElement(selector, this);
(...skipping 25 matching lines...) Expand all
1009 return !_resolverWorld.hasInvokedSetter(element) && 1027 return !_resolverWorld.hasInvokedSetter(element) &&
1010 !_resolverWorld.fieldSetters.contains(element); 1028 !_resolverWorld.fieldSetters.contains(element);
1011 } 1029 }
1012 return false; 1030 return false;
1013 } 1031 }
1014 1032
1015 SideEffects getSideEffectsOfSelector(Selector selector, TypeMask mask) { 1033 SideEffects getSideEffectsOfSelector(Selector selector, TypeMask mask) {
1016 // We're not tracking side effects of closures. 1034 // We're not tracking side effects of closures.
1017 if (selector.isClosureCall) return new SideEffects(); 1035 if (selector.isClosureCall) return new SideEffects();
1018 SideEffects sideEffects = new SideEffects.empty(); 1036 SideEffects sideEffects = new SideEffects.empty();
1019 for (MemberElement e in allFunctions.filter(selector, mask)) { 1037 for (MemberElement e in _allFunctions.filter(selector, mask, this)) {
1020 if (e.isField) { 1038 if (e.isField) {
1021 if (selector.isGetter) { 1039 if (selector.isGetter) {
1022 if (!fieldNeverChanges(e)) { 1040 if (!fieldNeverChanges(e)) {
1023 sideEffects.setDependsOnInstancePropertyStore(); 1041 sideEffects.setDependsOnInstancePropertyStore();
1024 } 1042 }
1025 } else if (selector.isSetter) { 1043 } else if (selector.isSetter) {
1026 sideEffects.setChangesInstanceProperty(); 1044 sideEffects.setChangesInstanceProperty();
1027 } else { 1045 } else {
1028 assert(selector.isCall); 1046 assert(selector.isCall);
1029 sideEffects.setAllSideEffects(); 1047 sideEffects.setAllSideEffects();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 } 1135 }
1118 1136
1119 class ClosedWorldImpl extends ClosedWorldBase { 1137 class ClosedWorldImpl extends ClosedWorldBase {
1120 ClosedWorldImpl( 1138 ClosedWorldImpl(
1121 {CommonElements commonElements, 1139 {CommonElements commonElements,
1122 ConstantSystem constantSystem, 1140 ConstantSystem constantSystem,
1123 NativeData nativeData, 1141 NativeData nativeData,
1124 InterceptorData interceptorData, 1142 InterceptorData interceptorData,
1125 BackendUsage backendUsage, 1143 BackendUsage backendUsage,
1126 ResolutionWorldBuilder resolutionWorldBuilder, 1144 ResolutionWorldBuilder resolutionWorldBuilder,
1127 FunctionSetBuilder functionSetBuilder, 1145 FunctionSet functionSet,
1128 Iterable<TypedefElement> allTypedefs, 1146 Iterable<TypedefElement> allTypedefs,
1129 Map<ClassEntity, Set<ClassEntity>> mixinUses, 1147 Map<ClassEntity, Set<ClassEntity>> mixinUses,
1130 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses, 1148 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses,
1131 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes, 1149 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes,
1132 Map<ClassEntity, ClassSet> classSets}) 1150 Map<ClassEntity, ClassSet> classSets})
1133 : super( 1151 : super(
1134 commonElements: commonElements, 1152 commonElements: commonElements,
1135 constantSystem: constantSystem, 1153 constantSystem: constantSystem,
1136 nativeData: nativeData, 1154 nativeData: nativeData,
1137 interceptorData: interceptorData, 1155 interceptorData: interceptorData,
1138 backendUsage: backendUsage, 1156 backendUsage: backendUsage,
1139 resolutionWorldBuilder: resolutionWorldBuilder, 1157 resolutionWorldBuilder: resolutionWorldBuilder,
1140 functionSetBuilder: functionSetBuilder, 1158 functionSet: functionSet,
1141 allTypedefs: allTypedefs, 1159 allTypedefs: allTypedefs,
1142 mixinUses: mixinUses, 1160 mixinUses: mixinUses,
1143 typesImplementedBySubclasses: typesImplementedBySubclasses, 1161 typesImplementedBySubclasses: typesImplementedBySubclasses,
1144 classHierarchyNodes: classHierarchyNodes, 1162 classHierarchyNodes: classHierarchyNodes,
1145 classSets: classSets); 1163 classSets: classSets);
1146 1164
1147 bool _checkClass(ClassElement cls) => cls.isDeclaration; 1165 bool _checkClass(ClassElement cls) => cls.isDeclaration;
1148 1166
1149 bool _checkEntity(Element element) => element.isDeclaration; 1167 bool _checkEntity(Element element) => element.isDeclaration;
1150 1168
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 } 1281 }
1264 1282
1265 class KernelClosedWorld extends ClosedWorldBase { 1283 class KernelClosedWorld extends ClosedWorldBase {
1266 KernelClosedWorld( 1284 KernelClosedWorld(
1267 {CommonElements commonElements, 1285 {CommonElements commonElements,
1268 ConstantSystem constantSystem, 1286 ConstantSystem constantSystem,
1269 NativeData nativeData, 1287 NativeData nativeData,
1270 InterceptorData interceptorData, 1288 InterceptorData interceptorData,
1271 BackendUsage backendUsage, 1289 BackendUsage backendUsage,
1272 ResolutionWorldBuilder resolutionWorldBuilder, 1290 ResolutionWorldBuilder resolutionWorldBuilder,
1273 FunctionSetBuilder functionSetBuilder, 1291 FunctionSet functionSet,
1274 Iterable<TypedefElement> allTypedefs, 1292 Iterable<TypedefElement> allTypedefs,
1275 Map<ClassEntity, Set<ClassEntity>> mixinUses, 1293 Map<ClassEntity, Set<ClassEntity>> mixinUses,
1276 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses, 1294 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses,
1277 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes, 1295 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes,
1278 Map<ClassEntity, ClassSet> classSets}) 1296 Map<ClassEntity, ClassSet> classSets})
1279 : super( 1297 : super(
1280 commonElements: commonElements, 1298 commonElements: commonElements,
1281 constantSystem: constantSystem, 1299 constantSystem: constantSystem,
1282 nativeData: nativeData, 1300 nativeData: nativeData,
1283 interceptorData: interceptorData, 1301 interceptorData: interceptorData,
1284 backendUsage: backendUsage, 1302 backendUsage: backendUsage,
1285 resolutionWorldBuilder: resolutionWorldBuilder, 1303 resolutionWorldBuilder: resolutionWorldBuilder,
1286 functionSetBuilder: functionSetBuilder, 1304 functionSet: functionSet,
1287 allTypedefs: allTypedefs, 1305 allTypedefs: allTypedefs,
1288 mixinUses: mixinUses, 1306 mixinUses: mixinUses,
1289 typesImplementedBySubclasses: typesImplementedBySubclasses, 1307 typesImplementedBySubclasses: typesImplementedBySubclasses,
1290 classHierarchyNodes: classHierarchyNodes, 1308 classHierarchyNodes: classHierarchyNodes,
1291 classSets: classSets); 1309 classSets: classSets);
1292 1310
1293 @override 1311 @override
1294 bool hasConcreteMatch(ClassEntity cls, Selector selector, 1312 bool hasConcreteMatch(ClassEntity cls, Selector selector,
1295 {ClassEntity stopAtSuperclass}) { 1313 {ClassEntity stopAtSuperclass}) {
1296 throw new UnimplementedError('KernelClosedWorld.hasConcreteMatch'); 1314 throw new UnimplementedError('KernelClosedWorld.hasConcreteMatch');
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 @override 1357 @override
1340 void registerClosureClass(ClassElement cls) { 1358 void registerClosureClass(ClassElement cls) {
1341 throw new UnimplementedError('KernelClosedWorld.registerClosureClass'); 1359 throw new UnimplementedError('KernelClosedWorld.registerClosureClass');
1342 } 1360 }
1343 1361
1344 @override 1362 @override
1345 bool hasElementIn(ClassEntity cls, Selector selector, Entity element) { 1363 bool hasElementIn(ClassEntity cls, Selector selector, Entity element) {
1346 throw new UnimplementedError('KernelClosedWorld.hasElementIn'); 1364 throw new UnimplementedError('KernelClosedWorld.hasElementIn');
1347 } 1365 }
1348 } 1366 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698