[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>
This commit is contained in:
Srujan Gaddam 2022-08-01 18:17:44 +00:00 committed by Commit Bot
parent 33b672f789
commit 61abaeda3f
10 changed files with 26 additions and 82 deletions

View file

@ -60,11 +60,7 @@ class StaticInteropClassEraser extends Transformer {
.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 @@ class _StaticInteropConstantReplacer extends ConstantReplacer {
@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);
}
}

View file

@ -137,13 +137,6 @@ class Dart2jsTarget extends Target {
@override
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,
@ -168,12 +161,14 @@ class Dart2jsTarget extends Target {
// 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");
}
}

View file

@ -7,12 +7,15 @@ import 'dart:async';
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 @@ class _LoadFromKernelResult {
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,

View file

@ -86,20 +86,16 @@ class WasmTarget extends Target {
..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);
@ -117,13 +113,6 @@ class WasmTarget extends Target {
_patchHostEndian(coreTypes);
}
@override
void performOutlineTransformations(Component component, CoreTypes coreTypes,
ReferenceFromIndex? referenceFromIndex) {
component.accept(StaticInteropStubCreator(
_staticInteropClassEraser(coreTypes, referenceFromIndex)));
}
@override
void performModularTransformationsOnLibraries(
Component component,

View file

@ -152,13 +152,6 @@ class DevCompilerTarget extends Target {
@override
bool get enableNoSuchMethodForwarders => true;
@override
void performOutlineTransformations(Component component, CoreTypes coreTypes,
ReferenceFromIndex? referenceFromIndex) {
component.accept(StaticInteropStubCreator(
StaticInteropClassEraser(coreTypes, referenceFromIndex)));
}
@override
void performModularTransformationsOnLibraries(
Component component,

View file

@ -12,8 +12,6 @@ import 'package:kernel/core_types.dart' show CoreTypes;
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 @@ class IncrementalCompilerResult {
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});
}

View file

@ -529,8 +529,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
return new IncrementalCompilerResult(result,
classHierarchy: currentKernelTarget.loader.hierarchy,
coreTypes: currentKernelTarget.loader.coreTypes,
neededDillLibraries: neededDillLibraries,
referenceFromIndex: currentKernelTarget.loader.referenceFromIndex);
neededDillLibraries: neededDillLibraries);
});
}

View file

@ -188,10 +188,7 @@ Future<CompilerResult> _buildInternal(
// 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).

View file

@ -396,10 +396,7 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
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));

View file

@ -314,8 +314,7 @@ abstract class Target {
/// 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 @@ class TargetWrapper extends Target {
}
@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 @@ mixin SummaryMixin on Target {
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);