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

Side by Side Diff: lib/compiler/implementation/universe.dart

Issue 10180001: Introduce typed selectors to do better tree shaking based on calls on 'this'. Getters and setters w… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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 class Universe { 5 class Universe {
6 Map<Element, String> generatedCode; 6 Map<Element, String> generatedCode;
7 Map<Element, String> generatedBailoutCode; 7 Map<Element, String> generatedBailoutCode;
8 final Set<ClassElement> instantiatedClasses; 8 final Set<ClassElement> instantiatedClasses;
9 final Set<SourceString> instantiatedClassInstanceFields; 9 final Set<SourceString> instantiatedClassInstanceFields;
10 final Set<FunctionElement> staticFunctionsNeedingGetter; 10 final Set<FunctionElement> staticFunctionsNeedingGetter;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 const Selector(SelectorKind.INDEX, 2); 71 const Selector(SelectorKind.INDEX, 2);
72 static final Selector GETTER_AND_SETTER = 72 static final Selector GETTER_AND_SETTER =
73 const Selector(SelectorKind.SETTER, 1); 73 const Selector(SelectorKind.SETTER, 1);
74 static final Selector INVOCATION_0 = 74 static final Selector INVOCATION_0 =
75 const Selector(SelectorKind.INVOCATION, 0); 75 const Selector(SelectorKind.INVOCATION, 0);
76 static final Selector INVOCATION_1 = 76 static final Selector INVOCATION_1 =
77 const Selector(SelectorKind.INVOCATION, 1); 77 const Selector(SelectorKind.INVOCATION, 1);
78 static final Selector INVOCATION_2 = 78 static final Selector INVOCATION_2 =
79 const Selector(SelectorKind.INVOCATION, 2); 79 const Selector(SelectorKind.INVOCATION, 2);
80 80
81 bool applies(FunctionParameters parameters) { 81 bool applies(FunctionElement element, Compiler compiler) {
kasperl 2012/04/23 12:34:45 Not sure I understand the name of this method.
ngeoffray 2012/04/23 13:48:18 The method is whether the selector applies to this
82 FunctionParameters parameters = element.computeParameters(compiler);
82 if (argumentCount > parameters.parameterCount) return false; 83 if (argumentCount > parameters.parameterCount) return false;
83 int requiredParameterCount = parameters.requiredParameterCount; 84 int requiredParameterCount = parameters.requiredParameterCount;
84 int optionalParameterCount = parameters.optionalParameterCount; 85 int optionalParameterCount = parameters.optionalParameterCount;
85 if (positionalArgumentCount < requiredParameterCount) return false; 86 if (positionalArgumentCount < requiredParameterCount) return false;
86 87
87 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty(); 88 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty();
88 if (namedArguments.isEmpty()) { 89 if (namedArguments.isEmpty()) {
89 if (!hasOptionalParameters) { 90 if (!hasOptionalParameters) {
90 return requiredParameterCount == argumentCount; 91 return requiredParameterCount == argumentCount;
91 } else { 92 } else {
(...skipping 22 matching lines...) Expand all
114 return true; 115 return true;
115 } 116 }
116 } 117 }
117 118
118 /** 119 /**
119 * Returns [:true:] if the selector and the [element] match; [:false:] 120 * Returns [:true:] if the selector and the [element] match; [:false:]
120 * otherwise. 121 * otherwise.
121 */ 122 */
122 bool addArgumentsToList(Link<Node> arguments, 123 bool addArgumentsToList(Link<Node> arguments,
123 List list, 124 List list,
124 FunctionParameters parameters, 125 FunctionElement element,
125 compileArgument(Node argument), 126 compileArgument(Node argument),
126 compileConstant(Element element)) { 127 compileConstant(Element element),
127 void addMatchingArgumentsToList(Link<Node> link) { 128 Compiler compiler) {
128 } 129 if (!this.applies(element, compiler)) return false;
129 130
130 if (!this.applies(parameters)) return false; 131 void addMatchingArgumentsToList(Link<Node> link) {}
132
133 FunctionParameters parameters = element.computeParameters(compiler);
131 if (this.positionalArgumentCount == parameters.parameterCount) { 134 if (this.positionalArgumentCount == parameters.parameterCount) {
132 for (Link<Node> link = arguments; !link.isEmpty(); link = link.tail) { 135 for (Link<Node> link = arguments; !link.isEmpty(); link = link.tail) {
133 list.add(compileArgument(link.head)); 136 list.add(compileArgument(link.head));
134 } 137 }
135 return true; 138 return true;
136 } 139 }
137 140
138 // If there are named arguments, provide them in the order 141 // If there are named arguments, provide them in the order
139 // expected by the called function, which is the source order. 142 // expected by the called function, which is the source order.
140 143
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 if (!orderedNamedArguments.isEmpty()) return orderedNamedArguments; 226 if (!orderedNamedArguments.isEmpty()) return orderedNamedArguments;
224 227
225 List<SourceString> list = new List<SourceString>.from(namedArguments); 228 List<SourceString> list = new List<SourceString>.from(namedArguments);
226 list.sort((SourceString first, SourceString second) { 229 list.sort((SourceString first, SourceString second) {
227 return first.slowToString().compareTo(second.slowToString()); 230 return first.slowToString().compareTo(second.slowToString());
228 }); 231 });
229 orderedNamedArguments = list; 232 orderedNamedArguments = list;
230 return orderedNamedArguments; 233 return orderedNamedArguments;
231 } 234 }
232 } 235 }
236
237 class TypedInvocation extends Invocation {
kasperl 2012/04/23 12:34:45 So this is a special invocation where we know some
ngeoffray 2012/04/23 13:48:18 Done.
238 final Type type;
kasperl 2012/04/23 12:34:45 type -> receiverType?
ngeoffray 2012/04/23 13:48:18 Done.
239
240 TypedInvocation(this.type, Selector selector)
241 : super(selector.argumentCount, selector.namedArguments);
242
243 bool applies(FunctionElement element, Compiler compiler) {
244 if (!element.enclosingElement.isClass()) return false;
245
246 ClassElement other = element.enclosingElement;
247 ClassElement self = type.element;
248 if (other === self || other.isSubclassOf(self)) {
249 return super.applies(element, compiler);
250 }
251 return false;
252 }
253
254 bool operator ==(other) {
255 if (other is !TypedInvocation) return false;
256 if (other.type !== type) return false;
257 return super == other;
258 }
259 }
OLDNEW
« lib/compiler/implementation/ssa/codegen.dart ('K') | « lib/compiler/implementation/ssa/optimize.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698