mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:37:53 +00:00
Move reify
to use fasta instead of dartk
Note the suite seemed to have a lot of tests crashing in verification. With my change I'm noting other crashes, but I haven't investigated where they are from. Also, to run the suite, before it used to be run as: dart pkg/kernel/test/reify/suite.dart Now it needs to be run as: DART_CONFIGURATION=ReleaseX64 out/ReleaseX64/dart pkg/kernel/test/reify/suite.dart BUG= R=paulberry@google.com Review-Url: https://codereview.chromium.org/2981813002 .
This commit is contained in:
parent
d0e3893d02
commit
4ad4f985af
|
@ -15,6 +15,8 @@ import 'dart:typed_data' show Uint8List;
|
|||
|
||||
import 'package:kernel/kernel.dart' show loadProgramFromBinary;
|
||||
|
||||
import 'package:kernel/target/targets.dart' show Target;
|
||||
|
||||
import 'package:kernel/text/ast_to_text.dart' show Printer;
|
||||
|
||||
import 'package:testing/testing.dart' show Result, StdioProcess, Step;
|
||||
|
@ -190,20 +192,28 @@ class Compile extends Step<TestDescription, Program, CompileContext> {
|
|||
}
|
||||
|
||||
Uri sdk = await computePatchedSdk();
|
||||
Program p = await kernelForProgram(
|
||||
description.uri,
|
||||
new CompilerOptions()
|
||||
..sdkRoot = sdk
|
||||
..packagesFileUri = Uri.base.resolve('.packages')
|
||||
..strongMode = context.strongMode
|
||||
..linkedDependencies = [sdk.resolve('platform.dill')]
|
||||
..onError = reportError);
|
||||
var options = new CompilerOptions()
|
||||
..sdkRoot = sdk
|
||||
..compileSdk = true
|
||||
..packagesFileUri = Uri.base.resolve('.packages')
|
||||
..strongMode = context.strongMode
|
||||
..onError = reportError;
|
||||
if (context.target != null) {
|
||||
options.target = context.target;
|
||||
// Do not link platform.dill, but recompile the platform libraries. This
|
||||
// ensures that if target defines extra libraries that those get included
|
||||
// too.
|
||||
} else {
|
||||
options.linkedDependencies = [sdk.resolve('platform.dill')];
|
||||
}
|
||||
Program p = await kernelForProgram(description.uri, options);
|
||||
return result ??= pass(p);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class CompileContext implements ChainContext {
|
||||
bool get strongMode;
|
||||
Target get target;
|
||||
}
|
||||
|
||||
class BytesCollector implements Sink<List<int>> {
|
||||
|
|
|
@ -30,6 +30,7 @@ const String STRONG_MODE = " strong mode ";
|
|||
|
||||
class ClosureConversionContext extends ChainContext implements CompileContext {
|
||||
final bool strongMode;
|
||||
Target get target => null;
|
||||
|
||||
final List<Step> steps;
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ import 'package:kernel/ast.dart' show Program, Library;
|
|||
import 'package:kernel/transformations/argument_extraction.dart'
|
||||
as argument_extraction;
|
||||
|
||||
import 'package:kernel/target/targets.dart' show Target;
|
||||
|
||||
import 'package:kernel/transformations/closure_conversion.dart'
|
||||
as closure_conversion;
|
||||
|
||||
|
@ -34,6 +36,8 @@ const String STRONG_MODE = " strong mode ";
|
|||
class ClosureConversionContext extends ChainContext implements CompileContext {
|
||||
final bool strongMode;
|
||||
|
||||
Target get target => null;
|
||||
|
||||
final List<Step> steps;
|
||||
|
||||
ClosureConversionContext(this.strongMode, bool updateExpectations)
|
||||
|
|
|
@ -13,6 +13,8 @@ import 'package:testing/testing.dart'
|
|||
|
||||
import 'package:kernel/ast.dart' show Program, Library;
|
||||
|
||||
import 'package:kernel/target/targets.dart' show Target;
|
||||
|
||||
import 'package:front_end/src/fasta/testing/kernel_chain.dart'
|
||||
show runDiff, Compile, CompileContext;
|
||||
|
||||
|
@ -22,6 +24,7 @@ const String STRONG_MODE = " strong mode ";
|
|||
|
||||
class InterpreterContext extends ChainContext implements CompileContext {
|
||||
final bool strongMode;
|
||||
Target get target => null;
|
||||
|
||||
final List<Step> steps;
|
||||
|
||||
|
|
|
@ -1,196 +0,0 @@
|
|||
// Copyright (c) 2016, 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.md file.
|
||||
|
||||
library test.kernel.reify.suite;
|
||||
|
||||
import 'dart:async' show Future;
|
||||
|
||||
import 'dart:io' show Directory, File, IOSink;
|
||||
|
||||
import 'dart:typed_data' show Uint8List;
|
||||
|
||||
import 'package:kernel/kernel.dart' show loadProgramFromBinary;
|
||||
|
||||
import 'package:kernel/text/ast_to_text.dart' show Printer;
|
||||
|
||||
import 'package:testing/testing.dart'
|
||||
show ChainContext, Result, StdioProcess, Step;
|
||||
|
||||
import 'package:kernel/ast.dart' show Library, Program;
|
||||
|
||||
import 'package:kernel/verifier.dart' show verifyProgram;
|
||||
|
||||
import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
|
||||
|
||||
import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;
|
||||
|
||||
Future<bool> fileExists(Uri base, String path) async {
|
||||
return await new File.fromUri(base.resolve(path)).exists();
|
||||
}
|
||||
|
||||
class Print extends Step<Program, Program, ChainContext> {
|
||||
const Print();
|
||||
|
||||
String get name => "print";
|
||||
|
||||
Future<Result<Program>> run(Program program, _) async {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (Library library in program.libraries) {
|
||||
Printer printer = new Printer(sb);
|
||||
if (library.importUri.scheme != "dart") {
|
||||
printer.writeLibraryFile(library);
|
||||
}
|
||||
}
|
||||
print("$sb");
|
||||
return pass(program);
|
||||
}
|
||||
}
|
||||
|
||||
class SanityCheck extends Step<Program, Program, ChainContext> {
|
||||
const SanityCheck();
|
||||
|
||||
String get name => "sanity check";
|
||||
|
||||
Future<Result<Program>> run(Program program, _) async {
|
||||
try {
|
||||
verifyProgram(program);
|
||||
return pass(program);
|
||||
} catch (e, s) {
|
||||
return crash(e, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MatchExpectation extends Step<Program, Program, ChainContext> {
|
||||
final String suffix;
|
||||
|
||||
final bool updateExpectations;
|
||||
|
||||
const MatchExpectation(this.suffix, {this.updateExpectations: true});
|
||||
|
||||
String get name => "match expectations";
|
||||
|
||||
Future<Result<Program>> run(Program program, _) async {
|
||||
Library library = program.libraries
|
||||
.firstWhere((Library library) => library.importUri.scheme != "dart");
|
||||
Uri uri = library.importUri;
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
new Printer(buffer).writeLibraryFile(library);
|
||||
|
||||
File expectedFile = new File("${uri.toFilePath()}$suffix");
|
||||
if (await expectedFile.exists()) {
|
||||
String expected = await expectedFile.readAsString();
|
||||
if (expected.trim() != "$buffer".trim()) {
|
||||
if (!updateExpectations) {
|
||||
String diff = await runDiff(expectedFile.uri, "$buffer");
|
||||
return fail(null, "$uri doesn't match ${expectedFile.uri}\n$diff");
|
||||
}
|
||||
} else {
|
||||
return pass(program);
|
||||
}
|
||||
}
|
||||
if (updateExpectations) {
|
||||
await openWrite(expectedFile.uri, (IOSink sink) {
|
||||
sink.writeln("$buffer".trim());
|
||||
});
|
||||
return pass(program);
|
||||
} else {
|
||||
return fail(program, """
|
||||
Please create file ${expectedFile.path} with this content:
|
||||
$buffer""");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class WriteDill extends Step<Program, Uri, ChainContext> {
|
||||
const WriteDill();
|
||||
|
||||
String get name => "write .dill";
|
||||
|
||||
Future<Result<Uri>> run(Program program, _) async {
|
||||
Directory tmp = await Directory.systemTemp.createTemp();
|
||||
Uri uri = tmp.uri.resolve("generated.dill");
|
||||
File generated = new File.fromUri(uri);
|
||||
IOSink sink = generated.openWrite();
|
||||
try {
|
||||
new BinaryPrinter(sink).writeProgramFile(program);
|
||||
} catch (e, s) {
|
||||
return fail(uri, e, s);
|
||||
} finally {
|
||||
print("Wrote `${generated.path}`");
|
||||
await sink.close();
|
||||
}
|
||||
return pass(uri);
|
||||
}
|
||||
}
|
||||
|
||||
class ReadDill extends Step<Uri, Uri, ChainContext> {
|
||||
const ReadDill();
|
||||
|
||||
String get name => "read .dill";
|
||||
|
||||
Future<Result<Uri>> run(Uri uri, _) async {
|
||||
try {
|
||||
loadProgramFromBinary(uri.toFilePath());
|
||||
} catch (e, s) {
|
||||
return fail(uri, e, s);
|
||||
}
|
||||
return pass(uri);
|
||||
}
|
||||
}
|
||||
|
||||
class Copy extends Step<Program, Program, ChainContext> {
|
||||
const Copy();
|
||||
|
||||
String get name => "copy program";
|
||||
|
||||
Future<Result<Program>> run(Program program, _) async {
|
||||
BytesCollector sink = new BytesCollector();
|
||||
new BinaryPrinter(sink).writeProgramFile(program);
|
||||
Uint8List bytes = sink.collect();
|
||||
var newProgram = new Program();
|
||||
new BinaryBuilder(bytes).readProgram(newProgram);
|
||||
return pass(newProgram);
|
||||
}
|
||||
}
|
||||
|
||||
class BytesCollector implements Sink<List<int>> {
|
||||
final List<List<int>> lists = <List<int>>[];
|
||||
|
||||
int length = 0;
|
||||
|
||||
void add(List<int> data) {
|
||||
lists.add(data);
|
||||
length += data.length;
|
||||
}
|
||||
|
||||
Uint8List collect() {
|
||||
Uint8List result = new Uint8List(length);
|
||||
int offset = 0;
|
||||
for (List<int> list in lists) {
|
||||
result.setRange(offset, offset += list.length, list);
|
||||
}
|
||||
lists.clear();
|
||||
length = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
void close() {}
|
||||
}
|
||||
|
||||
Future<String> runDiff(Uri expected, String actual) async {
|
||||
StdioProcess process = await StdioProcess
|
||||
.run("diff", <String>["-u", expected.toFilePath(), "-"], input: actual);
|
||||
return process.output;
|
||||
}
|
||||
|
||||
Future openWrite(Uri uri, f(IOSink sink)) async {
|
||||
IOSink sink = new File.fromUri(uri).openWrite();
|
||||
try {
|
||||
await f(sink);
|
||||
} finally {
|
||||
await sink.close();
|
||||
}
|
||||
print("Wrote $uri");
|
||||
}
|
|
@ -6,14 +6,7 @@ library test.kernel.reify.suite;
|
|||
|
||||
import 'dart:async' show Future;
|
||||
|
||||
import 'dart:io' show Directory, File, Platform;
|
||||
|
||||
import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
|
||||
|
||||
import 'package:analyzer/src/kernel/loader.dart'
|
||||
show DartLoader, DartOptions, createDartSdk;
|
||||
|
||||
import 'package:kernel/class_hierarchy.dart' show ClosedWorldClassHierarchy;
|
||||
import 'dart:io' show Platform, File;
|
||||
|
||||
import 'package:kernel/core_types.dart' show CoreTypes;
|
||||
|
||||
|
@ -21,63 +14,57 @@ import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget;
|
|||
|
||||
import 'package:kernel/target/vmcc.dart' show VmClosureConvertedTarget;
|
||||
|
||||
import 'kernel_chain.dart'
|
||||
show MatchExpectation, Print, ReadDill, SanityCheck, WriteDill;
|
||||
import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'
|
||||
show computeDartVm, computePatchedSdk;
|
||||
import 'package:front_end/src/fasta/testing/kernel_chain.dart'
|
||||
show
|
||||
Compile,
|
||||
CompileContext,
|
||||
MatchExpectation,
|
||||
Print,
|
||||
ReadDill,
|
||||
Verify,
|
||||
WriteDill;
|
||||
|
||||
import 'package:testing/testing.dart'
|
||||
show
|
||||
Chain,
|
||||
ChainContext,
|
||||
Result,
|
||||
StdioProcess,
|
||||
Step,
|
||||
TestDescription,
|
||||
runMe;
|
||||
show Chain, ChainContext, Result, StdioProcess, Step, runMe;
|
||||
|
||||
import 'package:kernel/ast.dart' show Program;
|
||||
|
||||
import 'package:kernel/transformations/generic_types_reification.dart'
|
||||
as generic_types_reification;
|
||||
|
||||
import 'package:package_config/discovery.dart' show loadPackagesFile;
|
||||
|
||||
class TestContext extends ChainContext {
|
||||
class TestContext extends ChainContext implements CompileContext {
|
||||
final Uri vm;
|
||||
final Uri platformUri;
|
||||
final Uri sdk;
|
||||
|
||||
final Uri packages;
|
||||
@override
|
||||
final Target target = new NotReifiedTarget(new TargetFlags(
|
||||
strongMode: true,
|
||||
kernelRuntime: Platform.script.resolve("../../runtime/")));
|
||||
|
||||
final DartOptions options;
|
||||
|
||||
final DartSdk dartSdk;
|
||||
// Strong mode is required to keep the type arguments in invocations of
|
||||
// generic methods.
|
||||
@override
|
||||
bool get strongMode => true;
|
||||
|
||||
final List<Step> steps;
|
||||
|
||||
TestContext(String sdk, this.vm, Uri packages, bool strongMode, this.dartSdk,
|
||||
bool updateExpectations)
|
||||
: packages = packages,
|
||||
options = new DartOptions(
|
||||
strongMode: strongMode,
|
||||
sdk: sdk,
|
||||
packagePath: packages.toFilePath()),
|
||||
steps = <Step>[
|
||||
const NotReifiedKernel(),
|
||||
TestContext(this.vm, this.platformUri, this.sdk, bool updateExpectations)
|
||||
: steps = <Step>[
|
||||
const Compile(),
|
||||
const Print(),
|
||||
const SanityCheck(),
|
||||
const Verify(true),
|
||||
const GenericTypesReification(),
|
||||
const Print(),
|
||||
const SanityCheck(),
|
||||
const Verify(true),
|
||||
new MatchExpectation(".expect",
|
||||
updateExpectations: updateExpectations),
|
||||
const WriteDill(),
|
||||
const ReadDill(),
|
||||
const Run(),
|
||||
];
|
||||
|
||||
Future<DartLoader> createLoader() async {
|
||||
return new DartLoader(
|
||||
new Program(), options, await loadPackagesFile(packages),
|
||||
dartSdk: dartSdk);
|
||||
}
|
||||
}
|
||||
|
||||
enum Environment {
|
||||
|
@ -85,58 +72,13 @@ enum Environment {
|
|||
file,
|
||||
}
|
||||
|
||||
Future<String> getEnvironmentVariable(
|
||||
String name, Environment kind, String undefined, notFound(String n)) async {
|
||||
String result = Platform.environment[name];
|
||||
if (result == null) {
|
||||
throw undefined;
|
||||
}
|
||||
switch (kind) {
|
||||
case Environment.directory:
|
||||
if (!await new Directory(result).exists()) throw notFound(result);
|
||||
break;
|
||||
|
||||
case Environment.file:
|
||||
if (!await new File(result).exists()) throw notFound(result);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<bool> fileExists(Uri base, String path) async {
|
||||
return await new File.fromUri(base.resolve(path)).exists();
|
||||
}
|
||||
|
||||
Future<TestContext> createContext(
|
||||
Chain suite, Map<String, String> environment) async {
|
||||
const String suggestion = """Try building the patched SDK by running
|
||||
'tools/build.py patched_sdk'""";
|
||||
|
||||
// TODO(karlklose): The path is different on MacOS.
|
||||
String sdk = "out/DebugX64/patched_sdk/";
|
||||
Uri sdkUri = Uri.base.resolve(sdk);
|
||||
const String asyncDart = "lib/async/async.dart";
|
||||
if (!await fileExists(sdkUri, asyncDart)) {
|
||||
throw "Couldn't find the patched SDK. $suggestion";
|
||||
}
|
||||
const String asyncSources = "lib/async/async_sources.gypi";
|
||||
if (await fileExists(sdkUri, asyncSources)) {
|
||||
throw "Found '$asyncSources' in '$sdk', so it isn't a patched SDK. "
|
||||
"$suggestion";
|
||||
}
|
||||
|
||||
// TODO(karlklose): select the VM based on the mode.
|
||||
Uri vm = Uri.base.resolve("out/ReleaseX64/dart");
|
||||
|
||||
Uri packages = Uri.base.resolve(".packages");
|
||||
// Strong mode is required to keep the type arguments in invocations of
|
||||
// generic methods.
|
||||
bool strongMode = true;
|
||||
bool updateExpectations = const String.fromEnvironment("updateExpectations",
|
||||
defaultValue: "false") ==
|
||||
"true";
|
||||
return new TestContext(sdk, vm, packages, strongMode,
|
||||
createDartSdk(sdk, strongMode: strongMode), updateExpectations);
|
||||
Uri sdk = await computePatchedSdk();
|
||||
Uri vm = computeDartVm(sdk);
|
||||
Uri platform = sdk.resolve('platform.dill');
|
||||
bool updateExpectations = environment["updateExpectations"] == "true";
|
||||
return new TestContext(vm, platform, sdk, updateExpectations);
|
||||
}
|
||||
|
||||
// [NotReifiedTarget] is intended to work as the [Target] class that
|
||||
|
@ -172,41 +114,6 @@ class NotReifiedTarget extends VmClosureConvertedTarget {
|
|||
}
|
||||
}
|
||||
|
||||
class NotReifiedKernel extends Step<TestDescription, Program, TestContext> {
|
||||
const NotReifiedKernel();
|
||||
|
||||
String get name => "kernel";
|
||||
|
||||
Future<Result<Program>> run(
|
||||
TestDescription description, TestContext testContext) async {
|
||||
try {
|
||||
DartLoader loader = await testContext.createLoader();
|
||||
|
||||
// Strong mode is required to keep the type arguments in invocations of
|
||||
// generic methods.
|
||||
Target target = new NotReifiedTarget(new TargetFlags(
|
||||
strongMode: true,
|
||||
kernelRuntime: Platform.script.resolve("../../runtime/")));
|
||||
|
||||
String path = description.file.path;
|
||||
Uri uri = Uri.base.resolve(path);
|
||||
loader.loadProgram(uri, target: target);
|
||||
var program = loader.program;
|
||||
for (var error in loader.errors) {
|
||||
return fail(program, "$error");
|
||||
}
|
||||
var coreTypes = new CoreTypes(program);
|
||||
var hierarchy = new ClosedWorldClassHierarchy(program);
|
||||
target
|
||||
..performModularTransformationsOnProgram(coreTypes, hierarchy, program)
|
||||
..performGlobalTransformations(coreTypes, program);
|
||||
return pass(program);
|
||||
} catch (e, s) {
|
||||
return crash(e, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GenericTypesReification extends Step<Program, Program, TestContext> {
|
||||
const GenericTypesReification();
|
||||
|
||||
|
@ -228,12 +135,17 @@ class Run extends Step<Uri, int, TestContext> {
|
|||
|
||||
String get name => "run";
|
||||
|
||||
bool get isAsync => true;
|
||||
|
||||
bool get isRuntime => true;
|
||||
|
||||
Future<Result<int>> run(Uri uri, TestContext context) async {
|
||||
File generated = new File.fromUri(uri);
|
||||
StdioProcess process;
|
||||
try {
|
||||
process =
|
||||
await StdioProcess.run(context.vm.toFilePath(), [generated.path]);
|
||||
var sdkPath = context.sdk.toFilePath();
|
||||
var args = ['--kernel-binaries=$sdkPath', generated.path];
|
||||
process = await StdioProcess.run(context.vm.toFilePath(), args);
|
||||
print(process.output);
|
||||
} finally {
|
||||
generated.parent.delete(recursive: true);
|
||||
|
|
Loading…
Reference in a new issue