Files
sdk/pkg/vm/test/transformations/deferred_loading_test.dart
T
Ryan Macnak 93a4247af3 Reapply "Account for @pragma("vm:entry-point") creating additional "root" libraries when partitioning the program into loading units."
Weaken assertion in gen_snapshot requiring all libraries to have a loading unit as there can still be unreachable libraries:
  - Google3 and Fuchsia will compile all the sources in a package to a single dill file, then present multiple input dill files to the AOT compilation. Since the set of libraries was derived from package membership instead of imports, many can be unreachable.
  - When the root library's main comes from an export, the frontend's representation will incorrectly report the library containing main as the root library and the true root library may be unreachable from it.

Instead, assert only that surviving compiled code is assigned a loading unit.

TEST=gallery
Bug: https://github.com/flutter/gallery/issues/545
Bug: https://github.com/dart-lang/sdk/issues/49325
Bug: https://github.com/dart-lang/sdk/issues/41974
Bug: b/237016312
Change-Id: Ia52563a6f517308d041368be11dcc85270f19acc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249724
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2022-06-27 18:56:12 +00:00

58 lines
1.8 KiB
Dart

// Copyright (c) 2020, 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:io';
import 'package:kernel/target/targets.dart';
import 'package:kernel/ast.dart';
import 'package:kernel/core_types.dart';
import 'package:kernel/kernel.dart';
import 'package:test/test.dart';
import 'package:vm/transformations/deferred_loading.dart'
show transformComponent;
import '../common_test_utils.dart';
final String pkgVmDir = Platform.script.resolve('../..').toFilePath();
runTestCase(Uri source) async {
final target = new TestingVmTarget(new TargetFlags());
Component component =
await compileTestCaseToKernelProgram(source, target: target);
// Disrupt the import order as a way of simulating issue 42985.
final reversed = component.libraries.reversed.toList();
component.libraries.setAll(0, reversed);
final coreTypes = CoreTypes(component);
component = transformComponent(component, coreTypes, target);
// Remove core libraries so the expected output isn't enormous and broken by
// core libraries changes.
component.libraries.removeWhere((lib) => lib.importUri.isScheme("dart"));
String actual = kernelComponentToString(component);
// Remove absolute library URIs.
actual = actual.replaceAll(new Uri.file(pkgVmDir).toString(), '#pkg/vm');
compareResultWithExpectationsFile(source, actual);
}
main() {
group('deferred-loading', () {
final testCasesDir =
new Directory(pkgVmDir + '/testcases/transformations/deferred_loading');
for (var entry in testCasesDir
.listSync(recursive: true, followLinks: false)
.reversed) {
if (entry.path.endsWith("main.dart")) {
test(entry.path, () => runTestCase(entry.uri));
}
}
});
}