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

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

Issue 12210142: Implement is-checks against type variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix a long line. 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<ClassElement>> subtypes;
10 final Map<ClassElement, Set<MixinApplicationElement>> mixinUses; 10 final Map<ClassElement, Set<MixinApplicationElement>> mixinUses;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 72 }
73 73
74 Set<ClassElement> dependencies = rtiDependencies[cls]; 74 Set<ClassElement> dependencies = rtiDependencies[cls];
75 if (dependencies != null) { 75 if (dependencies != null) {
76 dependencies.forEach((ClassElement other) { 76 dependencies.forEach((ClassElement other) {
77 potentiallyAddForRti(other); 77 potentiallyAddForRti(other);
78 }); 78 });
79 } 79 }
80 } 80 }
81 81
82 Set<ClassElement> classesUsingTypeVariableTests = new Set<ClassElement>();
82 compiler.resolverWorld.isChecks.forEach((DartType type) { 83 compiler.resolverWorld.isChecks.forEach((DartType type) {
83 if (type is InterfaceType) { 84 if (type.kind == TypeKind.TYPE_VARIABLE) {
85 TypeVariableElement variable = type.element;
86 classesUsingTypeVariableTests.add(variable.enclosingElement);
87 }
88 });
89 // Add is-checks that result from classes using type variables in checks.
90 compiler.resolverWorld.addImplicitChecks(classesUsingTypeVariableTests);
91 // Add the rti dependencies that are implicit in the way the backend
92 // generates code: when we create a new [List], we actually create
93 // a JSArray in the backend and we need to add type arguments to
94 // the calls of the list constructor whenever we determine that
95 // JSArray needs type arguments.
96 compiler.backend.addBackendRtiDependencies(this);
97 // Compute the set of all classes that need runtime type information.
98 compiler.resolverWorld.isChecks.forEach((DartType type) {
99 if (type.kind == TypeKind.INTERFACE) {
84 InterfaceType itf = type; 100 InterfaceType itf = type;
85 if (!itf.isRaw) { 101 if (!itf.isRaw) {
86 potentiallyAddForRti(itf.element); 102 potentiallyAddForRti(itf.element);
87 } 103 }
104 } else if (type.kind == TypeKind.TYPE_VARIABLE) {
105 TypeVariableElement variable = type.element;
106 potentiallyAddForRti(variable.enclosingElement);
88 } 107 }
89 }); 108 });
90 } 109 }
91 110
92 void registerMixinUse(MixinApplicationElement mixinApplication, 111 void registerMixinUse(MixinApplicationElement mixinApplication,
93 ClassElement mixin) { 112 ClassElement mixin) {
94 Set<MixinApplicationElement> users = 113 Set<MixinApplicationElement> users =
95 mixinUses.putIfAbsent(mixin, () => 114 mixinUses.putIfAbsent(mixin, () =>
96 new Set<MixinApplicationElement>()); 115 new Set<MixinApplicationElement>());
97 users.add(mixinApplication); 116 users.add(mixinApplication);
98 } 117 }
99 118
100 bool isUsedAsMixin(ClassElement cls) { 119 bool isUsedAsMixin(ClassElement cls) {
101 Set<MixinApplicationElement> uses = mixinUses[cls]; 120 Set<MixinApplicationElement> uses = mixinUses[cls];
102 return uses != null && !uses.isEmpty; 121 return uses != null && !uses.isEmpty;
103 } 122 }
104 123
105
106 void registerRtiDependency(Element element, Element dependency) { 124 void registerRtiDependency(Element element, Element dependency) {
107 // We're not dealing with typedef for now. 125 // We're not dealing with typedef for now.
108 if (!element.isClass() || !dependency.isClass()) return; 126 if (!element.isClass() || !dependency.isClass()) return;
109 Set<ClassElement> classes = 127 Set<ClassElement> classes =
110 rtiDependencies.putIfAbsent(element, () => new Set<ClassElement>()); 128 rtiDependencies.putIfAbsent(element, () => new Set<ClassElement>());
111 classes.add(dependency); 129 classes.add(dependency);
112 } 130 }
113 131
114 bool needsRti(ClassElement cls) { 132 bool needsRti(ClassElement cls) {
115 return classesNeedingRti.contains(cls) || compiler.enabledRuntimeType; 133 return classesNeedingRti.contains(cls) || compiler.enabledRuntimeType;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (mask != null) { 190 if (mask != null) {
173 noSuchMethodSelector = new TypedSelector(mask, noSuchMethodSelector); 191 noSuchMethodSelector = new TypedSelector(mask, noSuchMethodSelector);
174 } 192 }
175 ClassElement objectClass = compiler.objectClass; 193 ClassElement objectClass = compiler.objectClass;
176 return allFunctions 194 return allFunctions
177 .filter(noSuchMethodSelector) 195 .filter(noSuchMethodSelector)
178 .map((Element member) => member.getEnclosingClass()) 196 .map((Element member) => member.getEnclosingClass())
179 .where((ClassElement holder) => !identical(holder, objectClass)); 197 .where((ClassElement holder) => !identical(holder, objectClass));
180 } 198 }
181 } 199 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698