blob: 256c28c2cbcca0c5458a8721f62ae10b2b941676 [file] [log] [blame]
// 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 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/commandline_options.dart';
import 'package:compiler/src/common_elements.dart';
import 'package:compiler/src/compiler.dart';
import 'package:compiler/src/elements/entities.dart';
import 'package:compiler/src/js_backend/annotations.dart' as optimizerHints;
import 'package:compiler/src/world.dart' show ClosedWorld;
import '../memory_compiler.dart';
const Map MEMORY_SOURCE_FILES = const {
'main.dart': r"""
import 'package:meta/dart2js.dart';
int method(String arg) => arg.length;
@noInline
int methodNoInline(String arg) => arg.length;
@tryInline
int methodTryInline(String arg) => arg.length;
void main(List<String> args) {
print(method(args[0]));
print(methodNoInline('bar'));
print(methodTryInline('bar'));
}
"""
};
main() {
runTests({bool useKernel}) async {
CompilationResult result = await runCompiler(
memorySourceFiles: MEMORY_SOURCE_FILES,
options: useKernel ? [] : [Flags.useOldFrontend]);
Compiler compiler = result.compiler;
ClosedWorld closedWorld =
compiler.resolutionWorldBuilder.closedWorldForTesting;
ElementEnvironment elementEnvironment = closedWorld.elementEnvironment;
Expect.isFalse(compiler.compilationFailed, 'Unsuccessful compilation');
Expect.isNotNull(closedWorld.commonElements.metaNoInlineClass,
'NoInlineClass is unresolved.');
Expect.isNotNull(closedWorld.commonElements.metaTryInlineClass,
'TryInlineClass is unresolved.');
void test(String name,
{bool expectNoInline: false, bool expectTryInline: false}) {
LibraryEntity mainLibrary = elementEnvironment.mainLibrary;
FunctionEntity method =
elementEnvironment.lookupLibraryMember(mainLibrary, name);
Expect.isNotNull(method);
Expect.equals(
expectNoInline,
optimizerHints.noInline(closedWorld.elementEnvironment,
closedWorld.commonElements, method),
"Unexpected annotation of @noInline on '$method'.");
Expect.equals(
expectTryInline,
optimizerHints.tryInline(closedWorld.elementEnvironment,
closedWorld.commonElements, method),
"Unexpected annotation of @tryInline on '$method'.");
}
test('method');
test('methodNoInline', expectNoInline: true);
test('methodTryInline', expectTryInline: true);
}
asyncTest(() async {
print('--test from ast---------------------------------------------------');
await runTests(useKernel: false);
print('--test from kernel------------------------------------------------');
await runTests(useKernel: true);
});
}