mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:39:49 +00:00
Remove support for --emit-metadata in DDC
This flag is unused and the behavior it enables was only useful along with `dart:mirrors`. - Remove the flag and the field on the options object. - Prune code branches that are no longer reachable. - Remove or inline some functions that became either empty or trivially small. - Remove the manual check for a `dart:mirrors` import since this is handled by the CFE now. - Remove references to the flag in tests. - Remove test files which only existed to enable the flag for other tests. Change-Id: I21bf594271fb4eeb5b73fcbf07da736e9e8d1f33 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138018 Reviewed-by: Nicholas Shahan <nshahan@google.com> Commit-Queue: Nate Bosch <nbosch@google.com> Auto-Submit: Nate Bosch <nbosch@google.com>
This commit is contained in:
parent
6e8efe2a15
commit
9d76737487
|
@ -66,9 +66,6 @@ class SharedCompilerOptions {
|
|||
/// This is required for a modular build process.
|
||||
final bool summarizeApi;
|
||||
|
||||
/// Whether to preserve metdata only accessible via mirrors.
|
||||
final bool emitMetadata;
|
||||
|
||||
// Whether to enable assertions.
|
||||
final bool enableAsserts;
|
||||
|
||||
|
@ -98,7 +95,6 @@ class SharedCompilerOptions {
|
|||
{this.sourceMap = true,
|
||||
this.inlineSourceMap = false,
|
||||
this.summarizeApi = true,
|
||||
this.emitMetadata = false,
|
||||
this.enableAsserts = true,
|
||||
this.replCompile = false,
|
||||
this.summaryModules = const {},
|
||||
|
@ -112,7 +108,6 @@ class SharedCompilerOptions {
|
|||
sourceMap: args['source-map'] as bool,
|
||||
inlineSourceMap: args['inline-source-map'] as bool,
|
||||
summarizeApi: args['summarize'] as bool,
|
||||
emitMetadata: args['emit-metadata'] as bool,
|
||||
enableAsserts: args['enable-asserts'] as bool,
|
||||
experiments: parseExperimentalArguments(
|
||||
args['enable-experiment'] as List<String>),
|
||||
|
@ -139,8 +134,6 @@ class SharedCompilerOptions {
|
|||
help: 'emit source mapping', defaultsTo: true, hide: hide)
|
||||
..addFlag('inline-source-map',
|
||||
help: 'emit source mapping inline', defaultsTo: false, hide: hide)
|
||||
..addFlag('emit-metadata',
|
||||
help: 'emit metadata annotations queriable via mirrors', hide: hide)
|
||||
..addFlag('enable-asserts',
|
||||
help: 'enable assertions', defaultsTo: true, hide: hide)
|
||||
..addOption('module-name',
|
||||
|
|
|
@ -348,10 +348,6 @@ Future<CompilerResult> _compile(List<String> args,
|
|||
if (!librariesFromDill.contains(lib)) compiledLibraries.libraries.add(lib);
|
||||
}
|
||||
|
||||
if (!options.emitMetadata && _checkForDartMirrorsImport(compiledLibraries)) {
|
||||
return CompilerResult(1, kernelState: compilerState);
|
||||
}
|
||||
|
||||
// Output files can be written in parallel, so collect the futures.
|
||||
var outFiles = <Future>[];
|
||||
if (argResults['summarize'] as bool) {
|
||||
|
@ -631,21 +627,6 @@ final defaultSdkSummaryPath =
|
|||
|
||||
final defaultLibrarySpecPath = p.join(getSdkPath(), 'lib', 'libraries.json');
|
||||
|
||||
bool _checkForDartMirrorsImport(Component component) {
|
||||
for (var library in component.libraries) {
|
||||
if (library.importUri.scheme == 'dart') continue;
|
||||
for (var dep in library.dependencies) {
|
||||
var uri = dep.targetLibrary.importUri;
|
||||
if (uri.scheme == 'dart' && uri.path == 'mirrors') {
|
||||
print('${library.importUri}: Error: Cannot import "dart:mirrors" '
|
||||
'in web applications (https://goo.gl/R1anEs).');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Returns the absolute path to the default `.packages` file, or `null` if one
|
||||
/// could not be found.
|
||||
///
|
||||
|
|
|
@ -600,7 +600,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
if (!c.isMixinDeclaration) {
|
||||
_defineExtensionMembers(className, body);
|
||||
}
|
||||
_emitClassMetadata(c.annotations, className, body);
|
||||
|
||||
var classDef = js_ast.Statement.from(body);
|
||||
var typeFormals = c.typeParameters;
|
||||
|
@ -1162,19 +1161,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
}
|
||||
}
|
||||
|
||||
void _emitClassMetadata(List<Expression> metadata,
|
||||
js_ast.Expression className, List<js_ast.Statement> body) {
|
||||
// Metadata
|
||||
if (_options.emitMetadata && metadata.isNotEmpty) {
|
||||
body.add(js.statement('#[#.metadata] = #;', [
|
||||
className,
|
||||
runtimeModule,
|
||||
_arrowFunctionWithLetScope(() => js_ast.ArrayInitializer(
|
||||
metadata.map(_instantiateAnnotation).toList()))
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure `dartx.` symbols we will use are present.
|
||||
void _initExtensionSymbols(Class c) {
|
||||
if (_extensionTypes.hasNativeSubtype(c) || c == _coreTypes.objectClass) {
|
||||
|
@ -1272,7 +1258,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
for (var member in classProcedures) {
|
||||
// Static getters/setters/methods cannot be called with dynamic dispatch,
|
||||
// nor can they be torn off.
|
||||
if (!_options.emitMetadata && member.isStatic) continue;
|
||||
if (member.isStatic) continue;
|
||||
|
||||
var name = member.name.name;
|
||||
var reifiedType = _memberRuntimeType(member, c) as FunctionType;
|
||||
|
@ -1293,14 +1279,11 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
if (needsSignature) {
|
||||
js_ast.Expression type;
|
||||
if (member.isAccessor) {
|
||||
type = _emitAnnotatedResult(
|
||||
_emitType(member.isGetter
|
||||
? reifiedType.returnType
|
||||
: reifiedType.positionalParameters[0]),
|
||||
member.annotations,
|
||||
member);
|
||||
type = _emitType(member.isGetter
|
||||
? reifiedType.returnType
|
||||
: reifiedType.positionalParameters[0]);
|
||||
} else {
|
||||
type = _emitAnnotatedFunctionType(reifiedType, member);
|
||||
type = visitFunctionType(reifiedType, member: member);
|
||||
}
|
||||
var property = js_ast.Property(_declareMemberName(member), type);
|
||||
var signatures = getSignatureList(member);
|
||||
|
@ -1329,7 +1312,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
for (var field in classFields) {
|
||||
// Only instance fields need to be saved for dynamic dispatch.
|
||||
var isStatic = field.isStatic;
|
||||
if (!_options.emitMetadata && isStatic) continue;
|
||||
if (isStatic) continue;
|
||||
|
||||
var memberName = _declareMemberName(field);
|
||||
var fieldSig = _emitFieldSignature(field, c);
|
||||
|
@ -1339,24 +1322,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
emitSignature('Field', instanceFields);
|
||||
emitSignature('StaticField', staticFields);
|
||||
|
||||
if (_options.emitMetadata) {
|
||||
var constructors = <js_ast.Property>[];
|
||||
var allConstructors = [
|
||||
...c.constructors,
|
||||
...c.procedures.where((p) => p.isFactory),
|
||||
];
|
||||
for (var ctor in allConstructors) {
|
||||
var memberName = _constructorName(ctor.name.name);
|
||||
var type = _emitAnnotatedFunctionType(
|
||||
ctor.function
|
||||
.computeThisFunctionType(c.enclosingLibrary.nonNullable)
|
||||
.withoutTypeParameters,
|
||||
ctor);
|
||||
constructors.add(js_ast.Property(memberName, type));
|
||||
}
|
||||
emitSignature('Constructor', constructors);
|
||||
}
|
||||
|
||||
// Add static property dart._runtimeType to Object.
|
||||
// All other Dart classes will (statically) inherit this property.
|
||||
if (c == _coreTypes.objectClass) {
|
||||
|
@ -1370,16 +1335,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
js_ast.Expression _emitFieldSignature(Field field, Class fromClass) {
|
||||
var type = _typeFromClass(field.type, field.enclosingClass, fromClass);
|
||||
var args = [_emitType(type)];
|
||||
var annotations = field.annotations;
|
||||
if (_options.emitMetadata &&
|
||||
annotations != null &&
|
||||
annotations.isNotEmpty) {
|
||||
var savedUri = _currentUri;
|
||||
_currentUri = field.enclosingClass.fileUri;
|
||||
args.add(js_ast.ArrayInitializer(
|
||||
annotations.map(_instantiateAnnotation).toList()));
|
||||
_currentUri = savedUri;
|
||||
}
|
||||
return runtimeCall(
|
||||
field.isFinal ? 'finalFieldType(#)' : 'fieldType(#)', [args]);
|
||||
}
|
||||
|
@ -2067,9 +2022,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
]) as js_ast.Fun);
|
||||
}
|
||||
|
||||
js_ast.Expression _instantiateAnnotation(Expression node) =>
|
||||
_visitExpression(node);
|
||||
|
||||
void _registerExtensionType(
|
||||
Class c, String jsPeerName, List<js_ast.Statement> body) {
|
||||
var className = _emitTopLevelName(c);
|
||||
|
@ -2181,19 +2133,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
return body;
|
||||
}
|
||||
|
||||
js_ast.ArrowFun _arrowFunctionWithLetScope(
|
||||
js_ast.Expression Function() visitBody) {
|
||||
var savedLetVariables = _letVariables;
|
||||
_letVariables = [];
|
||||
|
||||
var expr = visitBody();
|
||||
var letVars = _initLetVariables();
|
||||
|
||||
_letVariables = savedLetVariables;
|
||||
return js_ast.ArrowFun(
|
||||
[], letVars == null ? expr : js_ast.Block([letVars, expr.toReturn()]));
|
||||
}
|
||||
|
||||
js_ast.PropertyAccess _emitTopLevelName(NamedNode n, {String suffix = ''}) {
|
||||
return _emitJSInterop(n) ?? _emitTopLevelNameNoInterop(n, suffix: suffix);
|
||||
}
|
||||
|
@ -2540,18 +2479,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
var nameExpr = _emitTopLevelName(p);
|
||||
body.add(js.statement('# = #',
|
||||
[nameExpr, js_ast.NamedFunction(_emitTemporaryId(p.name.name), fn)]));
|
||||
// Function types of top-level/static functions are only needed when
|
||||
// dart:mirrors is enabled.
|
||||
// TODO(jmesserly): do we even need this for mirrors, since statics are not
|
||||
// commonly reflected on?
|
||||
if (_options.emitMetadata && _reifyFunctionType(p.function)) {
|
||||
body.add(_emitFunctionTagged(
|
||||
nameExpr,
|
||||
p.function
|
||||
.computeThisFunctionType(p.enclosingLibrary.nonNullable),
|
||||
topLevel: true)
|
||||
.toStatement());
|
||||
}
|
||||
|
||||
_currentUri = savedUri;
|
||||
_staticTypeContext.leaveMember(p);
|
||||
|
@ -2887,24 +2814,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
return _emitNullabilityWrapper(typeRep, type.nullability);
|
||||
}
|
||||
|
||||
js_ast.Expression _emitAnnotatedFunctionType(
|
||||
FunctionType type, Member member) {
|
||||
var result = visitFunctionType(type, member: member);
|
||||
|
||||
var annotations = member.annotations;
|
||||
if (_options.emitMetadata && annotations.isNotEmpty) {
|
||||
// TODO(jmesserly): should we disable source info for annotations?
|
||||
var savedUri = _currentUri;
|
||||
_currentUri = member.enclosingClass.fileUri;
|
||||
result = js_ast.ArrayInitializer([
|
||||
result,
|
||||
for (var annotation in annotations) _instantiateAnnotation(annotation)
|
||||
]);
|
||||
_currentUri = savedUri;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Emits an expression that lets you access statics on a [type] from code.
|
||||
js_ast.Expression _emitConstructorAccess(InterfaceType type) {
|
||||
return _emitJSInterop(type.classNode) ??
|
||||
|
@ -2923,21 +2832,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
return _emitTopLevelName(c);
|
||||
}
|
||||
|
||||
// Wrap a result - usually a type - with its metadata. The runtime is
|
||||
// responsible for unpacking this.
|
||||
js_ast.Expression _emitAnnotatedResult(
|
||||
js_ast.Expression result, List<Expression> metadata, Member member) {
|
||||
if (_options.emitMetadata && metadata.isNotEmpty) {
|
||||
// TODO(jmesserly): should we disable source info for annotations?
|
||||
var savedUri = _currentUri;
|
||||
_currentUri = member.enclosingClass.fileUri;
|
||||
result = js_ast.ArrayInitializer(
|
||||
[result, for (var value in metadata) _instantiateAnnotation(value)]);
|
||||
_currentUri = savedUri;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Emits named parameters in the form '{name: type}'.
|
||||
js_ast.ObjectInitializer _emitTypeProperties(Iterable<NamedType> types) {
|
||||
return js_ast.ObjectInitializer(types
|
||||
|
@ -2949,17 +2843,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
///
|
||||
/// Annotatable contexts include typedefs and method/function declarations.
|
||||
js_ast.ArrayInitializer _emitTypeNames(List<DartType> types,
|
||||
List<VariableDeclaration> parameters, Member member) {
|
||||
var result = <js_ast.Expression>[];
|
||||
for (var i = 0; i < types.length; ++i) {
|
||||
var type = _emitType(types[i]);
|
||||
if (parameters != null) {
|
||||
type = _emitAnnotatedResult(type, parameters[i].annotations, member);
|
||||
}
|
||||
result.add(type);
|
||||
}
|
||||
return js_ast.ArrayInitializer(result);
|
||||
}
|
||||
List<VariableDeclaration> parameters, Member member) =>
|
||||
js_ast.ArrayInitializer([for (var type in types) _emitType(type)]);
|
||||
|
||||
@override
|
||||
js_ast.Expression visitTypeParameterType(TypeParameterType type) =>
|
||||
|
|
|
@ -287,11 +287,6 @@ getSetterType(type, name) {
|
|||
if (setters != null) {
|
||||
var type = JS('', '#[#]', setters, name);
|
||||
if (type != null) {
|
||||
if (JS('!', '# instanceof Array', type)) {
|
||||
// The type has metadata attached. Pull out just the type.
|
||||
// TODO(jmesserly): remove when we remove mirrors
|
||||
return JS('', '#[0]', type);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -282,10 +282,6 @@ _checkAndCall(f, ftype, obj, typeArgs, args, named, displayName) =>
|
|||
return $f.apply($obj, $args);
|
||||
}
|
||||
|
||||
// TODO(vsm): Remove when we no longer need mirrors metadata.
|
||||
// An array is used to encode annotations attached to the type.
|
||||
if ($ftype instanceof Array) $ftype = $ftype[0];
|
||||
|
||||
// Apply type arguments
|
||||
if ($ftype instanceof $GenericFunctionType) {
|
||||
let formalCount = $ftype.formalCount;
|
||||
|
|
|
@ -301,11 +301,6 @@ getSetterType(type, name) {
|
|||
if (setters != null) {
|
||||
var type = JS('', '#[#]', setters, name);
|
||||
if (type != null) {
|
||||
if (JS('!', '# instanceof Array', type)) {
|
||||
// The type has metadata attached. Pull out just the type.
|
||||
// TODO(jmesserly): remove when we remove mirrors
|
||||
return JS('', '#[0]', type);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -300,10 +300,6 @@ _checkAndCall(f, ftype, obj, typeArgs, args, named, displayName) =>
|
|||
return $f.apply($obj, $args);
|
||||
}
|
||||
|
||||
// TODO(vsm): Remove when we no longer need mirrors metadata.
|
||||
// An array is used to encode annotations attached to the type.
|
||||
if ($ftype instanceof Array) $ftype = $ftype[0];
|
||||
|
||||
// Apply type arguments
|
||||
if ($ftype instanceof $GenericFunctionType) {
|
||||
let formalCount = $ftype.formalCount;
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
// compile options: --emit-metadata
|
||||
// Copyright (c) 2017, 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.
|
||||
|
||||
// Run essentially the same test, but with emit-metadata compile option,
|
||||
// which allows us to reflect on the fields.
|
||||
import 'dart:mirrors';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
import 'field_metadata_test.dart' as field_metadata_test;
|
||||
import 'field_metadata_test.dart' show Foo, Bar;
|
||||
|
||||
void main() {
|
||||
// Make sure the other test still works.
|
||||
field_metadata_test.main();
|
||||
|
||||
// Check that we can now reflect on the annotations.
|
||||
dynamic f = new Foo();
|
||||
var members = reflect(f).type.declarations;
|
||||
var x = members[#x] as VariableMirror;
|
||||
var bar = x.metadata.first.reflectee as Bar;
|
||||
Expect.equals(bar.name, 'bar');
|
||||
|
||||
var y = members[#y] as VariableMirror;
|
||||
var baz = y.metadata.first.reflectee as Bar;
|
||||
Expect.equals(baz.name, 'baz');
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
// compile options: --emit-metadata
|
||||
// Copyright (c) 2013, 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.
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// compile options: --emit-metadata
|
||||
// Copyright (c) 2013, 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.
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// compile options: --emit-metadata
|
||||
// Copyright (c) 2014, 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.
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
// compile options: --emit-metadata
|
||||
// Copyright (c) 2017, 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.
|
||||
|
||||
// Run essentially the same test, but with emit-metadata compile option,
|
||||
// which allows us to reflect on the fields.
|
||||
import 'dart:mirrors';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
import 'field_metadata_test.dart' as field_metadata_test;
|
||||
import 'field_metadata_test.dart' show Foo, Bar;
|
||||
|
||||
void main() {
|
||||
// Make sure the other test still works.
|
||||
field_metadata_test.main();
|
||||
|
||||
// Check that we can now reflect on the annotations.
|
||||
dynamic f = new Foo();
|
||||
var members = reflect(f).type.declarations;
|
||||
var x = members[#x] as VariableMirror;
|
||||
var bar = x.metadata.first.reflectee as Bar;
|
||||
Expect.equals(bar.name, 'bar');
|
||||
|
||||
var y = members[#y] as VariableMirror;
|
||||
var baz = y.metadata.first.reflectee as Bar;
|
||||
Expect.equals(baz.name, 'baz');
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
// compile options: --emit-metadata
|
||||
// Copyright (c) 2013, 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.
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// compile options: --emit-metadata
|
||||
// Copyright (c) 2013, 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.
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// compile options: --emit-metadata
|
||||
// Copyright (c) 2014, 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.
|
||||
|
|
Loading…
Reference in a new issue