mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 13:35:05 +00:00
[Kernel/VM] Introduce VM-specific translation of Dart sources to kernel
This CL introduces compileToKernel() function in package:vm/kernel_front_end as the replacement for kernelForProgram() from package:front_end/kernel_generator. The new function will be used to customize kernel Programs for VM need. For example, it will perform additional AOT-specific global transformations. In future, compileToKernel() will be used from Flutter and precompiler2. Also, this CL cleans up Target.strongModeSdk as it is no longer used. Issue: https://github.com/dart-lang/sdk/issues/30480 Change-Id: Ib9c2b5d0af955475292df8e456073a5f0e6a64be Reviewed-on: https://dart-review.googlesource.com/25080 Reviewed-by: Vyacheslav Egorov <vegorov@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
parent
be65ed0704
commit
39f049d643
|
@ -101,6 +101,7 @@ typed_mock:pkg/typed_mock/lib
|
|||
unittest:third_party/pkg/unittest/lib
|
||||
usage:third_party/pkg/usage/lib
|
||||
utf:third_party/pkg/utf/lib
|
||||
vm:pkg/vm/lib
|
||||
watcher:third_party/pkg/watcher/lib
|
||||
# Note: this is pointing to the observatory_pub_packages version of pkg/observe
|
||||
web_components:third_party/observatory_pub_packages/packages/web_components/lib
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
library kernel.target.implementation_options;
|
||||
|
||||
class VmOptions {
|
||||
// TODO(alexmarkov): Cleanup this option.
|
||||
// Consider cleaning up implementation_options.
|
||||
static final ImplementationOption strongAOT = new ImplementationOption._(
|
||||
"strong-aot", Platform.vm, new DateTime.utc(2018, 1), """
|
||||
Enables strong-mode whole-program optimizations for AOT (precompiler) mode of
|
||||
|
|
|
@ -79,9 +79,6 @@ abstract class Target {
|
|||
/// promotion do not slow down compilation too much.
|
||||
bool get disableTypeInference => false;
|
||||
|
||||
/// If true, the SDK should be loaded in strong mode.
|
||||
bool get strongModeSdk => strongMode;
|
||||
|
||||
/// Perform target-specific modular transformations on the given program.
|
||||
///
|
||||
/// These transformations should not be whole-program transformations. They
|
||||
|
|
|
@ -11,10 +11,7 @@ import '../transformations/mixin_full_resolution.dart' as transformMixins
|
|||
show transformLibraries;
|
||||
import '../transformations/continuation.dart' as transformAsync
|
||||
show transformLibraries;
|
||||
import '../transformations/precompiler.dart' as transformPrecompiler
|
||||
show transformProgram;
|
||||
|
||||
import 'implementation_option.dart' show VmOptions;
|
||||
import 'targets.dart';
|
||||
|
||||
/// Specializes the kernel IR to the Dart VM.
|
||||
|
@ -26,12 +23,6 @@ class VmTarget extends Target {
|
|||
@override
|
||||
bool get strongMode => flags.strongMode;
|
||||
|
||||
/// The VM patch files are not strong mode clean, so we adopt a hybrid mode
|
||||
/// where the SDK is internally unchecked, but trusted to satisfy the types
|
||||
/// declared on its interface.
|
||||
@override
|
||||
bool get strongModeSdk => false;
|
||||
|
||||
@override
|
||||
String get name => 'vm';
|
||||
|
||||
|
@ -75,13 +66,7 @@ class VmTarget extends Target {
|
|||
|
||||
@override
|
||||
void performGlobalTransformations(CoreTypes coreTypes, Program program,
|
||||
{void logger(String msg)}) {
|
||||
if (strongMode &&
|
||||
(flags.implementationOptions != null) &&
|
||||
flags.implementationOptions.contains(VmOptions.strongAOT)) {
|
||||
transformPrecompiler.transformProgram(coreTypes, program);
|
||||
}
|
||||
}
|
||||
{void logger(String msg)}) {}
|
||||
|
||||
@override
|
||||
Expression instantiateInvocation(CoreTypes coreTypes, Expression receiver,
|
||||
|
|
43
pkg/vm/lib/kernel_front_end.dart
Normal file
43
pkg/vm/lib/kernel_front_end.dart
Normal file
|
@ -0,0 +1,43 @@
|
|||
// 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.
|
||||
|
||||
/// Defines the VM-specific translation of Dart source code to kernel binaries.
|
||||
library vm.kernel_front_end;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:front_end/compiler_options.dart';
|
||||
import 'package:front_end/kernel_generator.dart' show kernelForProgram;
|
||||
import 'package:kernel/ast.dart' show Program;
|
||||
import 'package:kernel/core_types.dart' show CoreTypes;
|
||||
|
||||
// TODO(alexmarkov): Move this transformation to pkg/vm.
|
||||
import 'package:kernel/transformations/precompiler.dart' as transformPrecompiler
|
||||
show transformProgram;
|
||||
|
||||
/// Generates a kernel representation of the program whose main library is in
|
||||
/// the given [source]. Intended for whole program (non-modular) compilation.
|
||||
///
|
||||
/// VM-specific replacement of [kernelForProgram].
|
||||
///
|
||||
Future<Program> compileToKernel(Uri source, CompilerOptions options,
|
||||
{bool aot: false}) async {
|
||||
final program = await kernelForProgram(source, options);
|
||||
|
||||
if (aot) {
|
||||
_runGlobalTransformations(program, options.strongMode);
|
||||
}
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
_runGlobalTransformations(Program program, bool strongMode) {
|
||||
final coreTypes = new CoreTypes(program);
|
||||
|
||||
// TODO(alexmarkov): AOT-specific whole-program transformations.
|
||||
|
||||
if (strongMode) {
|
||||
transformPrecompiler.transformProgram(coreTypes, program);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue