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 dart2js.world; | 5 library dart2js.world; |
6 | 6 |
7 import 'closure.dart' show ClosureClassElement; | 7 import 'closure.dart' show ClosureClassElement; |
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, ElementEnvironment; | 10 import 'common_elements.dart' show CommonElements, ElementEnvironment; |
(...skipping 10 matching lines...) Expand all Loading... | |
21 import 'elements/types.dart'; | 21 import 'elements/types.dart'; |
22 import 'js_backend/backend_usage.dart' show BackendUsage; | 22 import 'js_backend/backend_usage.dart' show BackendUsage; |
23 import 'js_backend/interceptor_data.dart' show InterceptorData; | 23 import 'js_backend/interceptor_data.dart' show InterceptorData; |
24 import 'js_backend/native_data.dart' show NativeData; | 24 import 'js_backend/native_data.dart' show NativeData; |
25 import 'ordered_typeset.dart'; | 25 import 'ordered_typeset.dart'; |
26 import 'types/masks.dart' show CommonMasks, FlatTypeMask, TypeMask; | 26 import 'types/masks.dart' show CommonMasks, FlatTypeMask, TypeMask; |
27 import 'universe/class_set.dart'; | 27 import 'universe/class_set.dart'; |
28 import 'universe/function_set.dart' show FunctionSet; | 28 import 'universe/function_set.dart' show FunctionSet; |
29 import 'universe/selector.dart' show Selector; | 29 import 'universe/selector.dart' show Selector; |
30 import 'universe/side_effects.dart' show SideEffects; | 30 import 'universe/side_effects.dart' show SideEffects; |
31 import 'universe/world_builder.dart' show ResolutionWorldBuilder; | |
32 import 'util/util.dart' show Link; | 31 import 'util/util.dart' show Link; |
33 | 32 |
34 /// Common superinterface for [OpenWorld] and [ClosedWorld]. | 33 /// Common superinterface for [OpenWorld] and [ClosedWorld]. |
35 abstract class World {} | 34 abstract class World {} |
36 | 35 |
37 /// The [ClosedWorld] represents the information known about a program when | 36 /// The [ClosedWorld] represents the information known about a program when |
38 /// compiling with closed-world semantics. | 37 /// compiling with closed-world semantics. |
39 /// | 38 /// |
40 /// Given the entrypoint of an application, we can track what's reachable from | 39 /// Given the entrypoint of an application, we can track what's reachable from |
41 /// it, what functions are called, what classes are allocated, which native | 40 /// it, what functions are called, what classes are allocated, which native |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 | 436 |
438 final Set<FunctionEntity> _functionsThatMightBePassedToApply = | 437 final Set<FunctionEntity> _functionsThatMightBePassedToApply = |
439 new Set<FunctionEntity>(); | 438 new Set<FunctionEntity>(); |
440 | 439 |
441 CommonMasks _commonMasks; | 440 CommonMasks _commonMasks; |
442 | 441 |
443 final ElementEnvironment elementEnvironment; | 442 final ElementEnvironment elementEnvironment; |
444 final DartTypes dartTypes; | 443 final DartTypes dartTypes; |
445 final CommonElements commonElements; | 444 final CommonElements commonElements; |
446 | 445 |
447 // TODO(johnniwinther): Avoid this. | |
448 final ResolutionWorldBuilder _resolverWorld; | |
Siggi Cherem (dart-lang)
2017/07/05 21:00:09
\o/
|
| |
449 | |
450 // TODO(johnniwinther): Can this be derived from [ClassSet]s? | 446 // TODO(johnniwinther): Can this be derived from [ClassSet]s? |
451 final Set<ClassEntity> _implementedClasses; | 447 final Set<ClassEntity> _implementedClasses; |
452 | 448 |
453 final Iterable<MemberEntity> liveInstanceMembers; | 449 final Iterable<MemberEntity> liveInstanceMembers; |
454 | 450 |
451 /// Members that are written either directly or through a setter selector. | |
452 final Iterable<MemberEntity> assignedInstanceMembers; | |
453 | |
455 ClosedWorldBase( | 454 ClosedWorldBase( |
456 this.elementEnvironment, | 455 this.elementEnvironment, |
457 this.dartTypes, | 456 this.dartTypes, |
458 this.commonElements, | 457 this.commonElements, |
459 this.constantSystem, | 458 this.constantSystem, |
460 this.nativeData, | 459 this.nativeData, |
461 this.interceptorData, | 460 this.interceptorData, |
462 this.backendUsage, | 461 this.backendUsage, |
463 ResolutionWorldBuilder resolutionWorldBuilder, | |
464 Set<ClassEntity> implementedClasses, | 462 Set<ClassEntity> implementedClasses, |
465 this.liveInstanceMembers, | 463 this.liveInstanceMembers, |
464 this.assignedInstanceMembers, | |
466 Set<TypedefElement> allTypedefs, | 465 Set<TypedefElement> allTypedefs, |
467 this.mixinUses, | 466 this.mixinUses, |
468 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses, | 467 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses, |
469 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes, | 468 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes, |
470 Map<ClassEntity, ClassSet> classSets) | 469 Map<ClassEntity, ClassSet> classSets) |
471 : this._resolverWorld = resolutionWorldBuilder, | 470 : this._implementedClasses = implementedClasses, |
472 this._implementedClasses = implementedClasses, | |
473 this._allTypedefs = allTypedefs, | 471 this._allTypedefs = allTypedefs, |
474 this._typesImplementedBySubclasses = typesImplementedBySubclasses, | 472 this._typesImplementedBySubclasses = typesImplementedBySubclasses, |
475 this._classHierarchyNodes = classHierarchyNodes, | 473 this._classHierarchyNodes = classHierarchyNodes, |
476 this._classSets = classSets { | 474 this._classSets = classSets { |
477 _commonMasks = new CommonMasks(this); | 475 _commonMasks = new CommonMasks(this); |
478 } | 476 } |
479 | 477 |
480 @override | 478 @override |
481 ClosedWorld get closedWorld => this; | 479 ClosedWorld get closedWorld => this; |
482 | 480 |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1059 // E.g. node.firstChild depends on parentNode.removeBefore(n1, n2). | 1057 // E.g. node.firstChild depends on parentNode.removeBefore(n1, n2). |
1060 // TODO(sra): Refine the effect classification so that native effects are | 1058 // TODO(sra): Refine the effect classification so that native effects are |
1061 // distinct from ordinary Dart effects. | 1059 // distinct from ordinary Dart effects. |
1062 return false; | 1060 return false; |
1063 } | 1061 } |
1064 | 1062 |
1065 if (!element.isAssignable) { | 1063 if (!element.isAssignable) { |
1066 return true; | 1064 return true; |
1067 } | 1065 } |
1068 if (element.isInstanceMember) { | 1066 if (element.isInstanceMember) { |
1069 return !_resolverWorld.hasInvokedSetter(element) && | 1067 return !assignedInstanceMembers.contains(element); |
1070 !_resolverWorld.fieldSetters.contains(element); | |
1071 } | 1068 } |
1072 return false; | 1069 return false; |
1073 } | 1070 } |
1074 | 1071 |
1075 SideEffects getSideEffectsOfSelector(Selector selector, TypeMask mask) { | 1072 SideEffects getSideEffectsOfSelector(Selector selector, TypeMask mask) { |
1076 // We're not tracking side effects of closures. | 1073 // We're not tracking side effects of closures. |
1077 if (selector.isClosureCall) return new SideEffects(); | 1074 if (selector.isClosureCall) return new SideEffects(); |
1078 SideEffects sideEffects = new SideEffects.empty(); | 1075 SideEffects sideEffects = new SideEffects.empty(); |
1079 _ensureFunctionSet(); | 1076 _ensureFunctionSet(); |
1080 for (MemberEntity e in _allFunctions.filter(selector, mask, this)) { | 1077 for (MemberEntity e in _allFunctions.filter(selector, mask, this)) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1173 | 1170 |
1174 class ClosedWorldImpl extends ClosedWorldBase { | 1171 class ClosedWorldImpl extends ClosedWorldBase { |
1175 ClosedWorldImpl( | 1172 ClosedWorldImpl( |
1176 {ElementEnvironment elementEnvironment, | 1173 {ElementEnvironment elementEnvironment, |
1177 DartTypes dartTypes, | 1174 DartTypes dartTypes, |
1178 CommonElements commonElements, | 1175 CommonElements commonElements, |
1179 ConstantSystem constantSystem, | 1176 ConstantSystem constantSystem, |
1180 NativeData nativeData, | 1177 NativeData nativeData, |
1181 InterceptorData interceptorData, | 1178 InterceptorData interceptorData, |
1182 BackendUsage backendUsage, | 1179 BackendUsage backendUsage, |
1183 ResolutionWorldBuilder resolutionWorldBuilder, | |
1184 Set<ClassEntity> implementedClasses, | 1180 Set<ClassEntity> implementedClasses, |
1185 Iterable<MemberEntity> liveInstanceMembers, | 1181 Iterable<MemberEntity> liveInstanceMembers, |
1182 Iterable<MemberEntity> assignedInstanceMembers, | |
1186 Set<TypedefElement> allTypedefs, | 1183 Set<TypedefElement> allTypedefs, |
1187 Map<ClassEntity, Set<ClassEntity>> mixinUses, | 1184 Map<ClassEntity, Set<ClassEntity>> mixinUses, |
1188 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses, | 1185 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses, |
1189 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes, | 1186 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes, |
1190 Map<ClassEntity, ClassSet> classSets}) | 1187 Map<ClassEntity, ClassSet> classSets}) |
1191 : super( | 1188 : super( |
1192 elementEnvironment, | 1189 elementEnvironment, |
1193 dartTypes, | 1190 dartTypes, |
1194 commonElements, | 1191 commonElements, |
1195 constantSystem, | 1192 constantSystem, |
1196 nativeData, | 1193 nativeData, |
1197 interceptorData, | 1194 interceptorData, |
1198 backendUsage, | 1195 backendUsage, |
1199 resolutionWorldBuilder, | |
1200 implementedClasses, | 1196 implementedClasses, |
1201 liveInstanceMembers, | 1197 liveInstanceMembers, |
1198 assignedInstanceMembers, | |
1202 allTypedefs, | 1199 allTypedefs, |
1203 mixinUses, | 1200 mixinUses, |
1204 typesImplementedBySubclasses, | 1201 typesImplementedBySubclasses, |
1205 classHierarchyNodes, | 1202 classHierarchyNodes, |
1206 classSets); | 1203 classSets); |
1207 | 1204 |
1208 bool checkClass(ClassElement cls) => cls.isDeclaration; | 1205 bool checkClass(ClassElement cls) => cls.isDeclaration; |
1209 | 1206 |
1210 bool checkEntity(Element element) => element.isDeclaration; | 1207 bool checkEntity(Element element) => element.isDeclaration; |
1211 | 1208 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1312 // does not see generative constructor bodies because they are | 1309 // does not see generative constructor bodies because they are |
1313 // created by the backend. Also, it does not make any distinction | 1310 // created by the backend. Also, it does not make any distinction |
1314 // between a constructor and its body for side effects. This | 1311 // between a constructor and its body for side effects. This |
1315 // implies that currently, the side effects of a constructor body | 1312 // implies that currently, the side effects of a constructor body |
1316 // contain the side effects of the initializers. | 1313 // contain the side effects of the initializers. |
1317 assert(!element.isGenerativeConstructorBody); | 1314 assert(!element.isGenerativeConstructorBody); |
1318 assert(!element.isField); | 1315 assert(!element.isField); |
1319 return super.getSideEffectsOfElement(element); | 1316 return super.getSideEffectsOfElement(element); |
1320 } | 1317 } |
1321 } | 1318 } |
OLD | NEW |