Skip to content

Commit da8cb47

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm/bytecode] Represent classes, libraries, scripts and recursive types in bytecode
Size of a large application: Before: 26628600 After: 21480120 (-19.3%) Size of snapshots: isolate_snapshot_framework.bin Before: 9322496 After: 6782976 (-27.2%) isolate_snapshot_product_framework.bin Before: 9166848 After: 6602752 (-27.9%) Regressions in tests: 1) Test language_2/type_alias_equality_test/04 fails similarly to default mode, as VM does not implement comparison of function types according to the specification. Previously this test was passing as function types were canonicalized in bytecode, which was not always correct. This CL fixes the problem with canonicalization of function types in bytecode and the test starts failing again. 2) Tests standalone_2/entrypoints_verification_test, standalone_2/io/test_extension_test, standalone_2/io/test_extension_fail_test fail as native extensions are not supported in bytecode yet. These tests start passing after df5e7aa, which switched bytecode tests to kernel service (on x64), because kernel service doesn't drop ASTs. This CL switches from reading AST library declarations to bytecode even if AST is not removed, so tests fail again. Change-Id: I8b7ba44bfa49d0b1599b2509553ff7c831a4e244 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/104700 Reviewed-by: Ryan Macnak <rmacnak@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Régis Crelier <regis@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
1 parent 85a4fdb commit da8cb47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3254
-1907
lines changed

pkg/front_end/lib/src/api_unstable/vm.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export '../fasta/fasta_codes.dart'
4040
templateFfiTypeInvalid,
4141
templateFfiTypeMismatch,
4242
templateFfiTypeUnsized,
43-
templateFfiFieldInitializer;
43+
templateFfiFieldInitializer,
44+
templateIllegalRecursiveType;
4445

4546
export '../fasta/hybrid_file_system.dart' show HybridFileSystem;
4647

pkg/front_end/lib/src/fasta/fasta_codes_generated.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4276,6 +4276,29 @@ Message _withArgumentsIllegalMixinDueToConstructorsCause(String name) {
42764276
arguments: {'name': name});
42774277
}
42784278

4279+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
4280+
const Template<Message Function(DartType _type)> templateIllegalRecursiveType =
4281+
const Template<Message Function(DartType _type)>(
4282+
messageTemplate: r"""Illegal recursive type '#type'.""",
4283+
withArguments: _withArgumentsIllegalRecursiveType);
4284+
4285+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
4286+
const Code<Message Function(DartType _type)> codeIllegalRecursiveType =
4287+
const Code<Message Function(DartType _type)>(
4288+
"IllegalRecursiveType",
4289+
templateIllegalRecursiveType,
4290+
);
4291+
4292+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
4293+
Message _withArgumentsIllegalRecursiveType(DartType _type) {
4294+
TypeLabeler labeler = new TypeLabeler();
4295+
List<Object> typeParts = labeler.labelType(_type);
4296+
String type = typeParts.join();
4297+
return new Message(codeIllegalRecursiveType,
4298+
message: """Illegal recursive type '${type}'.""" + labeler.originMessages,
4299+
arguments: {'type': _type});
4300+
}
4301+
42794302
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
42804303
const Code<Null> codeIllegalSyncGeneratorReturnType =
42814304
messageIllegalSyncGeneratorReturnType;

pkg/front_end/messages.status

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ IllegalAssignmentToNonAssignable/script1: Fail
280280
IllegalAsyncGeneratorVoidReturnType/analyzerCode: Fail # The analyzer doesn't report this error.
281281
IllegalMixin/example: Fail
282282
IllegalMixinDueToConstructors/example: Fail
283+
IllegalRecursiveType/analyzerCode: Fail
284+
IllegalRecursiveType/part_wrapped_script: Fail
285+
IllegalRecursiveType/script: Fail
283286
IllegalSyncGeneratorVoidReturnType/analyzerCode: Fail # The analyzer doesn't report this error.
284287
ImplementsBeforeExtends/part_wrapped_script: Fail
285288
ImplementsBeforeExtends/script: Fail

pkg/front_end/messages.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3560,3 +3560,9 @@ BadTypeVariableInSupertype:
35603560
script: >
35613561
class A<X> {}
35623562
class B<Y> extends A<Function(Y)> {}
3563+
3564+
IllegalRecursiveType:
3565+
template: "Illegal recursive type '#type'."
3566+
script: >
3567+
class Base<T> {}
3568+
class Derived<T> extends Base<Derived<Derived<T>>> {}

