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

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

Issue 2375613003: Handle getters/setters and try in kernel_impact. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | tests/compiler/dart2js/kernel/impact_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/names.dart'; 8 import '../common/names.dart';
9 import '../compiler.dart'; 9 import '../compiler.dart';
10 import '../constants/expressions.dart'; 10 import '../constants/expressions.dart';
(...skipping 11 matching lines...) Expand all
22 import 'kernel_ast_adapter.dart'; 22 import 'kernel_ast_adapter.dart';
23 import '../common/resolution.dart'; 23 import '../common/resolution.dart';
24 24
25 /// Computes the [ResolutionImpact] for [resolvedAst] through kernel. 25 /// Computes the [ResolutionImpact] for [resolvedAst] through kernel.
26 ResolutionImpact build(Compiler compiler, ResolvedAst resolvedAst) { 26 ResolutionImpact build(Compiler compiler, ResolvedAst resolvedAst) {
27 AstElement element = resolvedAst.element; 27 AstElement element = resolvedAst.element;
28 JavaScriptBackend backend = compiler.backend; 28 JavaScriptBackend backend = compiler.backend;
29 Kernel kernel = backend.kernelTask.kernel; 29 Kernel kernel = backend.kernelTask.kernel;
30 KernelImpactBuilder builder = 30 KernelImpactBuilder builder =
31 new KernelImpactBuilder(resolvedAst, compiler, kernel); 31 new KernelImpactBuilder(resolvedAst, compiler, kernel);
32 if (element.isFunction) { 32 if (element.isFunction || element.isGetter || element.isSetter) {
33 ir.Procedure function = kernel.functions[element]; 33 ir.Procedure function = kernel.functions[element];
34 if (function == null) { 34 if (function == null) {
35 print("FOUND NULL FUNCTION: $element"); 35 print("FOUND NULL FUNCTION: $element");
36 } else { 36 } else {
37 return builder.buildProcedure(function); 37 return builder.buildProcedure(function);
38 } 38 }
39 } else { 39 } else {
40 ir.Field field = kernel.fields[element]; 40 ir.Field field = kernel.fields[element];
41 if (field == null) { 41 if (field == null) {
42 print("FOUND NULL FUNCTION: $element"); 42 print("FOUND NULL FIELD: $element");
43 } else { 43 } else {
44 return builder.buildField(field); 44 return builder.buildField(field);
45 } 45 }
46 } 46 }
47 return null; 47 return null;
48 } 48 }
49 49
50 class KernelImpactBuilder extends ir.Visitor { 50 class KernelImpactBuilder extends ir.Visitor {
51 final ResolvedAst resolvedAst; 51 final ResolvedAst resolvedAst;
52 final Compiler compiler; 52 final Compiler compiler;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 if (!field.isConst) { 86 if (!field.isConst) {
87 impactBuilder.registerFeature(Feature.LAZY_FIELD); 87 impactBuilder.registerFeature(Feature.LAZY_FIELD);
88 } 88 }
89 } else { 89 } else {
90 impactBuilder.registerFeature(Feature.FIELD_WITHOUT_INITIALIZER); 90 impactBuilder.registerFeature(Feature.FIELD_WITHOUT_INITIALIZER);
91 } 91 }
92 return impactBuilder; 92 return impactBuilder;
93 } 93 }
94 94
95 ResolutionImpact buildProcedure(ir.Procedure procedure) { 95 ResolutionImpact buildProcedure(ir.Procedure procedure) {
96 if (procedure.kind == ir.ProcedureKind.Method || 96 if (procedure.kind != ir.ProcedureKind.Factory) {
97 procedure.kind == ir.ProcedureKind.Operator) {
98 checkFunctionTypes(procedure.function); 97 checkFunctionTypes(procedure.function);
99 visitNode(procedure.function.body); 98 visitNode(procedure.function.body);
100 switch (procedure.function.asyncMarker) { 99 switch (procedure.function.asyncMarker) {
101 case ir.AsyncMarker.Sync: 100 case ir.AsyncMarker.Sync:
102 break; 101 break;
103 case ir.AsyncMarker.SyncStar: 102 case ir.AsyncMarker.SyncStar:
104 impactBuilder.registerFeature(Feature.SYNC_STAR); 103 impactBuilder.registerFeature(Feature.SYNC_STAR);
105 break; 104 break;
106 case ir.AsyncMarker.Async: 105 case ir.AsyncMarker.Async:
107 impactBuilder.registerFeature(Feature.ASYNC); 106 impactBuilder.registerFeature(Feature.ASYNC);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 ir.Member target = node.target; 272 ir.Member target = node.target;
274 Element element = astAdapter.getElement(target).declaration; 273 Element element = astAdapter.getElement(target).declaration;
275 if (target is ir.Procedure && target.kind == ir.ProcedureKind.Method) { 274 if (target is ir.Procedure && target.kind == ir.ProcedureKind.Method) {
276 impactBuilder.registerStaticUse(new StaticUse.staticTearOff(element)); 275 impactBuilder.registerStaticUse(new StaticUse.staticTearOff(element));
277 } else { 276 } else {
278 impactBuilder.registerStaticUse(new StaticUse.staticGet(element)); 277 impactBuilder.registerStaticUse(new StaticUse.staticGet(element));
279 } 278 }
280 } 279 }
281 280
282 @override 281 @override
282 void visitStaticSet(ir.StaticSet node) {
283 visitNode(node.value);
284 Element element = astAdapter.getElement(node.target).declaration;
285 impactBuilder.registerStaticUse(new StaticUse.staticSet(element));
286 }
287
288 @override
283 void visitMethodInvocation(ir.MethodInvocation invocation) { 289 void visitMethodInvocation(ir.MethodInvocation invocation) {
284 var receiver = invocation.receiver; 290 var receiver = invocation.receiver;
285 if (receiver is ir.VariableGet && 291 if (receiver is ir.VariableGet &&
286 receiver.variable.isFinal && 292 receiver.variable.isFinal &&
287 receiver.variable.parent is ir.FunctionDeclaration) { 293 receiver.variable.parent is ir.FunctionDeclaration) {
288 // Invocation of a local function. No need for dynamic use. 294 // Invocation of a local function. No need for dynamic use.
289 } else { 295 } else {
290 visitNode(invocation.receiver); 296 visitNode(invocation.receiver);
291 impactBuilder.registerDynamicUse( 297 impactBuilder.registerDynamicUse(
292 new DynamicUse(astAdapter.getSelector(invocation), null)); 298 new DynamicUse(astAdapter.getSelector(invocation), null));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 impactBuilder.registerFeature(Feature.ASYNC_FOR_IN); 383 impactBuilder.registerFeature(Feature.ASYNC_FOR_IN);
378 } else { 384 } else {
379 impactBuilder.registerFeature(Feature.SYNC_FOR_IN); 385 impactBuilder.registerFeature(Feature.SYNC_FOR_IN);
380 impactBuilder 386 impactBuilder
381 .registerDynamicUse(new DynamicUse(Selectors.iterator, null)); 387 .registerDynamicUse(new DynamicUse(Selectors.iterator, null));
382 } 388 }
383 impactBuilder.registerDynamicUse(new DynamicUse(Selectors.current, null)); 389 impactBuilder.registerDynamicUse(new DynamicUse(Selectors.current, null));
384 impactBuilder.registerDynamicUse(new DynamicUse(Selectors.moveNext, null)); 390 impactBuilder.registerDynamicUse(new DynamicUse(Selectors.moveNext, null));
385 } 391 }
386 392
393 @override
394 void visitTryCatch(ir.TryCatch node) {
395 visitNode(node.body);
396 visitNodes(node.catches);
397 }
398
399 @override
400 void visitCatch(ir.Catch node) {
401 impactBuilder.registerFeature(Feature.CATCH_STATEMENT);
402 visitNode(node.exception);
403 if (node.stackTrace != null) {
404 impactBuilder.registerFeature(Feature.STACK_TRACE_IN_CATCH);
405 }
406 if (node.guard is! ir.DynamicType) {
407 impactBuilder.registerTypeUse(
408 new TypeUse.catchType(astAdapter.getDartType(node.guard)));
409 }
410 visitNode(node.body);
411 }
412
413 @override
414 void visitTryFinally(ir.TryFinally node) {
415 visitNode(node.body);
Harry Terkelsen 2016/09/27 17:12:37 also visit the finalizer
Johnni Winther 2016/09/30 07:59:04 Done.
416 }
417
387 // TODO(johnniwinther): Make this throw and visit child nodes explicitly 418 // TODO(johnniwinther): Make this throw and visit child nodes explicitly
388 // instead to ensure that we don't visit unwanted parts of the ir. 419 // instead to ensure that we don't visit unwanted parts of the ir.
389 @override 420 @override
390 void defaultNode(ir.Node node) => node.visitChildren(this); 421 void defaultNode(ir.Node node) => node.visitChildren(this);
391 } 422 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/kernel/impact_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698