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

Side by Side Diff: pkg/compiler/lib/src/inferrer/inferrer_engine.dart

Issue 2746293006: Pulling the element model out of global type inference. (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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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;
6
5 import '../common.dart'; 7 import '../common.dart';
6 import '../common/names.dart'; 8 import '../common/names.dart';
7 import '../compiler.dart'; 9 import '../compiler.dart';
8 import '../constants/expressions.dart'; 10 import '../constants/expressions.dart';
9 import '../constants/values.dart'; 11 import '../constants/values.dart';
10 import '../common_elements.dart'; 12 import '../common_elements.dart';
11 import '../elements/elements.dart'; 13 import '../elements/elements.dart';
12 import '../elements/entities.dart'; 14 import '../elements/entities.dart';
13 import '../js_backend/annotations.dart'; 15 import '../js_backend/annotations.dart';
14 import '../js_backend/js_backend.dart'; 16 import '../js_backend/js_backend.dart';
15 import '../native/behavior.dart' as native; 17 import '../native/behavior.dart' as native;
16 import '../resolution/tree_elements.dart'; 18 import '../resolution/tree_elements.dart';
17 import '../tree/nodes.dart' as ast; 19 import '../tree/nodes.dart' as ast;
18 import '../types/constants.dart'; 20 import '../types/constants.dart';
19 import '../types/types.dart'; 21 import '../types/types.dart';
20 import '../universe/call_structure.dart'; 22 import '../universe/call_structure.dart';
21 import '../universe/selector.dart'; 23 import '../universe/selector.dart';
22 import '../universe/side_effects.dart'; 24 import '../universe/side_effects.dart';
23 import '../util/util.dart'; 25 import '../util/util.dart';
24 import '../world.dart'; 26 import '../world.dart';
25 import 'closure_tracer.dart'; 27 import 'closure_tracer.dart';
26 import 'debug.dart' as debug; 28 import 'debug.dart' as debug;
27 import 'locals_handler.dart'; 29 import 'locals_handler.dart';
28 import 'list_tracer.dart'; 30 import 'list_tracer.dart';
29 import 'map_tracer.dart'; 31 import 'map_tracer.dart';
30 import 'builder.dart'; 32 import 'builder.dart';
33 import 'builder_kernel.dart';
31 import 'type_graph_dump.dart'; 34 import 'type_graph_dump.dart';
32 import 'type_graph_inferrer.dart'; 35 import 'type_graph_inferrer.dart';
33 import 'type_graph_nodes.dart'; 36 import 'type_graph_nodes.dart';
34 import 'type_system.dart'; 37 import 'type_system.dart';
35 38
36 /** 39 /**
37 * An inferencing engine that computes a call graph of 40 * An inferencing engine that computes a call graph of
38 * [TypeInformation] nodes by visiting the AST of the application, and 41 * [TypeInformation] nodes by visiting the AST of the application, and
39 * then does the inferencing on the graph. 42 * then does the inferencing on the graph.
40 */ 43 */
(...skipping 16 matching lines...) Expand all
57 60
58 final Compiler compiler; 61 final Compiler compiler;
59 62
60 /// The [ClosedWorld] on which inference reasoning is based. 63 /// The [ClosedWorld] on which inference reasoning is based.
61 final ClosedWorld closedWorld; 64 final ClosedWorld closedWorld;
62 65
63 final ClosedWorldRefiner closedWorldRefiner; 66 final ClosedWorldRefiner closedWorldRefiner;
64 final TypeSystem types; 67 final TypeSystem types;
65 final Map<ast.Node, TypeInformation> concreteTypes = 68 final Map<ast.Node, TypeInformation> concreteTypes =
66 new Map<ast.Node, TypeInformation>(); 69 new Map<ast.Node, TypeInformation>();
70
71 /// Parallel structure for concreteTypes.
72 // TODO(efortuna): Remove concreteTypes and/or parameterize InferrerEngine by
73 // ir.Node or ast.Node type. Then remove this in favor of `concreteTypes`.
74 final Map<ir.Node, TypeInformation> concreteKernelTypes =
75 new Map<ir.Node, TypeInformation>();
67 final Set<Element> generativeConstructorsExposingThis = new Set<Element>(); 76 final Set<Element> generativeConstructorsExposingThis = new Set<Element>();
68 77
69 /// Data computed internally within elements, like the type-mask of a send a 78 /// Data computed internally within elements, like the type-mask of a send a
70 /// list allocation, or a for-in loop. 79 /// list allocation, or a for-in loop.
71 final Map<Element, GlobalTypeInferenceElementData> inTreeData = 80 final Map<Element, GlobalTypeInferenceElementData> inTreeData =
72 new Map<Element, GlobalTypeInferenceElementData>(); 81 new Map<Element, GlobalTypeInferenceElementData>();
73 82
74 InferrerEngine(this.compiler, ClosedWorld closedWorld, 83 InferrerEngine(this.compiler, ClosedWorld closedWorld,
75 this.closedWorldRefiner, this.mainElement) 84 this.closedWorldRefiner, this.mainElement)
76 : this.types = new TypeSystem(closedWorld), 85 : this.types = new TypeSystem(closedWorld),
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 reporter.log('Inferred $overallRefineCount types.'); 468 reporter.log('Inferred $overallRefineCount types.');
460 469
461 processLoopInformation(); 470 processLoopInformation();
462 } 471 }
463 472
464 void analyze(ResolvedAst resolvedAst, ArgumentsTypes arguments) { 473 void analyze(ResolvedAst resolvedAst, ArgumentsTypes arguments) {
465 AstElement element = resolvedAst.element.implementation; 474 AstElement element = resolvedAst.element.implementation;
466 if (analyzedElements.contains(element)) return; 475 if (analyzedElements.contains(element)) return;
467 analyzedElements.add(element); 476 analyzedElements.add(element);
468 477
469 ElementGraphBuilder visitor = 478 var visitor = compiler.options.kernelGlobalInference
470 new ElementGraphBuilder(element, resolvedAst, compiler, this); 479 ? new KernelTypeGraphBuilder(element, resolvedAst, compiler, this)
480 : new ElementGraphBuilder(element, resolvedAst, compiler, this);
471 TypeInformation type; 481 TypeInformation type;
472 reporter.withCurrentElement(element, () { 482 reporter.withCurrentElement(element, () {
473 type = visitor.run(); 483 type = visitor.run();
474 }); 484 });
475 addedInGraph++; 485 addedInGraph++;
476 486
477 if (element.isField) { 487 if (element.isField) {
478 VariableElement fieldElement = element; 488 VariableElement fieldElement = element;
479 ast.Node node = resolvedAst.node; 489 ast.Node node = resolvedAst.node;
480 ast.Node initializer = resolvedAst.body; 490 ast.Node initializer = resolvedAst.body;
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 /** 1054 /**
1045 * Records that the captured variable [local] is read. 1055 * Records that the captured variable [local] is read.
1046 */ 1056 */
1047 void recordCapturedLocalRead(Local local) {} 1057 void recordCapturedLocalRead(Local local) {}
1048 1058
1049 /** 1059 /**
1050 * Records that the variable [local] is being updated. 1060 * Records that the variable [local] is being updated.
1051 */ 1061 */
1052 void recordLocalUpdate(Local local, TypeInformation type) {} 1062 void recordLocalUpdate(Local local, TypeInformation type) {}
1053 } 1063 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698