Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9d76737

Browse files
nateboschcommit-bot@chromium.org
authored andcommitted
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 <[email protected]> Commit-Queue: Nate Bosch <[email protected]> Auto-Submit: Nate Bosch <[email protected]>
1 parent 6e8efe2 commit 9d76737

File tree

15 files changed

+8
-229
lines changed

15 files changed

+8
-229
lines changed

pkg/dev_compiler/lib/src/compiler/shared_command.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ class SharedCompilerOptions {
6666
/// This is required for a modular build process.
6767
final bool summarizeApi;
6868

69-
/// Whether to preserve metdata only accessible via mirrors.
70-
final bool emitMetadata;
71-
7269
// Whether to enable assertions.
7370
final bool enableAsserts;
7471

@@ -98,7 +95,6 @@ class SharedCompilerOptions {
9895
{this.sourceMap = true,
9996
this.inlineSourceMap = false,
10097
this.summarizeApi = true,
101-
this.emitMetadata = false,
10298
this.enableAsserts = true,
10399
this.replCompile = false,
104100
this.summaryModules = const {},
@@ -112,7 +108,6 @@ class SharedCompilerOptions {
112108
sourceMap: args['source-map'] as bool,
113109
inlineSourceMap: args['inline-source-map'] as bool,
114110
summarizeApi: args['summarize'] as bool,
115-
emitMetadata: args['emit-metadata'] as bool,
116111
enableAsserts: args['enable-asserts'] as bool,
117112
experiments: parseExperimentalArguments(
118113
args['enable-experiment'] as List<String>),
@@ -139,8 +134,6 @@ class SharedCompilerOptions {
139134
help: 'emit source mapping', defaultsTo: true, hide: hide)
140135
..addFlag('inline-source-map',
141136
help: 'emit source mapping inline', defaultsTo: false, hide: hide)
142-
..addFlag('emit-metadata',
143-
help: 'emit metadata annotations queriable via mirrors', hide: hide)
144137
..addFlag('enable-asserts',
145138
help: 'enable assertions', defaultsTo: true, hide: hide)
146139
..addOption('module-name',

pkg/dev_compiler/lib/src/kernel/command.dart

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,6 @@ Future<CompilerResult> _compile(List<String> args,
348348
if (!librariesFromDill.contains(lib)) compiledLibraries.libraries.add(lib);
349349
}
350350

351-
if (!options.emitMetadata && _checkForDartMirrorsImport(compiledLibraries)) {
352-
return CompilerResult(1, kernelState: compilerState);
353-
}
354-
355351
// Output files can be written in parallel, so collect the futures.
356352
var outFiles = <Future>[];
357353
if (argResults['summarize'] as bool) {
@@ -631,21 +627,6 @@ final defaultSdkSummaryPath =
631627

632628
final defaultLibrarySpecPath = p.join(getSdkPath(), 'lib', 'libraries.json');
633629

634-
bool _checkForDartMirrorsImport(Component component) {
635-
for (var library in component.libraries) {
636-
if (library.importUri.scheme == 'dart') continue;
637-
for (var dep in library.dependencies) {
638-
var uri = dep.targetLibrary.importUri;
639-
if (uri.scheme == 'dart' && uri.path == 'mirrors') {
640-
print('${library.importUri}: Error: Cannot import "dart:mirrors" '
641-
'in web applications (https://goo.gl/R1anEs).');
642-
return true;
643-
}
644-
}
645-
}
646-
return false;
647-
}
648-
649630
/// Returns the absolute path to the default `.packages` file, or `null` if one
650631
/// could not be found.
651632
///

pkg/dev_compiler/lib/src/kernel/compiler.dart

Lines changed: 8 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
600600
if (!c.isMixinDeclaration) {
601601
_defineExtensionMembers(className, body);
602602
}
603-
_emitClassMetadata(c.annotations, className, body);
604603

605604
var classDef = js_ast.Statement.from(body);
606605
var typeFormals = c.typeParameters;
@@ -1162,19 +1161,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
11621161
}
11631162
}
11641163

1165-
void _emitClassMetadata(List<Expression> metadata,
1166-
js_ast.Expression className, List<js_ast.Statement> body) {
1167-
// Metadata
1168-
if (_options.emitMetadata && metadata.isNotEmpty) {
1169-
body.add(js.statement('#[#.metadata] = #;', [
1170-
className,
1171-
runtimeModule,
1172-
_arrowFunctionWithLetScope(() => js_ast.ArrayInitializer(
1173-
metadata.map(_instantiateAnnotation).toList()))
1174-
]));
1175-
}
1176-
}
1177-
11781164
/// Ensure `dartx.` symbols we will use are present.
11791165
void _initExtensionSymbols(Class c) {
11801166
if (_extensionTypes.hasNativeSubtype(c) || c == _coreTypes.objectClass) {
@@ -1272,7 +1258,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
12721258
for (var member in classProcedures) {
12731259
// Static getters/setters/methods cannot be called with dynamic dispatch,
12741260
// nor can they be torn off.
1275-
if (!_options.emitMetadata && member.isStatic) continue;
1261+
if (member.isStatic) continue;
12761262

12771263
var name = member.name.name;
12781264
var reifiedType = _memberRuntimeType(member, c) as FunctionType;
@@ -1293,14 +1279,11 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
12931279
if (needsSignature) {
12941280
js_ast.Expression type;
12951281
if (member.isAccessor) {
1296-
type = _emitAnnotatedResult(
1297-
_emitType(member.isGetter
1298-
? reifiedType.returnType
1299-
: reifiedType.positionalParameters[0]),
1300-
member.annotations,
1301-
member);
1282+
type = _emitType(member.isGetter
1283+
? reifiedType.returnType
1284+
: reifiedType.positionalParameters[0]);
13021285
} else {
1303-
type = _emitAnnotatedFunctionType(reifiedType, member);
1286+
type = visitFunctionType(reifiedType, member: member);
13041287
}
13051288
var property = js_ast.Property(_declareMemberName(member), type);
13061289
var signatures = getSignatureList(member);
@@ -1329,7 +1312,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
13291312
for (var field in classFields) {
13301313
// Only instance fields need to be saved for dynamic dispatch.
13311314
var isStatic = field.isStatic;
1332-
if (!_options.emitMetadata && isStatic) continue;
1315+
if (isStatic) continue;
13331316

13341317
var memberName = _declareMemberName(field);
13351318
var fieldSig = _emitFieldSignature(field, c);
@@ -1339,24 +1322,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
13391322
emitSignature('Field', instanceFields);
13401323
emitSignature('StaticField', staticFields);
13411324

1342-
if (_options.emitMetadata) {
1343-
var constructors = <js_ast.Property>[];
1344-
var allConstructors = [
1345-
...c.constructors,
1346-
...c.procedures.where((p) => p.isFactory),
1347-
];
1348-
for (var ctor in allConstructors) {
1349-
var memberName = _constructorName(ctor.name.name);
1350-
var type = _emitAnnotatedFunctionType(
1351-
ctor.function
1352-
.computeThisFunctionType(c.enclosingLibrary.nonNullable)
1353-
.withoutTypeParameters,
1354-
ctor);
1355-
constructors.add(js_ast.Property(memberName, type));
1356-
}
1357-
emitSignature('Constructor', constructors);
1358-
}
1359-
13601325
// Add static property dart._runtimeType to Object.
13611326
// All other Dart classes will (statically) inherit this property.
13621327
if (c == _coreTypes.objectClass) {
@@ -1370,16 +1335,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
13701335
js_ast.Expression _emitFieldSignature(Field field, Class fromClass) {
13711336
var type = _typeFromClass(field.type, field.enclosingClass, fromClass);
13721337
var args = [_emitType(type)];
1373-
var annotations = field.annotations;
1374-
if (_options.emitMetadata &&
1375-
annotations != null &&
1376-
annotations.isNotEmpty) {
1377-
var savedUri = _currentUri;
1378-
_currentUri = field.enclosingClass.fileUri;
1379-
args.add(js_ast.ArrayInitializer(
1380-
annotations.map(_instantiateAnnotation).toList()));
1381-
_currentUri = savedUri;
1382-
}
13831338
return runtimeCall(
13841339
field.isFinal ? 'finalFieldType(#)' : 'fieldType(#)', [args]);
13851340
}
@@ -2067,9 +2022,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
20672022
]) as js_ast.Fun);
20682023
}
20692024

2070-
js_ast.Expression _instantiateAnnotation(Expression node) =>
2071-
_visitExpression(node);
2072-
20732025
void _registerExtensionType(
20742026
Class c, String jsPeerName, List<js_ast.Statement> body) {
20752027
var className = _emitTopLevelName(c);
@@ -2181,19 +2133,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
21812133
return body;
21822134
}
21832135

2184-
js_ast.ArrowFun _arrowFunctionWithLetScope(
2185-
js_ast.Expression Function() visitBody) {
2186-
var savedLetVariables = _letVariables;
2187-
_letVariables = [];
2188-
2189-
var expr = visitBody();
2190-
var letVars = _initLetVariables();
2191-
2192-
_letVariables = savedLetVariables;
2193-
return js_ast.ArrowFun(
2194-
[], letVars == null ? expr : js_ast.Block([letVars, expr.toReturn()]));
2195-
}
2196-
21972136
js_ast.PropertyAccess _emitTopLevelName(NamedNode n, {String suffix = ''}) {
21982137
return _emitJSInterop(n) ?? _emitTopLevelNameNoInterop(n, suffix: suffix);
21992138
}
@@ -2540,18 +2479,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
25402479
var nameExpr = _emitTopLevelName(p);
25412480
body.add(js.statement('# = #',
25422481
[nameExpr, js_ast.NamedFunction(_emitTemporaryId(p.name.name), fn)]));
2543-
// Function types of top-level/static functions are only needed when
2544-
// dart:mirrors is enabled.
2545-
// TODO(jmesserly): do we even need this for mirrors, since statics are not
2546-
// commonly reflected on?
2547-
if (_options.emitMetadata && _reifyFunctionType(p.function)) {
2548-
body.add(_emitFunctionTagged(
2549-
nameExpr,
2550-
p.function
2551-
.computeThisFunctionType(p.enclosingLibrary.nonNullable),
2552-
topLevel: true)
2553-
.toStatement());
2554-
}
25552482

25562483
_currentUri = savedUri;
25572484
_staticTypeContext.leaveMember(p);
@@ -2887,24 +2814,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
28872814
return _emitNullabilityWrapper(typeRep, type.nullability);
28882815
}
28892816

2890-
js_ast.Expression _emitAnnotatedFunctionType(
2891-
FunctionType type, Member member) {
2892-
var result = visitFunctionType(type, member: member);
2893-
2894-
var annotations = member.annotations;
2895-
if (_options.emitMetadata && annotations.isNotEmpty) {
2896-
// TODO(jmesserly): should we disable source info for annotations?
2897-
var savedUri = _currentUri;
2898-
_currentUri = member.enclosingClass.fileUri;
2899-
result = js_ast.ArrayInitializer([
2900-
result,
2901-
for (var annotation in annotations) _instantiateAnnotation(annotation)
2902-
]);
2903-
_currentUri = savedUri;
2904-
}
2905-
return result;
2906-
}
2907-
29082817
/// Emits an expression that lets you access statics on a [type] from code.
29092818
js_ast.Expression _emitConstructorAccess(InterfaceType type) {
29102819
return _emitJSInterop(type.classNode) ??
@@ -2923,21 +2832,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
29232832
return _emitTopLevelName(c);
29242833
}
29252834

2926-
// Wrap a result - usually a type - with its metadata. The runtime is
2927-
// responsible for unpacking this.
2928-
js_ast.Expression _emitAnnotatedResult(
2929-
js_ast.Expression result, List<Expression> metadata, Member member) {
2930-
if (_options.emitMetadata && metadata.isNotEmpty) {
2931-
// TODO(jmesserly): should we disable source info for annotations?
2932-
var savedUri = _currentUri;
2933-
_currentUri = member.enclosingClass.fileUri;
2934-
result = js_ast.ArrayInitializer(
2935-
[result, for (var value in metadata) _instantiateAnnotation(value)]);
2936-
_currentUri = savedUri;
2937-
}
2938-
return result;
2939-
}
2940-
29412835
/// Emits named parameters in the form '{name: type}'.
29422836
js_ast.ObjectInitializer _emitTypeProperties(Iterable<NamedType> types) {
29432837
return js_ast.ObjectInitializer(types
@@ -2949,17 +2843,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
29492843
///
29502844
/// Annotatable contexts include typedefs and method/function declarations.
29512845
js_ast.ArrayInitializer _emitTypeNames(List<DartType> types,
2952-
List<VariableDeclaration> parameters, Member member) {
2953-
var result = <js_ast.Expression>[];
2954-
for (var i = 0; i < types.length; ++i) {
2955-
var type = _emitType(types[i]);
2956-
if (parameters != null) {
2957-
type = _emitAnnotatedResult(type, parameters[i].annotations, member);
2958-
}
2959-
result.add(type);
2960-
}
2961-
return js_ast.ArrayInitializer(result);
2962-
}
2846+
List<VariableDeclaration> parameters, Member member) =>
2847+
js_ast.ArrayInitializer([for (var type in types) _emitType(type)]);
29632848

29642849
@override
29652850
js_ast.Expression visitTypeParameterType(TypeParameterType type) =>

sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/classes.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,6 @@ getSetterType(type, name) {
287287
if (setters != null) {
288288
var type = JS('', '#[#]', setters, name);
289289
if (type != null) {
290-
if (JS('!', '# instanceof Array', type)) {
291-
// The type has metadata attached. Pull out just the type.
292-
// TODO(jmesserly): remove when we remove mirrors
293-
return JS('', '#[0]', type);
294-
}
295290
return type;
296291
}
297292
}

sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,6 @@ _checkAndCall(f, ftype, obj, typeArgs, args, named, displayName) =>
282282
return $f.apply($obj, $args);
283283
}
284284
285-
// TODO(vsm): Remove when we no longer need mirrors metadata.
286-
// An array is used to encode annotations attached to the type.
287-
if ($ftype instanceof Array) $ftype = $ftype[0];
288-
289285
// Apply type arguments
290286
if ($ftype instanceof $GenericFunctionType) {
291287
let formalCount = $ftype.formalCount;

sdk_nnbd/lib/_internal/js_dev_runtime/private/ddc_runtime/classes.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,6 @@ getSetterType(type, name) {
301301
if (setters != null) {
302302
var type = JS('', '#[#]', setters, name);
303303
if (type != null) {
304-
if (JS('!', '# instanceof Array', type)) {
305-
// The type has metadata attached. Pull out just the type.
306-
// TODO(jmesserly): remove when we remove mirrors
307-
return JS('', '#[0]', type);
308-
}
309304
return type;
310305
}
311306
}

sdk_nnbd/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,6 @@ _checkAndCall(f, ftype, obj, typeArgs, args, named, displayName) =>
300300
return $f.apply($obj, $args);
301301
}
302302
303-
// TODO(vsm): Remove when we no longer need mirrors metadata.
304-
// An array is used to encode annotations attached to the type.
305-
if ($ftype instanceof Array) $ftype = $ftype[0];
306-
307303
// Apply type arguments
308304
if ($ftype instanceof $GenericFunctionType) {
309305
let formalCount = $ftype.formalCount;

tests/lib/mirrors/field_metadata2_test.dart

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/lib/mirrors/metadata_constructed_constant_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// compile options: --emit-metadata
21
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
32
// for details. All rights reserved. Use of this source code is governed by a
43
// BSD-style license that can be found in the LICENSE file.

tests/lib/mirrors/metadata_constructor_arguments_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// compile options: --emit-metadata
21
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
32
// for details. All rights reserved. Use of this source code is governed by a
43
// BSD-style license that can be found in the LICENSE file.

0 commit comments

Comments
 (0)