pkg/vm/bin/kernel_service.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@ abstract class Compiler {
145145

146146
if (options.bytecode && errors.isEmpty) {
147147
await runWithFrontEndCompilerContext(script, options, component, () {
148-
// TODO(alexmarkov): disable source positions and local variables
149-
// in VM PRODUCT mode.
148+
// TODO(alexmarkov): disable source positions, local variables info
149+
// and source files in VM PRODUCT mode.
150150
generateBytecode(component,
151151
environmentDefines: options.environmentDefines,
152152
emitSourcePositions: true,
153-
emitLocalVarInfo: true);
153+
emitLocalVarInfo: true,
154+
emitSourceFiles: true);
154155
});
155156
}
156157

pkg/vm/lib/bytecode/ast_remover.dart

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

pkg/vm/lib/bytecode/bytecode_serialization.dart

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ class BufferedReader {
234234
return linkReader.get<T>(offset);
235235
}
236236

237+
ForwardReference<T> readLinkOffsetAsForwardReference<T>() {
238+
final offset = readPackedUInt30();
239+
return new ForwardReference<T>(offset, linkReader);
240+
}
241+
237242
void align(int alignment) {
238243
assert(alignment & (alignment - 1) == 0);
239244
_pos = ((_pos + alignment - 1) & -alignment);
@@ -455,6 +460,16 @@ class LinkReader {
455460
}
456461
}
457462

463+
// Placeholder for an object which will be read in future.
464+
class ForwardReference<T> {
465+
final int offset;
466+
final LinkReader linkReader;
467+
468+
ForwardReference(this.offset, this.linkReader);
469+
470+
T get() => linkReader.get<T>(offset);
471+
}
472+
458473
class NamedEntryStatistics {
459474
final String name;
460475
int size = 0;
@@ -471,7 +486,15 @@ class BytecodeSizeStatistics {
471486
static int objectTableSize = 0;
472487
static int objectTableEntriesCount = 0;
473488
static int stringTableSize = 0;
489+
static int librariesSize = 0;
490+
static int classesSize = 0;
474491
static int membersSize = 0;
492+
static int codeSize = 0;
493+
static int sourcePositionsSize = 0;
494+
static int sourceFilesSize = 0;
495+
static int lineStartsSize = 0;
496+
static int localVariablesSize = 0;
497+
static int annotationsSize = 0;
475498
static int constantPoolSize = 0;
476499
static int instructionsSize = 0;
477500
static List<NamedEntryStatistics> constantPoolStats =
@@ -483,7 +506,15 @@ class BytecodeSizeStatistics {
483506
objectTableSize = 0;
484507
objectTableEntriesCount = 0;
485508
stringTableSize = 0;
509+
librariesSize = 0;
510+
classesSize = 0;
486511
membersSize = 0;
512+
codeSize = 0;
513+
sourcePositionsSize = 0;
514+
sourceFilesSize = 0;
515+
lineStartsSize = 0;
516+
localVariablesSize = 0;
517+
annotationsSize = 0;
487518
constantPoolSize = 0;
488519
instructionsSize = 0;
489520
constantPoolStats = <NamedEntryStatistics>[];
@@ -499,7 +530,15 @@ class BytecodeSizeStatistics {
499530
print(" - $entry");
500531
}
501532
print(" - string table: $stringTableSize");
502-
print(" Bytecode members: $membersSize");
533+
print(" Libraries: $librariesSize");
534+
print(" Classes: $classesSize");
535+
print(" Members: $membersSize");
536+
print(" Source positions: $sourcePositionsSize");
537+
print(" Source files: $sourceFilesSize");
538+
print(" Line starts: $lineStartsSize");
539+
print(" Local variables: $localVariablesSize");
540+
print(" Annotations: $annotationsSize");
541+
print(" Code: $codeSize");
503542
print(" - constant pool: $constantPoolSize");
504543
for (var entry in constantPoolStats) {
505544
print(" - $entry");

pkg/vm/lib/bytecode/dbc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ library vm.bytecode.dbc;
1010
/// Before bumping current bytecode version format, make sure that
1111
/// all users have switched to a VM which is able to consume new
1212
/// version of bytecode.
13-
const int currentBytecodeFormatVersion = 9;
13+
const int currentBytecodeFormatVersion = 10;
1414

1515
/// Version of experimental / bleeding edge bytecode format.
1616
/// Produced by bytecode generator when --use-future-bytecode-format

0 commit comments

Comments
 (0)