OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 part of world_builder; | 5 part of world_builder; |
6 | 6 |
7 /// World builder specific to codegen. | 7 /// World builder specific to codegen. |
8 /// | 8 /// |
9 /// This adds additional access to liveness of selectors and elements. | 9 /// This adds additional access to liveness of selectors and elements. |
10 abstract class CodegenWorldBuilder implements WorldBuilder { | 10 abstract class CodegenWorldBuilder implements WorldBuilder { |
(...skipping 20 matching lines...) Expand all Loading... |
31 bool hasInvokedSetter(Element member, ClosedWorld world); | 31 bool hasInvokedSetter(Element member, ClosedWorld world); |
32 | 32 |
33 bool hasInvokedGetter(Element member, ClosedWorld world); | 33 bool hasInvokedGetter(Element member, ClosedWorld world); |
34 | 34 |
35 Map<Selector, SelectorConstraints> invocationsByName(String name); | 35 Map<Selector, SelectorConstraints> invocationsByName(String name); |
36 | 36 |
37 Map<Selector, SelectorConstraints> getterInvocationsByName(String name); | 37 Map<Selector, SelectorConstraints> getterInvocationsByName(String name); |
38 | 38 |
39 Map<Selector, SelectorConstraints> setterInvocationsByName(String name); | 39 Map<Selector, SelectorConstraints> setterInvocationsByName(String name); |
40 | 40 |
41 Iterable<FunctionElement> get staticFunctionsNeedingGetter; | 41 Iterable<FunctionEntity> get staticFunctionsNeedingGetter; |
42 Iterable<FunctionElement> get methodsNeedingSuperGetter; | 42 Iterable<FunctionEntity> get methodsNeedingSuperGetter; |
43 | 43 |
44 /// The set of all referenced static fields. | 44 /// The set of all referenced static fields. |
45 /// | 45 /// |
46 /// Invariant: Elements are declaration elements. | 46 /// Invariant: Elements are declaration elements. |
47 Iterable<FieldElement> get allReferencedStaticFields; | 47 Iterable<FieldEntity> get allReferencedStaticFields; |
| 48 |
| 49 /// Set of methods in instantiated classes that are potentially closurized. |
| 50 Iterable<FunctionEntity> get closurizedMembers; |
48 } | 51 } |
49 | 52 |
50 class CodegenWorldBuilderImpl implements CodegenWorldBuilder { | 53 class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
51 final NativeBasicData _nativeData; | 54 final NativeBasicData _nativeData; |
52 final ClosedWorld _world; | 55 final ClosedWorld _world; |
53 final JavaScriptConstantCompiler _constants; | 56 final JavaScriptConstantCompiler _constants; |
54 | 57 |
55 /// The set of all directly instantiated classes, that is, classes with a | 58 /// The set of all directly instantiated classes, that is, classes with a |
56 /// generative constructor that has been called directly and not only through | 59 /// generative constructor that has been called directly and not only through |
57 /// a super-call. | 60 /// a super-call. |
(...skipping 16 matching lines...) Expand all Loading... |
74 /// The set of all referenced static fields. | 77 /// The set of all referenced static fields. |
75 /// | 78 /// |
76 /// Invariant: Elements are declaration elements. | 79 /// Invariant: Elements are declaration elements. |
77 final Set<FieldElement> allReferencedStaticFields = new Set<FieldElement>(); | 80 final Set<FieldElement> allReferencedStaticFields = new Set<FieldElement>(); |
78 | 81 |
79 /** | 82 /** |
80 * Documentation wanted -- johnniwinther | 83 * Documentation wanted -- johnniwinther |
81 * | 84 * |
82 * Invariant: Elements are declaration elements. | 85 * Invariant: Elements are declaration elements. |
83 */ | 86 */ |
84 final Set<FunctionElement> staticFunctionsNeedingGetter = | 87 final Set<FunctionEntity> staticFunctionsNeedingGetter = |
85 new Set<FunctionElement>(); | 88 new Set<FunctionEntity>(); |
86 final Set<FunctionElement> methodsNeedingSuperGetter = | 89 final Set<FunctionEntity> methodsNeedingSuperGetter = |
87 new Set<FunctionElement>(); | 90 new Set<FunctionEntity>(); |
88 final Map<String, Map<Selector, SelectorConstraints>> _invokedNames = | 91 final Map<String, Map<Selector, SelectorConstraints>> _invokedNames = |
89 <String, Map<Selector, SelectorConstraints>>{}; | 92 <String, Map<Selector, SelectorConstraints>>{}; |
90 final Map<String, Map<Selector, SelectorConstraints>> _invokedGetters = | 93 final Map<String, Map<Selector, SelectorConstraints>> _invokedGetters = |
91 <String, Map<Selector, SelectorConstraints>>{}; | 94 <String, Map<Selector, SelectorConstraints>>{}; |
92 final Map<String, Map<Selector, SelectorConstraints>> _invokedSetters = | 95 final Map<String, Map<Selector, SelectorConstraints>> _invokedSetters = |
93 <String, Map<Selector, SelectorConstraints>>{}; | 96 <String, Map<Selector, SelectorConstraints>>{}; |
94 | 97 |
95 final Map<ClassElement, _ClassUsage> _processedClasses = | 98 final Map<ClassElement, _ClassUsage> _processedClasses = |
96 <ClassElement, _ClassUsage>{}; | 99 <ClassElement, _ClassUsage>{}; |
97 | 100 |
(...skipping 14 matching lines...) Expand all Loading... |
112 /// closurized. | 115 /// closurized. |
113 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName = | 116 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName = |
114 <String, Set<_MemberUsage>>{}; | 117 <String, Set<_MemberUsage>>{}; |
115 | 118 |
116 final Set<ResolutionDartType> isChecks = new Set<ResolutionDartType>(); | 119 final Set<ResolutionDartType> isChecks = new Set<ResolutionDartType>(); |
117 | 120 |
118 final SelectorConstraintsStrategy selectorConstraintsStrategy; | 121 final SelectorConstraintsStrategy selectorConstraintsStrategy; |
119 | 122 |
120 final Set<ConstantValue> _constantValues = new Set<ConstantValue>(); | 123 final Set<ConstantValue> _constantValues = new Set<ConstantValue>(); |
121 | 124 |
| 125 /// Set of methods in instantiated classes that are potentially closurized. |
| 126 final Set<FunctionEntity> closurizedMembers = new Set<FunctionEntity>(); |
| 127 |
122 CodegenWorldBuilderImpl(this._nativeData, this._world, this._constants, | 128 CodegenWorldBuilderImpl(this._nativeData, this._world, this._constants, |
123 this.selectorConstraintsStrategy); | 129 this.selectorConstraintsStrategy); |
124 | 130 |
125 /// Calls [f] with every instance field, together with its declarer, in an | 131 /// Calls [f] with every instance field, together with its declarer, in an |
126 /// instance of [cls]. | 132 /// instance of [cls]. |
127 void forEachInstanceField( | 133 void forEachInstanceField( |
128 ClassElement cls, void f(ClassEntity declarer, FieldEntity field)) { | 134 ClassElement cls, void f(ClassEntity declarer, FieldEntity field)) { |
129 cls.implementation | 135 cls.implementation |
130 .forEachInstanceField(f, includeSuperAndInjectedMembers: true); | 136 .forEachInstanceField(f, includeSuperAndInjectedMembers: true); |
131 } | 137 } |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 isChecks.add(type); | 327 isChecks.add(type); |
322 } | 328 } |
323 | 329 |
324 void _registerStaticUse(StaticUse staticUse) { | 330 void _registerStaticUse(StaticUse staticUse) { |
325 Element element = staticUse.element; | 331 Element element = staticUse.element; |
326 if (Elements.isStaticOrTopLevel(element) && element.isField) { | 332 if (Elements.isStaticOrTopLevel(element) && element.isField) { |
327 allReferencedStaticFields.add(element); | 333 allReferencedStaticFields.add(element); |
328 } | 334 } |
329 switch (staticUse.kind) { | 335 switch (staticUse.kind) { |
330 case StaticUseKind.STATIC_TEAR_OFF: | 336 case StaticUseKind.STATIC_TEAR_OFF: |
331 staticFunctionsNeedingGetter.add(element); | 337 MethodElement method = element; |
| 338 staticFunctionsNeedingGetter.add(method); |
332 break; | 339 break; |
333 case StaticUseKind.SUPER_TEAR_OFF: | 340 case StaticUseKind.SUPER_TEAR_OFF: |
334 methodsNeedingSuperGetter.add(element); | 341 MethodElement method = element; |
| 342 methodsNeedingSuperGetter.add(method); |
335 break; | 343 break; |
336 case StaticUseKind.SUPER_FIELD_SET: | 344 case StaticUseKind.SUPER_FIELD_SET: |
337 case StaticUseKind.FIELD_SET: | 345 case StaticUseKind.FIELD_SET: |
338 case StaticUseKind.GENERAL: | 346 case StaticUseKind.GENERAL: |
339 case StaticUseKind.DIRECT_USE: | 347 case StaticUseKind.DIRECT_USE: |
340 case StaticUseKind.CLOSURE: | 348 case StaticUseKind.CLOSURE: |
341 case StaticUseKind.FIELD_GET: | 349 case StaticUseKind.FIELD_GET: |
342 case StaticUseKind.CONSTRUCTOR_INVOKE: | 350 case StaticUseKind.CONSTRUCTOR_INVOKE: |
343 case StaticUseKind.CONST_CONSTRUCTOR_INVOKE: | 351 case StaticUseKind.CONST_CONSTRUCTOR_INVOKE: |
344 case StaticUseKind.REDIRECTION: | 352 case StaticUseKind.REDIRECTION: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 useSet.addAll(usage.normalUse()); | 401 useSet.addAll(usage.normalUse()); |
394 break; | 402 break; |
395 case StaticUseKind.INLINING: | 403 case StaticUseKind.INLINING: |
396 break; | 404 break; |
397 } | 405 } |
398 if (useSet.isNotEmpty) { | 406 if (useSet.isNotEmpty) { |
399 memberUsed(usage.entity, useSet); | 407 memberUsed(usage.entity, useSet); |
400 } | 408 } |
401 } | 409 } |
402 | 410 |
| 411 /// Registers that [element] has been closurized. |
| 412 void registerClosurizedMember(MemberEntity element) { |
| 413 closurizedMembers.add(element); |
| 414 } |
| 415 |
403 void processClassMembers(ClassElement cls, MemberUsedCallback memberUsed) { | 416 void processClassMembers(ClassElement cls, MemberUsedCallback memberUsed) { |
404 cls.implementation.forEachMember((_, MemberElement member) { | 417 cls.implementation.forEachMember((_, MemberElement member) { |
405 assert(invariant(member, member.isDeclaration)); | 418 assert(invariant(member, member.isDeclaration)); |
406 if (!member.isInstanceMember) return; | 419 if (!member.isInstanceMember) return; |
407 if (member.isMalformed) return; | 420 if (member.isMalformed) return; |
408 _getMemberUsage(member, memberUsed); | 421 _getMemberUsage(member, memberUsed); |
409 }); | 422 }); |
410 } | 423 } |
411 | 424 |
412 _MemberUsage _getMemberUsage( | 425 _MemberUsage _getMemberUsage( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 | 502 |
490 /// Register the constant [use] with this world builder. Returns `true` if | 503 /// Register the constant [use] with this world builder. Returns `true` if |
491 /// the constant use was new to the world. | 504 /// the constant use was new to the world. |
492 bool registerConstantUse(ConstantUse use) { | 505 bool registerConstantUse(ConstantUse use) { |
493 if (use.kind == ConstantUseKind.DIRECT) { | 506 if (use.kind == ConstantUseKind.DIRECT) { |
494 _constants.addCompileTimeConstantForEmission(use.value); | 507 _constants.addCompileTimeConstantForEmission(use.value); |
495 } | 508 } |
496 return _constantValues.add(use.value); | 509 return _constantValues.add(use.value); |
497 } | 510 } |
498 } | 511 } |
OLD | NEW |