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 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; |
11 import '../dart_types.dart'; | 11 import '../dart_types.dart'; |
12 import '../elements/elements.dart'; | 12 import '../elements/elements.dart'; |
13 import '../util/util.dart'; | 13 import '../util/util.dart'; |
14 import '../world.dart' show ClassWorld, World; | 14 import '../world.dart' show ClassWorld, ClosedWorld, OpenWorld; |
15 import 'selector.dart' show Selector; | 15 import 'selector.dart' show Selector; |
16 import 'use.dart' show DynamicUse, DynamicUseKind, StaticUse, StaticUseKind; | 16 import 'use.dart' show DynamicUse, DynamicUseKind, StaticUse, StaticUseKind; |
17 | 17 |
18 /// The known constraint on receiver for a dynamic call site. | 18 /// The known constraint on receiver for a dynamic call site. |
19 /// | 19 /// |
20 /// This can for instance be used to constrain this dynamic call to `foo` to | 20 /// This can for instance be used to constrain this dynamic call to `foo` to |
21 /// 'receivers of the exact instance `Bar`': | 21 /// 'receivers of the exact instance `Bar`': |
22 /// | 22 /// |
23 /// class Bar { | 23 /// class Bar { |
24 /// void foo() {} | 24 /// void foo() {} |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 /// Registers that [type] is checked in this universe. The unaliased type is | 120 /// Registers that [type] is checked in this universe. The unaliased type is |
121 /// returned. | 121 /// returned. |
122 DartType registerIsCheck(DartType type, Compiler compiler); | 122 DartType registerIsCheck(DartType type, Compiler compiler); |
123 | 123 |
124 /// All directly instantiated types, that is, the types of the directly | 124 /// All directly instantiated types, that is, the types of the directly |
125 /// instantiated classes. | 125 /// instantiated classes. |
126 // TODO(johnniwinther): Improve semantic precision. | 126 // TODO(johnniwinther): Improve semantic precision. |
127 Iterable<DartType> get instantiatedTypes; | 127 Iterable<DartType> get instantiatedTypes; |
128 | 128 |
129 /// Returns `true` if [member] is invoked as a setter. | 129 /// Returns `true` if [member] is invoked as a setter. |
130 bool hasInvokedSetter(Element member, World world); | 130 bool hasInvokedSetter(Element member, ClassWorld world); |
131 } | 131 } |
132 | 132 |
133 abstract class ResolutionUniverse implements Universe { | 133 abstract class ResolutionUniverse implements Universe { |
134 /// Set of (live) local functions (closures) whose signatures reference type | 134 /// Set of (live) local functions (closures) whose signatures reference type |
135 /// variables. | 135 /// variables. |
136 /// | 136 /// |
137 /// A live function is one whose enclosing member function has been enqueued. | 137 /// A live function is one whose enclosing member function has been enqueued. |
138 Set<Element> get closuresWithFreeTypeVariables; | 138 Set<Element> get closuresWithFreeTypeVariables; |
139 | 139 |
140 /// Set of (live) `call` methods whose signatures reference type variables. | 140 /// Set of (live) `call` methods whose signatures reference type variables. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 onImplemented(cls); | 291 onImplemented(cls); |
292 cls.allSupertypes.forEach((InterfaceType supertype) { | 292 cls.allSupertypes.forEach((InterfaceType supertype) { |
293 if (_implementedClasses.add(supertype.element)) { | 293 if (_implementedClasses.add(supertype.element)) { |
294 onImplemented(supertype.element); | 294 onImplemented(supertype.element); |
295 } | 295 } |
296 }); | 296 }); |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 bool _hasMatchingSelector(Map<Selector, SelectorConstraints> selectors, | 300 bool _hasMatchingSelector(Map<Selector, SelectorConstraints> selectors, |
301 Element member, World world) { | 301 Element member, ClassWorld world) { |
302 if (selectors == null) return false; | 302 if (selectors == null) return false; |
303 for (Selector selector in selectors.keys) { | 303 for (Selector selector in selectors.keys) { |
304 if (selector.appliesUnnamed(member, world)) { | 304 if (selector.appliesUnnamed(member, world.backend)) { |
305 SelectorConstraints masks = selectors[selector]; | 305 SelectorConstraints masks = selectors[selector]; |
306 if (masks.applies(member, selector, world)) { | 306 if (masks.applies(member, selector, world)) { |
307 return true; | 307 return true; |
308 } | 308 } |
309 } | 309 } |
310 } | 310 } |
311 return false; | 311 return false; |
312 } | 312 } |
313 | 313 |
314 bool hasInvocation(Element member, World world) { | 314 bool hasInvocation(Element member, OpenWorld world) { |
315 return _hasMatchingSelector(_invokedNames[member.name], member, world); | 315 return _hasMatchingSelector(_invokedNames[member.name], member, world); |
316 } | 316 } |
317 | 317 |
318 bool hasInvokedGetter(Element member, World world) { | 318 bool hasInvokedGetter(Element member, OpenWorld world) { |
319 return _hasMatchingSelector(_invokedGetters[member.name], member, world) || | 319 return _hasMatchingSelector(_invokedGetters[member.name], member, world) || |
320 member.isFunction && methodsNeedingSuperGetter.contains(member); | 320 member.isFunction && methodsNeedingSuperGetter.contains(member); |
321 } | 321 } |
322 | 322 |
323 bool hasInvokedSetter(Element member, World world) { | 323 bool hasInvokedSetter(Element member, OpenWorld world) { |
324 return _hasMatchingSelector(_invokedSetters[member.name], member, world); | 324 return _hasMatchingSelector(_invokedSetters[member.name], member, world); |
325 } | 325 } |
326 | 326 |
327 bool registerDynamicUse(DynamicUse dynamicUse) { | 327 bool registerDynamicUse(DynamicUse dynamicUse) { |
328 switch (dynamicUse.kind) { | 328 switch (dynamicUse.kind) { |
329 case DynamicUseKind.INVOKE: | 329 case DynamicUseKind.INVOKE: |
330 return _registerNewSelector(dynamicUse, _invokedNames); | 330 return _registerNewSelector(dynamicUse, _invokedNames); |
331 case DynamicUseKind.GET: | 331 case DynamicUseKind.GET: |
332 return _registerNewSelector(dynamicUse, _invokedGetters); | 332 return _registerNewSelector(dynamicUse, _invokedGetters); |
333 case DynamicUseKind.SET: | 333 case DynamicUseKind.SET: |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 abstract class CodegenUniverse implements Universe { | 409 abstract class CodegenUniverse implements Universe { |
410 void forEachInvokedName( | 410 void forEachInvokedName( |
411 f(String name, Map<Selector, SelectorConstraints> selectors)); | 411 f(String name, Map<Selector, SelectorConstraints> selectors)); |
412 | 412 |
413 void forEachInvokedGetter( | 413 void forEachInvokedGetter( |
414 f(String name, Map<Selector, SelectorConstraints> selectors)); | 414 f(String name, Map<Selector, SelectorConstraints> selectors)); |
415 | 415 |
416 void forEachInvokedSetter( | 416 void forEachInvokedSetter( |
417 f(String name, Map<Selector, SelectorConstraints> selectors)); | 417 f(String name, Map<Selector, SelectorConstraints> selectors)); |
418 | 418 |
419 bool hasInvokedGetter(Element member, World world); | 419 bool hasInvokedGetter(Element member, ClosedWorld world); |
420 | 420 |
421 Map<Selector, SelectorConstraints> invocationsByName(String name); | 421 Map<Selector, SelectorConstraints> invocationsByName(String name); |
422 | 422 |
423 Map<Selector, SelectorConstraints> getterInvocationsByName(String name); | 423 Map<Selector, SelectorConstraints> getterInvocationsByName(String name); |
424 | 424 |
425 Map<Selector, SelectorConstraints> setterInvocationsByName(String name); | 425 Map<Selector, SelectorConstraints> setterInvocationsByName(String name); |
426 | 426 |
427 Iterable<FunctionElement> get staticFunctionsNeedingGetter; | 427 Iterable<FunctionElement> get staticFunctionsNeedingGetter; |
428 Iterable<FunctionElement> get methodsNeedingSuperGetter; | 428 Iterable<FunctionElement> get methodsNeedingSuperGetter; |
429 | 429 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 onImplemented(cls); | 528 onImplemented(cls); |
529 cls.allSupertypes.forEach((InterfaceType supertype) { | 529 cls.allSupertypes.forEach((InterfaceType supertype) { |
530 if (_implementedClasses.add(supertype.element)) { | 530 if (_implementedClasses.add(supertype.element)) { |
531 onImplemented(supertype.element); | 531 onImplemented(supertype.element); |
532 } | 532 } |
533 }); | 533 }); |
534 } | 534 } |
535 } | 535 } |
536 | 536 |
537 bool _hasMatchingSelector(Map<Selector, SelectorConstraints> selectors, | 537 bool _hasMatchingSelector(Map<Selector, SelectorConstraints> selectors, |
538 Element member, World world) { | 538 Element member, ClosedWorld world) { |
539 if (selectors == null) return false; | 539 if (selectors == null) return false; |
540 for (Selector selector in selectors.keys) { | 540 for (Selector selector in selectors.keys) { |
541 if (selector.appliesUnnamed(member, world)) { | 541 if (selector.appliesUnnamed(member, world.backend)) { |
542 SelectorConstraints masks = selectors[selector]; | 542 SelectorConstraints masks = selectors[selector]; |
543 if (masks.applies(member, selector, world)) { | 543 if (masks.applies(member, selector, world)) { |
544 return true; | 544 return true; |
545 } | 545 } |
546 } | 546 } |
547 } | 547 } |
548 return false; | 548 return false; |
549 } | 549 } |
550 | 550 |
551 bool hasInvocation(Element member, World world) { | 551 bool hasInvocation(Element member, ClosedWorld world) { |
552 return _hasMatchingSelector(_invokedNames[member.name], member, world); | 552 return _hasMatchingSelector(_invokedNames[member.name], member, world); |
553 } | 553 } |
554 | 554 |
555 bool hasInvokedGetter(Element member, World world) { | 555 bool hasInvokedGetter(Element member, ClosedWorld world) { |
556 return _hasMatchingSelector(_invokedGetters[member.name], member, world) || | 556 return _hasMatchingSelector(_invokedGetters[member.name], member, world) || |
557 member.isFunction && methodsNeedingSuperGetter.contains(member); | 557 member.isFunction && methodsNeedingSuperGetter.contains(member); |
558 } | 558 } |
559 | 559 |
560 bool hasInvokedSetter(Element member, World world) { | 560 bool hasInvokedSetter(Element member, ClosedWorld world) { |
561 return _hasMatchingSelector(_invokedSetters[member.name], member, world); | 561 return _hasMatchingSelector(_invokedSetters[member.name], member, world); |
562 } | 562 } |
563 | 563 |
564 bool registerDynamicUse(DynamicUse dynamicUse) { | 564 bool registerDynamicUse(DynamicUse dynamicUse) { |
565 switch (dynamicUse.kind) { | 565 switch (dynamicUse.kind) { |
566 case DynamicUseKind.INVOKE: | 566 case DynamicUseKind.INVOKE: |
567 return _registerNewSelector(dynamicUse, _invokedNames); | 567 return _registerNewSelector(dynamicUse, _invokedNames); |
568 case DynamicUseKind.GET: | 568 case DynamicUseKind.GET: |
569 return _registerNewSelector(dynamicUse, _invokedGetters); | 569 return _registerNewSelector(dynamicUse, _invokedGetters); |
570 case DynamicUseKind.SET: | 570 case DynamicUseKind.SET: |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 | 652 |
653 void forgetElement(Element element, Compiler compiler) { | 653 void forgetElement(Element element, Compiler compiler) { |
654 _directlyInstantiatedClasses.remove(element); | 654 _directlyInstantiatedClasses.remove(element); |
655 if (element is ClassElement) { | 655 if (element is ClassElement) { |
656 assert(invariant(element, element.thisType.isRaw, | 656 assert(invariant(element, element.thisType.isRaw, |
657 message: 'Generic classes not supported (${element.thisType}).')); | 657 message: 'Generic classes not supported (${element.thisType}).')); |
658 _instantiatedTypes..remove(element.rawType)..remove(element.thisType); | 658 _instantiatedTypes..remove(element.rawType)..remove(element.thisType); |
659 } | 659 } |
660 } | 660 } |
661 } | 661 } |
OLD | NEW |