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 part of dart2js; | 5 part of dart2js; |
6 | 6 |
7 class World { | 7 class World { |
8 final Compiler compiler; | 8 final Compiler compiler; |
9 final Map<ClassElement, Set<ClassElement>> subtypes; | 9 final Map<ClassElement, Set<ClassElement>> subtypes; |
10 final Map<ClassElement, Set<MixinApplicationElement>> mixinUses; | 10 final Map<ClassElement, Set<MixinApplicationElement>> mixinUses; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 for (DartType current in cls.allSupertypes) { | 46 for (DartType current in cls.allSupertypes) { |
47 typesImplementedBySubclassesOfCls.add(current.element); | 47 typesImplementedBySubclassesOfCls.add(current.element); |
48 } | 48 } |
49 ClassElement classElement = type.element; | 49 ClassElement classElement = type.element; |
50 type = classElement.supertype; | 50 type = classElement.supertype; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 compiler.resolverWorld.instantiatedClasses.forEach(addSubtypes); | 54 compiler.resolverWorld.instantiatedClasses.forEach(addSubtypes); |
55 | 55 |
56 compiler.backend.addBackendRtiDependencies(this); | |
ngeoffray
2013/02/27 16:18:37
Explain why you're doing this, and why now.
karlklose
2013/02/28 11:37:46
Done.
| |
57 | |
56 // Find the classes that need runtime type information. Such | 58 // Find the classes that need runtime type information. Such |
57 // classes are: | 59 // classes are: |
58 // (1) used in a is check with type variables, | 60 // (1) used in a is check with type variables, |
59 // (2) dependencies of classes in (1), | 61 // (2) dependencies of classes in (1), |
60 // (3) subclasses of (2) and (3). | 62 // (3) subclasses of (2) and (3). |
61 | 63 |
62 void potentiallyAddForRti(ClassElement cls) { | 64 void potentiallyAddForRti(ClassElement cls) { |
63 if (cls.typeVariables.isEmpty) return; | 65 if (cls.typeVariables.isEmpty) return; |
64 if (classesNeedingRti.contains(cls)) return; | 66 if (classesNeedingRti.contains(cls)) return; |
65 classesNeedingRti.add(cls); | 67 classesNeedingRti.add(cls); |
66 | 68 |
67 Set<ClassElement> classes = subtypes[cls]; | 69 Set<ClassElement> classes = subtypes[cls]; |
68 if (classes != null) { | 70 if (classes != null) { |
69 classes.forEach((ClassElement sub) { | 71 classes.forEach((ClassElement sub) { |
70 potentiallyAddForRti(sub); | 72 potentiallyAddForRti(sub); |
71 }); | 73 }); |
72 } | 74 } |
73 | 75 |
74 Set<ClassElement> dependencies = rtiDependencies[cls]; | 76 Set<ClassElement> dependencies = rtiDependencies[cls]; |
75 if (dependencies != null) { | 77 if (dependencies != null) { |
76 dependencies.forEach((ClassElement other) { | 78 dependencies.forEach((ClassElement other) { |
77 potentiallyAddForRti(other); | 79 potentiallyAddForRti(other); |
78 }); | 80 }); |
79 } | 81 } |
80 } | 82 } |
81 | 83 |
84 Set<ClassElement> classesUsingTypeVariableTests = new Set<ClassElement>(); | |
82 compiler.resolverWorld.isChecks.forEach((DartType type) { | 85 compiler.resolverWorld.isChecks.forEach((DartType type) { |
83 if (type is InterfaceType) { | 86 if (type.kind == TypeKind.TYPE_VARIABLE) { |
87 TypeVariableElement variable = type.element; | |
88 classesUsingTypeVariableTests.add(variable.enclosingElement); | |
89 } | |
90 }); | |
91 compiler.resolverWorld.addImplicitChecks(classesUsingTypeVariableTests); | |
92 compiler.resolverWorld.isChecks.forEach((DartType type) { | |
93 if (type.kind == TypeKind.INTERFACE) { | |
84 InterfaceType itf = type; | 94 InterfaceType itf = type; |
85 if (!itf.isRaw) { | 95 if (!itf.isRaw) { |
86 potentiallyAddForRti(itf.element); | 96 potentiallyAddForRti(itf.element); |
87 } | 97 } |
98 } else if (type.kind == TypeKind.TYPE_VARIABLE) { | |
99 TypeVariableElement variable = type.element; | |
100 potentiallyAddForRti(variable.enclosingElement); | |
88 } | 101 } |
89 }); | 102 }); |
90 } | 103 } |
91 | 104 |
92 void registerMixinUse(MixinApplicationElement mixinApplication, | 105 void registerMixinUse(MixinApplicationElement mixinApplication, |
93 ClassElement mixin) { | 106 ClassElement mixin) { |
94 Set<MixinApplicationElement> users = | 107 Set<MixinApplicationElement> users = |
95 mixinUses.putIfAbsent(mixin, () => | 108 mixinUses.putIfAbsent(mixin, () => |
96 new Set<MixinApplicationElement>()); | 109 new Set<MixinApplicationElement>()); |
97 users.add(mixinApplication); | 110 users.add(mixinApplication); |
98 } | 111 } |
99 | 112 |
100 bool isUsedAsMixin(ClassElement cls) { | 113 bool isUsedAsMixin(ClassElement cls) { |
101 Set<MixinApplicationElement> uses = mixinUses[cls]; | 114 Set<MixinApplicationElement> uses = mixinUses[cls]; |
102 return uses != null && !uses.isEmpty; | 115 return uses != null && !uses.isEmpty; |
103 } | 116 } |
104 | 117 |
105 | |
106 void registerRtiDependency(Element element, Element dependency) { | 118 void registerRtiDependency(Element element, Element dependency) { |
107 // We're not dealing with typedef for now. | 119 // We're not dealing with typedef for now. |
108 if (!element.isClass() || !dependency.isClass()) return; | 120 if (!element.isClass() || !dependency.isClass()) return; |
109 Set<ClassElement> classes = | 121 Set<ClassElement> classes = |
110 rtiDependencies.putIfAbsent(element, () => new Set<ClassElement>()); | 122 rtiDependencies.putIfAbsent(element, () => new Set<ClassElement>()); |
111 classes.add(dependency); | 123 classes.add(dependency); |
112 } | 124 } |
113 | 125 |
114 bool needsRti(ClassElement cls) { | 126 bool needsRti(ClassElement cls) { |
115 return classesNeedingRti.contains(cls) || compiler.enabledRuntimeType; | 127 return classesNeedingRti.contains(cls) || compiler.enabledRuntimeType; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 noSuchMethodSelector = new TypedSelector( | 176 noSuchMethodSelector = new TypedSelector( |
165 receiverType, selector.typeKind, noSuchMethodSelector); | 177 receiverType, selector.typeKind, noSuchMethodSelector); |
166 } | 178 } |
167 ClassElement objectClass = compiler.objectClass; | 179 ClassElement objectClass = compiler.objectClass; |
168 return allFunctions | 180 return allFunctions |
169 .filter(noSuchMethodSelector) | 181 .filter(noSuchMethodSelector) |
170 .map((Element member) => member.getEnclosingClass()) | 182 .map((Element member) => member.getEnclosingClass()) |
171 .where((ClassElement holder) => !identical(holder, objectClass)); | 183 .where((ClassElement holder) => !identical(holder, objectClass)); |
172 } | 184 } |
173 } | 185 } |
OLD | NEW |