[dart2js] Remove metadata collection that was used for reflection
Change-Id: If4953135a84583a12fcf1c4b1f0d03cd1ae51f14
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/200321
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
diff --git a/pkg/compiler/lib/src/js/js.dart b/pkg/compiler/lib/src/js/js.dart
index 4518521..b49abc0 100644
--- a/pkg/compiler/lib/src/js/js.dart
+++ b/pkg/compiler/lib/src/js/js.dart
@@ -18,15 +18,13 @@
String prettyPrint(Node node,
{bool enableMinification: false,
bool allowVariableMinification: true,
- bool preferSemicolonToNewlineInMinifiedOutput: false,
- Renamer renamerForNames: JavaScriptPrintingOptions.identityRenamer}) {
+ bool preferSemicolonToNewlineInMinifiedOutput: false}) {
// TODO(johnniwinther): Do we need all the options here?
JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(
shouldCompressOutput: enableMinification,
minifyLocalVariables: allowVariableMinification,
preferSemicolonToNewlineInMinifiedOutput:
- preferSemicolonToNewlineInMinifiedOutput,
- renamerForNames: renamerForNames);
+ preferSemicolonToNewlineInMinifiedOutput);
SimpleJavaScriptPrintingContext context =
new SimpleJavaScriptPrintingContext();
Printer printer = new Printer(options, context);
@@ -38,12 +36,10 @@
JavaScriptSourceInformationStrategy sourceInformationStrategy,
{DumpInfoTask monitor,
bool allowVariableMinification: true,
- Renamer renamerForNames: JavaScriptPrintingOptions.identityRenamer,
List<CodeOutputListener> listeners: const []}) {
JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(
shouldCompressOutput: compilerOptions.enableMinification,
- minifyLocalVariables: allowVariableMinification,
- renamerForNames: renamerForNames);
+ minifyLocalVariables: allowVariableMinification);
CodeBuffer outBuffer = new CodeBuffer(listeners);
SourceInformationProcessor sourceInformationProcessor =
sourceInformationStrategy.createProcessor(
diff --git a/pkg/compiler/lib/src/js/size_estimator.dart b/pkg/compiler/lib/src/js/size_estimator.dart
index e2b8a9b..8ecfd9e 100644
--- a/pkg/compiler/lib/src/js/size_estimator.dart
+++ b/pkg/compiler/lib/src/js/size_estimator.dart
@@ -886,8 +886,6 @@
@override
visitName(Name node) {
// For simplicity and stability we use a constant name size estimate.
- // In production this is:
- // '${options.renamerForNames(node)}'
out(sizeEstimate(node));
}
diff --git a/pkg/compiler/lib/src/js_emitter/code_emitter_task.dart b/pkg/compiler/lib/src/js_emitter/code_emitter_task.dart
index b7fdafc..10ba94a 100644
--- a/pkg/compiler/lib/src/js_emitter/code_emitter_task.dart
+++ b/pkg/compiler/lib/src/js_emitter/code_emitter_task.dart
@@ -103,11 +103,7 @@
this,
_generateSourceMap);
metadataCollector = new MetadataCollector(
- _compiler.options,
- _compiler.reporter,
- _emitter,
- codegen.rtiRecipeEncoder,
- closedWorld.elementEnvironment);
+ _compiler.reporter, _emitter, codegen.rtiRecipeEncoder);
typeTestRegistry = new TypeTestRegistry(
_compiler.options, closedWorld.elementEnvironment);
});
diff --git a/pkg/compiler/lib/src/js_emitter/metadata_collector.dart b/pkg/compiler/lib/src/js_emitter/metadata_collector.dart
index db10350..4923f10 100644
--- a/pkg/compiler/lib/src/js_emitter/metadata_collector.dart
+++ b/pkg/compiler/lib/src/js_emitter/metadata_collector.dart
@@ -7,18 +7,12 @@
import 'package:js_ast/src/precedence.dart' as js_precedence;
import '../common.dart';
-import '../common_elements.dart' show JElementEnvironment;
-import '../constants/values.dart';
import '../deferred_load.dart' show OutputUnit;
-import '../elements/entities.dart' show FunctionEntity;
-import '../elements/entities.dart';
import '../elements/types.dart';
import '../js/js.dart' as jsAst;
-import '../js/js.dart' show js;
import '../js_backend/runtime_types_new.dart' show RecipeEncoder;
import '../js_model/type_recipe.dart' show TypeExpressionRecipe;
-import '../options.dart';
import 'code_emitter_task.dart' show Emitter;
@@ -99,20 +93,9 @@
}
class MetadataCollector implements jsAst.TokenFinalizer {
- final CompilerOptions _options;
final DiagnosticReporter reporter;
final Emitter _emitter;
final RecipeEncoder _rtiRecipeEncoder;
- final JElementEnvironment _elementEnvironment;
-
- /// A map with a token per output unit for a list of expressions that
- /// represent metadata, parameter names and type variable types.
- Map<OutputUnit, _MetadataList> _metadataTokens =
- new Map<OutputUnit, _MetadataList>();
-
- jsAst.Expression getMetadataForOutputUnit(OutputUnit outputUnit) {
- return _metadataTokens.putIfAbsent(outputUnit, () => new _MetadataList());
- }
/// A map used to canonicalize the entries of metadata.
Map<OutputUnit, Map<String, List<BoundMetadataEntry>>> _metadataMap = {};
@@ -120,16 +103,17 @@
/// A map with a token for a lists of JS expressions, one token for each
/// output unit. Once finalized, the entries represent types including
/// function types and typedefs.
- Map<OutputUnit, _MetadataList> _typesTokens =
- new Map<OutputUnit, _MetadataList>();
+ Map<OutputUnit, _MetadataList> _typesTokens = {};
+
+ /// A map used to canonicalize the entries of types.
+ Map<OutputUnit, Map<DartType, List<BoundMetadataEntry>>> _typesMap = {};
+
+ MetadataCollector(this.reporter, this._emitter, this._rtiRecipeEncoder);
jsAst.Expression getTypesForOutputUnit(OutputUnit outputUnit) {
return _typesTokens.putIfAbsent(outputUnit, () => new _MetadataList());
}
- /// A map used to canonicalize the entries of types.
- Map<OutputUnit, Map<DartType, List<BoundMetadataEntry>>> _typesMap = {};
-
void mergeOutputUnitMetadata(OutputUnit target, OutputUnit source) {
assert(target != source);
@@ -158,43 +142,8 @@
}
}
- MetadataCollector(this._options, this.reporter, this._emitter,
- this._rtiRecipeEncoder, this._elementEnvironment);
-
- List<jsAst.DeferredNumber> reifyDefaultArguments(
- FunctionEntity function, OutputUnit outputUnit) {
- // TODO(sra): These are stored on the InstanceMethod or StaticDartMethod.
- List<jsAst.DeferredNumber> defaultValues = <jsAst.DeferredNumber>[];
- _elementEnvironment.forEachParameter(function,
- (_, String name, ConstantValue constant) {
- if (constant == null) return;
- jsAst.Expression expression = _emitter.constantReference(constant);
- defaultValues.add(_addGlobalMetadata(expression, outputUnit));
- });
- return defaultValues;
- }
-
jsAst.Expression reifyType(DartType type, OutputUnit outputUnit) {
- return addTypeInOutputUnit(type, outputUnit);
- }
-
- jsAst.Expression reifyName(String name, OutputUnit outputUnit) {
- return _addGlobalMetadata(js.string(name), outputUnit);
- }
-
- jsAst.Expression reifyExpression(
- jsAst.Expression expression, OutputUnit outputUnit) {
- return _addGlobalMetadata(expression, outputUnit);
- }
-
- _MetadataEntry _addGlobalMetadata(jsAst.Node node, OutputUnit outputUnit) {
- String nameToKey(jsAst.Name name) => "${name.key}";
- String printed = jsAst.prettyPrint(node,
- enableMinification: _options.enableMinification,
- renamerForNames: nameToKey);
- final submap = _metadataMap[outputUnit] ??= {};
- final entries = submap[printed] ??= [BoundMetadataEntry(node)];
- return entries.single;
+ return _addTypeInOutputUnit(type, outputUnit);
}
jsAst.Expression _computeTypeRepresentationNewRti(DartType type) {
@@ -202,11 +151,10 @@
_emitter, TypeExpressionRecipe(type));
}
- jsAst.Expression addTypeInOutputUnit(DartType type, OutputUnit outputUnit) {
+ jsAst.Expression _addTypeInOutputUnit(DartType type, OutputUnit outputUnit) {
_typesMap[outputUnit] ??= Map<DartType, List<BoundMetadataEntry>>();
BoundMetadataEntry metadataEntry;
- // See comment for _addGlobalMetadata.
if (_typesMap[outputUnit].containsKey(type)) {
metadataEntry = _typesMap[outputUnit][type].single;
} else {
@@ -251,15 +199,6 @@
return new jsAst.ArrayInitializer(values);
}
- _metadataTokens.forEach((OutputUnit outputUnit, _MetadataList token) {
- Map metadataMap = _metadataMap[outputUnit];
- if (metadataMap != null) {
- token.setExpression(finalizeMap(metadataMap));
- } else {
- token.setExpression(new jsAst.ArrayInitializer([]));
- }
- });
-
_typesTokens.forEach((OutputUnit outputUnit, _MetadataList token) {
Map<DartType, List<BoundMetadataEntry>> typesMap = _typesMap[outputUnit];
if (typesMap != null) {
diff --git a/pkg/compiler/lib/src/js_emitter/model.dart b/pkg/compiler/lib/src/js_emitter/model.dart
index f2c81cf..8903eec 100644
--- a/pkg/compiler/lib/src/js_emitter/model.dart
+++ b/pkg/compiler/lib/src/js_emitter/model.dart
@@ -39,21 +39,6 @@
_metadataCollector.mergeOutputUnitMetadata(target, source);
}
- /// Accessor for the list of metadata entries for a given [OutputUnit].
- ///
- /// There is one list for each output unit. The list belonging to the main
- /// unit must be emitted in the `METADATA` embedded global.
- /// The list references constants and must hence be emitted after constants
- /// have been initialized.
- ///
- /// Note: the metadata is derived from the task's `metadataCollector`. The
- /// list must not be emitted before all operations on it are done. For
- /// example, the old emitter generates metadata when emitting reflection
- /// data.
- js.Expression metadataForOutputUnit(OutputUnit unit) {
- return _metadataCollector.getMetadataForOutputUnit(unit);
- }
-
/// Accessor for the list of type entries for a given [OutputUnit].
///
/// There is one list for each output unit. The list belonging to the main
diff --git a/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart b/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart
index 4695840..f84c045 100644
--- a/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart
@@ -1817,8 +1817,6 @@
}
var mainUnit = program.mainFragment.outputUnit;
- js.Expression metadata = program.metadataForOutputUnit(mainUnit);
- metadataGlobals.add(createGlobal(metadata, METADATA));
js.Expression types = program.metadataTypesForOutputUnit(mainUnit);
metadataGlobals.add(createGlobal(types, TYPES));
diff --git a/pkg/js_ast/lib/src/printer.dart b/pkg/js_ast/lib/src/printer.dart
index d851cb8..c6e9a9e 100644
--- a/pkg/js_ast/lib/src/printer.dart
+++ b/pkg/js_ast/lib/src/printer.dart
@@ -4,21 +4,16 @@
part of js_ast;
-typedef String Renamer(Name name);
-
class JavaScriptPrintingOptions {
final bool shouldCompressOutput;
final bool minifyLocalVariables;
final bool preferSemicolonToNewlineInMinifiedOutput;
- final Renamer renamerForNames;
- const JavaScriptPrintingOptions(
- {this.shouldCompressOutput: false,
- this.minifyLocalVariables: false,
- this.preferSemicolonToNewlineInMinifiedOutput: false,
- this.renamerForNames: identityRenamer});
-
- static String identityRenamer(Name name) => name.name;
+ const JavaScriptPrintingOptions({
+ this.shouldCompressOutput: false,
+ this.minifyLocalVariables: false,
+ this.preferSemicolonToNewlineInMinifiedOutput: false,
+ });
}
/// An environment in which JavaScript printing is done. Provides emitting of
@@ -1148,7 +1143,7 @@
@override
visitName(Name node) {
- out(options.renamerForNames(node));
+ out(node.name);
}
@override