From fa4851cd4e8e875d766e84b785cd2f6045d72acf Mon Sep 17 00:00:00 2001 From: Sigmund Cherem Date: Tue, 25 Oct 2022 16:42:16 +0000 Subject: [PATCH] [dart2js] prepare additional files in inferrer folder (part 2) This now breaks the cycle in this folder, so all libraries can be migrated in a specific order. Change-Id: Ib76d813804e2d0eac485bbeb84a1e0aac0027e7a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264360 Commit-Queue: Sigmund Cherem Reviewed-by: Nate Biggs --- pkg/compiler/lib/src/compiler.dart | 3 ++ pkg/compiler/lib/src/compiler_interfaces.dart | 11 +++++ pkg/compiler/lib/src/inferrer/engine.dart | 7 +++- .../lib/src/inferrer/engine_interfaces.dart | 6 +++ .../lib/src/inferrer/type_graph_inferrer.dart | 40 +++---------------- pkg/compiler/lib/src/inferrer/work_queue.dart | 37 +++++++++++++++++ .../lib/src/inferrer_experimental/engine.dart | 7 +++- .../engine_interfaces.dart | 8 +++- .../type_graph_inferrer.dart | 40 +++---------------- .../src/inferrer_experimental/work_queue.dart | 37 +++++++++++++++++ 10 files changed, 123 insertions(+), 73 deletions(-) create mode 100644 pkg/compiler/lib/src/inferrer/work_queue.dart create mode 100644 pkg/compiler/lib/src/inferrer_experimental/work_queue.dart diff --git a/pkg/compiler/lib/src/compiler.dart b/pkg/compiler/lib/src/compiler.dart index 26390dddbb8..a5686855282 100644 --- a/pkg/compiler/lib/src/compiler.dart +++ b/pkg/compiler/lib/src/compiler.dart @@ -24,6 +24,7 @@ import 'compiler_interfaces.dart' show CompilerDeferredLoadingFacade, CompilerDiagnosticsFacade, + CompilerInferrerFacade, CompilerKernelStrategyFacade, CompilerTypeInferenceFacade; import 'deferred_load/deferred_load.dart' show DeferredLoadTask; @@ -80,6 +81,7 @@ class Compiler implements CompilerDiagnosticsFacade, CompilerDeferredLoadingFacade, + CompilerInferrerFacade, CompilerKernelStrategyFacade, CompilerTypeInferenceFacade { @override @@ -145,6 +147,7 @@ class Compiler DumpInfoTask dumpInfoTask; SerializationTask serializationTask; + @override Progress progress = const Progress(); static const int PHASE_SCANNING = 0; diff --git a/pkg/compiler/lib/src/compiler_interfaces.dart b/pkg/compiler/lib/src/compiler_interfaces.dart index 83dfc025b90..d008624a163 100644 --- a/pkg/compiler/lib/src/compiler_interfaces.dart +++ b/pkg/compiler/lib/src/compiler_interfaces.dart @@ -21,6 +21,7 @@ import 'kernel/kernel_strategy_migrated.dart' show KernelFrontendStrategyForDeferredLoading; import 'options.dart' show CompilerOptions; import 'universe/world_impact.dart' show WorldImpact; +import 'compiler_migrated.dart'; /// Subset of [Compiler] needed by deferred loading. /// @@ -80,3 +81,13 @@ abstract class CompilerKernelStrategyFacade { ConstraintData? get programSplitConstraintsData; DeferredLoadTask get deferredLoadTask; } + +/// Subset of [Compiler] needed by type_graph_inferrer +/// +/// See definitions on [Compiler] for documentation. +abstract class CompilerInferrerFacade { + CompilerOptions get options; + Progress get progress; + DiagnosticReporter get reporter; + CompilerOutput get outputProvider; +} diff --git a/pkg/compiler/lib/src/inferrer/engine.dart b/pkg/compiler/lib/src/inferrer/engine.dart index f8851e81700..ffc6d7769fc 100644 --- a/pkg/compiler/lib/src/inferrer/engine.dart +++ b/pkg/compiler/lib/src/inferrer/engine.dart @@ -39,10 +39,10 @@ import 'list_tracer.dart'; import 'map_tracer.dart'; import 'set_tracer.dart'; import 'type_graph_dump.dart'; -import 'type_graph_inferrer.dart'; import 'type_graph_nodes.dart'; import 'type_system.dart'; import 'types.dart'; +import 'work_queue.dart'; /// An inferencing engine that computes a call graph of [TypeInformation] nodes /// by visiting the AST of the application, and then does the inferencing on the @@ -81,6 +81,7 @@ class InferrerEngine implements interfaces.InferrerEngine { final WorkQueue _workQueue = WorkQueue(); + @override final _InferrerEngineMetrics metrics = _InferrerEngineMetrics(); final Set _analyzedElements = {}; @@ -328,6 +329,7 @@ class InferrerEngine implements interfaces.InferrerEngine { _workQueue.add(info); } + @override void runOverAllElements() { metrics.time.measure(_runOverAllElements); } @@ -1071,6 +1073,7 @@ class InferrerEngine implements interfaces.InferrerEngine { return info; } + @override void close() { for (MemberTypeInformation typeInformation in types.memberTypeInformations.values) { @@ -1078,6 +1081,7 @@ class InferrerEngine implements interfaces.InferrerEngine { } } + @override void clear() { if (retainDataForTesting) return; @@ -1111,6 +1115,7 @@ class InferrerEngine implements interfaces.InferrerEngine { _memberData.clear(); } + @override Iterable getCallersOfForTesting(MemberEntity element) { MemberTypeInformation info = types.getInferredTypeOfMember(element); return info.callersForTesting; diff --git a/pkg/compiler/lib/src/inferrer/engine_interfaces.dart b/pkg/compiler/lib/src/inferrer/engine_interfaces.dart index 2b0c402874b..611a28a0bfc 100644 --- a/pkg/compiler/lib/src/inferrer/engine_interfaces.dart +++ b/pkg/compiler/lib/src/inferrer/engine_interfaces.dart @@ -5,6 +5,7 @@ import 'package:kernel/ast.dart' as ir; import '../common/elements.dart'; +import '../common/metrics.dart' show Metrics; import '../elements/entities.dart'; import '../js_backend/inferred_data.dart'; import '../js_backend/no_such_method_registry_interfaces.dart'; @@ -28,6 +29,7 @@ abstract class InferrerEngine { NoSuchMethodData get noSuchMethodData; Set get returnsListElementTypeSet; Map get concreteTypes; + Metrics get metrics; TypeInformation typeOfNativeBehavior(NativeBehavior nativeBehavior); bool canFieldBeUsedForGlobalOptimizations(FieldEntity element); @@ -91,6 +93,10 @@ abstract class InferrerEngine { void recordReturnType(FunctionEntity element, TypeInformation type); void recordTypeOfField(FieldEntity element, TypeInformation type); void setDefaultTypeOfParameter(Local parameter, TypeInformation type); + void runOverAllElements(); + Iterable getCallersOfForTesting(MemberEntity element); + void close(); + void clear(); } abstract class KernelGlobalTypeInferenceElementData diff --git a/pkg/compiler/lib/src/inferrer/type_graph_inferrer.dart b/pkg/compiler/lib/src/inferrer/type_graph_inferrer.dart index 6bbb19e16fe..92693ad75b9 100644 --- a/pkg/compiler/lib/src/inferrer/type_graph_inferrer.dart +++ b/pkg/compiler/lib/src/inferrer/type_graph_inferrer.dart @@ -6,56 +6,26 @@ library type_graph_inferrer; -import 'dart:collection' show Queue; - import 'package:kernel/ast.dart' as ir; import '../closure.dart'; import '../common/metrics.dart' show Metrics; -import '../compiler.dart'; +import '../compiler_interfaces.dart'; import '../elements/entities.dart'; import '../js_backend/inferred_data.dart'; import '../js_model/elements.dart' show JClosureCallMethod; import '../js_model/locals.dart'; import '../world.dart'; import 'abstract_value_domain.dart'; -import 'engine.dart'; +import 'engine_interfaces.dart'; +import 'engine.dart' as engine; import 'type_graph_nodes.dart'; import 'types.dart'; -/// A work queue for the inferrer. It filters out nodes that are tagged as -/// [TypeInformation.doNotEnqueue], as well as ensures through -/// [TypeInformation.inQueue] that a node is in the queue only once at -/// a time. -class WorkQueue { - final Queue queue = Queue(); - - void add(TypeInformation element) { - if (element.doNotEnqueue) return; - if (element.inQueue) return; - queue.addLast(element); - element.inQueue = true; - } - - void addAll(Iterable all) { - all.forEach(add); - } - - TypeInformation remove() { - TypeInformation element = queue.removeFirst(); - element.inQueue = false; - return element; - } - - bool get isEmpty => queue.isEmpty; - - int get length => queue.length; -} - class TypeGraphInferrer implements TypesInferrer { InferrerEngine inferrer; final JClosedWorld closedWorld; - final Compiler _compiler; + final CompilerInferrerFacade _compiler; final GlobalLocalsMap _globalLocalsMap; final InferredDataBuilder _inferredDataBuilder; Metrics _metrics = Metrics.none(); @@ -80,7 +50,7 @@ class TypeGraphInferrer implements TypesInferrer { } InferrerEngine createInferrerEngineFor(FunctionEntity main) { - return InferrerEngine( + return engine.InferrerEngine( _compiler.options, _compiler.progress, _compiler.reporter, diff --git a/pkg/compiler/lib/src/inferrer/work_queue.dart b/pkg/compiler/lib/src/inferrer/work_queue.dart new file mode 100644 index 00000000000..5ed6bfd5731 --- /dev/null +++ b/pkg/compiler/lib/src/inferrer/work_queue.dart @@ -0,0 +1,37 @@ +// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart = 2.10 + +import 'dart:collection' show Queue; +import 'type_graph_nodes.dart'; + +/// A work queue for the inferrer. It filters out nodes that are tagged as +/// [TypeInformation.doNotEnqueue], as well as ensures through +/// [TypeInformation.inQueue] that a node is in the queue only once at +/// a time. +class WorkQueue { + final Queue queue = Queue(); + + void add(TypeInformation element) { + if (element.doNotEnqueue) return; + if (element.inQueue) return; + queue.addLast(element); + element.inQueue = true; + } + + void addAll(Iterable all) { + all.forEach(add); + } + + TypeInformation remove() { + TypeInformation element = queue.removeFirst(); + element.inQueue = false; + return element; + } + + bool get isEmpty => queue.isEmpty; + + int get length => queue.length; +} diff --git a/pkg/compiler/lib/src/inferrer_experimental/engine.dart b/pkg/compiler/lib/src/inferrer_experimental/engine.dart index d95d2d3662f..fa85acaac60 100644 --- a/pkg/compiler/lib/src/inferrer_experimental/engine.dart +++ b/pkg/compiler/lib/src/inferrer_experimental/engine.dart @@ -39,10 +39,10 @@ import 'list_tracer.dart'; import 'map_tracer.dart'; import 'set_tracer.dart'; import 'type_graph_dump.dart'; -import 'type_graph_inferrer.dart'; import 'type_graph_nodes.dart'; import 'type_system.dart'; import 'types.dart'; +import 'work_queue.dart'; /// An inferencing engine that computes a call graph of [TypeInformation] nodes /// by visiting the AST of the application, and then does the inferencing on the @@ -81,6 +81,7 @@ class InferrerEngine implements interfaces.InferrerEngine { final WorkQueue _workQueue = WorkQueue(); + @override final _InferrerEngineMetrics metrics = _InferrerEngineMetrics(); final Set _analyzedElements = {}; @@ -328,6 +329,7 @@ class InferrerEngine implements interfaces.InferrerEngine { _workQueue.add(info); } + @override void runOverAllElements() { metrics.time.measure(_runOverAllElements); } @@ -1071,6 +1073,7 @@ class InferrerEngine implements interfaces.InferrerEngine { return info; } + @override void close() { for (MemberTypeInformation typeInformation in types.memberTypeInformations.values) { @@ -1078,6 +1081,7 @@ class InferrerEngine implements interfaces.InferrerEngine { } } + @override void clear() { if (retainDataForTesting) return; @@ -1111,6 +1115,7 @@ class InferrerEngine implements interfaces.InferrerEngine { _memberData.clear(); } + @override Iterable getCallersOfForTesting(MemberEntity element) { MemberTypeInformation info = types.getInferredTypeOfMember(element); return info.callersForTesting; diff --git a/pkg/compiler/lib/src/inferrer_experimental/engine_interfaces.dart b/pkg/compiler/lib/src/inferrer_experimental/engine_interfaces.dart index 11dcff2886e..8ececec2b6e 100644 --- a/pkg/compiler/lib/src/inferrer_experimental/engine_interfaces.dart +++ b/pkg/compiler/lib/src/inferrer_experimental/engine_interfaces.dart @@ -5,6 +5,7 @@ import 'package:kernel/ast.dart' as ir; import '../common/elements.dart'; +import '../common/metrics.dart' show Metrics; import '../elements/entities.dart'; import '../js_backend/inferred_data.dart'; import '../js_backend/no_such_method_registry_interfaces.dart'; @@ -13,10 +14,10 @@ import '../universe/selector.dart'; import '../universe/side_effects.dart'; import '../world_interfaces.dart'; import '../inferrer/abstract_value_domain.dart'; -import '../inferrer_experimental/types.dart'; import 'locals_handler.dart'; import 'type_graph_nodes.dart'; import 'type_system.dart'; +import 'types.dart'; abstract class InferrerEngine { AbstractValueDomain get abstractValueDomain; @@ -28,6 +29,7 @@ abstract class InferrerEngine { NoSuchMethodData get noSuchMethodData; Set get returnsListElementTypeSet; Map get concreteTypes; + Metrics get metrics; TypeInformation typeOfNativeBehavior(NativeBehavior nativeBehavior); bool canFieldBeUsedForGlobalOptimizations(FieldEntity element); @@ -91,6 +93,10 @@ abstract class InferrerEngine { void recordReturnType(FunctionEntity element, TypeInformation type); void recordTypeOfField(FieldEntity element, TypeInformation type); void setDefaultTypeOfParameter(Local parameter, TypeInformation type); + void runOverAllElements(); + Iterable getCallersOfForTesting(MemberEntity element); + void close(); + void clear(); } abstract class KernelGlobalTypeInferenceElementData diff --git a/pkg/compiler/lib/src/inferrer_experimental/type_graph_inferrer.dart b/pkg/compiler/lib/src/inferrer_experimental/type_graph_inferrer.dart index 0e27bd055d3..f85b47acf58 100644 --- a/pkg/compiler/lib/src/inferrer_experimental/type_graph_inferrer.dart +++ b/pkg/compiler/lib/src/inferrer_experimental/type_graph_inferrer.dart @@ -6,56 +6,26 @@ library type_graph_inferrer; -import 'dart:collection' show Queue; - import 'package:kernel/ast.dart' as ir; import '../closure.dart'; import '../common/metrics.dart' show Metrics; -import '../compiler.dart'; +import '../compiler_interfaces.dart'; import '../elements/entities.dart'; import '../js_backend/inferred_data.dart'; import '../js_model/elements.dart' show JClosureCallMethod; import '../js_model/locals.dart'; import '../world.dart'; import '../inferrer/abstract_value_domain.dart'; -import 'engine.dart'; +import 'engine_interfaces.dart'; +import 'engine.dart' as engine; import 'type_graph_nodes.dart'; import 'types.dart'; -/// A work queue for the inferrer. It filters out nodes that are tagged as -/// [TypeInformation.doNotEnqueue], as well as ensures through -/// [TypeInformation.inQueue] that a node is in the queue only once at -/// a time. -class WorkQueue { - final Queue queue = Queue(); - - void add(TypeInformation element) { - if (element.doNotEnqueue) return; - if (element.inQueue) return; - queue.addLast(element); - element.inQueue = true; - } - - void addAll(Iterable all) { - all.forEach(add); - } - - TypeInformation remove() { - TypeInformation element = queue.removeFirst(); - element.inQueue = false; - return element; - } - - bool get isEmpty => queue.isEmpty; - - int get length => queue.length; -} - class TypeGraphInferrer implements TypesInferrer { InferrerEngine inferrer; final JClosedWorld closedWorld; - final Compiler _compiler; + final CompilerInferrerFacade _compiler; final GlobalLocalsMap _globalLocalsMap; final InferredDataBuilder _inferredDataBuilder; Metrics _metrics = Metrics.none(); @@ -80,7 +50,7 @@ class TypeGraphInferrer implements TypesInferrer { } InferrerEngine createInferrerEngineFor(FunctionEntity main) { - return InferrerEngine( + return engine.InferrerEngine( _compiler.options, _compiler.progress, _compiler.reporter, diff --git a/pkg/compiler/lib/src/inferrer_experimental/work_queue.dart b/pkg/compiler/lib/src/inferrer_experimental/work_queue.dart new file mode 100644 index 00000000000..5ed6bfd5731 --- /dev/null +++ b/pkg/compiler/lib/src/inferrer_experimental/work_queue.dart @@ -0,0 +1,37 @@ +// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// @dart = 2.10 + +import 'dart:collection' show Queue; +import 'type_graph_nodes.dart'; + +/// A work queue for the inferrer. It filters out nodes that are tagged as +/// [TypeInformation.doNotEnqueue], as well as ensures through +/// [TypeInformation.inQueue] that a node is in the queue only once at +/// a time. +class WorkQueue { + final Queue queue = Queue(); + + void add(TypeInformation element) { + if (element.doNotEnqueue) return; + if (element.inQueue) return; + queue.addLast(element); + element.inQueue = true; + } + + void addAll(Iterable all) { + all.forEach(add); + } + + TypeInformation remove() { + TypeInformation element = queue.removeFirst(); + element.inQueue = false; + return element; + } + + bool get isEmpty => queue.isEmpty; + + int get length => queue.length; +}