Skip to content

Commit

Permalink
Add support for --strong option in the engine, create a strong mode v…
Browse files Browse the repository at this point in the history
…ersion of the platform file (flutter#4504)

* Add a --strong option to the front end server so we can use strong mode with preview-dart-2.

* Plumb the --strong option through the dart controller into the VM.

* - Build a strong version of platform.dill for use with the engine.
- Fix a strong mode static error in the assert statement

* Enable asserts when running debug version even in strong mode.

* Use the correct platform dill file for linking when doing the aot builds.

* Fix formatting issue.
  • Loading branch information
a-siva authored Jan 4, 2018
1 parent fb0cfcd commit 0f0b144
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 8 deletions.
2 changes: 1 addition & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ group("flutter") {
testonly = true

public_deps = [
"$flutter_root/lib/snapshot:compile_platform",
"$flutter_root/lib/snapshot:kernel_platform_files",
"$flutter_root/lib/snapshot:generate_snapshot_bin",
"$flutter_root/sky",
"$flutter_root/third_party/txt",
Expand Down
1 change: 1 addition & 0 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct Settings {
bool enable_dart_profiling = false;
bool use_test_fonts = false;
bool dart_non_checked_mode = false;
bool dart_strong_mode = false;
bool enable_software_rendering = false;
bool using_blink = true;
std::string aot_shared_library_path;
Expand Down
11 changes: 8 additions & 3 deletions frontend_server/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ ArgParser _argParser = new ArgParser(allowTrailingOptions: true)
..addFlag('aot',
help: 'Run compiler in AOT mode (enables whole-program transformations)',
defaultsTo: false)
..addFlag('strong',
help: 'Run compiler in strong mode (uses strong mode semantics)',
defaultsTo: false)
..addFlag('link-platform',
help:
'When in batch mode, link platform kernel file into result kernel file.'
Expand Down Expand Up @@ -147,8 +150,8 @@ class _FrontendCompiler implements CompilerInterface {
? new FileByteStore(byteStorePath)
: new MemoryByteStore()
..sdkRoot = sdkRoot
..strongMode = false
..target = new FlutterTarget(new TargetFlags())
..strongMode = options['strong']
..target = new FlutterTarget(new TargetFlags(strongMode: options['strong']))
..reportMessages = true;

Program program;
Expand All @@ -165,8 +168,10 @@ class _FrontendCompiler implements CompilerInterface {
if (options['link-platform']) {
// TODO(aam): Remove linkedDependencies once platform is directly embedded
// into VM snapshot and http://dartbug.com/30111 is fixed.
final String platformKernelDill =
options['strong'] ? 'platform_strong.dill' : 'platform.dill';
compilerOptions.linkedDependencies = <Uri>[
sdkRoot.resolve('platform.dill')
sdkRoot.resolve(platformKernelDill)
];
}
program = await _runWithPrintRedirection(() =>
Expand Down
54 changes: 54 additions & 0 deletions frontend_server/test/server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ Future<int> main() async {
)
).captured;
expect(capturedArgs.single['sdk-root'], equals('sdkroot'));
expect(capturedArgs.single['strong'], equals(false));
});

test('compile from command line (strong mode)', () async {
final List<String> args = <String>[
'server.dart',
'--sdk-root',
'sdkroot',
'--strong',
];
final int exitcode = await starter(args, compiler: compiler);
expect(exitcode, equals(0));
final List<ArgResults> capturedArgs =
verify(
compiler.compile(
argThat(equals('server.dart')),
captureAny,
generator: any,
)
).captured;
expect(capturedArgs.single['sdk-root'], equals('sdkroot'));
expect(capturedArgs.single['strong'], equals(true));
});

test('compile from command line with file byte store', () async {
Expand All @@ -73,6 +95,7 @@ Future<int> main() async {
).captured;
expect(capturedArgs.single['sdk-root'], equals('sdkroot'));
expect(capturedArgs.single['byte-store'], equals('path/to/bytestore'));
expect(capturedArgs.single['strong'], equals(false));
});

test('compile from command line with link platform', () async {
Expand All @@ -94,6 +117,7 @@ Future<int> main() async {
).captured;
expect(capturedArgs.single['sdk-root'], equals('sdkroot'));
expect(capturedArgs.single['link-platform'], equals(true));
expect(capturedArgs.single['strong'], equals(false));
});
});

Expand All @@ -118,6 +142,7 @@ Future<int> main() async {
equals('sdkroot'));
expect(invocation.positionalArguments[1]['byte-store'],
equals('path/to/bytestore'));
expect(invocation.positionalArguments[1]['strong'], equals(false));
compileCalled.sendPort.send(true);
}
);
Expand All @@ -139,6 +164,11 @@ Future<int> main() async {
'--sdk-root',
'sdkroot',
];
final List<String> strongArgs = <String>[
'--sdk-root',
'sdkroot',
'--strong',
];

test('compile one file', () async {
final StreamController<List<int>> inputStreamController =
Expand All @@ -148,6 +178,7 @@ Future<int> main() async {
(Invocation invocation) {
expect(invocation.positionalArguments[0], equals('server.dart'));
expect(invocation.positionalArguments[1]['sdk-root'], equals('sdkroot'));
expect(invocation.positionalArguments[1]['strong'], equals(false));
compileCalled.sendPort.send(true);
}
);
Expand All @@ -160,6 +191,28 @@ Future<int> main() async {
await compileCalled.first;
inputStreamController.close();
});

test('compile one file (strong mode)', () async {
final StreamController<List<int>> inputStreamController =
new StreamController<List<int>>();
final ReceivePort compileCalled = new ReceivePort();
when(compiler.compile(any, any, generator: any)).thenAnswer(
(Invocation invocation) {
expect(invocation.positionalArguments[0], equals('server.dart'));
expect(invocation.positionalArguments[1]['sdk-root'], equals('sdkroot'));
expect(invocation.positionalArguments[1]['strong'], equals(true));
compileCalled.sendPort.send(true);
}
);

final int exitcode = await starter(strongArgs, compiler: compiler,
input: inputStreamController.stream,
);
expect(exitcode, equals(0));
inputStreamController.add('compile server.dart\n'.codeUnits);
await compileCalled.first;
inputStreamController.close();
});

test('compile few files', () async {
final StreamController<List<int>> streamController =
Expand All @@ -170,6 +223,7 @@ Future<int> main() async {
(Invocation invocation) {
expect(invocation.positionalArguments[0], equals('server${counter++}.dart'));
expect(invocation.positionalArguments[1]['sdk-root'], equals('sdkroot'));
expect(invocation.positionalArguments[1]['strong'], equals(false));
compileCalled.sendPort.send(true);
}
);
Expand Down
39 changes: 38 additions & 1 deletion lib/snapshot/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,13 @@ generate_vm_patched_sdk("flutter_patched_sdk") {
]
}

action("compile_platform") {
action("compile_non_strong_platform") {
script = "//third_party/dart/tools/compile_platform.py"

visibility = [
":kernel_platform_files"
]

sources = [
"$root_out_dir/flutter_patched_sdk/lib/libraries.json",
]
Expand All @@ -423,8 +427,41 @@ action("compile_platform") {
rebase_path(outputs, root_build_dir)
}

action("compile_platform") {
script = "//third_party/dart/tools/compile_platform.py"

visibility = [
":kernel_platform_files"
]

sources = [
"$root_out_dir/flutter_patched_sdk/lib/libraries.json",
]

outputs = [
"$root_out_dir/flutter_patched_sdk/platform_strong.dill",
"$root_out_dir/flutter_patched_sdk/vm_outline_strong.dill",
]

inputs = []

deps = [
":flutter_patched_sdk",
]

depfile = "$root_out_dir/flutter_patched_sdk/platform_strong.dill.d"

args = [
"--target=flutter",
"--strong",
"dart:core"
] + rebase_path(sources, root_build_dir) +
rebase_path(outputs, root_build_dir)
}

group("kernel_platform_files") {
public_deps = [
":compile_platform",
":compile_non_strong_platform",
]
}
2 changes: 1 addition & 1 deletion lib/ui/natives.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void _setupHooks() {
// In debug mode, register the schedule frame extension.
developer.registerExtension('ext.ui.window.scheduleFrame', _scheduleFrame);
return true;
});
}());
}

void _scheduleMicrotask(void callback()) native "ScheduleMicrotask";
Expand Down
26 changes: 24 additions & 2 deletions runtime/dart_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,28 @@ static const char* kDartWriteProtectCodeArgs[] FXL_ALLOW_UNUSED_TYPE = {
"--no_write_protect_code",
};

static const char* kDartCheckedModeArgs[] = {
static const char* kDartAssertArgs[] = {
// clang-format off
"--enable_asserts",
// clang-format on
};

static const char* kDartCheckedModeArgs[] = {
// clang-format off
"--enable_type_checks",
"--error_on_bad_type",
"--error_on_bad_override",
// clang-format on
};

static const char* kDartStrongModeArgs[] = {
// clang-format off
"--strong",
"--reify_generic_functions",
"--limit_ints_to_64_bits",
// clang-format on
};

static const char* kDartStartPausedArgs[]{
"--pause_isolates_on_start",
};
Expand Down Expand Up @@ -584,8 +597,17 @@ void InitDartVM(const uint8_t* vm_snapshot_data,
arraysize(kDartWriteProtectCodeArgs));
#endif

if (use_checked_mode)
if (settings.dart_strong_mode) {
// In strong mode we enable all the strong mode options and if running
// debug product mode we also enable asserts.
PushBackAll(&args, kDartStrongModeArgs, arraysize(kDartStrongModeArgs));
if (use_checked_mode) {
PushBackAll(&args, kDartAssertArgs, arraysize(kDartAssertArgs));
}
} else if (use_checked_mode) {
PushBackAll(&args, kDartAssertArgs, arraysize(kDartAssertArgs));
PushBackAll(&args, kDartCheckedModeArgs, arraysize(kDartCheckedModeArgs));
}

if (settings.start_paused)
PushBackAll(&args, kDartStartPausedArgs, arraysize(kDartStartPausedArgs));
Expand Down
4 changes: 4 additions & 0 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ void Shell::InitStandalone(fxl::CommandLine command_line,
settings.dart_non_checked_mode =
command_line.HasOption(FlagForSwitch(Switch::DartNonCheckedMode));

// strong mode setting.
settings.dart_strong_mode =
command_line.HasOption(FlagForSwitch(Switch::DartStrongMode));

settings.ipv6 = command_line.HasOption(FlagForSwitch(Switch::IPv6));

settings.start_paused =
Expand Down
1 change: 1 addition & 0 deletions shell/common/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ DEF_SWITCH(DartNonCheckedMode,
"precompiled and checked mode is unsupported. However, this flag "
"may be specified if the user wishes to run in the debug product "
"mode (i.e. with JIT or DBC) with checked mode off.")
DEF_SWITCH(DartStrongMode, "strong", "Enable Dart 2.0 strong mode.")
DEF_SWITCHES_END

void PrintUsage(const std::string& executable_name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ private static String[] getArgsFromIntent(Intent intent) {
if (intent.getBooleanExtra("trace-skia", false)) {
args.add("--trace-skia");
}
if (intent.getBooleanExtra("strong", false)) {
args.add("--strong");
}
if (!args.isEmpty()) {
String[] argsArray = new String[args.size()];
return args.toArray(argsArray);
Expand Down

0 comments on commit 0f0b144

Please sign in to comment.