From 241d2c6cf5eb2e2675919e9c70992acccd3dcbca Mon Sep 17 00:00:00 2001 From: Jens Johansen Date: Thu, 23 Jan 2020 09:37:37 +0000 Subject: [PATCH] [CFE] Strong test can have linked dependencies Change-Id: Ia95789b658147f7e2676a9c92b6ba4a1c419395b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132642 Reviewed-by: Johnni Winther Commit-Queue: Jens Johansen --- pkg/front_end/test/fasta/testing/suite.dart | 131 ++++++++++++++---- .../variance_from_dill/link.options | 1 + .../variance_from_dill.dart | 6 + .../variance_from_dill_lib.dart | 1 + pkg/front_end/testcases/outline.status | 1 + pkg/front_end/testcases/strong.status | 1 + .../testcases/text_serialization.status | 1 + 7 files changed, 116 insertions(+), 26 deletions(-) create mode 100644 pkg/front_end/testcases/general/with_dependencies/variance_from_dill/link.options create mode 100644 pkg/front_end/testcases/general/with_dependencies/variance_from_dill/variance_from_dill.dart create mode 100644 pkg/front_end/testcases/general/with_dependencies/variance_from_dill/variance_from_dill_lib.dart diff --git a/pkg/front_end/test/fasta/testing/suite.dart b/pkg/front_end/test/fasta/testing/suite.dart index 8d5bda97594..666cd3888a5 100644 --- a/pkg/front_end/test/fasta/testing/suite.dart +++ b/pkg/front_end/test/fasta/testing/suite.dart @@ -161,6 +161,14 @@ class TestOptions { } } +class LinkDependenciesOptions { + final Set content; + Component component; + String errors; + + LinkDependenciesOptions(this.content) : assert(content != null); +} + class FastaContext extends ChainContext with MatchContext { final UriTranslator uriTranslator; final List steps; @@ -176,6 +184,7 @@ class FastaContext extends ChainContext with MatchContext { {}; final Uri platformBinaries; final Map _testOptions = {}; + final Map _linkDependencies = {}; @override final bool updateExpectations; @@ -296,6 +305,33 @@ class FastaContext extends ChainContext with MatchContext { return testOptions; } + /// Computes the link dependencies for [description]. + LinkDependenciesOptions computeLinkDependenciesOptions( + TestDescription description) { + Directory directory = new File.fromUri(description.uri).parent; + LinkDependenciesOptions linkDependenciesOptions = + _linkDependencies[directory.uri]; + if (linkDependenciesOptions == null) { + File optionsFile = + new File.fromUri(directory.uri.resolve('link.options')); + Set content = new Set(); + if (optionsFile.existsSync()) { + for (String line in optionsFile.readAsStringSync().split('\n')) { + line = line.trim(); + if (line.isEmpty) continue; + File f = new File.fromUri(description.uri.resolve(line)); + if (!f.existsSync()) { + throw new UnsupportedError("No file found: $f ($line)"); + } + content.add(f.uri); + } + } + linkDependenciesOptions = new LinkDependenciesOptions(content); + _linkDependencies[directory.uri] = linkDependenciesOptions; + } + return linkDependenciesOptions; + } + Expectation get verificationError => expectationSet["VerificationError"]; Future ensurePlatformUris() async { @@ -439,6 +475,8 @@ class Outline extends Step { Future> run( TestDescription description, FastaContext context) async { StringBuffer errors = new StringBuffer(); + LinkDependenciesOptions linkDependenciesOptions = + context.computeLinkDependenciesOptions(description); TestOptions testOptions = context.computeTestOptions(description); ProcessedOptions options = new ProcessedOptions( options: new CompilerOptions() @@ -454,31 +492,44 @@ class Outline extends Step { ..performNnbdChecks = testOptions.forceNnbdChecks ..nnbdStrongMode = !context.weak, inputs: [description.uri]); - return await CompilerContext.runWithOptions(options, (_) async { - // Disable colors to ensure that expectation files are the same across - // platforms and independent of stdin/stderr. - colors.enableColors = false; - Component platform = await context.loadPlatform(); - Ticker ticker = new Ticker(); - DillTarget dillTarget = new DillTarget( - ticker, - context.uriTranslator, - new TestVmTarget(new TargetFlags( - forceLateLoweringForTesting: testOptions.forceLateLowering)), - ); - dillTarget.loader.appendLibraries(platform); - // We create a new URI translator to avoid reading platform libraries from - // file system. - UriTranslator uriTranslator = new UriTranslator( - const TargetLibrariesSpecification('vm'), - context.uriTranslator.packages); - KernelTarget sourceTarget = new KernelTarget( - StandardFileSystem.instance, false, dillTarget, uriTranslator); - sourceTarget.setEntryPoints([description.uri]); - await dillTarget.buildOutlines(); - ValidatingInstrumentation instrumentation; - instrumentation = new ValidatingInstrumentation(); + // Disable colors to ensure that expectation files are the same across + // platforms and independent of stdin/stderr. + colors.enableColors = false; + + if (linkDependenciesOptions.content.isNotEmpty && + linkDependenciesOptions.component == null) { + // Compile linked dependency. + await CompilerContext.runWithOptions(options, (_) async { + KernelTarget sourceTarget = await outlineInitialization( + context, testOptions, linkDependenciesOptions.content.toList()); + if (linkDependenciesOptions.errors != null) { + errors.write(linkDependenciesOptions.errors); + } + Component p = await sourceTarget.buildOutlines(); + if (fullCompile) { + p = await sourceTarget.buildComponent(verify: context.verify); + } + linkDependenciesOptions.component = p; + List keepLibraries = new List(); + for (Library lib in p.libraries) { + if (linkDependenciesOptions.content.contains(lib.fileUri)) { + keepLibraries.add(lib); + } + } + p.libraries.clear(); + p.libraries.addAll(keepLibraries); + linkDependenciesOptions.errors = errors.toString(); + errors.clear(); + }); + } + + return await CompilerContext.runWithOptions(options, (_) async { + KernelTarget sourceTarget = await outlineInitialization( + context, testOptions, [description.uri], + alsoAppend: linkDependenciesOptions.component); + ValidatingInstrumentation instrumentation = + new ValidatingInstrumentation(); await instrumentation.loadExpectations(description.uri); sourceTarget.loader.instrumentation = instrumentation; Component p = await sourceTarget.buildOutlines(); @@ -488,8 +539,8 @@ class Outline extends Step { context.componentToDiagnostics[p] = errors; if (fullCompile) { p = await sourceTarget.buildComponent(verify: context.verify); - instrumentation?.finish(); - if (instrumentation != null && instrumentation.hasProblems) { + instrumentation.finish(); + if (instrumentation.hasProblems) { if (updateComments) { await instrumentation.fixSource(description.uri, false); } else { @@ -504,6 +555,34 @@ class Outline extends Step { return pass(p); }); } + + Future outlineInitialization( + FastaContext context, TestOptions testOptions, List entryPoints, + {Component alsoAppend}) async { + Component platform = await context.loadPlatform(); + Ticker ticker = new Ticker(); + DillTarget dillTarget = new DillTarget( + ticker, + context.uriTranslator, + new TestVmTarget(new TargetFlags( + forceLateLoweringForTesting: testOptions.forceLateLowering)), + ); + dillTarget.loader.appendLibraries(platform); + if (alsoAppend != null) { + dillTarget.loader.appendLibraries(alsoAppend); + } + // We create a new URI translator to avoid reading platform libraries + // from file system. + UriTranslator uriTranslator = new UriTranslator( + const TargetLibrariesSpecification('vm'), + context.uriTranslator.packages); + KernelTarget sourceTarget = new KernelTarget( + StandardFileSystem.instance, false, dillTarget, uriTranslator); + + sourceTarget.setEntryPoints(entryPoints); + await dillTarget.buildOutlines(); + return sourceTarget; + } } class Transform extends Step { diff --git a/pkg/front_end/testcases/general/with_dependencies/variance_from_dill/link.options b/pkg/front_end/testcases/general/with_dependencies/variance_from_dill/link.options new file mode 100644 index 00000000000..0785ad47361 --- /dev/null +++ b/pkg/front_end/testcases/general/with_dependencies/variance_from_dill/link.options @@ -0,0 +1 @@ +variance_from_dill_lib.dart diff --git a/pkg/front_end/testcases/general/with_dependencies/variance_from_dill/variance_from_dill.dart b/pkg/front_end/testcases/general/with_dependencies/variance_from_dill/variance_from_dill.dart new file mode 100644 index 00000000000..90073560956 --- /dev/null +++ b/pkg/front_end/testcases/general/with_dependencies/variance_from_dill/variance_from_dill.dart @@ -0,0 +1,6 @@ +import "variance_from_dill_lib.dart"; +typedef G = Function(F); + +main() { + print(G); +} \ No newline at end of file diff --git a/pkg/front_end/testcases/general/with_dependencies/variance_from_dill/variance_from_dill_lib.dart b/pkg/front_end/testcases/general/with_dependencies/variance_from_dill/variance_from_dill_lib.dart new file mode 100644 index 00000000000..3c62f223352 --- /dev/null +++ b/pkg/front_end/testcases/general/with_dependencies/variance_from_dill/variance_from_dill_lib.dart @@ -0,0 +1 @@ +typedef F = Function(); \ No newline at end of file diff --git a/pkg/front_end/testcases/outline.status b/pkg/front_end/testcases/outline.status index 6aef73b0a25..9df9418e1f1 100644 --- a/pkg/front_end/testcases/outline.status +++ b/pkg/front_end/testcases/outline.status @@ -14,6 +14,7 @@ general/override_check_after_inference: TypeCheckError general/override_check_basic: TypeCheckError general/override_check_with_covariant_modifier: TypeCheckError general/override_setter_with_field: TypeCheckError +general/with_dependencies/variance_from_dill/variance_from_dill: Crash general_nnbd_opt_out/abstract_members: TypeCheckError general_nnbd_opt_out/bug30695: TypeCheckError diff --git a/pkg/front_end/testcases/strong.status b/pkg/front_end/testcases/strong.status index 9db924979a9..f05fdc62368 100644 --- a/pkg/front_end/testcases/strong.status +++ b/pkg/front_end/testcases/strong.status @@ -65,6 +65,7 @@ general/type_variable_bound_access: TypeCheckError general/unsound_promotion: TypeCheckError general/void_methods: RuntimeError general/warn_unresolved_sends: InstrumentationMismatch # Test assumes Dart 1.0 semantics +general/with_dependencies/variance_from_dill/variance_from_dill: Crash general_nnbd_opt_out/abstract_members: TypeCheckError general_nnbd_opt_out/accessors: RuntimeError general_nnbd_opt_out/ambiguous_exports: RuntimeError # Expected, this file exports two main methods. diff --git a/pkg/front_end/testcases/text_serialization.status b/pkg/front_end/testcases/text_serialization.status index 33433526d91..6205e7d7b56 100644 --- a/pkg/front_end/testcases/text_serialization.status +++ b/pkg/front_end/testcases/text_serialization.status @@ -336,6 +336,7 @@ general/unused_methods: TextSerializationFailure # Was: Pass general/var_as_type_name: TextSerializationFailure # Was: Pass general/void_methods: TextSerializationFailure general/warn_unresolved_sends: InstrumentationMismatch # Test assumes Dart 1.0 semantics +general/with_dependencies/variance_from_dill/variance_from_dill: Crash general_nnbd_opt_out/DeltaBlue: TextSerializationFailure # Was: Pass general_nnbd_opt_out/abstract_members: TypeCheckError general_nnbd_opt_out/abstract_overrides_concrete_with_no_such_method: TextSerializationFailure