[vm,dyn_modules] Remove unused library dependencies from bytecode
Fixes https://github.com/dart-lang/sdk/issues/61362 TEST=ci Change-Id: I1e15b100a9d5f486addce11e85ea6d69389a6bb7 Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446101 Reviewed-by: Tess Strickland <sstrickl@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
committed by
Commit Queue
parent
aa0e081066
commit
ea746d21c2
@@ -348,7 +348,7 @@ class BytecodeGenerator extends RecursiveVisitor {
|
||||
flags |= ClassDeclaration.hasSourcePositionsFlag;
|
||||
position = library.fileOffset;
|
||||
}
|
||||
Annotations annotations = getLibraryAnnotations(library);
|
||||
Annotations annotations = getAnnotations(library.annotations);
|
||||
if (annotations.object != null) {
|
||||
flags |= ClassDeclaration.hasAnnotationsFlag;
|
||||
if (annotations.hasPragma) {
|
||||
@@ -441,67 +441,6 @@ class BytecodeGenerator extends RecursiveVisitor {
|
||||
return new Annotations(functionDecl, hasPragma);
|
||||
}
|
||||
|
||||
// Insert annotations for library and its dependencies into the
|
||||
// annotations section. Returns annotations for the library only.
|
||||
// Bytecode reader will implicitly find library dependencies by reading
|
||||
// an extra object after reading library annotations.
|
||||
Annotations getLibraryAnnotations(Library library) {
|
||||
Annotations annotations = getAnnotations(library.annotations);
|
||||
final bool emitDependencies =
|
||||
options.emitAnnotations && library.dependencies.isNotEmpty;
|
||||
if (annotations.object == null && !emitDependencies) {
|
||||
return annotations;
|
||||
}
|
||||
|
||||
// We need to emit both annotations and dependencies objects, appending
|
||||
// null if an object is missing.
|
||||
if (annotations.object == null) {
|
||||
final annotationsDecl = new AnnotationsDeclaration(null);
|
||||
bytecodeComponent.annotations.add(annotationsDecl);
|
||||
annotations = new Annotations(annotationsDecl, false);
|
||||
}
|
||||
if (!emitDependencies) {
|
||||
bytecodeComponent.annotations.add(new AnnotationsDeclaration(null));
|
||||
return annotations;
|
||||
}
|
||||
|
||||
// Create a constant object representing library dependencies.
|
||||
// These objects are used by dart:mirrors and vm-service implementation.
|
||||
final deps = <Constant>[];
|
||||
for (var dependency in library.dependencies) {
|
||||
final dependencyName = dependency.name;
|
||||
final prefix = dependencyName != null
|
||||
? StringConstant(dependencyName)
|
||||
: NullConstant();
|
||||
final showNames = dependency.combinators
|
||||
.where((c) => c.isShow)
|
||||
.expand((c) => c.names)
|
||||
.map((name) => StringConstant(name))
|
||||
.toList();
|
||||
final hideNames = dependency.combinators
|
||||
.where((c) => c.isHide)
|
||||
.expand((c) => c.names)
|
||||
.map((name) => StringConstant(name))
|
||||
.toList();
|
||||
final depAnnots = dependency.annotations.map(_getConstant).toList();
|
||||
deps.add(ListConstant(const DynamicType(), <Constant>[
|
||||
StringConstant(dependency.targetLibrary.importUri.toString()),
|
||||
BoolConstant(dependency.isExport),
|
||||
BoolConstant(dependency.isDeferred),
|
||||
prefix,
|
||||
ListConstant(const DynamicType(), showNames),
|
||||
ListConstant(const DynamicType(), hideNames),
|
||||
ListConstant(const DynamicType(), depAnnots),
|
||||
]));
|
||||
}
|
||||
final ObjectHandle dependenciesObject =
|
||||
objectTable.getHandle(ListConstant(const DynamicType(), deps))!;
|
||||
final dependenciesDecl = new AnnotationsDeclaration(dependenciesObject);
|
||||
bytecodeComponent.annotations.add(dependenciesDecl);
|
||||
|
||||
return annotations;
|
||||
}
|
||||
|
||||
FieldDeclaration getFieldDeclaration(Field field, Code? initializer) {
|
||||
int flags = 0;
|
||||
Constant? value;
|
||||
|
||||
Reference in New Issue
Block a user