| Index: pkg/front_end/lib/src/fasta/kernel/kernel_target.dart
|
| diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart
|
| index 8ec51b3db2366e2e3e0e87e6ab0b2bdc6ee37698..893b8748770deae04868adb09269e409eac52010 100644
|
| --- a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart
|
| +++ b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart
|
| @@ -86,6 +86,7 @@ import 'kernel_builder.dart'
|
| TypeVariableBuilder;
|
|
|
| import 'verifier.dart' show verifyProgram;
|
| +import 'kernel_outline_shaker.dart' show trimProgram;
|
|
|
| class KernelTarget extends TargetImplementation {
|
| /// The [FileSystem] which should be used to access files.
|
| @@ -218,13 +219,18 @@ class KernelTarget extends TargetImplementation {
|
| }
|
|
|
| Future<Program> handleInputError(Uri uri, InputError error,
|
| - {bool isFullProgram}) {
|
| + {bool isFullProgram, bool trimDependencies: false}) {
|
| if (error != null) {
|
| String message = error.format();
|
| print(message);
|
| errors.add(message);
|
| }
|
| _program = erroneousProgram(isFullProgram);
|
| + if (trimDependencies) {
|
| + var excluded =
|
| + dillTarget.loader.libraries.map((lib) => lib.importUri).toSet();
|
| + trimProgram(_program, (uri) => !excluded.contains(uri));
|
| + }
|
| return uri == null
|
| ? new Future<Program>.value(_program)
|
| : writeLinkedProgram(uri, _program, isFullProgram: isFullProgram);
|
| @@ -249,13 +255,13 @@ class KernelTarget extends TargetImplementation {
|
| installDefaultConstructors(sourceClasses);
|
| loader.resolveConstructors();
|
| loader.finishTypeVariables(objectClassBuilder);
|
| - _program =
|
| + var outline =
|
| link(new List<Library>.from(loader.libraries), nameRoot: nameRoot);
|
| - loader.computeHierarchy(_program);
|
| + loader.computeHierarchy(outline);
|
| loader.checkOverrides(sourceClasses);
|
| loader.prepareInitializerInference();
|
| loader.performInitializerInference();
|
| - return _program;
|
| + return _program = outline;
|
| } on InputError catch (e) {
|
| return handleInputError(null, e, isFullProgram: false);
|
| } catch (e, s) {
|
| @@ -269,20 +275,24 @@ class KernelTarget extends TargetImplementation {
|
| await writeLinkedProgram(uri, _program, isFullProgram: false);
|
| }
|
| } on InputError catch (e) {
|
| - handleInputError(uri, e, isFullProgram: false);
|
| + handleInputError(uri, e, isFullProgram: false, trimDependencies: false);
|
| } catch (e, s) {
|
| reportCrash(e, s, loader?.currentUriForCrashReporting);
|
| }
|
| }
|
|
|
| @override
|
| - Future<Program> buildProgram({bool verify: false}) async {
|
| + Future<Program> buildProgram(
|
| + {bool verify: false, bool trimDependencies: false}) async {
|
| if (loader.first == null) return null;
|
| if (errors.isNotEmpty) {
|
| - return handleInputError(null, null, isFullProgram: true);
|
| + return handleInputError(null, null,
|
| + isFullProgram: true, trimDependencies: trimDependencies);
|
| }
|
| try {
|
| await loader.buildBodies();
|
| + _program = link(new List<Library>.from(loader.libraries),
|
| + trimDependencies: trimDependencies);
|
| loader.finishStaticInvocations();
|
| finishAllConstructors();
|
| loader.finishNativeMethods();
|
| @@ -291,11 +301,13 @@ class KernelTarget extends TargetImplementation {
|
| if (verify) this.verify();
|
| errors.addAll(loader.collectCompileTimeErrors().map((e) => e.format()));
|
| if (errors.isNotEmpty) {
|
| - return handleInputError(null, null, isFullProgram: true);
|
| + return handleInputError(null, null,
|
| + isFullProgram: true, trimDependencies: trimDependencies);
|
| }
|
| return _program;
|
| } on InputError catch (e) {
|
| - return handleInputError(null, e, isFullProgram: true);
|
| + return handleInputError(null, e,
|
| + isFullProgram: true, trimDependencies: trimDependencies);
|
| } catch (e, s) {
|
| return reportCrash(e, s, loader?.currentUriForCrashReporting);
|
| }
|
| @@ -390,11 +402,13 @@ class KernelTarget extends TargetImplementation {
|
|
|
| /// Creates a program by combining [libraries] with the libraries of
|
| /// `dillTarget.loader.program`.
|
| - Program link(List<Library> libraries, {CanonicalName nameRoot}) {
|
| + Program link(List<Library> libraries,
|
| + {CanonicalName nameRoot, trimDependencies: false}) {
|
| Map<String, Source> uriToSource =
|
| new Map<String, Source>.from(this.uriToSource);
|
|
|
| - libraries.addAll(dillTarget.loader.libraries);
|
| + List<Library> extraLibraries = dillTarget.loader.libraries;
|
| + libraries.addAll(extraLibraries);
|
| // TODO(scheglov) Should we also somehow update `uriToSource`?
|
| // uriToSource.addAll(binary.uriToSource);
|
|
|
| @@ -405,14 +419,17 @@ class KernelTarget extends TargetImplementation {
|
| Program program = new Program(
|
| nameRoot: nameRoot, libraries: libraries, uriToSource: uriToSource);
|
| if (loader.first != null) {
|
| + // TODO(sigmund): do only for full program
|
| Builder builder = loader.first.lookup("main", -1, null);
|
| if (builder is KernelProcedureBuilder) {
|
| program.mainMethod = builder.procedure;
|
| }
|
| }
|
| - if (errors.isEmpty || dillTarget.isLoaded) {
|
| - runLinkTransformations(program);
|
| + if (trimDependencies) {
|
| + var excluded = extraLibraries.map((lib) => lib.importUri).toSet();
|
| + trimProgram(program, (uri) => !excluded.contains(uri));
|
| }
|
| +
|
| ticker.logMs("Linked program");
|
| return program;
|
| }
|
| @@ -696,9 +713,6 @@ class KernelTarget extends TargetImplementation {
|
| otherTransformations();
|
| }
|
|
|
| - /// Run all transformations that are needed when linking a program.
|
| - void runLinkTransformations(Program program) {}
|
| -
|
| void transformMixinApplications() {
|
| new MixinFullResolution().transform(_program);
|
| ticker.logMs("Transformed mixin applications");
|
|
|