| OLD | NEW |
| 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 Loading... |
| 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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 reporter.log('Inferred $overallRefineCount types.'); | 469 reporter.log('Inferred $overallRefineCount types.'); |
| 461 | 470 |
| 462 processLoopInformation(); | 471 processLoopInformation(); |
| 463 } | 472 } |
| 464 | 473 |
| 465 void analyze(ResolvedAst resolvedAst, ArgumentsTypes arguments) { | 474 void analyze(ResolvedAst resolvedAst, ArgumentsTypes arguments) { |
| 466 AstElement element = resolvedAst.element.implementation; | 475 AstElement element = resolvedAst.element.implementation; |
| 467 if (analyzedElements.contains(element)) return; | 476 if (analyzedElements.contains(element)) return; |
| 468 analyzedElements.add(element); | 477 analyzedElements.add(element); |
| 469 | 478 |
| 470 ElementGraphBuilder visitor = | 479 var visitor = compiler.options.kernelGlobalInference |
| 471 new ElementGraphBuilder(element, resolvedAst, compiler, this); | 480 ? new KernelTypeGraphBuilder(element, resolvedAst, compiler, this) |
| 481 : new ElementGraphBuilder(element, resolvedAst, compiler, this); |
| 472 TypeInformation type; | 482 TypeInformation type; |
| 473 reporter.withCurrentElement(element, () { | 483 reporter.withCurrentElement(element, () { |
| 474 type = visitor.run(); | 484 type = visitor.run(); |
| 475 }); | 485 }); |
| 476 addedInGraph++; | 486 addedInGraph++; |
| 477 | 487 |
| 478 if (element.isField) { | 488 if (element.isField) { |
| 479 VariableElement fieldElement = element; | 489 VariableElement fieldElement = element; |
| 480 ast.Node node = resolvedAst.node; | 490 ast.Node node = resolvedAst.node; |
| 481 ast.Node initializer = resolvedAst.body; | 491 ast.Node initializer = resolvedAst.body; |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 /** | 1055 /** |
| 1046 * Records that the captured variable [local] is read. | 1056 * Records that the captured variable [local] is read. |
| 1047 */ | 1057 */ |
| 1048 void recordCapturedLocalRead(Local local) {} | 1058 void recordCapturedLocalRead(Local local) {} |
| 1049 | 1059 |
| 1050 /** | 1060 /** |
| 1051 * Records that the variable [local] is being updated. | 1061 * Records that the variable [local] is being updated. |
| 1052 */ | 1062 */ |
| 1053 void recordLocalUpdate(Local local, TypeInformation type) {} | 1063 void recordLocalUpdate(Local local, TypeInformation type) {} |
| 1054 } | 1064 } |
| OLD | NEW |