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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/world.dart

Issue 12437009: Revert "Add superclasses, subclasses, and subtypes tracking to the world." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
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<MixinApplicationElement>> mixinUses; 10 final Map<ClassElement, Set<MixinApplicationElement>> mixinUses;
10 final Map<ClassElement, Set<ClassElement>> typesImplementedBySubclasses; 11 final Map<ClassElement, Set<ClassElement>> typesImplementedBySubclasses;
11 final Set<ClassElement> classesNeedingRti; 12 final Set<ClassElement> classesNeedingRti;
12 final Map<ClassElement, Set<ClassElement>> rtiDependencies; 13 final Map<ClassElement, Set<ClassElement>> rtiDependencies;
13 final FullFunctionSet allFunctions; 14 final FullFunctionSet allFunctions;
14 15
15 // We keep track of subtype and subclass relationships in four
16 // distinct sets to make class hierarchy analysis faster.
17 final Map<ClassElement, Set<ClassElement>> subclasses =
18 new Map<ClassElement, Set<ClassElement>>();
19 final Map<ClassElement, Set<ClassElement>> superclasses =
20 new Map<ClassElement, Set<ClassElement>>();
21 final Map<ClassElement, Set<ClassElement>> subtypes =
22 new Map<ClassElement, Set<ClassElement>>();
23 final Map<ClassElement, Set<ClassElement>> supertypes =
24 new Map<ClassElement, Set<ClassElement>>();
25
26 World(Compiler compiler) 16 World(Compiler compiler)
27 : mixinUses = new Map<ClassElement, Set<MixinApplicationElement>>(), 17 : subtypes = new Map<ClassElement, Set<ClassElement>>(),
18 mixinUses = new Map<ClassElement, Set<MixinApplicationElement>>(),
28 typesImplementedBySubclasses = 19 typesImplementedBySubclasses =
29 new Map<ClassElement, Set<ClassElement>>(), 20 new Map<ClassElement, Set<ClassElement>>(),
30 classesNeedingRti = new Set<ClassElement>(), 21 classesNeedingRti = new Set<ClassElement>(),
31 rtiDependencies = new Map<ClassElement, Set<ClassElement>>(), 22 rtiDependencies = new Map<ClassElement, Set<ClassElement>>(),
32 allFunctions = new FullFunctionSet(compiler), 23 allFunctions = new FullFunctionSet(compiler),
33 this.compiler = compiler; 24 this.compiler = compiler;
34 25
35 void populate() { 26 void populate() {
36 void addSubtypes(ClassElement cls) { 27 void addSubtypes(ClassElement cls) {
37 if (cls.resolutionState != STATE_DONE) { 28 if (cls.resolutionState != STATE_DONE) {
38 compiler.internalErrorOnElement( 29 compiler.internalErrorOnElement(
39 cls, 'Class "${cls.name.slowToString()}" is not resolved.'); 30 cls, 'Class "${cls.name.slowToString()}" is not resolved.');
40 } 31 }
41 32
42 for (DartType type in cls.allSupertypes) { 33 for (DartType type in cls.allSupertypes) {
43 Set<Element> supertypesOfClass = 34 Set<Element> subtypesOfCls =
44 supertypes.putIfAbsent(cls, () => new Set<ClassElement>()); 35 subtypes.putIfAbsent(type.element, () => new Set<ClassElement>());
45 Set<Element> subtypesOfSupertype = 36 subtypesOfCls.add(cls);
46 subtypes.putIfAbsent(type.element, () => new Set<ClassElement>());
47 supertypesOfClass.add(type.element);
48 subtypesOfSupertype.add(cls);
49 } 37 }
50 38
51 // Walk through the superclasses, and record the types 39 // Walk through the superclasses, and record the types
52 // implemented by that type on the superclasses. 40 // implemented by that type on the superclasses.
53 DartType type = cls.supertype; 41 DartType type = cls.supertype;
54 while (type != null) { 42 while (type != null) {
55 Set<Element> superclassesOfClass =
56 superclasses.putIfAbsent(cls, () => new Set<ClassElement>());
57 Set<Element> subclassesOfSuperclass =
58 subclasses.putIfAbsent(type.element, () => new Set<ClassElement>());
59 superclassesOfClass.add(type.element);
60 subclassesOfSuperclass.add(cls);
61
62 Set<Element> typesImplementedBySubclassesOfCls = 43 Set<Element> typesImplementedBySubclassesOfCls =
63 typesImplementedBySubclasses.putIfAbsent( 44 typesImplementedBySubclasses.putIfAbsent(
64 type.element, () => new Set<ClassElement>()); 45 type.element, () => new Set<ClassElement>());
65 for (DartType current in cls.allSupertypes) { 46 for (DartType current in cls.allSupertypes) {
66 typesImplementedBySubclassesOfCls.add(current.element); 47 typesImplementedBySubclassesOfCls.add(current.element);
67 } 48 }
68 ClassElement classElement = type.element; 49 ClassElement classElement = type.element;
69 type = classElement.supertype; 50 type = classElement.supertype;
70 } 51 }
71 } 52 }
72 53
73 // Use the [:seenClasses:] set to include non-instantiated 54 // Use the [:seenClasses:] set to include non-instantiated
74 // classes: if the superclass of these classes require RTI, then 55 // classes: if the superclass of these classes require RTI, then
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 if (!itf.isRaw) { 106 if (!itf.isRaw) {
126 potentiallyAddForRti(itf.element); 107 potentiallyAddForRti(itf.element);
127 } 108 }
128 } else if (type.kind == TypeKind.TYPE_VARIABLE) { 109 } else if (type.kind == TypeKind.TYPE_VARIABLE) {
129 TypeVariableElement variable = type.element; 110 TypeVariableElement variable = type.element;
130 potentiallyAddForRti(variable.enclosingElement); 111 potentiallyAddForRti(variable.enclosingElement);
131 } 112 }
132 }); 113 });
133 } 114 }
134 115
135 Iterable<ClassElement> commonSupertypesOf(ClassElement x, ClassElement y) {
136 Set<ClassElement> xSet = supertypes[x];
137 if (xSet == null) return const <ClassElement>[];
138 Set<ClassElement> ySet = supertypes[y];
139 if (ySet == null) return const <ClassElement>[];
140 Set<ClassElement> smallSet, largeSet;
141 if (xSet.length <= ySet.length) {
142 smallSet = xSet;
143 largeSet = ySet;
144 } else {
145 smallSet = ySet;
146 largeSet = xSet;
147 }
148 return smallSet.where((ClassElement each) => largeSet.contains(each));
149 }
150
151 void registerMixinUse(MixinApplicationElement mixinApplication, 116 void registerMixinUse(MixinApplicationElement mixinApplication,
152 ClassElement mixin) { 117 ClassElement mixin) {
153 Set<MixinApplicationElement> users = 118 Set<MixinApplicationElement> users =
154 mixinUses.putIfAbsent(mixin, () => 119 mixinUses.putIfAbsent(mixin, () =>
155 new Set<MixinApplicationElement>()); 120 new Set<MixinApplicationElement>());
156 users.add(mixinApplication); 121 users.add(mixinApplication);
157 } 122 }
158 123
159 bool isUsedAsMixin(ClassElement cls) { 124 bool isUsedAsMixin(ClassElement cls) {
160 Set<MixinApplicationElement> uses = mixinUses[cls]; 125 Set<MixinApplicationElement> uses = mixinUses[cls];
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 if (mask != null) { 195 if (mask != null) {
231 noSuchMethodSelector = new TypedSelector(mask, noSuchMethodSelector); 196 noSuchMethodSelector = new TypedSelector(mask, noSuchMethodSelector);
232 } 197 }
233 ClassElement objectClass = compiler.objectClass; 198 ClassElement objectClass = compiler.objectClass;
234 return allFunctions 199 return allFunctions
235 .filter(noSuchMethodSelector) 200 .filter(noSuchMethodSelector)
236 .map((Element member) => member.getEnclosingClass()) 201 .map((Element member) => member.getEnclosingClass())
237 .where((ClassElement holder) => !identical(holder, objectClass)); 202 .where((ClassElement holder) => !identical(holder, objectClass));
238 } 203 }
239 } 204 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/types/type_mask.dart ('k') | tests/compiler/dart2js/field_type_inferer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698