a9469269d7
In AOT this makes reading faster: Output from `out/ReleaseX64/dart pkg/front_end/tool/benchmarker.dart --iterations=10 --snapshot=pkg/front_end/test/kernel_binary_bench.aot.1 --snapshot=pkg/front_end/test/kernel_binary_bench.aot.2 --arguments="--warmups=10" --arguments="--iterations=5" --arguments="AstFromBinaryEager" --arguments="out/ReleaseX64/vm_platform_strong.dill"`: ``` msec task-clock:u: -8.6925% +/- 0.5737% (-167.09 +/- 11.03) page-faults:u: 0.1410% +/- 0.0051% (243.00 +/- 8.71) cycles:u: -10.2918% +/- 0.6161% (-732576747.50 +/- 43853449.16) instructions:u: -14.4988% +/- 0.0004% (-1636799813.90 +/- 39902.18) branch-misses:u: -3.4891% +/- 2.1142% (-1166085.00 +/- 706582.35) seconds time elapsed: -8.7005% +/- 0.5634% (-0.17 +/- 0.01) seconds user: -9.9752% +/- 1.5104% (-0.17 +/- 0.03) ``` Stats running manually (run as e.g. `out/ReleaseX64/dart-sdk/bin/dartaotruntime pkg/front_end/test/kernel_binary_bench.aot.1 --warmups=10 --iterations=5 AstFromBinaryEager out/ReleaseX64/vm_platform_strong.dill`): ``` AstFromBinaryEagerCold: -12.5174% +/- 3.10688% AstFromBinaryEagerWarmup: -8.33675% +/- 2.62433% AstFromBinaryEager: -10.3432% +/- 3.68375% ``` I don't expect there to be much of a change (if any) in JIT as the actual type was in practise always Uint8List anyway. TEST=Existing tests. Change-Id: I86b16ed207343848dee2e376f42598c223bbc48f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393740 Reviewed-by: Mayank Patke <fishythefish@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Jens Johansen <jensj@google.com> Reviewed-by: Morgan :) <davidmorgan@google.com> Reviewed-by: Srujan Gaddam <srujzs@google.com> Reviewed-by: Alexander Aprelev <aam@google.com>
133 lines
5.2 KiB
Dart
133 lines
5.2 KiB
Dart
// Copyright (c) 2017, 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:typed_data';
|
|
|
|
import 'package:front_end/src/api_prototype/front_end.dart';
|
|
import 'package:front_end/src/testing/compiler_common.dart';
|
|
import 'package:kernel/kernel.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
void main() {
|
|
test('summary has no source-info by default', () async {
|
|
var summary = await summarize(['a.dart'], allSources);
|
|
var component = loadComponentFromBytes(summary!);
|
|
|
|
// Note: the kernel representation always includes the Uri entries, but
|
|
// doesn't include the actual source here.
|
|
for (Source source in component.uriToSource.values) {
|
|
expect(source.source.length, 0);
|
|
expect(source.lineStarts!.length, 0);
|
|
}
|
|
});
|
|
|
|
test('summary includes declarations, but no method bodies', () async {
|
|
var summary = await summarize(['a.dart'], allSources);
|
|
var component = loadComponentFromBytes(summary!);
|
|
var aLib = findLibrary(component, 'a.dart');
|
|
expect(aLib.importUri.path, '/a/b/c/a.dart');
|
|
var classA = aLib.classes.first;
|
|
expect(classA.name, 'A');
|
|
var fooMethod = classA.procedures.first;
|
|
expect(fooMethod.name.text, 'foo');
|
|
expect(fooMethod.function.body is EmptyStatement, isTrue);
|
|
});
|
|
|
|
test('dependencies can be combined without conflict', () async {
|
|
var summaryA = await summarize(['a.dart'], allSources);
|
|
var sourcesWithA = new Map<String, dynamic>.from(allSources);
|
|
sourcesWithA['a.dill'] = summaryA;
|
|
|
|
var summaryBC = await summarize(['b.dart', 'c.dart'], sourcesWithA,
|
|
additionalDills: ['a.dill']);
|
|
|
|
var sourcesWithABC = new Map<String, dynamic>.from(sourcesWithA);
|
|
sourcesWithABC['bc.dill'] = summaryBC;
|
|
|
|
// Note: a is loaded first, bc.dill have a.dart as an external reference so
|
|
// we want to ensure loading them here will not create a problem.
|
|
var summaryD = await summarize(['d.dart'], sourcesWithABC,
|
|
additionalDills: ['a.dill', 'bc.dill']);
|
|
|
|
checkDSummary(summaryD!);
|
|
});
|
|
|
|
test('dependencies can be combined in any order', () async {
|
|
var summaryA = await summarize(['a.dart'], allSources);
|
|
var sourcesWithA = new Map<String, dynamic>.from(allSources);
|
|
sourcesWithA['a.dill'] = summaryA;
|
|
|
|
var summaryBC = await summarize(['b.dart', 'c.dart'], sourcesWithA,
|
|
additionalDills: ['a.dill']);
|
|
|
|
var sourcesWithABC = new Map<String, dynamic>.from(sourcesWithA);
|
|
sourcesWithABC['bc.dill'] = summaryBC;
|
|
|
|
// Note: unlike the previous test now bc.dill is loaded first and contains
|
|
// an external definition of library a.dart. Using this order also works
|
|
// because we share a CanonicalName root to resolve names across multiple
|
|
// dill files and because of how the kernel loader merges definitions.
|
|
var summaryD = await summarize(['d.dart'], sourcesWithABC,
|
|
additionalDills: ['bc.dill', 'a.dill']);
|
|
checkDSummary(summaryD!);
|
|
});
|
|
|
|
test('dependencies not included in truncated summaries', () async {
|
|
// Note: by default this test is loading the SDK from summaries.
|
|
var summaryA = await summarize(['a.dart'], allSources, truncate: true);
|
|
var component = loadComponentFromBytes(summaryA!);
|
|
expect(component.libraries.length, 1);
|
|
expect(
|
|
component.libraries.single.importUri.path.endsWith('a.dart'), isTrue);
|
|
|
|
var sourcesWithA = new Map<String, dynamic>.from(allSources);
|
|
sourcesWithA['a.dill'] = summaryA;
|
|
var summaryB = await summarize(['b.dart'], sourcesWithA,
|
|
additionalDills: ['a.dill'], truncate: true);
|
|
component = loadComponentFromBytes(summaryB!);
|
|
expect(component.libraries.length, 1);
|
|
expect(
|
|
component.libraries.single.importUri.path.endsWith('b.dart'), isTrue);
|
|
});
|
|
|
|
test('summarization by default is not hermetic', () async {
|
|
var errors = [];
|
|
var options = new CompilerOptions()..onDiagnostic = errors.add;
|
|
await summarize(['b.dart'], allSources, options: options);
|
|
expect(errors, isEmpty);
|
|
});
|
|
|
|
// TODO(sigmund): test trimDependencies when it is part of the public API.
|
|
}
|
|
|
|
var allSources = <String, String>{
|
|
'a.dart': 'class A { foo() { print("hi"); } }',
|
|
'b.dart': 'import "a.dart"; class B extends A {}',
|
|
'c.dart': 'class C { bar() => 1; }',
|
|
'd.dart': '''
|
|
import "a.dart";
|
|
import "b.dart";
|
|
import "c.dart";
|
|
class D extends B with C implements A { }''',
|
|
};
|
|
|
|
/// Helper function to check that some expectations from the summary of D.
|
|
void checkDSummary(Uint8List summary) {
|
|
var component = loadComponentFromBytes(summary);
|
|
var aLib = findLibrary(component, 'a.dart');
|
|
var bLib = findLibrary(component, 'b.dart');
|
|
var dLib = findLibrary(component, 'd.dart');
|
|
|
|
// The type-hierarchy for A, B, D is visible and correct
|
|
var aClass = aLib.classes.firstWhere((c) => c.name == 'A');
|
|
var bClass = bLib.classes.firstWhere((c) => c.name == 'B');
|
|
expect(bClass.superclass, same(aClass));
|
|
|
|
var dClass = dLib.classes.firstWhere((c) => c.name == 'D');
|
|
expect(dClass.superclass!.superclass, same(bClass));
|
|
|
|
var dInterface = dClass.implementedTypes.first.classNode;
|
|
expect(dInterface, same(aClass));
|
|
}
|