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

Side by Side Diff: pkg/compiler/lib/src/ssa/graph_builder.dart

Issue 2722753002: Remove HRuntimeType implementation (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import '../common/codegen.dart' show CodegenRegistry; 5 import '../common/codegen.dart' show CodegenRegistry;
6 import '../compiler.dart'; 6 import '../compiler.dart';
7 import '../elements/elements.dart'; 7 import '../elements/elements.dart';
8 import '../elements/entities.dart' show Entity, Local; 8 import '../elements/entities.dart' show Entity, Local;
9 import '../elements/resolution_types.dart'; 9 import '../elements/resolution_types.dart';
10 import '../js_backend/js_backend.dart'; 10 import '../js_backend/js_backend.dart';
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 HSubGraphBlockInformation wrapStatementGraph(SubGraph statements) { 182 HSubGraphBlockInformation wrapStatementGraph(SubGraph statements) {
183 if (statements == null) return null; 183 if (statements == null) return null;
184 return new HSubGraphBlockInformation(statements); 184 return new HSubGraphBlockInformation(statements);
185 } 185 }
186 186
187 HSubExpressionBlockInformation wrapExpressionGraph(SubExpression expression) { 187 HSubExpressionBlockInformation wrapExpressionGraph(SubExpression expression) {
188 if (expression == null) return null; 188 if (expression == null) return null;
189 return new HSubExpressionBlockInformation(expression); 189 return new HSubExpressionBlockInformation(expression);
190 } 190 }
191 191
192 HInstruction buildFunctionType(ResolutionFunctionType type) {
193 type.accept(new ReifiedTypeRepresentationBuilder(closedWorld), this);
194 return pop();
195 }
196
197 HInstruction buildFunctionTypeConversion(
198 HInstruction original, ResolutionDartType type, int kind);
199
200 /// Returns the current source element. 192 /// Returns the current source element.
201 /// 193 ///
202 /// The returned element is a declaration element. 194 /// The returned element is a declaration element.
203 Element get sourceElement; 195 Element get sourceElement;
204 196
205 // TODO(karlklose): this is needed to avoid a bug where the resolved type is 197 // TODO(karlklose): this is needed to avoid a bug where the resolved type is
206 // not stored on a type annotation in the closure translator. Remove when 198 // not stored on a type annotation in the closure translator. Remove when
207 // fixed. 199 // fixed.
208 bool hasDirectLocal(Local local) { 200 bool hasDirectLocal(Local local) {
209 return !localsHandler.isAccessedDirectly(local) || 201 return !localsHandler.isAccessedDirectly(local) ||
(...skipping 25 matching lines...) Expand all
235 open(newBlock); 227 open(newBlock);
236 } 228 }
237 229
238 HInstruction callSetRuntimeTypeInfo( 230 HInstruction callSetRuntimeTypeInfo(
239 HInstruction typeInfo, HInstruction newObject); 231 HInstruction typeInfo, HInstruction newObject);
240 232
241 /// The element for which this SSA builder is being used. 233 /// The element for which this SSA builder is being used.
242 Element get targetElement; 234 Element get targetElement;
243 TypeBuilder get typeBuilder; 235 TypeBuilder get typeBuilder;
244 } 236 }
245
246 class ReifiedTypeRepresentationBuilder
247 implements DartTypeVisitor<dynamic, GraphBuilder> {
248 final ClosedWorld closedWorld;
249
250 ReifiedTypeRepresentationBuilder(this.closedWorld);
251
252 void visit(ResolutionDartType type, GraphBuilder builder) =>
253 type.accept(this, builder);
254
255 void visitVoidType(ResolutionVoidType type, GraphBuilder builder) {
256 ClassElement cls = builder.backend.helpers.VoidRuntimeType;
257 builder.push(new HVoidType(type, new TypeMask.exact(cls, closedWorld)));
258 }
259
260 void visitTypeVariableType(
261 ResolutionTypeVariableType type, GraphBuilder builder) {
262 ClassElement cls = builder.backend.helpers.RuntimeType;
263 TypeMask instructionType = new TypeMask.subclass(cls, closedWorld);
264
265 // TODO(floitsch): this hack maps type variables of generic function
266 // typedefs to dynamic. For example: `typedef F = Function<T>(T)`.
267 if (type is MethodTypeVariableType) {
268 visitDynamicType(const ResolutionDynamicType(), builder);
269 return;
270 }
271
272 if (!builder.sourceElement.enclosingElement.isClosure &&
273 builder.sourceElement.isInstanceMember) {
274 HInstruction receiver = builder.localsHandler.readThis();
275 builder.push(new HReadTypeVariable(type, receiver, instructionType));
276 } else {
277 builder.push(new HReadTypeVariable.noReceiver(
278 type,
279 builder.typeBuilder
280 .addTypeVariableReference(type, builder.sourceElement),
281 instructionType));
282 }
283 }
284
285 void visitFunctionType(ResolutionFunctionType type, GraphBuilder builder) {
286 type.returnType.accept(this, builder);
287 HInstruction returnType = builder.pop();
288 List<HInstruction> inputs = <HInstruction>[returnType];
289
290 for (ResolutionDartType parameter in type.parameterTypes) {
291 parameter.accept(this, builder);
292 inputs.add(builder.pop());
293 }
294
295 for (ResolutionDartType parameter in type.optionalParameterTypes) {
296 parameter.accept(this, builder);
297 inputs.add(builder.pop());
298 }
299
300 List<ResolutionDartType> namedParameterTypes = type.namedParameterTypes;
301 List<String> names = type.namedParameters;
302 for (int index = 0; index < names.length; index++) {
303 ast.DartString dartString = new ast.DartString.literal(names[index]);
304 inputs.add(
305 builder.graph.addConstantString(dartString, builder.closedWorld));
306 namedParameterTypes[index].accept(this, builder);
307 inputs.add(builder.pop());
308 }
309
310 ClassElement cls = builder.backend.helpers.RuntimeFunctionType;
311 builder.push(
312 new HFunctionType(inputs, type, new TypeMask.exact(cls, closedWorld)));
313 }
314
315 void visitMalformedType(MalformedType type, GraphBuilder builder) {
316 visitDynamicType(const ResolutionDynamicType(), builder);
317 }
318
319 void visitInterfaceType(ResolutionInterfaceType type, GraphBuilder builder) {
320 List<HInstruction> inputs = <HInstruction>[];
321 for (ResolutionDartType typeArgument in type.typeArguments) {
322 typeArgument.accept(this, builder);
323 inputs.add(builder.pop());
324 }
325 ClassElement cls;
326 if (type.typeArguments.isEmpty) {
327 cls = builder.backend.helpers.RuntimeTypePlain;
328 } else {
329 cls = builder.backend.helpers.RuntimeTypeGeneric;
330 }
331 builder.push(
332 new HInterfaceType(inputs, type, new TypeMask.exact(cls, closedWorld)));
333 }
334
335 void visitTypedefType(ResolutionTypedefType type, GraphBuilder builder) {
336 ResolutionDartType unaliased = type.unaliased;
337 if (unaliased is ResolutionTypedefType) throw 'unable to unalias $type';
338 unaliased.accept(this, builder);
339 }
340
341 void visitDynamicType(ResolutionDynamicType type, GraphBuilder builder) {
342 JavaScriptBackend backend = builder.compiler.backend;
343 ClassElement cls = backend.helpers.DynamicRuntimeType;
344 builder.push(new HDynamicType(type, new TypeMask.exact(cls, closedWorld)));
345 }
346 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698