Skip to content

Commit cb93b8d

Browse files
mralephcommit-bot@chromium.org
authored andcommitted
[vm] Plumb enable_asserts to CFE through VM and kernel_front_end
When constant-update-2018 is enable it would be CFE's responsibility to report compile time errors when assert in a constant fails. Change-Id: Icfa5e9c1756439cdd46bdbaf5c7fb8124c24becf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108723 Reviewed-by: Samir Jindel <[email protected]> Commit-Queue: Vyacheslav Egorov <[email protected]> Auto-Submit: Vyacheslav Egorov <[email protected]>
1 parent bae176b commit cb93b8d

File tree

3 files changed

+33
-38
lines changed

3 files changed

+33
-38
lines changed

pkg/vm/bin/kernel_service.dart

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,19 @@ bool allowDartInternalImport = false;
7070
abstract class Compiler {
7171
final FileSystem fileSystem;
7272
final Uri platformKernelPath;
73-
bool suppressWarnings;
74-
List<String> experimentalFlags;
75-
bool bytecode;
76-
String packageConfig;
73+
final bool suppressWarnings;
74+
final bool enableAsserts;
75+
final List<String> experimentalFlags;
76+
final bool bytecode;
77+
final String packageConfig;
7778

7879
final List<String> errors = new List<String>();
7980

8081
CompilerOptions options;
8182

8283
Compiler(this.fileSystem, this.platformKernelPath,
8384
{this.suppressWarnings: false,
85+
this.enableAsserts: false,
8486
this.experimentalFlags: null,
8587
this.bytecode: false,
8688
this.packageConfig: null}) {
@@ -116,6 +118,7 @@ abstract class Compiler {
116118
..experimentalFlags =
117119
parseExperimentalFlags(expFlags, (msg) => errors.add(msg))
118120
..environmentDefines = new EnvironmentMap()
121+
..enableAsserts = enableAsserts
119122
..onDiagnostic = (DiagnosticMessage message) {
120123
bool printMessage;
121124
switch (message.severity) {
@@ -148,11 +151,10 @@ abstract class Compiler {
148151
await runWithFrontEndCompilerContext(script, options, component, () {
149152
// TODO(alexmarkov): disable source positions, local variables info,
150153
// debugger stops and source files in VM PRODUCT mode.
151-
// TODO(alexmarkov): disable asserts if they are not enabled in VM.
152154
// TODO(rmacnak): disable annotations if mirrors are not enabled.
153155
generateBytecode(component,
154156
options: new BytecodeOptions(
155-
enableAsserts: true,
157+
enableAsserts: enableAsserts,
156158
environmentDefines: options.environmentDefines,
157159
emitSourcePositions: true,
158160
emitLocalVarInfo: true,
@@ -210,11 +212,13 @@ class IncrementalCompilerWrapper extends Compiler {
210212

211213
IncrementalCompilerWrapper(FileSystem fileSystem, Uri platformKernelPath,
212214
{bool suppressWarnings: false,
215+
bool enableAsserts: false,
213216
List<String> experimentalFlags: null,
214217
bool bytecode: false,
215218
String packageConfig: null})
216219
: super(fileSystem, platformKernelPath,
217220
suppressWarnings: suppressWarnings,
221+
enableAsserts: enableAsserts,
218222
experimentalFlags: experimentalFlags,
219223
bytecode: bytecode,
220224
packageConfig: packageConfig);
@@ -235,6 +239,7 @@ class IncrementalCompilerWrapper extends Compiler {
235239
IncrementalCompilerWrapper clone = IncrementalCompilerWrapper(
236240
fileSystem, platformKernelPath,
237241
suppressWarnings: suppressWarnings,
242+
enableAsserts: enableAsserts,
238243
experimentalFlags: experimentalFlags,
239244
bytecode: bytecode,
240245
packageConfig: packageConfig);
@@ -263,11 +268,13 @@ class SingleShotCompilerWrapper extends Compiler {
263268
SingleShotCompilerWrapper(FileSystem fileSystem, Uri platformKernelPath,
264269
{this.requireMain: false,
265270
bool suppressWarnings: false,
271+
bool enableAsserts: false,
266272
List<String> experimentalFlags: null,
267273
bool bytecode: false,
268274
String packageConfig: null})
269275
: super(fileSystem, platformKernelPath,
270276
suppressWarnings: suppressWarnings,
277+
enableAsserts: enableAsserts,
271278
experimentalFlags: experimentalFlags,
272279
bytecode: bytecode,
273280
packageConfig: packageConfig);
@@ -292,6 +299,7 @@ IncrementalCompilerWrapper lookupIncrementalCompiler(int isolateId) {
292299
Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateId,
293300
List sourceFiles, Uri platformKernelPath, List<int> platformKernel,
294301
{bool suppressWarnings: false,
302+
bool enableAsserts: false,
295303
List<String> experimentalFlags: null,
296304
bool bytecode: false,
297305
String packageConfig: null,
@@ -321,6 +329,7 @@ Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateId,
321329
// isolate was shut down. Message should be handled here in this script.
322330
compiler = new IncrementalCompilerWrapper(fileSystem, platformKernelPath,
323331
suppressWarnings: suppressWarnings,
332+
enableAsserts: enableAsserts,
324333
experimentalFlags: experimentalFlags,
325334
bytecode: bytecode,
326335
packageConfig: packageConfig);
@@ -499,12 +508,13 @@ Future _processLoadRequest(request) async {
499508
final int isolateId = request[6];
500509
final List sourceFiles = request[7];
501510
final bool suppressWarnings = request[8];
511+
final bool enableAsserts = request[9];
502512
final List<String> experimentalFlags =
503-
request[9] != null ? request[9].cast<String>() : null;
504-
final bool bytecode = request[10];
505-
final String packageConfig = request[11];
506-
final String multirootFilepaths = request[12];
507-
final String multirootScheme = request[13];
513+
request[10] != null ? request[10].cast<String>() : null;
514+
final bool bytecode = request[11];
515+
final String packageConfig = request[12];
516+
final String multirootFilepaths = request[13];
517+
final String multirootScheme = request[14];
508518

509519
if (bytecode) {
510520
// Bytecode generator is hooked into kernel service after kernel component
@@ -568,6 +578,7 @@ Future _processLoadRequest(request) async {
568578
compiler = await lookupOrBuildNewIncrementalCompiler(
569579
isolateId, sourceFiles, platformKernelPath, platformKernel,
570580
suppressWarnings: suppressWarnings,
581+
enableAsserts: enableAsserts,
571582
experimentalFlags: experimentalFlags,
572583
bytecode: bytecode,
573584
packageConfig: packageConfig,
@@ -579,6 +590,7 @@ Future _processLoadRequest(request) async {
579590
compiler = new SingleShotCompilerWrapper(fileSystem, platformKernelPath,
580591
requireMain: false,
581592
suppressWarnings: suppressWarnings,
593+
enableAsserts: enableAsserts,
582594
experimentalFlags: experimentalFlags,
583595
bytecode: bytecode,
584596
packageConfig: packageConfig);
@@ -704,6 +716,7 @@ train(String scriptUri, String platformKernelPath) {
704716
1 /* isolateId chosen randomly */,
705717
[] /* source files */,
706718
false /* suppress warnings */,
719+
false /* enable asserts */,
707720
null /* experimental_flags */,
708721
false /* generate bytecode */,
709722
null /* package_config */,

pkg/vm/lib/kernel_front_end.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ Future<int> runCompiler(ArgResults options, String usage) async {
215215
..linkedDependencies = linkedDependencies
216216
..packagesFileUri = packagesUri
217217
..experimentalFlags = parseExperimentalFlags(experimentalFlags, print)
218+
..enableAsserts = enableAsserts
218219
..onDiagnostic = (DiagnosticMessage m) {
219220
errorDetector(m);
220221
}

runtime/vm/kernel_isolate.cc

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -485,23 +485,6 @@ class KernelCompilationRequest : public ValueObject {
485485
isolate_id.value.as_int64 =
486486
isolate != NULL ? static_cast<int64_t>(isolate->main_port()) : 0;
487487

488-
Dart_CObject suppress_warnings;
489-
suppress_warnings.type = Dart_CObject_kBool;
490-
suppress_warnings.value.as_bool = FLAG_suppress_fe_warnings;
491-
492-
intptr_t num_experimental_flags = experimental_flags->length();
493-
Dart_CObject** experimental_flags_array =
494-
new Dart_CObject*[num_experimental_flags];
495-
for (intptr_t i = 0; i < num_experimental_flags; ++i) {
496-
experimental_flags_array[i] = new Dart_CObject;
497-
experimental_flags_array[i]->type = Dart_CObject_kString;
498-
experimental_flags_array[i]->value.as_string = (*experimental_flags)[i];
499-
}
500-
Dart_CObject experimental_flags_object;
501-
experimental_flags_object.type = Dart_CObject_kArray;
502-
experimental_flags_object.value.as_array.values = experimental_flags_array;
503-
experimental_flags_object.value.as_array.length = num_experimental_flags;
504-
505488
Dart_CObject message;
506489
message.type = Dart_CObject_kArray;
507490
Dart_CObject* message_arr[] = {&tag,
@@ -512,9 +495,7 @@ class KernelCompilationRequest : public ValueObject {
512495
&type_definitions_object,
513496
&library_uri_object,
514497
&class_object,
515-
&is_static_object,
516-
&suppress_warnings,
517-
&experimental_flags_object};
498+
&is_static_object};
518499
message.value.as_array.values = message_arr;
519500
message.value.as_array.length = ARRAY_SIZE(message_arr);
520501

@@ -542,11 +523,6 @@ class KernelCompilationRequest : public ValueObject {
542523
}
543524
delete[] type_definitions_array;
544525

545-
for (intptr_t i = 0; i < num_experimental_flags; ++i) {
546-
delete experimental_flags_array[i];
547-
}
548-
delete[] experimental_flags_array;
549-
550526
return result_;
551527
}
552528

@@ -563,8 +539,7 @@ class KernelCompilationRequest : public ValueObject {
563539
const char* multiroot_filepaths,
564540
const char* multiroot_scheme,
565541
const MallocGrowableArray<char*>* experimental_flags) {
566-
// Build the [null, send_port, script_uri, platform_kernel,
567-
// incremental_compile, isolate_id, [files]] message for the Kernel isolate.
542+
// Build the message for the Kernel isolate.
568543
// tag is used to specify which operation the frontend should perform.
569544
Dart_CObject tag;
570545
tag.type = Dart_CObject_kInt32;
@@ -632,6 +607,11 @@ class KernelCompilationRequest : public ValueObject {
632607
suppress_warnings.type = Dart_CObject_kBool;
633608
suppress_warnings.value.as_bool = FLAG_suppress_fe_warnings;
634609

610+
Dart_CObject enable_asserts;
611+
enable_asserts.type = Dart_CObject_kBool;
612+
enable_asserts.value.as_bool =
613+
isolate != NULL ? isolate->asserts() : FLAG_enable_asserts;
614+
635615
intptr_t num_experimental_flags = experimental_flags->length();
636616
Dart_CObject** experimental_flags_array =
637617
new Dart_CObject*[num_experimental_flags];
@@ -700,6 +680,7 @@ class KernelCompilationRequest : public ValueObject {
700680
&isolate_id,
701681
&files,
702682
&suppress_warnings,
683+
&enable_asserts,
703684
&experimental_flags_object,
704685
&bytecode,
705686
&package_config_uri,

0 commit comments

Comments
 (0)