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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 | 53 |
54 compiler.resolverWorld.instantiatedClasses.forEach(addSubtypes); | 54 compiler.resolverWorld.instantiatedClasses.forEach(addSubtypes); |
55 | 55 |
56 // Find the classes that need runtime type information. Such | 56 // Find the classes that need runtime type information. Such |
57 // classes are: | 57 // classes are: |
58 // (1) used in a is check with type variables, | 58 // (1) used in a is check with type variables, |
59 // (2) dependencies of classes in (1), | 59 // (2) dependencies of classes in (1), |
60 // (3) subclasses of (2) and (3). | 60 // (3) subclasses of (2) and (3). |
61 | 61 |
62 void potentiallyAddForRti(ClassElement cls) { | 62 void potentiallyAddForRti(ClassElement cls) { |
63 if (cls.typeVariables.isEmpty) return; | |
64 if (classesNeedingRti.contains(cls)) return; | 63 if (classesNeedingRti.contains(cls)) return; |
65 classesNeedingRti.add(cls); | 64 classesNeedingRti.add(cls); |
66 | 65 |
67 Set<ClassElement> classes = subtypes[cls]; | 66 Set<ClassElement> classes = subtypes[cls]; |
68 if (classes != null) { | 67 if (classes != null) { |
69 classes.forEach((ClassElement sub) { | 68 classes.forEach((ClassElement sub) { |
70 potentiallyAddForRti(sub); | 69 potentiallyAddForRti(sub); |
71 }); | 70 }); |
72 } | 71 } |
73 | 72 |
74 Set<ClassElement> dependencies = rtiDependencies[cls]; | 73 Set<ClassElement> dependencies = rtiDependencies[cls]; |
75 if (dependencies != null) { | 74 if (dependencies != null) { |
76 dependencies.forEach((ClassElement other) { | 75 dependencies.forEach((ClassElement other) { |
77 potentiallyAddForRti(other); | 76 potentiallyAddForRti(other); |
78 }); | 77 }); |
79 } | 78 } |
80 } | 79 } |
81 | 80 |
82 compiler.resolverWorld.isChecks.forEach((DartType type) { | 81 compiler.resolverWorld.isChecks.forEach((DartType type) { |
83 if (type is InterfaceType) { | 82 if (type is InterfaceType) { |
84 InterfaceType itf = type; | 83 InterfaceType itf = type; |
85 if (!itf.isRaw) { | 84 if (!itf.isRaw) { |
86 potentiallyAddForRti(itf.element); | 85 potentiallyAddForRti(itf.element); |
87 } | 86 } |
87 } else if (type is TypeVariableType) { | |
88 TypeVariableElement variable = type.element; | |
89 ClassElement enclosing = variable.enclosingElement; | |
ngeoffray
2013/02/22 11:04:30
Why this change?
| |
90 potentiallyAddForRti(enclosing); | |
88 } | 91 } |
89 }); | 92 }); |
90 } | 93 } |
91 | 94 |
92 void registerMixinUse(MixinApplicationElement mixinApplication, | 95 void registerMixinUse(MixinApplicationElement mixinApplication, |
93 ClassElement mixin) { | 96 ClassElement mixin) { |
94 Set<MixinApplicationElement> users = | 97 Set<MixinApplicationElement> users = |
95 mixinUses.putIfAbsent(mixin, () => | 98 mixinUses.putIfAbsent(mixin, () => |
96 new Set<MixinApplicationElement>()); | 99 new Set<MixinApplicationElement>()); |
97 users.add(mixinApplication); | 100 users.add(mixinApplication); |
98 } | 101 } |
99 | 102 |
100 bool isUsedAsMixin(ClassElement cls) { | 103 bool isUsedAsMixin(ClassElement cls) { |
101 Set<MixinApplicationElement> uses = mixinUses[cls]; | 104 Set<MixinApplicationElement> uses = mixinUses[cls]; |
102 return uses != null && !uses.isEmpty; | 105 return uses != null && !uses.isEmpty; |
103 } | 106 } |
104 | 107 |
105 | 108 |
106 void registerRtiDependency(Element element, Element dependency) { | 109 void registerRtiDependency(Element element, Element dependency) { |
107 // We're not dealing with typedef for now. | 110 // We're not dealing with typedef for now. |
108 if (!element.isClass() || !dependency.isClass()) return; | 111 if (!element.isClass() || !dependency.isClass()) return; |
109 Set<ClassElement> classes = | 112 Set<ClassElement> classes = |
110 rtiDependencies.putIfAbsent(element, () => new Set<ClassElement>()); | 113 rtiDependencies.putIfAbsent(element, () => new Set<ClassElement>()); |
111 classes.add(dependency); | 114 classes.add(dependency); |
112 } | 115 } |
113 | 116 |
114 bool needsRti(ClassElement cls) { | 117 bool needsRti(ClassElement cls) { |
115 return classesNeedingRti.contains(cls) || compiler.enabledRuntimeType; | 118 return classesNeedingRti.contains(cls) || |
119 compiler.enabledRuntimeType || | |
120 compiler.hasVariableTypecheck; | |
ngeoffray
2013/02/22 11:04:30
So any class needs rti when the check is on? Shoul
| |
116 } | 121 } |
117 | 122 |
118 bool hasAnyUserDefinedGetter(Selector selector) { | 123 bool hasAnyUserDefinedGetter(Selector selector) { |
119 return allFunctions.filter(selector).any((each) => each.isGetter()); | 124 return allFunctions.filter(selector).any((each) => each.isGetter()); |
120 } | 125 } |
121 | 126 |
122 bool hasAnyUserDefinedSetter(Selector selector) { | 127 bool hasAnyUserDefinedSetter(Selector selector) { |
123 return allFunctions.filter(selector).any((each) => each.isSetter()); | 128 return allFunctions.filter(selector).any((each) => each.isSetter()); |
124 } | 129 } |
125 | 130 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 noSuchMethodSelector = new TypedSelector( | 169 noSuchMethodSelector = new TypedSelector( |
165 receiverType, selector.typeKind, noSuchMethodSelector); | 170 receiverType, selector.typeKind, noSuchMethodSelector); |
166 } | 171 } |
167 ClassElement objectClass = compiler.objectClass; | 172 ClassElement objectClass = compiler.objectClass; |
168 return allFunctions | 173 return allFunctions |
169 .filter(noSuchMethodSelector) | 174 .filter(noSuchMethodSelector) |
170 .map((Element member) => member.getEnclosingClass()) | 175 .map((Element member) => member.getEnclosingClass()) |
171 .where((ClassElement holder) => !identical(holder, objectClass)); | 176 .where((ClassElement holder) => !identical(holder, objectClass)); |
172 } | 177 } |
173 } | 178 } |
OLD | NEW |