Files
sdk/pkg/kernel/lib/binary/limited_ast_to_binary.dart
T
Jens Johansen d854c77e58 [kernel] Only serialize non-external libaries and sources from those.
Previously the VM couldn't handle external libraries, but that was
fixed in 2f49198520.

Part of the CL was reverted though because the compilatin was changed
to using an outline instead of the platform which doesn't work.
What does work though, is not including the external libraries in the
output.

This CL makes the following changes:

* Don't include external libraries in the output (by not setting all
  libraries to be non-external).

* Only writes the sources actually used to the binary (i.e. whatever
  libraries left out because they were external will not contribute
  source code either).

* Cleanup of now unused code.


Timings (only run once though):


Without this CL (but with the CL it's based on):

$ time python tools/test.py -m release -cdartk language -j6
Test configuration: dartk_vm_release_x64
[05:43 | 100% | + 3504 | -    0]

real    5m43.597s
user    33m48.152s
sys     9m34.140s


Only the "utils/kernel-service/kernel-service.dart" part of this CL:

$ time python tools/test.py -m release -cdartk language -j6
Test configuration: dartk_vm_release_x64
[04:55 | 100% | + 3504 | -    0]

real    4m55.684s
user    29m54.360s
sys     8m7.408s


Entire CL:

$ time python tools/test.py -m release -cdartk language -j6
Test configuration: dartk_vm_release_x64
[04:20 | 100% | + 3504 | -    0]

real    4m20.416s
user    27m17.320s
sys     6m53.472s

Change-Id: Ie9c5bfa958e558a5007784e821a0b58d417bae55
Reviewed-on: https://dart-review.googlesource.com/3161
Reviewed-by: Samir Jindel <sjindel@google.com>
2017-09-06 11:56:24 +00:00

73 lines
2.2 KiB
Dart

// 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.
import 'package:kernel/ast.dart';
import 'package:kernel/binary/ast_to_binary.dart';
/// Writes libraries that satisfy the [predicate].
///
/// Only the referenced subset of canonical names is indexed and written,
/// so we don't waste time indexing all libraries of a program, when only
/// a tiny subset is used.
class LimitedBinaryPrinter extends BinaryPrinter {
final LibraryFilter predicate;
/// Excludes all uriToSource information.
///
/// By default the [predicate] above will only exclude canonical names and
/// kernel libraries, but it will still emit the sources for all libraries.
/// filtered by libraries matching [predicate].
// TODO(sigmund): provide a way to filter sources directly based on
// [predicate]. That requires special logic to handle sources from part files.
final bool excludeUriToSource;
LimitedBinaryPrinter(
Sink<List<int>> sink, this.predicate, this.excludeUriToSource)
: super(sink);
@override
void computeCanonicalNames(Program program) {
for (var library in program.libraries) {
if (predicate(library)) {
program.root
.getChildFromUri(library.importUri)
.bindTo(library.reference);
library.computeCanonicalNames();
}
}
}
@override
bool shouldWriteLibraryCanonicalNames(Library library) {
return predicate(library);
}
@override
void writeLibraries(Program program) {
var librariesToWrite = program.libraries.where(predicate).toList();
writeList(librariesToWrite, writeNode);
}
@override
void writeNode(Node node) {
if (node is Library && !predicate(node)) return;
node.accept(this);
}
@override
void writeProgramIndex(Program program, List<Library> libraries) {
var librariesToWrite = libraries.where(predicate).toList();
super.writeProgramIndex(program, librariesToWrite);
}
@override
void indexUris(Program program) {
if (!excludeUriToSource) {
super.indexUris(program);
} else {
// We pretend not to know any uris, thereby excluding all sources.
}
}
}