61f0f5bc43
This change replaces kernel AST declarations of fields and functions with bytecode declarations. Size of dilp files is reduced by 11-12%. Startup latency: Time to the first full frame: 1.945s -> 1.687s FinalizeClass: 554ms -> 277ms FinishClassLoading: 296ms -> 156ms There are following regressions in bytecode mode, which will be fixed in future: * dart:mirrors are not supported yet (implementation of mirrors relies on reading kernel AST in certain cases). As the result, lib_2/mirrors/* tests fail. * native extensions are not supported yet (annotations on libraries and classes in AST are cleaned up as they could reference members which are now removed from AST). As the result, standalone_2/entrypoints_verification_test test fails. * language_2/spread_collections/const_error_test/* tests fail due to https://github.com/dart-lang/sdk/issues/36286. Change-Id: I5130f401fd7b84038b136136e7ccc1a6e51b6cea Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97561 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
95 lines
3.1 KiB
Dart
95 lines
3.1 KiB
Dart
// Copyright (c) 2018, 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 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:front_end/src/api_unstable/vm.dart'
|
|
show
|
|
CompilerOptions,
|
|
DiagnosticMessage,
|
|
computePlatformBinariesLocation,
|
|
kernelForProgram;
|
|
import 'package:kernel/ast.dart';
|
|
import 'package:kernel/text/ast_to_text.dart' show Printer;
|
|
import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
|
|
import 'package:kernel/target/targets.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'package:vm/target/vm.dart' show VmTarget;
|
|
|
|
const bool kDumpActualResult = const bool.fromEnvironment('dump.actual.result');
|
|
|
|
class TestingVmTarget extends VmTarget {
|
|
TestingVmTarget(TargetFlags flags) : super(flags);
|
|
|
|
@override
|
|
bool enableSuperMixins = false;
|
|
}
|
|
|
|
Future<Component> compileTestCaseToKernelProgram(Uri sourceUri,
|
|
{Target target, bool enableSuperMixins: false}) async {
|
|
final platformKernel =
|
|
computePlatformBinariesLocation().resolve('vm_platform_strong.dill');
|
|
target ??= new TestingVmTarget(new TargetFlags())
|
|
..enableSuperMixins = enableSuperMixins;
|
|
final options = new CompilerOptions()
|
|
..target = target
|
|
..linkedDependencies = <Uri>[platformKernel]
|
|
..onDiagnostic = (DiagnosticMessage message) {
|
|
fail("Compilation error: ${message.plainTextFormatted.join('\n')}");
|
|
};
|
|
|
|
final Component component = await kernelForProgram(sourceUri, options);
|
|
|
|
// Make sure the library name is the same and does not depend on the order
|
|
// of test cases.
|
|
component.mainMethod.enclosingLibrary.name = '#lib';
|
|
|
|
return component;
|
|
}
|
|
|
|
String kernelLibraryToString(Library library) {
|
|
final StringBuffer buffer = new StringBuffer();
|
|
new Printer(buffer, showExternal: false, showMetadata: true)
|
|
.writeLibraryFile(library);
|
|
return buffer
|
|
.toString()
|
|
.replaceAll(library.importUri.toString(), library.name);
|
|
}
|
|
|
|
String kernelComponentToString(Component component) {
|
|
final StringBuffer buffer = new StringBuffer();
|
|
new Printer(buffer, showExternal: false, showMetadata: true)
|
|
.writeComponentFile(component);
|
|
final mainLibrary = component.mainMethod.enclosingLibrary;
|
|
return buffer
|
|
.toString()
|
|
.replaceAll(mainLibrary.importUri.toString(), mainLibrary.name);
|
|
}
|
|
|
|
class DevNullSink<T> extends Sink<T> {
|
|
@override
|
|
void add(T data) {}
|
|
|
|
@override
|
|
void close() {}
|
|
}
|
|
|
|
void ensureKernelCanBeSerializedToBinary(Component component) {
|
|
new BinaryPrinter(new DevNullSink<List<int>>()).writeComponentFile(component);
|
|
}
|
|
|
|
void compareResultWithExpectationsFile(Uri source, String actual) {
|
|
final expectFile = new File(source.toFilePath() + '.expect');
|
|
final expected = expectFile.existsSync() ? expectFile.readAsStringSync() : '';
|
|
|
|
if (actual != expected) {
|
|
if (kDumpActualResult) {
|
|
new File(source.toFilePath() + '.actual').writeAsStringSync(actual);
|
|
}
|
|
expect(actual, equals(expected), reason: "Test case: $source");
|
|
}
|
|
}
|