mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
Reapply "Use backend targets to run Kernel transformations in Fasta"
This reverts commit 0b424ca5d2
R=ahe@google.com
Review-Url: https://codereview.chromium.org/2919003003 .
This commit is contained in:
parent
a79a59d19c
commit
1e2f06f8da
|
@ -21,7 +21,7 @@ class AnalyzerTarget extends KernelTarget {
|
|||
DillTarget dillTarget, TranslateUri uriTranslator, bool strongMode,
|
||||
[Map<String, Source> uriToSource])
|
||||
: super(PhysicalFileSystem.instance, dillTarget, uriTranslator,
|
||||
strongMode, uriToSource);
|
||||
uriToSource);
|
||||
|
||||
@override
|
||||
AnalyzerLoader<Library> createLoader() => new AnalyzerLoader<Library>(this);
|
||||
|
|
|
@ -22,6 +22,7 @@ import 'package:front_end/file_system.dart';
|
|||
import 'package:front_end/physical_file_system.dart';
|
||||
import 'package:front_end/src/fasta/kernel/utils.dart';
|
||||
import 'package:kernel/ast.dart' show Source, Library;
|
||||
import 'package:kernel/target/targets.dart' show TargetFlags;
|
||||
|
||||
import 'package:front_end/src/fasta/builder/builder.dart' show LibraryBuilder;
|
||||
import 'package:front_end/src/fasta/compiler_context.dart' show CompilerContext;
|
||||
|
@ -89,8 +90,7 @@ class KernelTargetForDart2js extends KernelTarget {
|
|||
KernelTargetForDart2js(
|
||||
DillTarget target, TranslateUri uriTranslator, bool strongMode,
|
||||
[Map<String, Source> uriToSource])
|
||||
: super(PhysicalFileSystem.instance, target, uriTranslator, strongMode,
|
||||
uriToSource);
|
||||
: super(PhysicalFileSystem.instance, target, uriTranslator, uriToSource);
|
||||
@override
|
||||
SourceLoader<Library> createLoader() =>
|
||||
new SourceLoaderForDart2js<Library>(fileSystem, this);
|
||||
|
@ -139,8 +139,9 @@ class SourceLoaderForDart2js<L> extends SourceLoader<L> {
|
|||
/// Specializes [DillTarget] to build kernel for dart2js: JS-specific libraries
|
||||
/// are included in the SDK, and native clauses have no string parameter.
|
||||
class DillTargetForDart2js extends DillTarget {
|
||||
DillTargetForDart2js(Ticker ticker, TranslateUri uriTranslator)
|
||||
: super(ticker, uriTranslator, "none");
|
||||
DillTargetForDart2js(Ticker ticker, TranslateUri uriTranslator,
|
||||
{TargetFlags flags})
|
||||
: super(ticker, uriTranslator, "none", flags: flags);
|
||||
|
||||
@override
|
||||
Token skipNativeClause(Token token) => _skipNative(token);
|
||||
|
|
|
@ -13,6 +13,7 @@ import 'src/fasta/dill/dill_target.dart' show DillTarget;
|
|||
import 'src/fasta/errors.dart' show InputError;
|
||||
import 'src/fasta/kernel/kernel_target.dart' show KernelTarget;
|
||||
import 'package:kernel/kernel.dart' show Program;
|
||||
import 'package:kernel/target/targets.dart' show TargetFlags;
|
||||
import 'src/fasta/ticker.dart' show Ticker;
|
||||
import 'src/fasta/translate_uri.dart' show TranslateUri;
|
||||
import 'src/simple_error.dart';
|
||||
|
@ -52,15 +53,16 @@ Future<Program> kernelForProgram(Uri source, CompilerOptions options) async {
|
|||
try {
|
||||
TranslateUri uriTranslator = await pOptions.getUriTranslator();
|
||||
|
||||
var dillTarget =
|
||||
new DillTarget(new Ticker(isVerbose: false), uriTranslator, "vm");
|
||||
var dillTarget = new DillTarget(
|
||||
new Ticker(isVerbose: false), uriTranslator, "vm_fasta",
|
||||
flags: new TargetFlags(strongMode: options.strongMode));
|
||||
var summary = await pOptions.sdkSummaryProgram;
|
||||
if (summary != null) {
|
||||
dillTarget.loader.appendLibraries(summary);
|
||||
}
|
||||
|
||||
var kernelTarget = new KernelTarget(
|
||||
options.fileSystem, dillTarget, uriTranslator, options.strongMode);
|
||||
var kernelTarget =
|
||||
new KernelTarget(options.fileSystem, dillTarget, uriTranslator);
|
||||
kernelTarget.read(source);
|
||||
|
||||
await dillTarget.buildOutlines();
|
||||
|
@ -148,8 +150,9 @@ Future<Program> kernelForBuildUnit(
|
|||
try {
|
||||
TranslateUri uriTranslator = await pOptions.getUriTranslator();
|
||||
|
||||
var dillTarget =
|
||||
new DillTarget(new Ticker(isVerbose: false), uriTranslator, "vm");
|
||||
var dillTarget = new DillTarget(
|
||||
new Ticker(isVerbose: false), uriTranslator, "vm_fasta",
|
||||
flags: new TargetFlags(strongMode: options.strongMode));
|
||||
var summary = await pOptions.sdkSummaryProgram;
|
||||
if (summary != null) {
|
||||
dillTarget.loader.appendLibraries(summary);
|
||||
|
@ -164,8 +167,8 @@ Future<Program> kernelForBuildUnit(
|
|||
|
||||
await dillTarget.buildOutlines();
|
||||
|
||||
var kernelTarget = new KernelTarget(
|
||||
options.fileSystem, dillTarget, uriTranslator, options.strongMode);
|
||||
var kernelTarget =
|
||||
new KernelTarget(options.fileSystem, dillTarget, uriTranslator);
|
||||
sources.forEach(kernelTarget.read);
|
||||
await kernelTarget.buildOutlines();
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ import 'ticker.dart' show Ticker;
|
|||
|
||||
import 'translate_uri.dart' show TranslateUri;
|
||||
|
||||
import 'package:kernel/target/targets.dart' show TargetFlags;
|
||||
|
||||
const int iterations = const int.fromEnvironment("iterations", defaultValue: 1);
|
||||
|
||||
Future mainEntryPoint(List<String> arguments) async {
|
||||
|
@ -71,10 +73,11 @@ Future compilePlatformInternal(CompilerContext c, Ticker ticker, Uri patchedSdk,
|
|||
.parse(c.fileSystem, patchedSdk, packages: c.options.packages);
|
||||
ticker.logMs("Read packages file");
|
||||
|
||||
DillTarget dillTarget =
|
||||
new DillTarget(ticker, uriTranslator, c.options.target);
|
||||
KernelTarget kernelTarget = new KernelTarget(c.fileSystem, dillTarget,
|
||||
uriTranslator, c.options.strongMode, c.uriToSource);
|
||||
DillTarget dillTarget = new DillTarget(
|
||||
ticker, uriTranslator, c.options.target,
|
||||
flags: new TargetFlags(strongMode: c.options.strongMode));
|
||||
KernelTarget kernelTarget =
|
||||
new KernelTarget(c.fileSystem, dillTarget, uriTranslator, c.uriToSource);
|
||||
|
||||
kernelTarget.read(Uri.parse("dart:core"));
|
||||
await dillTarget.buildOutlines();
|
||||
|
|
|
@ -91,7 +91,7 @@ class CompilerCommandLine extends CommandLine {
|
|||
bool get strongMode => options.containsKey("--strong-mode");
|
||||
|
||||
String get target {
|
||||
return options["-t"] ?? options["--target"] ?? "vm";
|
||||
return options["-t"] ?? options["--target"] ?? "vm_fasta";
|
||||
}
|
||||
|
||||
static dynamic withGlobalOptions(String programName, List<String> arguments,
|
||||
|
|
|
@ -8,7 +8,7 @@ import 'dart:async' show Future;
|
|||
|
||||
import 'package:kernel/ast.dart' show Class;
|
||||
|
||||
import 'package:kernel/target/targets.dart' show getTarget;
|
||||
import 'package:kernel/target/targets.dart' show getTarget, TargetFlags;
|
||||
|
||||
import '../errors.dart' show internalError;
|
||||
import '../kernel/kernel_builder.dart' show ClassBuilder;
|
||||
|
@ -23,8 +23,10 @@ class DillTarget extends TargetImplementation {
|
|||
DillLoader loader;
|
||||
|
||||
DillTarget(
|
||||
Ticker ticker, TranslateUri uriTranslator, String backendTargetName)
|
||||
: super(ticker, uriTranslator, getTarget(backendTargetName, null)) {
|
||||
Ticker ticker, TranslateUri uriTranslator, String backendTargetName,
|
||||
{TargetFlags flags})
|
||||
: super(ticker, uriTranslator,
|
||||
getTarget(backendTargetName, flags ?? new TargetFlags())) {
|
||||
loader = new DillLoader(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,13 +16,9 @@ import 'package:front_end/src/fasta/kernel/utils.dart';
|
|||
import 'package:kernel/binary/ast_to_binary.dart'
|
||||
show LibraryFilteringBinaryPrinter;
|
||||
|
||||
import 'package:kernel/class_hierarchy.dart' show ClassHierarchy;
|
||||
|
||||
import 'package:kernel/core_types.dart' show CoreTypes;
|
||||
|
||||
import 'package:kernel/kernel.dart' show Library, Program, loadProgramFromBytes;
|
||||
|
||||
import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget;
|
||||
import 'package:kernel/target/targets.dart' show TargetFlags;
|
||||
|
||||
import 'compiler_command_line.dart' show CompilerCommandLine;
|
||||
|
||||
|
@ -118,13 +114,14 @@ class CompileTask {
|
|||
CompileTask(this.c, this.ticker);
|
||||
|
||||
DillTarget createDillTarget(TranslateUri uriTranslator) {
|
||||
return new DillTarget(ticker, uriTranslator, c.options.target);
|
||||
return new DillTarget(ticker, uriTranslator, c.options.target,
|
||||
flags: new TargetFlags(strongMode: c.options.strongMode));
|
||||
}
|
||||
|
||||
KernelTarget createKernelTarget(
|
||||
DillTarget dillTarget, TranslateUri uriTranslator, bool strongMode) {
|
||||
return new KernelTarget(
|
||||
c.fileSystem, dillTarget, uriTranslator, strongMode, c.uriToSource);
|
||||
c.fileSystem, dillTarget, uriTranslator, c.uriToSource);
|
||||
}
|
||||
|
||||
Future<KernelTarget> buildOutline([Uri output]) async {
|
||||
|
@ -186,7 +183,7 @@ Future<CompilationResult> parseScript(
|
|||
Future<CompilationResult> parseScriptInFileSystem(
|
||||
Uri fileName, FileSystem fileSystem, Uri packages, Uri patchedSdk,
|
||||
{bool verbose: false, bool strongMode: false, String backendTarget}) async {
|
||||
backendTarget ??= "vm";
|
||||
backendTarget ??= "vm_fasta";
|
||||
try {
|
||||
if (!await fileSystem.entityForUri(fileName).exists()) {
|
||||
return new CompilationResult.error(
|
||||
|
@ -197,23 +194,20 @@ Future<CompilationResult> parseScriptInFileSystem(
|
|||
formatUnexpected(patchedSdk, -1, "Patched sdk directory not found."));
|
||||
}
|
||||
|
||||
CoreTypes coreTypes;
|
||||
ClassHierarchy hierarchy;
|
||||
Program program;
|
||||
try {
|
||||
TranslateUri uriTranslator =
|
||||
await TranslateUri.parse(fileSystem, patchedSdk, packages: packages);
|
||||
final Ticker ticker = new Ticker(isVerbose: verbose);
|
||||
final DillTarget dillTarget =
|
||||
new DillTarget(ticker, uriTranslator, backendTarget);
|
||||
final DillTarget dillTarget = new DillTarget(
|
||||
ticker, uriTranslator, backendTarget,
|
||||
flags: new TargetFlags(strongMode: strongMode));
|
||||
_appendDillForUri(dillTarget, patchedSdk.resolve('platform.dill'));
|
||||
final KernelTarget kernelTarget =
|
||||
new KernelTarget(fileSystem, dillTarget, uriTranslator, strongMode);
|
||||
new KernelTarget(fileSystem, dillTarget, uriTranslator);
|
||||
kernelTarget.read(fileName);
|
||||
await dillTarget.buildOutlines();
|
||||
await kernelTarget.buildOutlines();
|
||||
coreTypes = kernelTarget.loader.coreTypes;
|
||||
hierarchy = kernelTarget.loader.hierarchy;
|
||||
program = await kernelTarget.buildProgram();
|
||||
if (kernelTarget.errors.isNotEmpty) {
|
||||
return new CompilationResult.errors(kernelTarget.errors);
|
||||
|
@ -226,11 +220,6 @@ Future<CompilationResult> parseScriptInFileSystem(
|
|||
return new CompilationResult.error("No 'main' method found.");
|
||||
}
|
||||
|
||||
// Perform target-specific transformations.
|
||||
Target target = getTarget("vm", new TargetFlags(strongMode: false));
|
||||
target.performModularTransformations(coreTypes, hierarchy, program);
|
||||
target.performGlobalTransformations(coreTypes, program);
|
||||
|
||||
// Write the program to a list of bytes and return it. Do not include
|
||||
// libraries that have a dart: import URI.
|
||||
//
|
||||
|
@ -249,9 +238,14 @@ Future<CompilationResult> parseScriptInFileSystem(
|
|||
}
|
||||
|
||||
Future compilePlatform(Uri patchedSdk, Uri fullOutput,
|
||||
{Uri outlineOutput, Uri packages, bool verbose: false}) async {
|
||||
{Uri outlineOutput,
|
||||
Uri packages,
|
||||
bool verbose: false,
|
||||
String backendTarget}) async {
|
||||
backendTarget ??= "vm_fasta";
|
||||
Ticker ticker = new Ticker(isVerbose: verbose);
|
||||
await CompilerCommandLine.withGlobalOptions("", [""], (CompilerContext c) {
|
||||
c.options.options["--target"] = backendTarget;
|
||||
c.options.options["--packages"] = packages;
|
||||
if (verbose) {
|
||||
c.options.options["--verbose"] = true;
|
||||
|
@ -268,7 +262,7 @@ Future writeDepsFile(Uri script, Uri depsFile, Uri output,
|
|||
Iterable<Uri> extraDependencies,
|
||||
bool verbose: false,
|
||||
String backendTarget}) async {
|
||||
backendTarget ??= "vm";
|
||||
backendTarget ??= "vm_fasta";
|
||||
Ticker ticker = new Ticker(isVerbose: verbose);
|
||||
await CompilerCommandLine.withGlobalOptions("", [""],
|
||||
(CompilerContext c) async {
|
||||
|
@ -281,11 +275,11 @@ Future writeDepsFile(Uri script, Uri depsFile, Uri output,
|
|||
TranslateUri uriTranslator = await TranslateUri.parse(c.fileSystem, sdk,
|
||||
packages: c.options.packages);
|
||||
ticker.logMs("Read packages file");
|
||||
DillTarget dillTarget =
|
||||
new DillTarget(ticker, uriTranslator, backendTarget);
|
||||
DillTarget dillTarget = new DillTarget(ticker, uriTranslator, backendTarget,
|
||||
flags: new TargetFlags(strongMode: false));
|
||||
_appendDillForUri(dillTarget, platform);
|
||||
KernelTarget kernelTarget = new KernelTarget(PhysicalFileSystem.instance,
|
||||
dillTarget, uriTranslator, false, c.uriToSource);
|
||||
KernelTarget kernelTarget = new KernelTarget(
|
||||
PhysicalFileSystem.instance, dillTarget, uriTranslator, c.uriToSource);
|
||||
|
||||
kernelTarget.read(script);
|
||||
await dillTarget.buildOutlines();
|
||||
|
|
|
@ -40,12 +40,6 @@ import 'package:kernel/ast.dart'
|
|||
VariableGet,
|
||||
VoidType;
|
||||
|
||||
import 'package:kernel/transformations/erasure.dart' show Erasure;
|
||||
|
||||
import 'package:kernel/transformations/continuation.dart' as transformAsync;
|
||||
|
||||
import 'package:kernel/transformations/mixin_full_resolution.dart' as mix;
|
||||
|
||||
import 'package:kernel/type_algebra.dart' show substitute;
|
||||
|
||||
import '../source/source_loader.dart' show SourceLoader;
|
||||
|
@ -89,8 +83,6 @@ class KernelTarget extends TargetImplementation {
|
|||
/// The [FileSystem] which should be used to access files.
|
||||
final FileSystem fileSystem;
|
||||
|
||||
final bool strongMode;
|
||||
|
||||
final DillTarget dillTarget;
|
||||
|
||||
/// Shared with [CompilerContext].
|
||||
|
@ -105,8 +97,10 @@ class KernelTarget extends TargetImplementation {
|
|||
final TypeBuilder dynamicType =
|
||||
new KernelNamedTypeBuilder("dynamic", null, -1, null);
|
||||
|
||||
KernelTarget(this.fileSystem, DillTarget dillTarget,
|
||||
TranslateUri uriTranslator, this.strongMode,
|
||||
bool get strongMode => backendTarget.strongMode;
|
||||
|
||||
KernelTarget(
|
||||
this.fileSystem, DillTarget dillTarget, TranslateUri uriTranslator,
|
||||
[Map<String, Source> uriToSource])
|
||||
: dillTarget = dillTarget,
|
||||
uriToSource = uriToSource ?? CompilerContext.current.uriToSource,
|
||||
|
@ -655,27 +649,11 @@ class KernelTarget extends TargetImplementation {
|
|||
/// Run all transformations that are needed when building a program for the
|
||||
/// first time.
|
||||
void runBuildTransformations() {
|
||||
transformMixinApplications();
|
||||
otherTransformations();
|
||||
}
|
||||
|
||||
void transformMixinApplications() {
|
||||
mix.transformLibraries(
|
||||
backendTarget, loader.coreTypes, loader.hierarchy, loader.libraries);
|
||||
ticker.logMs("Transformed mixin applications");
|
||||
}
|
||||
|
||||
void otherTransformations() {
|
||||
if (!strongMode) {
|
||||
// TODO(ahe): Don't generate type variables in the first place.
|
||||
program.accept(new Erasure());
|
||||
ticker.logMs("Erased type variables in generic methods");
|
||||
}
|
||||
if (errors.isEmpty && loader.collectCompileTimeErrors().isEmpty) {
|
||||
// TODO(kmillikin): Make this run on a per-method basis.
|
||||
transformAsync.transformLibraries(loader.coreTypes, loader.libraries);
|
||||
}
|
||||
ticker.logMs("Transformed async methods");
|
||||
backendTarget.performModularTransformationsOnLibraries(
|
||||
loader.coreTypes, loader.hierarchy, loader.libraries,
|
||||
logger: (String msg) => ticker.logMs(msg));
|
||||
backendTarget.performGlobalTransformations(loader.coreTypes, program,
|
||||
logger: (String msg) => ticker.logMs(msg));
|
||||
}
|
||||
|
||||
void verify() {
|
||||
|
|
|
@ -20,6 +20,7 @@ import 'package:front_end/src/incremental/file_state.dart';
|
|||
import 'package:kernel/binary/ast_from_binary.dart';
|
||||
import 'package:kernel/binary/limited_ast_to_binary.dart';
|
||||
import 'package:kernel/kernel.dart' hide Source;
|
||||
import 'package:kernel/target/targets.dart' show TargetFlags;
|
||||
|
||||
dynamic unimplemented() {
|
||||
// TODO(paulberry): get rid of this.
|
||||
|
@ -100,8 +101,9 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
|
|||
});
|
||||
|
||||
CanonicalName nameRoot = new CanonicalName.root();
|
||||
DillTarget dillTarget =
|
||||
new DillTarget(new Ticker(isVerbose: false), _uriTranslator, "vm");
|
||||
DillTarget dillTarget = new DillTarget(
|
||||
new Ticker(isVerbose: false), _uriTranslator, "vm_fasta",
|
||||
flags: new TargetFlags(strongMode: _options.strongMode));
|
||||
|
||||
List<_LibraryCycleResult> results = [];
|
||||
await _logger.runAsync('Compute results for cycles', () async {
|
||||
|
@ -204,8 +206,8 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
|
|||
}
|
||||
|
||||
// Create KernelTarget and configure it for compiling the cycle URIs.
|
||||
KernelTarget kernelTarget = new KernelTarget(_fsState.fileSystemView,
|
||||
dillTarget, _uriTranslator, _options.strongMode);
|
||||
KernelTarget kernelTarget =
|
||||
new KernelTarget(_fsState.fileSystemView, dillTarget, _uriTranslator);
|
||||
for (FileState library in cycle.libraries) {
|
||||
kernelTarget.read(library.uri);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri;
|
|||
import 'package:front_end/src/fasta/util/relativize.dart' show relativizeUri;
|
||||
import 'package:kernel/ast.dart' show Program;
|
||||
import 'package:kernel/kernel.dart' show loadProgramFromBytes;
|
||||
import 'package:kernel/target/targets.dart' show TargetFlags;
|
||||
import 'package:testing/testing.dart'
|
||||
show Chain, ChainContext, ExpectationSet, Result, Step, TestDescription;
|
||||
import 'testing/suite.dart';
|
||||
|
@ -95,10 +96,11 @@ class BuildProgram
|
|||
var platformOutline = context.loadPlatformOutline();
|
||||
platformOutline.unbindCanonicalNames();
|
||||
var dillTarget = new DillTarget(
|
||||
new Ticker(isVerbose: false), context.uriTranslator, "vm");
|
||||
new Ticker(isVerbose: false), context.uriTranslator, "vm_fasta",
|
||||
flags: new TargetFlags(strongMode: false));
|
||||
dillTarget.loader.appendLibraries(platformOutline);
|
||||
var sourceTarget = new KernelTarget(PhysicalFileSystem.instance,
|
||||
dillTarget, context.uriTranslator, false);
|
||||
var sourceTarget = new KernelTarget(
|
||||
PhysicalFileSystem.instance, dillTarget, context.uriTranslator);
|
||||
await dillTarget.buildOutlines();
|
||||
|
||||
var inputUri = description.uri;
|
||||
|
@ -113,8 +115,8 @@ class BuildProgram
|
|||
|
||||
/// This new KernelTarget contains only sources from the test without
|
||||
/// lib.dart.
|
||||
sourceTarget = new KernelTarget(PhysicalFileSystem.instance, dillTarget,
|
||||
context.uriTranslator, false);
|
||||
sourceTarget = new KernelTarget(
|
||||
PhysicalFileSystem.instance, dillTarget, context.uriTranslator);
|
||||
|
||||
await dillTarget.buildOutlines();
|
||||
sourceTarget.read(inputUri);
|
||||
|
|
|
@ -50,6 +50,8 @@ import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget;
|
|||
|
||||
import 'package:kernel/kernel.dart' show loadProgramFromBytes;
|
||||
|
||||
import 'package:kernel/target/targets.dart' show TargetFlags;
|
||||
|
||||
export 'package:testing/testing.dart' show Chain, runMe;
|
||||
|
||||
const String STRONG_MODE = " strong mode ";
|
||||
|
@ -216,7 +218,9 @@ class Outline extends Step<TestDescription, Program, FastaContext> {
|
|||
CompilerContext.current.disableColors();
|
||||
Program platformOutline = await context.loadPlatformOutline();
|
||||
Ticker ticker = new Ticker();
|
||||
DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator, "vm");
|
||||
DillTarget dillTarget = new DillTarget(
|
||||
ticker, context.uriTranslator, "vm_fasta",
|
||||
flags: new TargetFlags(strongMode: strongMode));
|
||||
platformOutline.unbindCanonicalNames();
|
||||
dillTarget.loader.appendLibraries(platformOutline);
|
||||
// We create a new URI translator to avoid reading plaform libraries from
|
||||
|
@ -228,7 +232,7 @@ class Outline extends Step<TestDescription, Program, FastaContext> {
|
|||
KernelTarget sourceTarget = astKind == AstKind.Analyzer
|
||||
? new AnalyzerTarget(dillTarget, uriTranslator, strongMode)
|
||||
: new KernelTarget(
|
||||
PhysicalFileSystem.instance, dillTarget, uriTranslator, strongMode);
|
||||
PhysicalFileSystem.instance, dillTarget, uriTranslator);
|
||||
|
||||
Program p;
|
||||
try {
|
||||
|
|
|
@ -22,6 +22,7 @@ import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri;
|
|||
import 'package:front_end/src/fasta/translate_uri.dart';
|
||||
import 'package:front_end/src/fasta/parser/dart_vm_native.dart'
|
||||
show skipNativeClause;
|
||||
import 'package:kernel/target/targets.dart' show TargetFlags;
|
||||
|
||||
/// Cumulative total number of chars scanned.
|
||||
int inputSize = 0;
|
||||
|
@ -214,9 +215,10 @@ generateKernel(Uri entryUri,
|
|||
|
||||
var timer = new Stopwatch()..start();
|
||||
final Ticker ticker = new Ticker();
|
||||
final DillTarget dillTarget = new DillTarget(ticker, uriResolver, "vm");
|
||||
final KernelTarget kernelTarget = new KernelTarget(
|
||||
PhysicalFileSystem.instance, dillTarget, uriResolver, strongMode);
|
||||
final DillTarget dillTarget = new DillTarget(ticker, uriResolver, "vm_fasta",
|
||||
flags: new TargetFlags(strongMode: strongMode));
|
||||
final KernelTarget kernelTarget =
|
||||
new KernelTarget(PhysicalFileSystem.instance, dillTarget, uriResolver);
|
||||
var entrypoints = [
|
||||
entryUri,
|
||||
// These extra libraries are added to match the same set of libraries
|
||||
|
|
|
@ -51,12 +51,14 @@ class FlutterTarget extends Target {
|
|||
'dart:vmservice_sky',
|
||||
];
|
||||
|
||||
void performModularTransformations(
|
||||
CoreTypes coreTypes, ClassHierarchy hierarchy, Program program) {
|
||||
mix.transformLibraries(this, coreTypes, hierarchy, program.libraries);
|
||||
void performModularTransformationsOnLibraries(
|
||||
CoreTypes coreTypes, ClassHierarchy hierarchy, List<Library> libraries,
|
||||
{void logger(String msg)}) {
|
||||
mix.transformLibraries(this, coreTypes, hierarchy, libraries);
|
||||
}
|
||||
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program) {
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program,
|
||||
{void logger(String msg)}) {
|
||||
cont.transformProgram(coreTypes, program);
|
||||
|
||||
// Repair `_getMainClosure()` function in dart:{_builtin,ui} libraries.
|
||||
|
|
|
@ -7,10 +7,11 @@ import '../ast.dart';
|
|||
import '../class_hierarchy.dart';
|
||||
import '../core_types.dart';
|
||||
import '../transformations/treeshaker.dart' show ProgramRoot;
|
||||
import 'flutter.dart';
|
||||
import 'vm.dart';
|
||||
import 'vmcc.dart';
|
||||
import 'vmreify.dart';
|
||||
import 'flutter.dart' show FlutterTarget;
|
||||
import 'vm.dart' show VmTarget;
|
||||
import 'vm_fasta.dart' show VmFastaTarget;
|
||||
import 'vmcc.dart' show VmClosureConvertedTarget;
|
||||
import 'vmreify.dart' show VmGenericTypesReifiedTarget;
|
||||
|
||||
final List<String> targetNames = targets.keys.toList();
|
||||
|
||||
|
@ -32,6 +33,7 @@ typedef Target _TargetBuilder(TargetFlags flags);
|
|||
final Map<String, _TargetBuilder> targets = <String, _TargetBuilder>{
|
||||
'none': (TargetFlags flags) => new NoneTarget(flags),
|
||||
'vm': (TargetFlags flags) => new VmTarget(flags),
|
||||
'vm_fasta': (TargetFlags flags) => new VmFastaTarget(flags),
|
||||
'vmcc': (TargetFlags flags) => new VmClosureConvertedTarget(flags),
|
||||
'vmreify': (TargetFlags flags) => new VmGenericTypesReifiedTarget(flags),
|
||||
'flutter': (TargetFlags flags) => new FlutterTarget(flags),
|
||||
|
@ -68,19 +70,47 @@ abstract class Target {
|
|||
/// If true, the SDK should be loaded in strong mode.
|
||||
bool get strongModeSdk => strongMode;
|
||||
|
||||
/// Perform target-specific modular transformations.
|
||||
/// Perform target-specific modular transformations on the given program.
|
||||
///
|
||||
/// These transformations should not be whole-program transformations. They
|
||||
/// should expect that the program will contain external libraries.
|
||||
void performModularTransformations(
|
||||
CoreTypes coreTypes, ClassHierarchy hierarchy, Program program);
|
||||
void performModularTransformationsOnProgram(
|
||||
CoreTypes coreTypes, ClassHierarchy hierarchy, Program program,
|
||||
{void logger(String msg)}) {
|
||||
performModularTransformationsOnLibraries(
|
||||
coreTypes, hierarchy, program.libraries,
|
||||
logger: logger);
|
||||
}
|
||||
|
||||
/// Perform target-specific modular transformations on the given libraries.
|
||||
///
|
||||
/// The intent of this method is to perform the transformations only on some
|
||||
/// subset of the program libraries and avoid packing them into a temporary
|
||||
/// [Program] instance to pass into [performModularTransformationsOnProgram].
|
||||
///
|
||||
/// Note that the following should be equivalent:
|
||||
///
|
||||
/// target.performModularTransformationsOnProgram(coreTypes, program);
|
||||
///
|
||||
/// and
|
||||
///
|
||||
/// target.performModularTransformationsOnLibraries(
|
||||
/// coreTypes, program.libraries);
|
||||
void performModularTransformationsOnLibraries(
|
||||
CoreTypes coreTypes, ClassHierarchy hierarchy, List<Library> libraries,
|
||||
{void logger(String msg)});
|
||||
|
||||
/// Perform target-specific whole-program transformations.
|
||||
///
|
||||
/// These transformations should be optimizations and not required for
|
||||
/// correctness. Everything should work if a simple and fast linker chooses
|
||||
/// not to apply these transformations.
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program);
|
||||
///
|
||||
/// Note that [performGlobalTransformations] doesn't have -OnProgram and
|
||||
/// -OnLibraries alternatives, because the global knowledge required by the
|
||||
/// transformations is assumed to be retrieved from a [Program] instance.
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program,
|
||||
{void logger(String msg)});
|
||||
|
||||
/// Builds an expression that instantiates an [Invocation] that can be passed
|
||||
/// to [noSuchMethod].
|
||||
|
@ -98,9 +128,11 @@ class NoneTarget extends Target {
|
|||
bool get strongMode => flags.strongMode;
|
||||
String get name => 'none';
|
||||
List<String> get extraRequiredLibraries => <String>[];
|
||||
void performModularTransformations(
|
||||
CoreTypes coreTypes, ClassHierarchy hierarchy, Program program) {}
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program) {}
|
||||
void performModularTransformationsOnLibraries(
|
||||
CoreTypes coreTypes, ClassHierarchy hierarchy, List<Library> libraries,
|
||||
{void logger(String msg)}) {}
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program,
|
||||
{void logger(String msg)}) {}
|
||||
|
||||
@override
|
||||
Expression instantiateInvocation(Member target, Expression receiver,
|
||||
|
|
|
@ -56,15 +56,17 @@ class VmTarget extends Target {
|
|||
|
||||
ClassHierarchy _hierarchy;
|
||||
|
||||
void performModularTransformations(
|
||||
CoreTypes coreTypes, ClassHierarchy hierarchy, Program program) {
|
||||
void performModularTransformationsOnLibraries(
|
||||
CoreTypes coreTypes, ClassHierarchy hierarchy, List<Library> libraries,
|
||||
{void logger(String msg)}) {
|
||||
var mixins = new mix.MixinFullResolution(this, coreTypes, hierarchy)
|
||||
..transform(program.libraries);
|
||||
..transform(libraries);
|
||||
|
||||
_hierarchy = mixins.hierarchy;
|
||||
}
|
||||
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program) {
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program,
|
||||
{void logger(String msg)}) {
|
||||
if (strongMode) {
|
||||
new InsertTypeChecks(coreTypes, _hierarchy).transformProgram(program);
|
||||
new InsertCovarianceChecks(coreTypes, _hierarchy)
|
||||
|
|
44
pkg/kernel/lib/target/vm_fasta.dart
Normal file
44
pkg/kernel/lib/target/vm_fasta.dart
Normal file
|
@ -0,0 +1,44 @@
|
|||
// 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 file.
|
||||
library kernel.target.vm_fasta;
|
||||
|
||||
import '../ast.dart' show Program, Library;
|
||||
import '../core_types.dart' show CoreTypes;
|
||||
import '../class_hierarchy.dart' show ClassHierarchy;
|
||||
|
||||
import '../transformations/mixin_full_resolution.dart' as transformMixins
|
||||
show transformLibraries;
|
||||
import '../transformations/continuation.dart' as transformAsync
|
||||
show transformLibraries;
|
||||
import '../transformations/erasure.dart' as tranformErasure
|
||||
show transformLibraries;
|
||||
|
||||
import 'targets.dart' show TargetFlags;
|
||||
import 'vm.dart' as vm_target;
|
||||
|
||||
class VmFastaTarget extends vm_target.VmTarget {
|
||||
VmFastaTarget(TargetFlags flags) : super(flags);
|
||||
|
||||
String get name => "vm_fasta";
|
||||
|
||||
void performModularTransformationsOnLibraries(
|
||||
CoreTypes coreTypes, ClassHierarchy hierarchy, List<Library> libraries,
|
||||
{void logger(String msg)}) {
|
||||
transformMixins.transformLibraries(this, coreTypes, hierarchy, libraries);
|
||||
logger?.call("Transformed mixin applications");
|
||||
|
||||
// TODO(ahe): Don't generate type variables in the first place.
|
||||
if (!strongMode) {
|
||||
tranformErasure.transformLibraries(coreTypes, libraries);
|
||||
logger?.call("Erased type variables in generic methods");
|
||||
}
|
||||
|
||||
// TODO(kmillikin): Make this run on a per-method basis.
|
||||
transformAsync.transformLibraries(coreTypes, libraries);
|
||||
logger?.call("Transformed async methods");
|
||||
}
|
||||
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program,
|
||||
{void logger(String msg)}) {}
|
||||
}
|
|
@ -16,7 +16,8 @@ class VmClosureConvertedTarget extends vm_target.VmTarget {
|
|||
String get name => "vmcc";
|
||||
|
||||
@override
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program) {
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program,
|
||||
{void logger(String msg)}) {
|
||||
super.performGlobalTransformations(coreTypes, program);
|
||||
cc.transformProgram(coreTypes, program);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@ class VmGenericTypesReifiedTarget extends vmcc_target.VmClosureConvertedTarget {
|
|||
}
|
||||
|
||||
@override
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program) {
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program,
|
||||
{void logger(String msg)}) {
|
||||
super.performGlobalTransformations(coreTypes, program);
|
||||
// TODO(dmitryas) this transformation should be made modular
|
||||
reify.transformProgram(coreTypes, program);
|
||||
|
|
|
@ -5,6 +5,18 @@ library kernel.transformations.erasure;
|
|||
|
||||
import '../ast.dart';
|
||||
import '../type_algebra.dart';
|
||||
import '../core_types.dart';
|
||||
|
||||
Program transformProgram(CoreTypes coreTypes, Program program) {
|
||||
program.accept(new Erasure());
|
||||
}
|
||||
|
||||
void transformLibraries(CoreTypes coreTypes, List<Library> libraries) {
|
||||
Erasure erasure = new Erasure();
|
||||
for (Library library in libraries) {
|
||||
library.accept(erasure);
|
||||
}
|
||||
}
|
||||
|
||||
/// This pass is a temporary measure to run strong mode code in the VM, which
|
||||
/// does not yet have the necessary runtime support.
|
||||
|
|
|
@ -27,10 +27,12 @@ abstract class TestTarget extends Target {
|
|||
Annotator get annotator => null;
|
||||
|
||||
// Return a list of strings so that we can accumulate errors.
|
||||
List<String> performModularTransformations(
|
||||
CoreTypes coreTypes, ClassHierarchy hierarchy, Program program);
|
||||
List<String> performModularTransformationsOnProgram(
|
||||
CoreTypes coreTypes, ClassHierarchy hierarchy, Program program,
|
||||
{void logger(String msg)});
|
||||
List<String> performGlobalTransformations(
|
||||
CoreTypes coreTypes, Program program);
|
||||
CoreTypes coreTypes, Program program,
|
||||
{void logger(String msg)});
|
||||
}
|
||||
|
||||
void runBaselineTests(String folderName, TestTarget target) {
|
||||
|
@ -61,7 +63,7 @@ void runBaselineTests(String folderName, TestTarget target) {
|
|||
loader.loadProgram(dartPath, target: target);
|
||||
verifyProgram(program);
|
||||
var errors = <String>[];
|
||||
errors.addAll(target.performModularTransformations(
|
||||
errors.addAll(target.performModularTransformationsOnProgram(
|
||||
coreTypes, hierarchy, program));
|
||||
verifyProgram(program);
|
||||
errors.addAll(target.performGlobalTransformations(coreTypes, program));
|
||||
|
|
|
@ -39,6 +39,8 @@ import 'package:front_end/src/fasta/testing/patched_sdk_location.dart';
|
|||
|
||||
import 'package:kernel/kernel.dart' show loadProgramFromBinary;
|
||||
|
||||
import 'package:kernel/target/targets.dart' show TargetFlags;
|
||||
|
||||
const String STRONG_MODE = " strong mode ";
|
||||
|
||||
class ClosureConversionContext extends ChainContext {
|
||||
|
@ -99,11 +101,13 @@ class FastaCompile
|
|||
TestDescription description, ClosureConversionContext context) async {
|
||||
Program platform = await context.loadPlatform();
|
||||
Ticker ticker = new Ticker();
|
||||
DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator, "vm");
|
||||
DillTarget dillTarget = new DillTarget(
|
||||
ticker, context.uriTranslator, "vm_fasta",
|
||||
flags: new TargetFlags(strongMode: context.strongMode));
|
||||
platform.unbindCanonicalNames();
|
||||
dillTarget.loader.appendLibraries(platform);
|
||||
KernelTarget sourceTarget = new KernelTarget(PhysicalFileSystem.instance,
|
||||
dillTarget, context.uriTranslator, context.strongMode);
|
||||
KernelTarget sourceTarget = new KernelTarget(
|
||||
PhysicalFileSystem.instance, dillTarget, context.uriTranslator);
|
||||
|
||||
Program p;
|
||||
try {
|
||||
|
|
|
@ -35,6 +35,8 @@ import 'package:front_end/src/fasta/testing/patched_sdk_location.dart';
|
|||
|
||||
import 'package:kernel/kernel.dart' show loadProgramFromBinary;
|
||||
|
||||
import 'package:kernel/target/targets.dart' show TargetFlags;
|
||||
|
||||
import 'package:kernel/interpreter/interpreter.dart';
|
||||
|
||||
const String STRONG_MODE = " strong mode ";
|
||||
|
@ -80,11 +82,13 @@ class FastaCompile extends Step<TestDescription, Program, InterpreterContext> {
|
|||
TestDescription description, InterpreterContext context) async {
|
||||
Program platform = await context.loadPlatform();
|
||||
Ticker ticker = new Ticker();
|
||||
DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator, "vm");
|
||||
DillTarget dillTarget = new DillTarget(
|
||||
ticker, context.uriTranslator, "vm_fasta",
|
||||
flags: new TargetFlags(strongMode: context.strongMode));
|
||||
platform.unbindCanonicalNames();
|
||||
dillTarget.loader.appendLibraries(platform);
|
||||
KernelTarget sourceTarget = new KernelTarget(PhysicalFileSystem.instance,
|
||||
dillTarget, context.uriTranslator, context.strongMode);
|
||||
KernelTarget sourceTarget = new KernelTarget(
|
||||
PhysicalFileSystem.instance, dillTarget, context.uriTranslator);
|
||||
|
||||
Program p;
|
||||
try {
|
||||
|
|
|
@ -198,7 +198,7 @@ class NotReifiedKernel extends Step<TestDescription, Program, TestContext> {
|
|||
var coreTypes = new CoreTypes(program);
|
||||
var hierarchy = new ClosedWorldClassHierarchy(program);
|
||||
target
|
||||
..performModularTransformations(coreTypes, hierarchy, program)
|
||||
..performModularTransformationsOnProgram(coreTypes, hierarchy, program)
|
||||
..performGlobalTransformations(coreTypes, program);
|
||||
return pass(program);
|
||||
} catch (e, s) {
|
||||
|
|
|
@ -409,7 +409,8 @@ Future<CompilerOutcome> batchMain(
|
|||
if (target != null && canContinueCompilation) {
|
||||
CoreTypes coreTypes = new CoreTypes(program);
|
||||
ClassHierarchy hierarchy = new ClosedWorldClassHierarchy(program);
|
||||
target.performModularTransformations(coreTypes, hierarchy, program);
|
||||
target.performModularTransformationsOnProgram(
|
||||
coreTypes, hierarchy, program);
|
||||
runVerifier();
|
||||
if (options['link']) {
|
||||
target.performGlobalTransformations(coreTypes, program);
|
||||
|
|
Loading…
Reference in a new issue