OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 compiler.src.inferrer.type_graph_nodes; | 5 library compiler.src.inferrer.type_graph_nodes; |
6 | 6 |
7 import 'dart:collection' show IterableBase; | 7 import 'dart:collection' show IterableBase; |
8 | 8 |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../common/names.dart' show Identifiers; | 10 import '../common/names.dart' show Identifiers; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 var /* List|ParameterAssignments */ _assignments; | 53 var /* List|ParameterAssignments */ _assignments; |
54 | 54 |
55 /// The type the inferrer has found for this [TypeInformation]. | 55 /// The type the inferrer has found for this [TypeInformation]. |
56 /// Initially empty. | 56 /// Initially empty. |
57 TypeMask type = const TypeMask.nonNullEmpty(); | 57 TypeMask type = const TypeMask.nonNullEmpty(); |
58 | 58 |
59 /// The graph node of the member this [TypeInformation] node belongs to. | 59 /// The graph node of the member this [TypeInformation] node belongs to. |
60 final MemberTypeInformation context; | 60 final MemberTypeInformation context; |
61 | 61 |
62 /// The element this [TypeInformation] node belongs to. | 62 /// The element this [TypeInformation] node belongs to. |
63 MemberElement get contextMember => context == null ? null : context.member; | 63 MemberEntity get contextMember => context == null ? null : context.member; |
64 | 64 |
65 Iterable<TypeInformation> get assignments => _assignments; | 65 Iterable<TypeInformation> get assignments => _assignments; |
66 | 66 |
67 /// We abandon inference in certain cases (complex cyclic flow, native | 67 /// We abandon inference in certain cases (complex cyclic flow, native |
68 /// behaviours, etc.). In some case, we might resume inference in the | 68 /// behaviours, etc.). In some case, we might resume inference in the |
69 /// closure tracer, which is handled by checking whether [assignments] has | 69 /// closure tracer, which is handled by checking whether [assignments] has |
70 /// been set to [STOP_TRACKING_ASSIGNMENTS_MARKER]. | 70 /// been set to [STOP_TRACKING_ASSIGNMENTS_MARKER]. |
71 bool abandonInferencing = false; | 71 bool abandonInferencing = false; |
72 bool get mightResume => | 72 bool get mightResume => |
73 !identical(assignments, STOP_TRACKING_ASSIGNMENTS_MARKER); | 73 !identical(assignments, STOP_TRACKING_ASSIGNMENTS_MARKER); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 type = const TypeMask.nonNullEmpty(); | 196 type = const TypeMask.nonNullEmpty(); |
197 refineCount = 0; | 197 refineCount = 0; |
198 return true; | 198 return true; |
199 } | 199 } |
200 | 200 |
201 accept(TypeInformationVisitor visitor); | 201 accept(TypeInformationVisitor visitor); |
202 | 202 |
203 /// The [Element] where this [TypeInformation] was created. May be `null` | 203 /// The [Element] where this [TypeInformation] was created. May be `null` |
204 /// for some [TypeInformation] nodes, where we do not need to store | 204 /// for some [TypeInformation] nodes, where we do not need to store |
205 /// the information. | 205 /// the information. |
206 TypedElement get owner => (context != null) ? context.member : null; | 206 MemberEntity get owner => (context != null) ? context.member : null; |
207 | 207 |
208 /// Returns whether the type cannot change after it has been | 208 /// Returns whether the type cannot change after it has been |
209 /// inferred. | 209 /// inferred. |
210 bool hasStableType(InferrerEngine inferrer) { | 210 bool hasStableType(InferrerEngine inferrer) { |
211 return !mightResume && assignments.every((e) => e.isStable); | 211 return !mightResume && assignments.every((e) => e.isStable); |
212 } | 212 } |
213 | 213 |
214 void removeAndClearReferences(InferrerEngine inferrer) { | 214 void removeAndClearReferences(InferrerEngine inferrer) { |
215 assignments.forEach((info) { | 215 assignments.forEach((info) { |
216 info.removeUser(this); | 216 info.removeUser(this); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 /** | 382 /** |
383 * This map contains the callers of [element]. It stores all unique call sites | 383 * This map contains the callers of [element]. It stores all unique call sites |
384 * to enable counting the global number of call sites of [element]. | 384 * to enable counting the global number of call sites of [element]. |
385 * | 385 * |
386 * A call site is either an AST [ast.Node], an [Element] (see uses of | 386 * A call site is either an AST [ast.Node], an [Element] (see uses of |
387 * [synthesizeForwardingCall] in [SimpleTypeInferrerVisitor]). | 387 * [synthesizeForwardingCall] in [SimpleTypeInferrerVisitor]). |
388 * | 388 * |
389 * The global information is summarized in [cleanup], after which [_callers] | 389 * The global information is summarized in [cleanup], after which [_callers] |
390 * is set to `null`. | 390 * is set to `null`. |
391 */ | 391 */ |
392 Map<MemberElement, Setlet<Spannable>> _callers; | 392 Map<MemberEntity, Setlet<Spannable>> _callers; |
393 | 393 |
394 MemberTypeInformation._internal(this._member) : super._internal(null); | 394 MemberTypeInformation._internal(this._member) : super._internal(null); |
395 | 395 |
396 MemberElement get member => _member; | 396 MemberElement get member => _member; |
397 | 397 |
398 String get debugName => '$member'; | 398 String get debugName => '$member'; |
399 | 399 |
400 void addCall(MemberElement caller, Spannable node) { | 400 void addCall(MemberEntity caller, Spannable node) { |
401 assert(node is ast.Node || node is Element); | 401 assert(node is ast.Node || node is Element); |
402 _callers ??= <MemberElement, Setlet<Spannable>>{}; | 402 _callers ??= <MemberEntity, Setlet<Spannable>>{}; |
403 _callers.putIfAbsent(caller, () => new Setlet()).add(node); | 403 _callers.putIfAbsent(caller, () => new Setlet()).add(node); |
404 } | 404 } |
405 | 405 |
406 void removeCall(MemberElement caller, node) { | 406 void removeCall(MemberEntity caller, node) { |
407 if (_callers == null) return; | 407 if (_callers == null) return; |
408 Setlet calls = _callers[caller]; | 408 Setlet calls = _callers[caller]; |
409 if (calls == null) return; | 409 if (calls == null) return; |
410 calls.remove(node); | 410 calls.remove(node); |
411 if (calls.isEmpty) { | 411 if (calls.isEmpty) { |
412 _callers.remove(caller); | 412 _callers.remove(caller); |
413 } | 413 } |
414 } | 414 } |
415 | 415 |
416 Iterable<MemberElement> get callers { | 416 Iterable<MemberEntity> get callers { |
417 // TODO(sra): This is called only from an unused API and a test. If it | 417 // TODO(sra): This is called only from an unused API and a test. If it |
418 // becomes used, [cleanup] will need to copy `_caller.keys`. | 418 // becomes used, [cleanup] will need to copy `_caller.keys`. |
419 | 419 |
420 // `simple_inferrer_callers_test.dart` ensures that cleanup has not | 420 // `simple_inferrer_callers_test.dart` ensures that cleanup has not |
421 // happened. | 421 // happened. |
422 return _callers.keys; | 422 return _callers.keys; |
423 } | 423 } |
424 | 424 |
425 bool isCalledOnce() { | 425 bool isCalledOnce() { |
426 // If this assert fires it means that this MemberTypeInformation for the | 426 // If this assert fires it means that this MemberTypeInformation for the |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 } | 643 } |
644 | 644 |
645 bool hasStableType(InferrerEngine inferrer) { | 645 bool hasStableType(InferrerEngine inferrer) { |
646 return super.hasStableType(inferrer); | 646 return super.hasStableType(inferrer); |
647 } | 647 } |
648 } | 648 } |
649 | 649 |
650 class GenerativeConstructorTypeInformation extends MemberTypeInformation { | 650 class GenerativeConstructorTypeInformation extends MemberTypeInformation { |
651 ConstructorEntity get _constructor => _member; | 651 ConstructorEntity get _constructor => _member; |
652 | 652 |
653 GenerativeConstructorTypeInformation(ConstructorElement element) | 653 GenerativeConstructorTypeInformation(ConstructorEntity element) |
654 : super._internal(element); | 654 : super._internal(element); |
655 | 655 |
656 TypeMask handleSpecialCases(InferrerEngine inferrer) { | 656 TypeMask handleSpecialCases(InferrerEngine inferrer) { |
657 return _handleFunctionCase(_constructor, inferrer); | 657 return _handleFunctionCase(_constructor, inferrer); |
658 } | 658 } |
659 | 659 |
660 TypeMask _potentiallyNarrowType(TypeMask mask, InferrerEngine inferrer) { | 660 TypeMask _potentiallyNarrowType(TypeMask mask, InferrerEngine inferrer) { |
661 return mask; | 661 return mask; |
662 } | 662 } |
663 | 663 |
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1889 // TODO(ngeoffray): Narrow to bound. | 1889 // TODO(ngeoffray): Narrow to bound. |
1890 return type; | 1890 return type; |
1891 } else { | 1891 } else { |
1892 ResolutionInterfaceType interfaceType = annotation; | 1892 ResolutionInterfaceType interfaceType = annotation; |
1893 otherType = new TypeMask.nonNullSubtype(interfaceType.element, closedWorld); | 1893 otherType = new TypeMask.nonNullSubtype(interfaceType.element, closedWorld); |
1894 } | 1894 } |
1895 if (isNullable) otherType = otherType.nullable(); | 1895 if (isNullable) otherType = otherType.nullable(); |
1896 if (type == null) return otherType; | 1896 if (type == null) return otherType; |
1897 return type.intersection(otherType, closedWorld); | 1897 return type.intersection(otherType, closedWorld); |
1898 } | 1898 } |
OLD | NEW |