[kernel] add ability to disable offsets for bazel worker to use

This is a lightly modified version of Jennys CL @
https://dart-review.googlesource.com/100275

Change-Id: I46a1665d84d04602af1f338cf963bc25b4e6b25c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101280
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Kevin Millikin <kmillikin@google.com>
This commit is contained in:
Jens Johansen 2019-05-21 07:55:10 +00:00 committed by commit-bot@chromium.org
parent 4fe9951dca
commit 099af47a69
4 changed files with 23 additions and 8 deletions

View file

@ -60,12 +60,15 @@ Future<Null> writeComponentToFile(Component component, Uri uri,
/// Serialize the libraries in [component] that match [filter].
List<int> serializeComponent(Component component,
{bool filter(Library library), bool includeSources: true}) {
{bool filter(Library library),
bool includeSources: true,
bool includeOffsets: true}) {
ByteSink byteSink = new ByteSink();
BinaryPrinter printer = filter == null
? new BinaryPrinter(byteSink, includeSources: includeSources)
: new LimitedBinaryPrinter(
byteSink, filter ?? (_) => true, !includeSources);
? new BinaryPrinter(byteSink,
includeSources: includeSources, includeOffsets: includeOffsets)
: new LimitedBinaryPrinter(byteSink, filter, !includeSources,
includeOffsets: includeOffsets);
printer.writeComponentFile(component);
return byteSink.builder.takeBytes();
}

View file

@ -37,6 +37,7 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
BufferedSink _constantsSink;
BufferedSink _sink;
bool includeSources;
bool includeOffsets;
List<int> libraryOffsets;
List<int> classOffsets;
@ -57,7 +58,9 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
/// The BinaryPrinter will use its own buffer, so the [sink] does not need
/// one.
BinaryPrinter(Sink<List<int>> sink,
{StringIndexer stringIndexer, this.includeSources = true})
{StringIndexer stringIndexer,
this.includeSources = true,
this.includeOffsets = true})
: _mainSink = new BufferedSink(sink),
_metadataSink = new BufferedSink(new BytesSink()),
_constantsBytesSink = new BytesSink(),
@ -875,7 +878,11 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
// TODO(jensj): Delta-encoding.
// File offset ranges from -1 and up,
// but is here saved as unsigned (thus the +1)
writeUInt30(offset + 1);
if (!includeOffsets) {
writeUInt30(0);
} else {
writeUInt30(offset + 1);
}
}
void writeClassReference(Class class_) {

View file

@ -23,8 +23,11 @@ class LimitedBinaryPrinter extends BinaryPrinter {
final bool excludeUriToSource;
LimitedBinaryPrinter(
Sink<List<int>> sink, this.predicate, this.excludeUriToSource)
: super(sink, includeSources: !excludeUriToSource);
Sink<List<int>> sink, this.predicate, this.excludeUriToSource,
{bool includeOffsets = true})
: super(sink,
includeSources: !excludeUriToSource,
includeOffsets: includeOffsets);
@override
void computeCanonicalNames(Component component) {

View file

@ -291,6 +291,8 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
incrementalComponent.problemsAsJson = null;
incrementalComponent.mainMethod = null;
target.performOutlineTransformations(incrementalComponent);
return Future.value(fe.serializeComponent(incrementalComponent,
includeSources: false, includeOffsets: false));
}
return Future.value(fe.serializeComponent(incrementalComponent));