Skip to content

Commit 4b1180a

Browse files
a-sivacommit-bot@chromium.org
authored andcommitted
[VM] When --preview-dart-2 option is specified make the options
'--snapshot_kind=script --snapshot=xyz' produce a kernel dill file which is the equivalent of a script snapshot in Dart2 world. Change-Id: I7ba66eb86d9ecdfe1426b8b22b8d673598c4b71f Reviewed-on: https://dart-review.googlesource.com/52740 Commit-Queue: Siva Annamalai <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent 384a595 commit 4b1180a

10 files changed

+89
-47
lines changed

runtime/bin/dfe.cc

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ intptr_t kPlatformStrongDillSize = 0;
3333
namespace dart {
3434
namespace bin {
3535

36+
#if !defined(DART_PRECOMPILED_RUNTIME)
37+
DFE dfe;
38+
#endif
39+
3640
#if defined(DART_NO_SNAPSHOT) || defined(DART_PRECOMPILER)
3741
const uint8_t* kernel_service_dill = NULL;
3842
const intptr_t kernel_service_dill_size = 0;
@@ -213,11 +217,10 @@ class WindowsPathSanitizer {
213217
DISALLOW_COPY_AND_ASSIGN(WindowsPathSanitizer);
214218
};
215219

216-
void* DFE::CompileAndReadScript(const char* script_uri,
217-
char** error,
218-
int* exit_code,
219-
bool strong,
220-
const char* package_config) {
220+
Dart_KernelCompilationResult DFE::CompileScript(const char* script_uri,
221+
bool strong,
222+
bool incremental,
223+
const char* package_config) {
221224
// TODO(aam): When Frontend is ready, VM should be passing vm_outline.dill
222225
// instead of vm_platform.dill to Frontend for compilation.
223226
#if defined(HOST_OS_WINDOWS)
@@ -231,8 +234,18 @@ void* DFE::CompileAndReadScript(const char* script_uri,
231234
strong ? platform_strong_dill : platform_dill;
232235
intptr_t platform_binary_size =
233236
strong ? platform_strong_dill_size : platform_dill_size;
234-
Dart_KernelCompilationResult result = Dart_CompileToKernel(
235-
sanitized_uri, platform_binary, platform_binary_size, package_config);
237+
return Dart_CompileToKernel(sanitized_uri, platform_binary,
238+
platform_binary_size, incremental,
239+
package_config);
240+
}
241+
242+
void* DFE::CompileAndReadScript(const char* script_uri,
243+
char** error,
244+
int* exit_code,
245+
bool strong,
246+
const char* package_config) {
247+
Dart_KernelCompilationResult result =
248+
CompileScript(script_uri, strong, true, package_config);
236249
switch (result.status) {
237250
case Dart_KernelCompilationStatus_Ok:
238251
return Dart_ReadKernelBinary(result.kernel, result.kernel_size,

runtime/bin/dfe.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ class DFE {
4545
}
4646
void* application_kernel_binary() const { return application_kernel_binary_; }
4747

48-
// Compiles a script and reads the resulting kernel file.
48+
// Compiles specified script.
49+
// Returns result from compiling the script.
50+
Dart_KernelCompilationResult CompileScript(const char* script_uri,
51+
bool strong,
52+
bool incremental,
53+
const char* package_config);
54+
55+
// Compiles specified script and reads the resulting kernel file.
4956
// If the compilation is successful, returns a valid in memory kernel
5057
// representation of the script, NULL otherwise
5158
// 'error' and 'exit_code' have the error values in case of errors.
@@ -95,6 +102,10 @@ class DFE {
95102
DISALLOW_COPY_AND_ASSIGN(DFE);
96103
};
97104

105+
#if !defined(DART_PRECOMPILED_RUNTIME)
106+
extern DFE dfe;
107+
#endif
108+
98109
} // namespace bin
99110
} // namespace dart
100111

runtime/bin/gen_snapshot.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
namespace dart {
3737
namespace bin {
3838

39-
DFE dfe;
40-
4139
// Exit code indicating an API error.
4240
static const int kApiErrorExitCode = 253;
4341
// Exit code indicating a compilation error.

runtime/bin/main.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ const uint8_t* core_isolate_snapshot_instructions =
8080
* dart <app_snapshot_filename> [<script_options>]
8181
*/
8282
static bool vm_run_app_snapshot = false;
83-
#if !defined(DART_PRECOMPILED_RUNTIME)
84-
DFE dfe;
85-
#endif
86-
8783
static char* app_script_uri = NULL;
8884
static const uint8_t* app_isolate_snapshot_data = NULL;
8985
static const uint8_t* app_isolate_snapshot_instructions = NULL;
@@ -261,7 +257,7 @@ static Dart_Isolate IsolateSetupHelper(Dart_Isolate isolate,
261257
CHECK_RESULT(result);
262258

263259
#if !defined(DART_PRECOMPILED_RUNTIME)
264-
if (dfe.UseDartFrontend() && !isolate_run_app_snapshot &&
260+
if (Options::preview_dart_2() && !isolate_run_app_snapshot &&
265261
kernel_program == NULL && !Dart_IsKernelIsolate(isolate)) {
266262
if (!dfe.CanUseDartFrontend()) {
267263
const char* format = "Dart frontend unavailable to compile script %s.";
@@ -467,7 +463,7 @@ static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri,
467463
ASSERT(flags != NULL);
468464
flags->load_vmservice_library = true;
469465

470-
if (dfe.UseDartFrontend()) {
466+
if (Options::preview_dart_2()) {
471467
// If there is intention to use DFE, then we create the isolate
472468
// from kernel only if we can.
473469
void* platform_program = dfe.platform_program(flags->strong) != NULL
@@ -580,7 +576,7 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
580576
Dart_Isolate isolate = NULL;
581577

582578
#if !defined(DART_PRECOMPILED_RUNTIME)
583-
if (dfe.UseDartFrontend()) {
579+
if (Options::preview_dart_2()) {
584580
void* platform_program = dfe.platform_program(flags->strong) != NULL
585581
? dfe.platform_program(flags->strong)
586582
: kernel_program;
@@ -882,7 +878,12 @@ bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) {
882878
// the core snapshot.
883879
Platform::Exit(kErrorExitCode);
884880
}
885-
Snapshot::GenerateScript(Options::snapshot_filename());
881+
if (Options::preview_dart_2()) {
882+
Snapshot::GenerateKernel(Options::snapshot_filename(), script_name,
883+
flags.strong, Options::packages_file());
884+
} else {
885+
Snapshot::GenerateScript(Options::snapshot_filename());
886+
}
886887
} else {
887888
// Lookup the library of the root script.
888889
Dart_Handle root_lib = Dart_RootLibrary();
@@ -1161,9 +1162,9 @@ void main(int argc, char** argv) {
11611162
if (application_kernel_binary != NULL) {
11621163
// Since we loaded the script anyway, save it.
11631164
dfe.set_application_kernel_binary(application_kernel_binary);
1164-
// Since we saw a dill file, it means we have to use DFE for
1165-
// any further source file parsing.
1166-
dfe.set_use_dfe();
1165+
// Since we saw a dill file, it means we have to turn on all the
1166+
// preview_dart_2 options.
1167+
Options::SetPreviewDart2Options(&vm_options);
11671168
}
11681169
#endif
11691170

runtime/bin/main_options.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,19 @@ ENUM_OPTIONS_LIST(ENUM_OPTION_DEFINITION)
6363
CB_OPTIONS_LIST(CB_OPTION_DEFINITION)
6464
#undef CB_OPTION_DEFINITION
6565

66-
static bool checked_set = false;
67-
static bool preview_dart_2_set = false;
68-
69-
static void SetPreviewDart2Options(CommandLineOptions* vm_options) {
66+
void Options::SetPreviewDart2Options(CommandLineOptions* vm_options) {
7067
#if !defined(DART_PRECOMPILED_RUNTIME)
7168
Options::dfe()->set_use_dfe();
7269
#endif // !defined(DART_PRECOMPILED_RUNTIME)
73-
preview_dart_2_set = true;
70+
OPTION_FIELD(preview_dart_2) = true;
7471
vm_options->AddArgument("--strong");
7572
vm_options->AddArgument("--reify-generic-functions");
7673
vm_options->AddArgument("--limit-ints-to-64-bits");
7774
}
7875

79-
DEFINE_BOOL_OPTION_CB(preview_dart_2, { SetPreviewDart2Options(vm_options); });
76+
bool OPTION_FIELD(preview_dart_2) = false;
77+
DEFINE_BOOL_OPTION_CB(preview_dart_2,
78+
{ Options::SetPreviewDart2Options(vm_options); });
8079

8180
#if !defined(DART_PRECOMPILED_RUNTIME)
8281
DFE* Options::dfe_ = NULL;
@@ -326,6 +325,8 @@ bool Options::ProcessObserveOption(const char* arg,
326325
return true;
327326
}
328327

328+
static bool checked_set = false;
329+
329330
int Options::ParseArguments(int argc,
330331
char** argv,
331332
bool vm_run_app_snapshot,
@@ -457,7 +458,7 @@ int Options::ParseArguments(int argc,
457458
" run using a snapshot is invalid.\n");
458459
return -1;
459460
}
460-
if (checked_set && preview_dart_2_set) {
461+
if (checked_set && Options::preview_dart_2()) {
461462
Log::PrintErr("Flags --checked and --preview-dart-2 are not compatible.\n");
462463
return -1;
463464
}

runtime/bin/main_options.h

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ class Options {
107107
CB_OPTIONS_LIST(CB_OPTIONS_DECL)
108108
#undef CB_OPTIONS_DECL
109109

110+
static bool preview_dart_2() { return preview_dart_2_; }
111+
static void SetPreviewDart2Options(CommandLineOptions* vm_options);
112+
110113
static dart::HashMap* environment() { return environment_; }
111114

112115
static const char* vm_service_server_ip() { return vm_service_server_ip_; }
@@ -123,34 +126,24 @@ class Options {
123126
static void DestroyEnvironment();
124127

125128
private:
126-
#define STRING_OPTION_DECL(flag, variable) \
127-
static const char* variable##_; \
128-
static bool Process_##variable(const char* arg, \
129-
CommandLineOptions* vm_options);
129+
#define STRING_OPTION_DECL(flag, variable) static const char* variable##_;
130130
STRING_OPTIONS_LIST(STRING_OPTION_DECL)
131131
#undef STRING_OPTION_DECL
132132

133-
#define BOOL_OPTION_DECL(flag, variable) \
134-
static bool variable##_; \
135-
static bool Process_##variable(const char* arg, \
136-
CommandLineOptions* vm_options);
133+
#define BOOL_OPTION_DECL(flag, variable) static bool variable##_;
137134
BOOL_OPTIONS_LIST(BOOL_OPTION_DECL)
138135
#undef BOOL_OPTION_DECL
139136

140137
#define SHORT_BOOL_OPTION_DECL(short_name, long_name, variable) \
141-
static bool variable##_; \
142-
static bool Process_##variable(const char* arg, \
143-
CommandLineOptions* vm_options);
138+
static bool variable##_;
144139
SHORT_BOOL_OPTIONS_LIST(SHORT_BOOL_OPTION_DECL)
145140
#undef SHORT_BOOL_OPTION_DECL
146141

147-
#define ENUM_OPTION_DECL(flag, type, variable) \
148-
static type variable##_; \
149-
static bool Process_##variable(const char* arg, \
150-
CommandLineOptions* vm_options);
142+
#define ENUM_OPTION_DECL(flag, type, variable) static type variable##_;
151143
ENUM_OPTIONS_LIST(ENUM_OPTION_DECL)
152144
#undef ENUM_OPTION_DECL
153145

146+
static bool preview_dart_2_;
154147
static dart::HashMap* environment_;
155148

156149
// Frontend argument processing.
@@ -170,7 +163,7 @@ class Options {
170163
#define OPTION_FRIEND(flag, variable) friend class OptionProcessor_##flag;
171164
STRING_OPTIONS_LIST(OPTION_FRIEND)
172165
BOOL_OPTIONS_LIST(OPTION_FRIEND)
173-
#undef STRING_OPTION_FRIEND
166+
#undef OPTION_FRIEND
174167

175168
#define SHORT_BOOL_OPTION_FRIEND(short_name, long_name, variable) \
176169
friend class OptionProcessor_##long_name;
@@ -182,6 +175,8 @@ class Options {
182175
ENUM_OPTIONS_LIST(ENUM_OPTION_FRIEND)
183176
#undef ENUM_OPTION_FRIEND
184177

178+
friend class OptionProcessor_preview_dart_2;
179+
185180
DISALLOW_ALLOCATION();
186181
DISALLOW_IMPLICIT_CONSTRUCTORS(Options);
187182
};

runtime/bin/snapshot_utils.cc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "bin/snapshot_utils.h"
66

77
#include "bin/dartutils.h"
8+
#include "bin/dfe.h"
89
#include "bin/error_exit.h"
910
#include "bin/extensions.h"
1011
#include "bin/file.h"
@@ -241,7 +242,7 @@ AppSnapshot* Snapshot::TryReadAppSnapshot(const char* script_name) {
241242
if (snapshot != NULL) {
242243
return snapshot;
243244
}
244-
#endif // defined(DART_PRECOMPILED_RUNTIME)
245+
#endif // defined(DART_PRECOMPILED_RUNTIME)
245246
return NULL;
246247
}
247248

@@ -317,6 +318,22 @@ static void WriteAppSnapshot(const char* filename,
317318
file->Release();
318319
}
319320

321+
void Snapshot::GenerateKernel(const char* snapshot_filename,
322+
const char* script_name,
323+
bool strong,
324+
const char* package_config) {
325+
#if !defined(EXCLUDE_CFE_AND_KERNEL_PLATFORM) && !defined(TESTING)
326+
Dart_KernelCompilationResult result =
327+
dfe.CompileScript(script_name, strong, false, package_config);
328+
if (result.status != Dart_KernelCompilationStatus_Ok) {
329+
ErrorExit(kErrorExitCode, "%s\n", result.error);
330+
}
331+
WriteSnapshotFile(snapshot_filename, result.kernel, result.kernel_size);
332+
#else
333+
UNREACHABLE();
334+
#endif // !defined(EXCLUDE_CFE_AND_KERNEL_PLATFORM) && !defined(TESTING)
335+
}
336+
320337
void Snapshot::GenerateScript(const char* snapshot_filename) {
321338
// First create a snapshot.
322339
uint8_t* buffer = NULL;

runtime/bin/snapshot_utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class AppSnapshot {
2828

2929
class Snapshot {
3030
public:
31+
static void GenerateKernel(const char* snapshot_filename,
32+
const char* script_name,
33+
bool strong,
34+
const char* package_config);
3135
static void GenerateScript(const char* snapshot_filename);
3236
static void GenerateAppJIT(const char* snapshot_filename);
3337
static void GenerateAppAOTAsBlobs(const char* snapshot_filename,

runtime/include/dart_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3214,6 +3214,7 @@ DART_EXPORT Dart_KernelCompilationResult
32143214
Dart_CompileToKernel(const char* script_uri,
32153215
const uint8_t* platform_kernel,
32163216
const intptr_t platform_kernel_size,
3217+
bool incremental_compile,
32173218
const char* package_config);
32183219

32193220
typedef struct {

runtime/vm/dart_api_impl.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6011,6 +6011,7 @@ DART_EXPORT Dart_KernelCompilationResult
60116011
Dart_CompileToKernel(const char* script_uri,
60126012
const uint8_t* platform_kernel,
60136013
intptr_t platform_kernel_size,
6014+
bool incremental_compile,
60146015
const char* package_config) {
60156016
Dart_KernelCompilationResult result;
60166017
#if defined(DART_PRECOMPILED_RUNTIME)
@@ -6019,8 +6020,8 @@ Dart_CompileToKernel(const char* script_uri,
60196020
return result;
60206021
#else
60216022
result = KernelIsolate::CompileToKernel(script_uri, platform_kernel,
6022-
platform_kernel_size, 0, NULL, true,
6023-
package_config);
6023+
platform_kernel_size, 0, NULL,
6024+
incremental_compile, package_config);
60246025
if (result.status == Dart_KernelCompilationStatus_Ok) {
60256026
if (KernelIsolate::AcceptCompilation().status !=
60266027
Dart_KernelCompilationStatus_Ok) {

0 commit comments

Comments
 (0)