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

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

Issue 2381793003: Rename Universe to WorldBuilder. (Closed)
Patch Set: Created 4 years, 2 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 universe; 5 library universe;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import '../common.dart'; 9 import '../common.dart';
10 import '../compiler.dart' show Compiler; 10 import '../compiler.dart' show Compiler;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 /// 80 ///
81 /// class A {} 81 /// class A {}
82 /// class B { foo() {} } 82 /// class B { foo() {} }
83 /// m(b) => (b ? new A() : new B()).foo(); 83 /// m(b) => (b ? new A() : new B()).foo();
84 /// 84 ///
85 /// the potential receiver `new A()` has no implementation of `foo` and thus 85 /// the potential receiver `new A()` has no implementation of `foo` and thus
86 /// needs to handle the call through its `noSuchMethod` handler. 86 /// needs to handle the call through its `noSuchMethod` handler.
87 bool needsNoSuchMethodHandling(Selector selector, World world); 87 bool needsNoSuchMethodHandling(Selector selector, World world);
88 } 88 }
89 89
90 /// A mutable [SelectorConstraints] used in [Universe]. 90 /// A mutable [SelectorConstraints] used in [WorldBuilder].
91 abstract class UniverseSelectorConstraints extends SelectorConstraints { 91 abstract class UniverseSelectorConstraints extends SelectorConstraints {
92 /// Adds [constraint] to these selector constraints. Return `true` if the set 92 /// Adds [constraint] to these selector constraints. Return `true` if the set
93 /// of potential receivers expanded due to the new constraint. 93 /// of potential receivers expanded due to the new constraint.
94 bool addReceiverConstraint(ReceiverConstraint constraint); 94 bool addReceiverConstraint(ReceiverConstraint constraint);
95 } 95 }
96 96
97 /// Strategy for computing the constraints on potential receivers of dynamic 97 /// Strategy for computing the constraints on potential receivers of dynamic
98 /// call sites. 98 /// call sites.
99 abstract class SelectorConstraintsStrategy { 99 abstract class SelectorConstraintsStrategy {
100 /// Create a [UniverseSelectorConstraints] to represent the global receiver 100 /// Create a [UniverseSelectorConstraints] to represent the global receiver
101 /// constraints for dynamic call sites with [selector]. 101 /// constraints for dynamic call sites with [selector].
102 UniverseSelectorConstraints createSelectorConstraints(Selector selector); 102 UniverseSelectorConstraints createSelectorConstraints(Selector selector);
103 } 103 }
104 104
105 /// The [Universe] is an auxiliary class used in the process of computing the 105 /// The [WorldBuilder] is an auxiliary class used in the process of computing
106 /// [ClosedWorld]. The concepts here and in [ClosedWorld] are very similar -- in 106 /// the [ClosedWorld]. The concepts here and in [ClosedWorld] are very similar
Siggi Cherem (dart-lang) 2016/09/29 18:14:48 nit: remove everything after the first sentence
107 /// the same way that the "universe expands" you can think of this as a mutable 107 /// -- in the same way that the "universe expands" you can think of this as a
108 /// world that is expanding as we visit and discover parts of the program. 108 /// mutable world that is expanding as we visit and discover parts of the
109 /// program.
109 // TODO(sigmund): rename to "growing/expanding/mutable world"? 110 // TODO(sigmund): rename to "growing/expanding/mutable world"?
Siggi Cherem (dart-lang) 2016/09/29 18:14:48 remove TODO :)
Johnni Winther 2016/09/30 08:43:14 Done.
110 // TODO(johnniwinther): Move common implementation to a [UniverseBase] when 111 // TODO(johnniwinther): Move common implementation to a [UniverseBase] when
111 // universes and worlds have been unified. 112 // universes and worlds have been unified.
112 abstract class Universe { 113 abstract class WorldBuilder {
113 /// All directly instantiated classes, that is, classes with a generative 114 /// All directly instantiated classes, that is, classes with a generative
114 /// constructor that has been called directly and not only through a 115 /// constructor that has been called directly and not only through a
115 /// super-call. 116 /// super-call.
116 // TODO(johnniwinther): Improve semantic precision. 117 // TODO(johnniwinther): Improve semantic precision.
117 Iterable<ClassElement> get directlyInstantiatedClasses; 118 Iterable<ClassElement> get directlyInstantiatedClasses;
118 119
119 /// All types that are checked either through is, as or checked mode checks. 120 /// All types that are checked either through is, as or checked mode checks.
120 Iterable<DartType> get isChecks; 121 Iterable<DartType> get isChecks;
121 122
122 /// Registers that [type] is checked in this universe. The unaliased type is 123 /// Registers that [type] is checked in this universe. The unaliased type is
123 /// returned. 124 /// returned.
124 DartType registerIsCheck(DartType type, Compiler compiler); 125 DartType registerIsCheck(DartType type, Compiler compiler);
125 126
126 /// All directly instantiated types, that is, the types of the directly 127 /// All directly instantiated types, that is, the types of the directly
127 /// instantiated classes. 128 /// instantiated classes.
128 // TODO(johnniwinther): Improve semantic precision. 129 // TODO(johnniwinther): Improve semantic precision.
129 Iterable<DartType> get instantiatedTypes; 130 Iterable<DartType> get instantiatedTypes;
130 131
131 /// Returns `true` if [member] is invoked as a setter. 132 /// Returns `true` if [member] is invoked as a setter.
132 bool hasInvokedSetter(Element member, World world); 133 bool hasInvokedSetter(Element member, World world);
133 } 134 }
134 135
135 abstract class ResolutionUniverse implements Universe { 136 abstract class ResolutionWorldBuilder implements WorldBuilder {
136 /// Set of (live) local functions (closures) whose signatures reference type 137 /// Set of (live) local functions (closures) whose signatures reference type
137 /// variables. 138 /// variables.
138 /// 139 ///
139 /// A live function is one whose enclosing member function has been enqueued. 140 /// A live function is one whose enclosing member function has been enqueued.
140 Set<Element> get closuresWithFreeTypeVariables; 141 Set<Element> get closuresWithFreeTypeVariables;
141 142
142 /// Set of (live) `call` methods whose signatures reference type variables. 143 /// Set of (live) `call` methods whose signatures reference type variables.
143 /// 144 ///
144 /// A live `call` method is one whose enclosing class has been instantiated. 145 /// A live `call` method is one whose enclosing class has been instantiated.
145 Iterable<Element> get callMethodsWithFreeTypeVariables; 146 Iterable<Element> get callMethodsWithFreeTypeVariables;
146 147
147 /// Set of all closures in the program. Used by the mirror tracking system 148 /// Set of all closures in the program. Used by the mirror tracking system
148 /// to find all live closure instances. 149 /// to find all live closure instances.
149 Iterable<LocalFunctionElement> get allClosures; 150 Iterable<LocalFunctionElement> get allClosures;
150 151
151 /// Set of methods in instantiated classes that are potentially closurized. 152 /// Set of methods in instantiated classes that are potentially closurized.
152 Iterable<Element> get closurizedMembers; 153 Iterable<Element> get closurizedMembers;
153 154
154 /// Returns `true` if [cls] is considered to be implemented by an 155 /// Returns `true` if [cls] is considered to be implemented by an
155 /// instantiated class, either directly, through subclasses or through 156 /// instantiated class, either directly, through subclasses or through
156 /// subtypes. The latter case only contains spurious information from 157 /// subtypes. The latter case only contains spurious information from
157 /// instantiations through factory constructors and mixins. 158 /// instantiations through factory constructors and mixins.
158 bool isImplemented(ClassElement cls); 159 bool isImplemented(ClassElement cls);
159 160
160 /// Set of all fields that are statically known to be written to. 161 /// Set of all fields that are statically known to be written to.
161 Iterable<Element> get fieldSetters; 162 Iterable<Element> get fieldSetters;
162 } 163 }
163 164
164 class ResolutionUniverseImpl implements ResolutionUniverse { 165 class ResolutionWorldBuilderImpl implements ResolutionWorldBuilder {
165 /// The set of all directly instantiated classes, that is, classes with a 166 /// The set of all directly instantiated classes, that is, classes with a
166 /// generative constructor that has been called directly and not only through 167 /// generative constructor that has been called directly and not only through
167 /// a super-call. 168 /// a super-call.
168 /// 169 ///
169 /// Invariant: Elements are declaration elements. 170 /// Invariant: Elements are declaration elements.
170 // TODO(johnniwinther): [_directlyInstantiatedClasses] and 171 // TODO(johnniwinther): [_directlyInstantiatedClasses] and
171 // [_instantiatedTypes] sets should be merged. 172 // [_instantiatedTypes] sets should be merged.
172 final Set<ClassElement> _directlyInstantiatedClasses = 173 final Set<ClassElement> _directlyInstantiatedClasses =
173 new Set<ClassElement>(); 174 new Set<ClassElement>();
174 175
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 final Set<LocalFunctionElement> allClosures = new Set<LocalFunctionElement>(); 227 final Set<LocalFunctionElement> allClosures = new Set<LocalFunctionElement>();
227 228
228 /** 229 /**
229 * Set of methods in instantiated classes that are potentially 230 * Set of methods in instantiated classes that are potentially
230 * closurized. 231 * closurized.
231 */ 232 */
232 final Set<Element> closurizedMembers = new Set<Element>(); 233 final Set<Element> closurizedMembers = new Set<Element>();
233 234
234 final SelectorConstraintsStrategy selectorConstraintsStrategy; 235 final SelectorConstraintsStrategy selectorConstraintsStrategy;
235 236
236 ResolutionUniverseImpl(this.selectorConstraintsStrategy); 237 ResolutionWorldBuilderImpl(this.selectorConstraintsStrategy);
237 238
238 /// All directly instantiated classes, that is, classes with a generative 239 /// All directly instantiated classes, that is, classes with a generative
239 /// constructor that has been called directly and not only through a 240 /// constructor that has been called directly and not only through a
240 /// super-call. 241 /// super-call.
241 // TODO(johnniwinther): Improve semantic precision. 242 // TODO(johnniwinther): Improve semantic precision.
242 Iterable<ClassElement> get directlyInstantiatedClasses { 243 Iterable<ClassElement> get directlyInstantiatedClasses {
243 return _directlyInstantiatedClasses; 244 return _directlyInstantiatedClasses;
244 } 245 }
245 246
246 /// All directly instantiated types, that is, the types of the directly 247 /// All directly instantiated types, that is, the types of the directly
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 // by using a map. 401 // by using a map.
401 List<LocalFunctionElement> slowDirectlyNestedClosures(Element element) { 402 List<LocalFunctionElement> slowDirectlyNestedClosures(Element element) {
402 // Return new list to guard against concurrent modifications. 403 // Return new list to guard against concurrent modifications.
403 return new List<LocalFunctionElement>.from( 404 return new List<LocalFunctionElement>.from(
404 allClosures.where((LocalFunctionElement closure) { 405 allClosures.where((LocalFunctionElement closure) {
405 return closure.executableContext == element; 406 return closure.executableContext == element;
406 })); 407 }));
407 } 408 }
408 } 409 }
409 410
410 /// Universe specific to codegen. 411 /// World builder specific to codegen.
411 /// 412 ///
412 /// This adds additional access to liveness of selectors and elements. 413 /// This adds additional access to liveness of selectors and elements.
413 abstract class CodegenUniverse implements Universe { 414 abstract class CodegenWorldBuilder implements WorldBuilder {
414 void forEachInvokedName( 415 void forEachInvokedName(
415 f(String name, Map<Selector, SelectorConstraints> selectors)); 416 f(String name, Map<Selector, SelectorConstraints> selectors));
416 417
417 void forEachInvokedGetter( 418 void forEachInvokedGetter(
418 f(String name, Map<Selector, SelectorConstraints> selectors)); 419 f(String name, Map<Selector, SelectorConstraints> selectors));
419 420
420 void forEachInvokedSetter( 421 void forEachInvokedSetter(
421 f(String name, Map<Selector, SelectorConstraints> selectors)); 422 f(String name, Map<Selector, SelectorConstraints> selectors));
422 423
423 bool hasInvokedGetter(Element member, ClosedWorld world); 424 bool hasInvokedGetter(Element member, ClosedWorld world);
424 425
425 Map<Selector, SelectorConstraints> invocationsByName(String name); 426 Map<Selector, SelectorConstraints> invocationsByName(String name);
426 427
427 Map<Selector, SelectorConstraints> getterInvocationsByName(String name); 428 Map<Selector, SelectorConstraints> getterInvocationsByName(String name);
428 429
429 Map<Selector, SelectorConstraints> setterInvocationsByName(String name); 430 Map<Selector, SelectorConstraints> setterInvocationsByName(String name);
430 431
431 Iterable<FunctionElement> get staticFunctionsNeedingGetter; 432 Iterable<FunctionElement> get staticFunctionsNeedingGetter;
432 Iterable<FunctionElement> get methodsNeedingSuperGetter; 433 Iterable<FunctionElement> get methodsNeedingSuperGetter;
433 434
434 /// The set of all referenced static fields. 435 /// The set of all referenced static fields.
435 /// 436 ///
436 /// Invariant: Elements are declaration elements. 437 /// Invariant: Elements are declaration elements.
437 Iterable<FieldElement> get allReferencedStaticFields; 438 Iterable<FieldElement> get allReferencedStaticFields;
438 } 439 }
439 440
440 class CodegenUniverseImpl implements CodegenUniverse { 441 class CodegenWorldBuilderImpl implements CodegenWorldBuilder {
441 /// The set of all directly instantiated classes, that is, classes with a 442 /// The set of all directly instantiated classes, that is, classes with a
442 /// generative constructor that has been called directly and not only through 443 /// generative constructor that has been called directly and not only through
443 /// a super-call. 444 /// a super-call.
444 /// 445 ///
445 /// Invariant: Elements are declaration elements. 446 /// Invariant: Elements are declaration elements.
446 // TODO(johnniwinther): [_directlyInstantiatedClasses] and 447 // TODO(johnniwinther): [_directlyInstantiatedClasses] and
447 // [_instantiatedTypes] sets should be merged. 448 // [_instantiatedTypes] sets should be merged.
448 final Set<ClassElement> _directlyInstantiatedClasses = 449 final Set<ClassElement> _directlyInstantiatedClasses =
449 new Set<ClassElement>(); 450 new Set<ClassElement>();
450 451
(...skipping 24 matching lines...) Expand all
475 <String, Map<Selector, SelectorConstraints>>{}; 476 <String, Map<Selector, SelectorConstraints>>{};
476 final Map<String, Map<Selector, SelectorConstraints>> _invokedGetters = 477 final Map<String, Map<Selector, SelectorConstraints>> _invokedGetters =
477 <String, Map<Selector, SelectorConstraints>>{}; 478 <String, Map<Selector, SelectorConstraints>>{};
478 final Map<String, Map<Selector, SelectorConstraints>> _invokedSetters = 479 final Map<String, Map<Selector, SelectorConstraints>> _invokedSetters =
479 <String, Map<Selector, SelectorConstraints>>{}; 480 <String, Map<Selector, SelectorConstraints>>{};
480 481
481 final Set<DartType> isChecks = new Set<DartType>(); 482 final Set<DartType> isChecks = new Set<DartType>();
482 483
483 final SelectorConstraintsStrategy selectorConstraintsStrategy; 484 final SelectorConstraintsStrategy selectorConstraintsStrategy;
484 485
485 CodegenUniverseImpl(this.selectorConstraintsStrategy); 486 CodegenWorldBuilderImpl(this.selectorConstraintsStrategy);
486 487
487 /// All directly instantiated classes, that is, classes with a generative 488 /// All directly instantiated classes, that is, classes with a generative
488 /// constructor that has been called directly and not only through a 489 /// constructor that has been called directly and not only through a
489 /// super-call. 490 /// super-call.
490 // TODO(johnniwinther): Improve semantic precision. 491 // TODO(johnniwinther): Improve semantic precision.
491 Iterable<ClassElement> get directlyInstantiatedClasses { 492 Iterable<ClassElement> get directlyInstantiatedClasses {
492 return _directlyInstantiatedClasses; 493 return _directlyInstantiatedClasses;
493 } 494 }
494 495
495 /// All directly instantiated types, that is, the types of the directly 496 /// All directly instantiated types, that is, the types of the directly
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 657
657 void forgetElement(Element element, Compiler compiler) { 658 void forgetElement(Element element, Compiler compiler) {
658 _directlyInstantiatedClasses.remove(element); 659 _directlyInstantiatedClasses.remove(element);
659 if (element is ClassElement) { 660 if (element is ClassElement) {
660 assert(invariant(element, element.thisType.isRaw, 661 assert(invariant(element, element.thisType.isRaw,
661 message: 'Generic classes not supported (${element.thisType}).')); 662 message: 'Generic classes not supported (${element.thisType}).'));
662 _instantiatedTypes..remove(element.rawType)..remove(element.thisType); 663 _instantiatedTypes..remove(element.rawType)..remove(element.thisType);
663 } 664 }
664 } 665 }
665 } 666 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698