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

Unified Diff: pkg/compiler/lib/src/inferrer/inferrer_engine.dart

Issue 3004713002: Remove use of Compiler in inferrer engines. (Closed)
Patch Set: Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/inferrer/inferrer_engine.dart
diff --git a/pkg/compiler/lib/src/inferrer/inferrer_engine.dart b/pkg/compiler/lib/src/inferrer/inferrer_engine.dart
index be53f53742eba2d64b5931cc370eafed05fbb28a..b04c4ab71245246dd9cd591d745ead504d619c03 100644
--- a/pkg/compiler/lib/src/inferrer/inferrer_engine.dart
+++ b/pkg/compiler/lib/src/inferrer/inferrer_engine.dart
@@ -4,6 +4,7 @@
import 'package:kernel/ast.dart' as ir;
+import '../../compiler_new.dart';
import '../common.dart';
import '../common/names.dart';
import '../compiler.dart';
@@ -19,8 +20,10 @@ import '../elements/elements.dart'
import '../elements/entities.dart';
import '../elements/names.dart';
import '../js_backend/annotations.dart';
-import '../js_backend/js_backend.dart';
+import '../js_backend/mirrors_data.dart';
+import '../js_backend/no_such_method_registry.dart';
import '../native/behavior.dart' as native;
+import '../options.dart';
import '../types/constants.dart';
import '../types/types.dart';
import '../universe/call_structure.dart';
@@ -57,15 +60,18 @@ abstract class InferrerEngine<T> {
new Selector.call(const PublicName('removeLast'), CallStructure.NO_ARGS)
]);
- Compiler get compiler;
+ CompilerOptions get options;
ClosedWorld get closedWorld;
ClosedWorldRefiner get closedWorldRefiner;
- JavaScriptBackend get backend => compiler.backend;
- OptimizerHintsForTests get optimizerHints => backend.optimizerHints;
- DiagnosticReporter get reporter => compiler.reporter;
+ OptimizerHintsForTests get optimizerHints;
+ DiagnosticReporter get reporter;
CommonMasks get commonMasks => closedWorld.commonMasks;
CommonElements get commonElements => closedWorld.commonElements;
+ // TODO(johnniwinther): This should be part of [ClosedWorld] or
+ // [ClosureWorldRefiner].
+ NoSuchMethodRegistry get noSuchMethodRegistry;
+
TypeSystem<T> get types;
Map<T, TypeInformation> get concreteTypes;
@@ -223,6 +229,21 @@ abstract class InferrerEngine<T> {
bool returnsMapValueType(Selector selector, TypeMask mask);
void clear();
+
+ /// Returns true if global optimizations such as type inferencing can apply to
+ /// the field [element].
+ ///
+ /// One category of elements that do not apply is runtime helpers that the
+ /// backend calls, but the optimizations don't see those calls.
+ bool canFieldBeUsedForGlobalOptimizations(FieldEntity element);
+
+ /// Returns true if global optimizations such as type inferencing can apply to
+ /// the parameter [element].
+ ///
+ /// One category of elements that do not apply is runtime helpers that the
+ /// backend calls, but the optimizations don't see those calls.
+ bool canFunctionParametersBeUsedForGlobalOptimizations(
+ FunctionEntity function);
}
abstract class InferrerEngineImpl<T> extends InferrerEngine<T> {
@@ -240,7 +261,11 @@ abstract class InferrerEngineImpl<T> extends InferrerEngine<T> {
int overallRefineCount = 0;
int addedInGraph = 0;
- final Compiler compiler;
+ final CompilerOptions options;
+ final Progress progress;
+ final DiagnosticReporter reporter;
+ final CompilerOutput _compilerOutput;
+ final OptimizerHintsForTests optimizerHints;
/// The [ClosedWorld] on which inference reasoning is based.
final ClosedWorld closedWorld;
@@ -259,14 +284,24 @@ abstract class InferrerEngineImpl<T> extends InferrerEngine<T> {
final Map<MemberEntity, GlobalTypeInferenceElementData> _memberData =
new Map<MemberEntity, GlobalTypeInferenceElementData>();
+ // TODO(johnniwinther): This should be accessible throught [closedWorld].
+ final MirrorsData mirrorsData;
+
+ final NoSuchMethodRegistry noSuchMethodRegistry;
+
InferrerEngineImpl(
- this.compiler,
- ClosedWorld closedWorld,
+ this.options,
+ this.progress,
+ this.reporter,
+ this._compilerOutput,
+ this.optimizerHints,
+ this.closedWorld,
this.closedWorldRefiner,
+ this.mirrorsData,
+ this.noSuchMethodRegistry,
this.mainElement,
TypeSystemStrategy<T> typeSystemStrategy)
- : this.types = new TypeSystem<T>(closedWorld, typeSystemStrategy),
- this.closedWorld = closedWorld;
+ : this.types = new TypeSystem<T>(closedWorld, typeSystemStrategy);
void forEachElementMatching(
Selector selector, TypeMask mask, bool f(MemberEntity element)) {
@@ -457,13 +492,12 @@ abstract class InferrerEngineImpl<T> extends InferrerEngine<T> {
}
void runOverAllElements() {
- if (compiler.disableTypeInference) return;
- if (compiler.options.verbose) {
- compiler.progress.reset();
- }
+ progress.startPhase();
+
analyzeAllElements();
- TypeGraphDump dump = debug.PRINT_GRAPH ? new TypeGraphDump(this) : null;
+ TypeGraphDump dump =
+ debug.PRINT_GRAPH ? new TypeGraphDump(_compilerOutput, this) : null;
dump?.beforeAnalysis();
buildWorkQueue();
@@ -630,10 +664,8 @@ abstract class InferrerEngineImpl<T> extends InferrerEngine<T> {
void analyzeAllElements() {
sortMembers(closedWorld.processedMembers, computeMemberSize)
.forEach((MemberEntity member) {
- if (compiler.shouldPrintProgress) {
- reporter.log('Added $addedInGraph elements in inferencing graph.');
- compiler.progress.reset();
- }
+ progress.showProgress(
+ 'Added ', addedInGraph, ' elements in inferencing graph.');
// This also forces the creation of the [ElementTypeInformation] to ensure
// it is in the graph.
T body = computeMemberBody(member);
@@ -747,10 +779,7 @@ abstract class InferrerEngineImpl<T> extends InferrerEngine<T> {
void refine() {
while (!workQueue.isEmpty) {
- if (compiler.shouldPrintProgress) {
- reporter.log('Inferred $overallRefineCount types.');
- compiler.progress.reset();
- }
+ progress.showProgress('Inferred ', overallRefineCount, ' types.');
TypeInformation info = workQueue.remove();
TypeMask oldType = info.type;
TypeMask newType = info.refine(this);
@@ -1071,10 +1100,6 @@ abstract class InferrerEngineImpl<T> extends InferrerEngine<T> {
}
Iterable<MemberEntity> getCallersOf(MemberEntity element) {
- if (compiler.disableTypeInference) {
- throw new UnsupportedError(
- "Cannot query the type inferrer when type inference is disabled.");
- }
MemberTypeInformation info = types.getInferredTypeOfMember(element);
return info.callers;
}
@@ -1108,6 +1133,32 @@ abstract class InferrerEngineImpl<T> extends InferrerEngine<T> {
}
}
+ /// Returns true if global optimizations such as type inferencing can apply to
+ /// the field [element].
+ ///
+ /// One category of elements that do not apply is runtime helpers that the
+ /// backend calls, but the optimizations don't see those calls.
+ bool canFieldBeUsedForGlobalOptimizations(FieldEntity element) {
+ if (closedWorld.backendUsage.isFieldUsedByBackend(element)) {
+ return false;
+ }
+ if ((element.isTopLevel || element.isStatic) && !element.isAssignable) {
+ return true;
+ }
+ return !mirrorsData.isMemberAccessibleByReflection(element);
+ }
+
+ /// Returns true if global optimizations such as type inferencing can apply to
+ /// the parameter [element].
+ ///
+ /// One category of elements that do not apply is runtime helpers that the
+ /// backend calls, but the optimizations don't see those calls.
+ bool canFunctionParametersBeUsedForGlobalOptimizations(
+ FunctionEntity function) {
+ return !closedWorld.backendUsage.isFunctionUsedByBackend(function) &&
+ !mirrorsData.isMemberAccessibleByReflection(function);
+ }
+
// Sorts the resolved elements by size. We do this for this inferrer
// to get the same results for [ListTracer] compared to the
// [SimpleTypesInferrer].
« no previous file with comments | « pkg/compiler/lib/src/inferrer/ast_inferrer_engine.dart ('k') | pkg/compiler/lib/src/inferrer/kernel_inferrer_engine.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698