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

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

Issue 2392943003: Handle const constructor invocation in kernel_impact. (Closed)
Patch Set: Updated cf. comments. 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
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';
11 import '../dart_types.dart'; 11 import '../dart_types.dart';
12 import '../elements/elements.dart'; 12 import '../elements/elements.dart';
13 import '../js_backend/backend.dart' show JavaScriptBackend; 13 import '../js_backend/backend.dart' show JavaScriptBackend;
14 import '../kernel/kernel.dart'; 14 import '../kernel/kernel.dart';
15 import '../kernel/kernel_debug.dart'; 15 import '../kernel/kernel_debug.dart';
16 import '../kernel/kernel_visitor.dart'; 16 import '../kernel/kernel_visitor.dart';
17 import '../resolution/registry.dart' show ResolutionWorldImpactBuilder; 17 import '../resolution/registry.dart' show ResolutionWorldImpactBuilder;
18 import '../universe/call_structure.dart';
18 import '../universe/feature.dart'; 19 import '../universe/feature.dart';
19 import '../universe/selector.dart'; 20 import '../universe/selector.dart';
20 import '../universe/use.dart'; 21 import '../universe/use.dart';
21 22
22 import 'kernel_ast_adapter.dart'; 23 import 'kernel_ast_adapter.dart';
23 import '../common/resolution.dart'; 24 import '../common/resolution.dart';
24 25
25 /// Computes the [ResolutionImpact] for [resolvedAst] through kernel. 26 /// Computes the [ResolutionImpact] for [resolvedAst] through kernel.
26 ResolutionImpact build(Compiler compiler, ResolvedAst resolvedAst) { 27 ResolutionImpact build(Compiler compiler, ResolvedAst resolvedAst) {
27 AstElement element = resolvedAst.element; 28 AstElement element = resolvedAst.element;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 visitNode(entry.value); 209 visitNode(entry.value);
209 } 210 }
210 211
211 void _visitArguments(ir.Arguments arguments) { 212 void _visitArguments(ir.Arguments arguments) {
212 arguments.positional.forEach(visitNode); 213 arguments.positional.forEach(visitNode);
213 arguments.named.forEach(visitNode); 214 arguments.named.forEach(visitNode);
214 } 215 }
215 216
216 @override 217 @override
217 void visitConstructorInvocation(ir.ConstructorInvocation node) { 218 void visitConstructorInvocation(ir.ConstructorInvocation node) {
218 handleNew(node, node.target); 219 handleNew(node, node.target, isConst: node.isConst);
219 } 220 }
220 221
221 void handleNew(ir.InvocationExpression node, ir.Member target) { 222 void handleNew(ir.InvocationExpression node, ir.Member target,
223 {bool isConst: false}) {
222 _visitArguments(node.arguments); 224 _visitArguments(node.arguments);
223 Element element = astAdapter.getElement(target).declaration; 225 Element element = astAdapter.getElement(target).declaration;
224 impactBuilder.registerStaticUse(new StaticUse.constructorInvoke(
225 element, astAdapter.getCallStructure(node.arguments)));
226 ClassElement cls = astAdapter.getElement(target.enclosingClass); 226 ClassElement cls = astAdapter.getElement(target.enclosingClass);
227 List<DartType> typeArguments = 227 List<DartType> typeArguments =
228 astAdapter.getDartTypes(node.arguments.types); 228 astAdapter.getDartTypes(node.arguments.types);
229 impactBuilder.registerTypeUse( 229 InterfaceType type = new InterfaceType(cls, typeArguments);
230 new TypeUse.instantiation(new InterfaceType(cls, typeArguments))); 230 CallStructure callStructure = astAdapter.getCallStructure(node.arguments);
231 impactBuilder.registerStaticUse(isConst
232 ? new StaticUse.constConstructorInvoke(element, callStructure, type)
233 : new StaticUse.typedConstructorInvoke(element, callStructure, type));
231 if (typeArguments.any((DartType type) => !type.isDynamic)) { 234 if (typeArguments.any((DartType type) => !type.isDynamic)) {
232 impactBuilder.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); 235 impactBuilder.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK);
233 } 236 }
234 } 237 }
235 238
236 @override 239 @override
237 void visitStaticInvocation(ir.StaticInvocation node) { 240 void visitStaticInvocation(ir.StaticInvocation node) {
238 Element target = astAdapter.getElement(node.target).declaration; 241 Element target = astAdapter.getElement(node.target).declaration;
239 if (target.isFactoryConstructor) { 242 if (target.isFactoryConstructor) {
240 // TODO(johnniwinther): We should not mark the type as instantiated but 243 // TODO(johnniwinther): We should not mark the type as instantiated but
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 void visitTryFinally(ir.TryFinally node) { 417 void visitTryFinally(ir.TryFinally node) {
415 visitNode(node.body); 418 visitNode(node.body);
416 visitNode(node.finalizer); 419 visitNode(node.finalizer);
417 } 420 }
418 421
419 // TODO(johnniwinther): Make this throw and visit child nodes explicitly 422 // TODO(johnniwinther): Make this throw and visit child nodes explicitly
420 // instead to ensure that we don't visit unwanted parts of the ir. 423 // instead to ensure that we don't visit unwanted parts of the ir.
421 @override 424 @override
422 void defaultNode(ir.Node node) => node.visitChildren(this); 425 void defaultNode(ir.Node node) => node.visitChildren(this);
423 } 426 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/serialization/impact_serialization.dart ('k') | pkg/compiler/lib/src/universe/use.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698