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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart

Issue 1637843002: typeInformation in CreateInstance is a kind of TypeExpression (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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) 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 library dart2js.ir_nodes; 4 library dart2js.ir_nodes;
5 5
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'cps_fragment.dart' show CpsFragment; 7 import 'cps_fragment.dart' show CpsFragment;
8 import 'cps_ir_nodes_sexpr.dart'; 8 import 'cps_ir_nodes_sexpr.dart';
9 import '../constants/values.dart' as values; 9 import '../constants/values.dart' as values;
10 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; 10 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType;
(...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1476 1476
1477 /// Initial values for the fields on the class. 1477 /// Initial values for the fields on the class.
1478 /// The order corresponds to the order of fields on the class. 1478 /// The order corresponds to the order of fields on the class.
1479 final List<Reference<Primitive>> arguments; 1479 final List<Reference<Primitive>> arguments;
1480 1480
1481 /// The runtime type information structure which contains the type arguments. 1481 /// The runtime type information structure which contains the type arguments.
1482 /// 1482 ///
1483 /// May be `null` to indicate that no type information is needed because the 1483 /// May be `null` to indicate that no type information is needed because the
1484 /// compiler determined that the type information for instances of this class 1484 /// compiler determined that the type information for instances of this class
1485 /// is not needed at runtime. 1485 /// is not needed at runtime.
1486 final List<Reference<Primitive>> typeInformation; 1486 final Reference<Primitive> typeInformation;
1487 1487
1488 final SourceInformation sourceInformation; 1488 final SourceInformation sourceInformation;
1489 1489
1490 CreateInstance(this.classElement, List<Primitive> arguments, 1490 CreateInstance(this.classElement, List<Primitive> arguments,
1491 List<Primitive> typeInformation, 1491 Primitive typeInformation,
1492 this.sourceInformation) 1492 this.sourceInformation)
1493 : this.arguments = _referenceList(arguments), 1493 : this.arguments = _referenceList(arguments),
1494 this.typeInformation = _referenceList(typeInformation); 1494 this.typeInformation = typeInformation == null
1495 ? null
1496 : new Reference<Primitive>(typeInformation);
1495 1497
1496 accept(Visitor visitor) => visitor.visitCreateInstance(this); 1498 accept(Visitor visitor) => visitor.visitCreateInstance(this);
1497 1499
1498 bool get hasValue => true; 1500 bool get hasValue => true;
1499 bool get isSafeForElimination => true; 1501 bool get isSafeForElimination => true;
1500 bool get isSafeForReordering => true; 1502 bool get isSafeForReordering => true;
1501 1503
1502 toString() => 'CreateInstance($classElement)'; 1504 toString() => 'CreateInstance($classElement)';
1503 1505
1504 void setParentPointers() { 1506 void setParentPointers() {
1505 _setParentsOnList(arguments, this); 1507 _setParentsOnList(arguments, this);
1506 if (typeInformation != null) _setParentsOnList(typeInformation, this); 1508 if (typeInformation != null) typeInformation.parent = this;
1507 } 1509 }
1508 } 1510 }
1509 1511
1510 /// Obtains the interceptor for the given value. This is a method table 1512 /// Obtains the interceptor for the given value. This is a method table
1511 /// corresponding to the Dart class of the value. 1513 /// corresponding to the Dart class of the value.
1512 /// 1514 ///
1513 /// All values are either intercepted or self-intercepted. The interceptor for 1515 /// All values are either intercepted or self-intercepted. The interceptor for
1514 /// an "intercepted value" is one of the subclasses of Interceptor. 1516 /// an "intercepted value" is one of the subclasses of Interceptor.
1515 /// The interceptor for a "self-intercepted value" is the value itself. 1517 /// The interceptor for a "self-intercepted value" is the value itself.
1516 /// 1518 ///
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1791 1793
1792 bool get hasValue => true; 1794 bool get hasValue => true;
1793 bool get isSafeForElimination => true; 1795 bool get isSafeForElimination => true;
1794 bool get isSafeForReordering => true; 1796 bool get isSafeForReordering => true;
1795 1797
1796 void setParentPointers() { 1798 void setParentPointers() {
1797 target.parent = this; 1799 target.parent = this;
1798 } 1800 }
1799 } 1801 }
1800 1802
1801 /// Representation of a closed type (that is, a type without type variables). 1803 enum TypeExpressionKind {
1804 COMPLETE,
1805 INSTANCE
1806 }
1807
1808 /// Constructs a representation of a closed or ground-term type (that is, a type
1809 /// without type variables).
1802 /// 1810 ///
1803 /// The resulting value is constructed from [dartType] by replacing the type 1811 /// There are two forms:
1812 ///
1813 /// - COMPLETE: A complete form that is self contained, used for the values of
1814 /// type parameters and non-raw is-checks.
1815 ///
1816 /// - INSTANCE: A headless flat form for representing the sequence of values of
1817 /// the type parameters of an instance of a generic type.
1818 ///
1819 /// The COMPLETE form value is constructed from [dartType] by replacing the type
1804 /// variables with consecutive values from [arguments], in the order generated 1820 /// variables with consecutive values from [arguments], in the order generated
1805 /// by [DartType.forEachTypeVariable]. The type variables in [dartType] are 1821 /// by [DartType.forEachTypeVariable]. The type variables in [dartType] are
1806 /// treated as 'holes' in the term, which means that it must be ensured at 1822 /// treated as 'holes' in the term, which means that it must be ensured at
1807 /// construction, that duplicate occurences of a type variable in [dartType] 1823 /// construction, that duplicate occurences of a type variable in [dartType]
1808 /// are assigned the same value. 1824 /// are assigned the same value.
1825 ///
1826 /// The INSTANCE form is constructed as a list of [arguments]. This is the same
1827 /// as the COMPLETE form for the 'thisType', except the root term's type is
1828 /// missing; this is implicit as the raw type of instance. The [dartType] of
1829 /// the INSTANCE form must be the thisType of some class.
1830 ///
1831 /// While we would like to remove the constrains on the INSTANCE form, we can
1832 /// get by with a tree of TypeExpressions. Consider:
1833 ///
1834 /// class Foo<T> {
1835 /// ... new Set<List<T>>()
1836 /// }
1837 /// class Set<E1> {
1838 /// factory Set() => new _LinkedHashSet<E1>();
1839 /// }
1840 /// class List<E2> { ... }
1841 /// class _LinkedHashSet<E3> { ... }
1842 ///
1843 /// After inlining the factory constructor for `Set<E1>`, the CreateInstance
1844 /// should have type `_LinkedHashSet<List<T>>` and the TypeExpression should be
1845 /// a tree:
1846 ///
1847 /// CreateInstance(dartType: _LinkedHashSet<List<T>>,
1848 /// [], // No arguments
1849 /// TypeExpression(INSTANCE,
1850 /// dartType: _LinkedHashSet<E3>, // _LinkedHashSet's thisType
1851 /// TypeExpression(COMPLETE, // E3 = List<T>
1852 /// dartType: List<E2>,
1853 /// ReadTypeVariable(this, T)))) // E2 = T
1854 //
1855 // TODO(sra): The INSTANCE form requires the actual instance for full
1856 // interpretation. I want to move to a representation where the INSTANCE form is
1857 // also a complete form (possibly the same).
1809 class TypeExpression extends Primitive { 1858 class TypeExpression extends Primitive {
1859 final TypeExpressionKind kind;
1810 final DartType dartType; 1860 final DartType dartType;
1811 final List<Reference<Primitive>> arguments; 1861 final List<Reference<Primitive>> arguments;
1812 1862
1813 TypeExpression(this.dartType, 1863 TypeExpression(this.kind,
1814 [List<Primitive> arguments = const <Primitive>[]]) 1864 this.dartType,
1815 : this.arguments = _referenceList(arguments); 1865 List<Primitive> arguments)
1866 : this.arguments = _referenceList(arguments) {
1867 assert(kind == TypeExpressionKind.INSTANCE
1868 ? dartType == dartType.element.thisType
1869 : true);
1870 }
1816 1871
1817 @override 1872 @override
1818 accept(Visitor visitor) { 1873 accept(Visitor visitor) {
1819 return visitor.visitTypeExpression(this); 1874 return visitor.visitTypeExpression(this);
1820 } 1875 }
1821 1876
1822 bool get hasValue => true; 1877 bool get hasValue => true;
1823 bool get isSafeForElimination => true; 1878 bool get isSafeForElimination => true;
1824 bool get isSafeForReordering => true; 1879 bool get isSafeForReordering => true;
1825 1880
1826 void setParentPointers() { 1881 void setParentPointers() {
1827 _setParentsOnList(arguments, this); 1882 _setParentsOnList(arguments, this);
1828 } 1883 }
1884
1885 String get kindAsString {
1886 switch (kind) {
1887 case TypeExpressionKind.COMPLETE: return 'COMPLETE';
1888 case TypeExpressionKind.INSTANCE: return 'INSTANCE';
1889 }
1890 }
1829 } 1891 }
1830 1892
1831 class Await extends UnsafePrimitive { 1893 class Await extends UnsafePrimitive {
1832 final Reference<Primitive> input; 1894 final Reference<Primitive> input;
1833 1895
1834 Await(Primitive input) 1896 Await(Primitive input)
1835 : this.input = new Reference<Primitive>(input); 1897 : this.input = new Reference<Primitive>(input);
1836 1898
1837 @override 1899 @override
1838 accept(Visitor visitor) { 1900 accept(Visitor visitor) {
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
2194 processInterceptor(Interceptor node) {} 2256 processInterceptor(Interceptor node) {}
2195 visitInterceptor(Interceptor node) { 2257 visitInterceptor(Interceptor node) {
2196 processInterceptor(node); 2258 processInterceptor(node);
2197 processReference(node.input); 2259 processReference(node.input);
2198 } 2260 }
2199 2261
2200 processCreateInstance(CreateInstance node) {} 2262 processCreateInstance(CreateInstance node) {}
2201 visitCreateInstance(CreateInstance node) { 2263 visitCreateInstance(CreateInstance node) {
2202 processCreateInstance(node); 2264 processCreateInstance(node);
2203 node.arguments.forEach(processReference); 2265 node.arguments.forEach(processReference);
2204 node.typeInformation.forEach(processReference); 2266 if (node.typeInformation != null) processReference(node.typeInformation);
2205 } 2267 }
2206 2268
2207 processSetField(SetField node) {} 2269 processSetField(SetField node) {}
2208 visitSetField(SetField node) { 2270 visitSetField(SetField node) {
2209 processSetField(node); 2271 processSetField(node);
2210 processReference(node.object); 2272 processReference(node.object);
2211 processReference(node.value); 2273 processReference(node.value);
2212 } 2274 }
2213 2275
2214 processGetField(GetField node) {} 2276 processGetField(GetField node) {}
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
2606 Definition visitGetStatic(GetStatic node) { 2668 Definition visitGetStatic(GetStatic node) {
2607 return new GetStatic(node.element, node.sourceInformation); 2669 return new GetStatic(node.element, node.sourceInformation);
2608 } 2670 }
2609 2671
2610 Definition visitInterceptor(Interceptor node) { 2672 Definition visitInterceptor(Interceptor node) {
2611 return new Interceptor(getCopy(node.input), node.sourceInformation) 2673 return new Interceptor(getCopy(node.input), node.sourceInformation)
2612 ..interceptedClasses.addAll(node.interceptedClasses); 2674 ..interceptedClasses.addAll(node.interceptedClasses);
2613 } 2675 }
2614 2676
2615 Definition visitCreateInstance(CreateInstance node) { 2677 Definition visitCreateInstance(CreateInstance node) {
2616 return new CreateInstance(node.classElement, getList(node.arguments), 2678 return new CreateInstance(
2617 getList(node.typeInformation), 2679 node.classElement,
2680 getList(node.arguments),
2681 node.typeInformation == null ? null : getCopy(node.typeInformation),
2618 node.sourceInformation); 2682 node.sourceInformation);
2619 } 2683 }
2620 2684
2621 Definition visitGetField(GetField node) { 2685 Definition visitGetField(GetField node) {
2622 return new GetField(getCopy(node.object), node.field); 2686 return new GetField(getCopy(node.object), node.field);
2623 } 2687 }
2624 2688
2625 Definition visitCreateBox(CreateBox node) { 2689 Definition visitCreateBox(CreateBox node) {
2626 return new CreateBox(); 2690 return new CreateBox();
2627 } 2691 }
2628 2692
2629 Definition visitReifyRuntimeType(ReifyRuntimeType node) { 2693 Definition visitReifyRuntimeType(ReifyRuntimeType node) {
2630 return new ReifyRuntimeType(getCopy(node.value), node.sourceInformation); 2694 return new ReifyRuntimeType(getCopy(node.value), node.sourceInformation);
2631 } 2695 }
2632 2696
2633 Definition visitReadTypeVariable(ReadTypeVariable node) { 2697 Definition visitReadTypeVariable(ReadTypeVariable node) {
2634 return new ReadTypeVariable(node.variable, getCopy(node.target), 2698 return new ReadTypeVariable(node.variable, getCopy(node.target),
2635 node.sourceInformation); 2699 node.sourceInformation);
2636 } 2700 }
2637 2701
2638 Definition visitTypeExpression(TypeExpression node) { 2702 Definition visitTypeExpression(TypeExpression node) {
2639 return new TypeExpression(node.dartType, getList(node.arguments)); 2703 return new TypeExpression(
2704 node.kind, node.dartType, getList(node.arguments));
2640 } 2705 }
2641 2706
2642 Definition visitCreateInvocationMirror(CreateInvocationMirror node) { 2707 Definition visitCreateInvocationMirror(CreateInvocationMirror node) {
2643 return new CreateInvocationMirror(node.selector, getList(node.arguments)); 2708 return new CreateInvocationMirror(node.selector, getList(node.arguments));
2644 } 2709 }
2645 2710
2646 Definition visitTypeTest(TypeTest node) { 2711 Definition visitTypeTest(TypeTest node) {
2647 return new TypeTest(getCopy(node.value), node.dartType, 2712 return new TypeTest(getCopy(node.value), node.dartType,
2648 getList(node.typeArguments)); 2713 getList(node.typeArguments));
2649 } 2714 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
2841 plug(new Branch.loose(_definitions.getCopy(node.condition), 2906 plug(new Branch.loose(_definitions.getCopy(node.condition),
2842 _copies[node.trueContinuation.definition], 2907 _copies[node.trueContinuation.definition],
2843 _copies[node.falseContinuation.definition]) 2908 _copies[node.falseContinuation.definition])
2844 ..isStrictCheck = node.isStrictCheck); 2909 ..isStrictCheck = node.isStrictCheck);
2845 } 2910 }
2846 2911
2847 visitUnreachable(Unreachable node) { 2912 visitUnreachable(Unreachable node) {
2848 plug(new Unreachable()); 2913 plug(new Unreachable());
2849 } 2914 }
2850 } 2915 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698