[CFE/web] Move static interop erasure and remove outline stubber
Deletes the outline stubber as it's not necessary on any backend.
DDC should compile the entire sources and outline dill in one step.
dart2wasm operates similarly, and so only needs the modular transformer.
dart2js moves the erasure to a global transform.
Also, this CL reverts now unnecessary plumbing that was needed for the
outline stubber.
Change-Id: Ic085c4fad5a6bdfc7d6916f7fa575c6ef9b20110
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253000
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
diff --git a/pkg/_js_interop_checks/lib/src/transformations/static_interop_class_eraser.dart b/pkg/_js_interop_checks/lib/src/transformations/static_interop_class_eraser.dart
index a907d2c..565faa5 100644
--- a/pkg/_js_interop_checks/lib/src/transformations/static_interop_class_eraser.dart
+++ b/pkg/_js_interop_checks/lib/src/transformations/static_interop_class_eraser.dart
@@ -60,11 +60,7 @@
.where((procedure) => procedure.name.text == stubName);
if (stubs.isEmpty) {
// We should only create the stub if we're processing the component in
- // which the stub should exist. Any static invocation of the factory that
- // doesn't exist in the same component as the factory should be processed
- // after the component in which the factory exists. In modular
- // compilation, the outline of that component should already contain the
- // needed stub.
+ // which the stub should exist.
if (currentComponent != null) {
assert(factoryTarget.enclosingComponent == currentComponent);
}
@@ -241,23 +237,3 @@
@override
TreeNode visitTreeNode(TreeNode node) => node.accept(_eraser);
}
-
-/// Used to create stubs for factories when computing outlines.
-///
-/// These stubs can then be used in downstream dependencies in modular
-/// compilation.
-class StaticInteropStubCreator extends RecursiveVisitor {
- final StaticInteropClassEraser _eraser;
- StaticInteropStubCreator(this._eraser);
-
- @override
- void visitLibrary(Library node) {
- _eraser.currentComponent = node.enclosingComponent;
- super.visitLibrary(node);
- }
-
- @override
- void visitProcedure(Procedure node) {
- _eraser.visitProcedure(node);
- }
-}
diff --git a/pkg/compiler/lib/src/kernel/dart2js_target.dart b/pkg/compiler/lib/src/kernel/dart2js_target.dart
index 00f0fb4..18b1d8e 100644
--- a/pkg/compiler/lib/src/kernel/dart2js_target.dart
+++ b/pkg/compiler/lib/src/kernel/dart2js_target.dart
@@ -138,13 +138,6 @@
bool get errorOnUnexactWebIntLiterals => true;
@override
- void performOutlineTransformations(ir.Component component,
- CoreTypes coreTypes, ReferenceFromIndex? referenceFromIndex) {
- component.accept(StaticInteropStubCreator(
- StaticInteropClassEraser(coreTypes, referenceFromIndex)));
- }
-
- @override
void performModularTransformationsOnLibraries(
ir.Component component,
CoreTypes coreTypes,
@@ -168,12 +161,14 @@
// TODO (rileyporter): Merge js_util optimizations with other lowerings
// in the single pass in `transformations/lowering.dart`.
jsUtilOptimizer.visitLibrary(library);
- staticInteropClassEraser.visitLibrary(library);
}
lowering.transformLibraries(libraries, coreTypes, hierarchy, options);
logger?.call("Lowering transformations performed");
if (canPerformGlobalTransforms) {
transformMixins.transformLibraries(libraries);
+ for (var library in libraries) {
+ staticInteropClassEraser.visitLibrary(library);
+ }
logger?.call("Mixin transformations performed");
}
}
diff --git a/pkg/compiler/lib/src/phase/load_kernel.dart b/pkg/compiler/lib/src/phase/load_kernel.dart
index 6145d84..676afba 100644
--- a/pkg/compiler/lib/src/phase/load_kernel.dart
+++ b/pkg/compiler/lib/src/phase/load_kernel.dart
@@ -7,12 +7,15 @@
import 'package:collection/collection.dart';
import 'package:front_end/src/fasta/kernel/utils.dart';
import 'package:kernel/ast.dart' as ir;
+import 'package:kernel/core_types.dart' as ir;
import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;
import 'package:front_end/src/api_unstable/dart2js.dart' as fe;
import 'package:kernel/kernel.dart' hide LibraryDependency, Combinator;
import 'package:kernel/target/targets.dart' hide DiagnosticReporter;
+import 'package:_js_interop_checks/src/transformations/static_interop_class_eraser.dart';
+
import '../../compiler_api.dart' as api;
import '../commandline_options.dart';
import '../common.dart';
@@ -130,6 +133,12 @@
void _doGlobalTransforms(Component component) {
transformMixins.transformLibraries(component.libraries);
+ // referenceFromIndex is only necessary in the case where a module containing
+ // a stub definition is invalidated, and then reloaded, because we need to
+ // keep existing references to that stub valid. Here, we have the whole
+ // program, and therefore do not need it.
+ StaticInteropClassEraser(ir.CoreTypes(component), null)
+ .visitComponent(component);
}
Future<_LoadFromKernelResult> _loadFromKernel(CompilerOptions options,
diff --git a/pkg/dart2wasm/lib/target.dart b/pkg/dart2wasm/lib/target.dart
index 604072e..871f07a 100644
--- a/pkg/dart2wasm/lib/target.dart
+++ b/pkg/dart2wasm/lib/target.dart
@@ -86,20 +86,16 @@
..parent = host;
}
- StaticInteropClassEraser _staticInteropClassEraser(
- CoreTypes coreTypes, ReferenceFromIndex? referenceFromIndex) =>
- StaticInteropClassEraser(coreTypes, referenceFromIndex,
- libraryForJavaScriptObject: 'dart:_js_helper',
- classNameOfJavaScriptObject: 'JSValue');
-
void _performJSInteropTransformations(
CoreTypes coreTypes,
ClassHierarchy hierarchy,
List<Library> interopDependentLibraries,
ReferenceFromIndex? referenceFromIndex) {
final jsUtilOptimizer = JsUtilWasmOptimizer(coreTypes, hierarchy);
- final staticInteropClassEraser =
- _staticInteropClassEraser(coreTypes, referenceFromIndex);
+ final staticInteropClassEraser = StaticInteropClassEraser(
+ coreTypes, referenceFromIndex,
+ libraryForJavaScriptObject: 'dart:_js_helper',
+ classNameOfJavaScriptObject: 'JSValue');
for (Library library in interopDependentLibraries) {
jsUtilOptimizer.visitLibrary(library);
staticInteropClassEraser.visitLibrary(library);
@@ -118,13 +114,6 @@
}
@override
- void performOutlineTransformations(Component component, CoreTypes coreTypes,
- ReferenceFromIndex? referenceFromIndex) {
- component.accept(StaticInteropStubCreator(
- _staticInteropClassEraser(coreTypes, referenceFromIndex)));
- }
-
- @override
void performModularTransformationsOnLibraries(
Component component,
CoreTypes coreTypes,
diff --git a/pkg/dev_compiler/lib/src/kernel/target.dart b/pkg/dev_compiler/lib/src/kernel/target.dart
index 795d503..3d5e682 100644
--- a/pkg/dev_compiler/lib/src/kernel/target.dart
+++ b/pkg/dev_compiler/lib/src/kernel/target.dart
@@ -153,13 +153,6 @@
bool get enableNoSuchMethodForwarders => true;
@override
- void performOutlineTransformations(Component component, CoreTypes coreTypes,
- ReferenceFromIndex? referenceFromIndex) {
- component.accept(StaticInteropStubCreator(
- StaticInteropClassEraser(coreTypes, referenceFromIndex)));
- }
-
- @override
void performModularTransformationsOnLibraries(
Component component,
CoreTypes coreTypes,
diff --git a/pkg/front_end/lib/src/api_prototype/incremental_kernel_generator.dart b/pkg/front_end/lib/src/api_prototype/incremental_kernel_generator.dart
index 8f0f4f3..880d764 100644
--- a/pkg/front_end/lib/src/api_prototype/incremental_kernel_generator.dart
+++ b/pkg/front_end/lib/src/api_prototype/incremental_kernel_generator.dart
@@ -12,8 +12,6 @@
import 'package:kernel/kernel.dart'
show Component, Library, Procedure, DartType, TypeParameter;
-import 'package:kernel/reference_from_index.dart';
-
import '../base/processed_options.dart' show ProcessedOptions;
import '../fasta/compiler_context.dart' show CompilerContext;
@@ -154,11 +152,7 @@
final ClassHierarchy? classHierarchy;
final CoreTypes? coreTypes;
final Set<Library>? neededDillLibraries;
- final ReferenceFromIndex? referenceFromIndex;
IncrementalCompilerResult(this.component,
- {this.classHierarchy,
- this.coreTypes,
- this.neededDillLibraries,
- this.referenceFromIndex});
+ {this.classHierarchy, this.coreTypes, this.neededDillLibraries});
}
diff --git a/pkg/front_end/lib/src/fasta/incremental_compiler.dart b/pkg/front_end/lib/src/fasta/incremental_compiler.dart
index d6687f9..489a220 100644
--- a/pkg/front_end/lib/src/fasta/incremental_compiler.dart
+++ b/pkg/front_end/lib/src/fasta/incremental_compiler.dart
@@ -529,8 +529,7 @@
return new IncrementalCompilerResult(result,
classHierarchy: currentKernelTarget.loader.hierarchy,
coreTypes: currentKernelTarget.loader.coreTypes,
- neededDillLibraries: neededDillLibraries,
- referenceFromIndex: currentKernelTarget.loader.referenceFromIndex);
+ neededDillLibraries: neededDillLibraries);
});
}
diff --git a/pkg/front_end/lib/src/kernel_generator_impl.dart b/pkg/front_end/lib/src/kernel_generator_impl.dart
index 1d35c50..b8eb49e 100644
--- a/pkg/front_end/lib/src/kernel_generator_impl.dart
+++ b/pkg/front_end/lib/src/kernel_generator_impl.dart
@@ -188,10 +188,7 @@
// summaries without building a full component (at this time, that's
// the only need we have for these transformations).
if (!buildComponent) {
- options.target.performOutlineTransformations(
- trimmedSummaryComponent,
- kernelTarget.loader.coreTypes,
- kernelTarget.loader.referenceFromIndex);
+ options.target.performOutlineTransformations(trimmedSummaryComponent);
options.ticker.logMs("Transformed outline");
}
// Don't include source (but do add it above to include importUris).
diff --git a/pkg/frontend_server/lib/compute_kernel.dart b/pkg/frontend_server/lib/compute_kernel.dart
index 24a0fa4..918c891 100644
--- a/pkg/frontend_server/lib/compute_kernel.dart
+++ b/pkg/frontend_server/lib/compute_kernel.dart
@@ -396,10 +396,7 @@
incrementalComponent.problemsAsJson = null;
incrementalComponent.setMainMethodAndMode(
null, true, incrementalComponent.mode);
- target.performOutlineTransformations(
- incrementalComponent,
- incrementalCompilerResult.coreTypes!,
- incrementalCompilerResult.referenceFromIndex);
+ target.performOutlineTransformations(incrementalComponent);
makeStable(incrementalComponent);
return Future.value(fe.serializeComponent(incrementalComponent,
includeSources: false, includeOffsets: false));
diff --git a/pkg/kernel/lib/target/targets.dart b/pkg/kernel/lib/target/targets.dart
index 477f255..0c594a5 100644
--- a/pkg/kernel/lib/target/targets.dart
+++ b/pkg/kernel/lib/target/targets.dart
@@ -314,8 +314,7 @@
/// transformation is not applied when compiling full kernel programs to
/// prevent affecting the internal invariants of the compiler and accidentally
/// slowing down compilation.
- void performOutlineTransformations(Component component, CoreTypes coreTypes,
- ReferenceFromIndex? referenceFromIndex) {}
+ void performOutlineTransformations(Component component) {}
/// Perform target-specific transformations on the given libraries that must
/// run before constant evaluation.
@@ -1008,10 +1007,8 @@
}
@override
- void performOutlineTransformations(Component component, CoreTypes coreTypes,
- ReferenceFromIndex? referenceFromIndex) {
- _target.performOutlineTransformations(
- component, coreTypes, referenceFromIndex);
+ void performOutlineTransformations(Component component) {
+ _target.performOutlineTransformations(component);
}
@override
@@ -1076,10 +1073,8 @@
bool get excludeNonSources;
@override
- void performOutlineTransformations(Component component, CoreTypes coreTypes,
- ReferenceFromIndex? referenceFromIndex) {
- super.performOutlineTransformations(
- component, coreTypes, referenceFromIndex);
+ void performOutlineTransformations(Component component) {
+ super.performOutlineTransformations(component);
if (!excludeNonSources) return;
List<Library> libraries = new List.of(component.libraries);