mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:29:47 +00:00
[vm] Fix --enable-mirrors VM flag to affect environment and conditional imports
This change propagates --enable-mirrors VM flag to CFE via TargetFlags.supportMirrors. CFE uses that to select conditional imports and for constant evaluation of bool.fromEnvironment. TEST=runtime/tests/vm/dart/enable_mirrors_test Issue: https://github.com/dart-lang/sdk/issues/49266 Change-Id: I9f6b03f1ab224d13cbe9f035fb5b6fa6eb59055c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249020 Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
parent
a60df664b3
commit
8bc1cda3f7
|
@ -95,7 +95,8 @@ CompilerOptions setupCompilerOptions(
|
||||||
List<String> errorsPlain,
|
List<String> errorsPlain,
|
||||||
List<String> errorsColorized,
|
List<String> errorsColorized,
|
||||||
String invocationModes,
|
String invocationModes,
|
||||||
String verbosityLevel) {
|
String verbosityLevel,
|
||||||
|
bool enableMirrors) {
|
||||||
final expFlags = <String>[];
|
final expFlags = <String>[];
|
||||||
if (experimentalFlags != null) {
|
if (experimentalFlags != null) {
|
||||||
for (String flag in experimentalFlags) {
|
for (String flag in experimentalFlags) {
|
||||||
|
@ -107,7 +108,8 @@ CompilerOptions setupCompilerOptions(
|
||||||
return new CompilerOptions()
|
return new CompilerOptions()
|
||||||
..fileSystem = fileSystem
|
..fileSystem = fileSystem
|
||||||
..target = new VmTarget(new TargetFlags(
|
..target = new VmTarget(new TargetFlags(
|
||||||
enableNullSafety: nullSafety == kNullSafetyOptionStrong))
|
enableNullSafety: nullSafety == kNullSafetyOptionStrong,
|
||||||
|
supportMirrors: enableMirrors))
|
||||||
..packagesFileUri = packagesUri
|
..packagesFileUri = packagesUri
|
||||||
..sdkSummary = platformKernelPath
|
..sdkSummary = platformKernelPath
|
||||||
..verbose = verbose
|
..verbose = verbose
|
||||||
|
@ -165,6 +167,7 @@ abstract class Compiler {
|
||||||
final String? packageConfig;
|
final String? packageConfig;
|
||||||
final String invocationModes;
|
final String invocationModes;
|
||||||
final String verbosityLevel;
|
final String verbosityLevel;
|
||||||
|
final bool enableMirrors;
|
||||||
|
|
||||||
// Code coverage and hot reload are only supported by incremental compiler,
|
// Code coverage and hot reload are only supported by incremental compiler,
|
||||||
// which is used if vm-service is enabled.
|
// which is used if vm-service is enabled.
|
||||||
|
@ -184,7 +187,8 @@ abstract class Compiler {
|
||||||
this.supportHotReload: false,
|
this.supportHotReload: false,
|
||||||
this.packageConfig: null,
|
this.packageConfig: null,
|
||||||
this.invocationModes: '',
|
this.invocationModes: '',
|
||||||
this.verbosityLevel: Verbosity.defaultValue}) {
|
this.verbosityLevel: Verbosity.defaultValue,
|
||||||
|
required this.enableMirrors}) {
|
||||||
Uri? packagesUri = null;
|
Uri? packagesUri = null;
|
||||||
final packageConfig = this.packageConfig ?? Platform.packageConfig;
|
final packageConfig = this.packageConfig ?? Platform.packageConfig;
|
||||||
if (packageConfig != null) {
|
if (packageConfig != null) {
|
||||||
|
@ -208,7 +212,8 @@ abstract class Compiler {
|
||||||
errorsPlain,
|
errorsPlain,
|
||||||
errorsColorized,
|
errorsColorized,
|
||||||
invocationModes,
|
invocationModes,
|
||||||
verbosityLevel);
|
verbosityLevel,
|
||||||
|
enableMirrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<CompilerResult> compile(Uri script) {
|
Future<CompilerResult> compile(Uri script) {
|
||||||
|
@ -295,7 +300,8 @@ class IncrementalCompilerWrapper extends Compiler {
|
||||||
List<String>? experimentalFlags,
|
List<String>? experimentalFlags,
|
||||||
String? packageConfig,
|
String? packageConfig,
|
||||||
String invocationModes: '',
|
String invocationModes: '',
|
||||||
String verbosityLevel: Verbosity.defaultValue})
|
String verbosityLevel: Verbosity.defaultValue,
|
||||||
|
required bool enableMirrors})
|
||||||
: super(isolateGroupId, fileSystem, platformKernelPath,
|
: super(isolateGroupId, fileSystem, platformKernelPath,
|
||||||
enableAsserts: enableAsserts,
|
enableAsserts: enableAsserts,
|
||||||
nullSafety: nullSafety,
|
nullSafety: nullSafety,
|
||||||
|
@ -304,7 +310,8 @@ class IncrementalCompilerWrapper extends Compiler {
|
||||||
supportCodeCoverage: true,
|
supportCodeCoverage: true,
|
||||||
packageConfig: packageConfig,
|
packageConfig: packageConfig,
|
||||||
invocationModes: invocationModes,
|
invocationModes: invocationModes,
|
||||||
verbosityLevel: verbosityLevel);
|
verbosityLevel: verbosityLevel,
|
||||||
|
enableMirrors: enableMirrors);
|
||||||
|
|
||||||
factory IncrementalCompilerWrapper.forExpressionCompilationOnly(
|
factory IncrementalCompilerWrapper.forExpressionCompilationOnly(
|
||||||
Component component,
|
Component component,
|
||||||
|
@ -314,13 +321,15 @@ class IncrementalCompilerWrapper extends Compiler {
|
||||||
{bool enableAsserts: false,
|
{bool enableAsserts: false,
|
||||||
List<String>? experimentalFlags,
|
List<String>? experimentalFlags,
|
||||||
String? packageConfig,
|
String? packageConfig,
|
||||||
String invocationModes: ''}) {
|
String invocationModes: '',
|
||||||
|
required bool enableMirrors}) {
|
||||||
IncrementalCompilerWrapper result = IncrementalCompilerWrapper(
|
IncrementalCompilerWrapper result = IncrementalCompilerWrapper(
|
||||||
isolateGroupId, fileSystem, platformKernelPath,
|
isolateGroupId, fileSystem, platformKernelPath,
|
||||||
enableAsserts: enableAsserts,
|
enableAsserts: enableAsserts,
|
||||||
experimentalFlags: experimentalFlags,
|
experimentalFlags: experimentalFlags,
|
||||||
packageConfig: packageConfig,
|
packageConfig: packageConfig,
|
||||||
invocationModes: invocationModes);
|
invocationModes: invocationModes,
|
||||||
|
enableMirrors: enableMirrors);
|
||||||
result.generator = new IncrementalCompiler.forExpressionCompilationOnly(
|
result.generator = new IncrementalCompiler.forExpressionCompilationOnly(
|
||||||
component,
|
component,
|
||||||
result.options,
|
result.options,
|
||||||
|
@ -349,7 +358,8 @@ class IncrementalCompilerWrapper extends Compiler {
|
||||||
nullSafety: nullSafety,
|
nullSafety: nullSafety,
|
||||||
experimentalFlags: experimentalFlags,
|
experimentalFlags: experimentalFlags,
|
||||||
packageConfig: packageConfig,
|
packageConfig: packageConfig,
|
||||||
invocationModes: invocationModes);
|
invocationModes: invocationModes,
|
||||||
|
enableMirrors: enableMirrors);
|
||||||
final generator = this.generator!;
|
final generator = this.generator!;
|
||||||
// TODO(VM TEAM): This does not seem safe. What if cloning while having
|
// TODO(VM TEAM): This does not seem safe. What if cloning while having
|
||||||
// pending deltas for instance?
|
// pending deltas for instance?
|
||||||
|
@ -384,14 +394,16 @@ class SingleShotCompilerWrapper extends Compiler {
|
||||||
List<String>? experimentalFlags,
|
List<String>? experimentalFlags,
|
||||||
String? packageConfig,
|
String? packageConfig,
|
||||||
String invocationModes: '',
|
String invocationModes: '',
|
||||||
String verbosityLevel: Verbosity.defaultValue})
|
String verbosityLevel: Verbosity.defaultValue,
|
||||||
|
required bool enableMirrors})
|
||||||
: super(isolateGroupId, fileSystem, platformKernelPath,
|
: super(isolateGroupId, fileSystem, platformKernelPath,
|
||||||
enableAsserts: enableAsserts,
|
enableAsserts: enableAsserts,
|
||||||
nullSafety: nullSafety,
|
nullSafety: nullSafety,
|
||||||
experimentalFlags: experimentalFlags,
|
experimentalFlags: experimentalFlags,
|
||||||
packageConfig: packageConfig,
|
packageConfig: packageConfig,
|
||||||
invocationModes: invocationModes,
|
invocationModes: invocationModes,
|
||||||
verbosityLevel: verbosityLevel);
|
verbosityLevel: verbosityLevel,
|
||||||
|
enableMirrors: enableMirrors);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<CompilerResult> compileInternal(Uri script) async {
|
Future<CompilerResult> compileInternal(Uri script) async {
|
||||||
|
@ -428,7 +440,8 @@ Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateGroupId,
|
||||||
String? multirootFilepaths,
|
String? multirootFilepaths,
|
||||||
String? multirootScheme,
|
String? multirootScheme,
|
||||||
String invocationModes: '',
|
String invocationModes: '',
|
||||||
String verbosityLevel: Verbosity.defaultValue}) async {
|
String verbosityLevel: Verbosity.defaultValue,
|
||||||
|
required bool enableMirrors}) async {
|
||||||
IncrementalCompilerWrapper? compiler =
|
IncrementalCompilerWrapper? compiler =
|
||||||
lookupIncrementalCompiler(isolateGroupId);
|
lookupIncrementalCompiler(isolateGroupId);
|
||||||
if (compiler != null) {
|
if (compiler != null) {
|
||||||
|
@ -457,7 +470,8 @@ Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateGroupId,
|
||||||
experimentalFlags: experimentalFlags,
|
experimentalFlags: experimentalFlags,
|
||||||
packageConfig: packageConfig,
|
packageConfig: packageConfig,
|
||||||
invocationModes: invocationModes,
|
invocationModes: invocationModes,
|
||||||
verbosityLevel: verbosityLevel);
|
verbosityLevel: verbosityLevel,
|
||||||
|
enableMirrors: enableMirrors);
|
||||||
}
|
}
|
||||||
isolateCompilers[isolateGroupId] = compiler;
|
isolateCompilers[isolateGroupId] = compiler;
|
||||||
}
|
}
|
||||||
|
@ -513,6 +527,7 @@ Future _processExpressionCompilationRequest(request) async {
|
||||||
final bool enableAsserts = request[16];
|
final bool enableAsserts = request[16];
|
||||||
final List<String>? experimentalFlags =
|
final List<String>? experimentalFlags =
|
||||||
request[17] != null ? request[17].cast<String>() : null;
|
request[17] != null ? request[17].cast<String>() : null;
|
||||||
|
final bool enableMirrors = request[18];
|
||||||
|
|
||||||
IncrementalCompilerWrapper? compiler = isolateCompilers[isolateGroupId];
|
IncrementalCompilerWrapper? compiler = isolateCompilers[isolateGroupId];
|
||||||
|
|
||||||
|
@ -595,7 +610,8 @@ Future _processExpressionCompilationRequest(request) async {
|
||||||
component, isolateGroupId, fileSystem, null,
|
component, isolateGroupId, fileSystem, null,
|
||||||
enableAsserts: enableAsserts,
|
enableAsserts: enableAsserts,
|
||||||
experimentalFlags: experimentalFlags,
|
experimentalFlags: experimentalFlags,
|
||||||
packageConfig: dotPackagesFile);
|
packageConfig: dotPackagesFile,
|
||||||
|
enableMirrors: enableMirrors);
|
||||||
isolateCompilers[isolateGroupId] = compiler;
|
isolateCompilers[isolateGroupId] = compiler;
|
||||||
await compiler.compile(
|
await compiler.compile(
|
||||||
component.mainMethod?.enclosingLibrary.importUri ??
|
component.mainMethod?.enclosingLibrary.importUri ??
|
||||||
|
@ -776,6 +792,7 @@ Future _processLoadRequest(request) async {
|
||||||
final String? multirootScheme = request[13];
|
final String? multirootScheme = request[13];
|
||||||
final String? workingDirectory = request[14];
|
final String? workingDirectory = request[14];
|
||||||
final String verbosityLevel = request[15];
|
final String verbosityLevel = request[15];
|
||||||
|
final bool enableMirrors = request[16];
|
||||||
Uri platformKernelPath;
|
Uri platformKernelPath;
|
||||||
List<int>? platformKernel = null;
|
List<int>? platformKernel = null;
|
||||||
if (request[3] is String) {
|
if (request[3] is String) {
|
||||||
|
@ -844,7 +861,8 @@ Future _processLoadRequest(request) async {
|
||||||
errorsPlain,
|
errorsPlain,
|
||||||
errorsColorized,
|
errorsColorized,
|
||||||
invocationModes,
|
invocationModes,
|
||||||
verbosityLevel);
|
verbosityLevel,
|
||||||
|
false);
|
||||||
|
|
||||||
// script should only be null for kUpdateSourcesTag.
|
// script should only be null for kUpdateSourcesTag.
|
||||||
await autoDetectNullSafetyMode(script!, options);
|
await autoDetectNullSafetyMode(script!, options);
|
||||||
|
@ -870,7 +888,8 @@ Future _processLoadRequest(request) async {
|
||||||
multirootFilepaths: multirootFilepaths,
|
multirootFilepaths: multirootFilepaths,
|
||||||
multirootScheme: multirootScheme,
|
multirootScheme: multirootScheme,
|
||||||
invocationModes: invocationModes,
|
invocationModes: invocationModes,
|
||||||
verbosityLevel: verbosityLevel);
|
verbosityLevel: verbosityLevel,
|
||||||
|
enableMirrors: enableMirrors);
|
||||||
} else {
|
} else {
|
||||||
FileSystem fileSystem = _buildFileSystem(
|
FileSystem fileSystem = _buildFileSystem(
|
||||||
sourceFiles, platformKernel, multirootFilepaths, multirootScheme);
|
sourceFiles, platformKernel, multirootFilepaths, multirootScheme);
|
||||||
|
@ -882,7 +901,8 @@ Future _processLoadRequest(request) async {
|
||||||
experimentalFlags: experimentalFlags,
|
experimentalFlags: experimentalFlags,
|
||||||
packageConfig: packageConfig,
|
packageConfig: packageConfig,
|
||||||
invocationModes: invocationModes,
|
invocationModes: invocationModes,
|
||||||
verbosityLevel: verbosityLevel);
|
verbosityLevel: verbosityLevel,
|
||||||
|
enableMirrors: enableMirrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
CompilationResult result;
|
CompilationResult result;
|
||||||
|
@ -1044,6 +1064,7 @@ Future trainInternal(String scriptUri, String? platformKernelPath) async {
|
||||||
null /* multirootScheme */,
|
null /* multirootScheme */,
|
||||||
null /* original working directory */,
|
null /* original working directory */,
|
||||||
'all' /* CFE logging mode */,
|
'all' /* CFE logging mode */,
|
||||||
|
true /* enableMirrors */,
|
||||||
];
|
];
|
||||||
await _processLoadRequest(request);
|
await _processLoadRequest(request);
|
||||||
}
|
}
|
||||||
|
|
7
runtime/tests/vm/dart/enable_mirrors_lib_false.dart
Normal file
7
runtime/tests/vm/dart/enable_mirrors_lib_false.dart
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
// Copyright (c) 2022, 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.
|
||||||
|
|
||||||
|
// Auxiliary library for enable_mirrors_test.dart.
|
||||||
|
|
||||||
|
bool dartLibraryMirrorsConditionalImport = false;
|
7
runtime/tests/vm/dart/enable_mirrors_lib_true.dart
Normal file
7
runtime/tests/vm/dart/enable_mirrors_lib_true.dart
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
// Copyright (c) 2022, 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.
|
||||||
|
|
||||||
|
// Auxiliary library for enable_mirrors_test.dart.
|
||||||
|
|
||||||
|
bool dartLibraryMirrorsConditionalImport = true;
|
18
runtime/tests/vm/dart/enable_mirrors_test.dart
Normal file
18
runtime/tests/vm/dart/enable_mirrors_test.dart
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright (c) 2022, 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.
|
||||||
|
|
||||||
|
// VMOptions=--enable-mirrors=false
|
||||||
|
|
||||||
|
// Verfies that '--enable-mirrors=false' affects conditional imports and
|
||||||
|
// constant bool.fromEnvironment.
|
||||||
|
|
||||||
|
import "package:expect/expect.dart";
|
||||||
|
|
||||||
|
import 'enable_mirrors_lib_false.dart'
|
||||||
|
if (dart.library.mirrors) 'enable_mirrors_lib_true.dart';
|
||||||
|
|
||||||
|
main() {
|
||||||
|
Expect.isFalse(const bool.fromEnvironment('dart.library.mirrors'));
|
||||||
|
Expect.isFalse(dartLibraryMirrorsConditionalImport);
|
||||||
|
}
|
9
runtime/tests/vm/dart_2/enable_mirrors_lib_false.dart
Normal file
9
runtime/tests/vm/dart_2/enable_mirrors_lib_false.dart
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// Copyright (c) 2022, 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.
|
||||||
|
|
||||||
|
// Auxiliary library for enable_mirrors_test.dart.
|
||||||
|
|
||||||
|
// @dart = 2.9
|
||||||
|
|
||||||
|
bool dartLibraryMirrorsConditionalImport = false;
|
9
runtime/tests/vm/dart_2/enable_mirrors_lib_true.dart
Normal file
9
runtime/tests/vm/dart_2/enable_mirrors_lib_true.dart
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// Copyright (c) 2022, 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.
|
||||||
|
|
||||||
|
// Auxiliary library for enable_mirrors_test.dart.
|
||||||
|
|
||||||
|
// @dart = 2.9
|
||||||
|
|
||||||
|
bool dartLibraryMirrorsConditionalImport = true;
|
20
runtime/tests/vm/dart_2/enable_mirrors_test.dart
Normal file
20
runtime/tests/vm/dart_2/enable_mirrors_test.dart
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright (c) 2022, 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.
|
||||||
|
|
||||||
|
// VMOptions=--enable-mirrors=false
|
||||||
|
|
||||||
|
// Verfies that '--enable-mirrors=false' affects conditional imports and
|
||||||
|
// constant bool.fromEnvironment.
|
||||||
|
|
||||||
|
// @dart = 2.9
|
||||||
|
|
||||||
|
import "package:expect/expect.dart";
|
||||||
|
|
||||||
|
import 'enable_mirrors_lib_false.dart'
|
||||||
|
if (dart.library.mirrors) 'enable_mirrors_lib_true.dart';
|
||||||
|
|
||||||
|
main() {
|
||||||
|
Expect.isFalse(const bool.fromEnvironment('dart.library.mirrors'));
|
||||||
|
Expect.isFalse(dartLibraryMirrorsConditionalImport);
|
||||||
|
}
|
|
@ -699,6 +699,10 @@ class KernelCompilationRequest : public ValueObject {
|
||||||
experimental_flags_object.value.as_array.values = experimental_flags_array;
|
experimental_flags_object.value.as_array.values = experimental_flags_array;
|
||||||
experimental_flags_object.value.as_array.length = num_experimental_flags;
|
experimental_flags_object.value.as_array.length = num_experimental_flags;
|
||||||
|
|
||||||
|
Dart_CObject enable_mirrors;
|
||||||
|
enable_mirrors.type = Dart_CObject_kBool;
|
||||||
|
enable_mirrors.value.as_bool = FLAG_enable_mirrors;
|
||||||
|
|
||||||
Dart_CObject message;
|
Dart_CObject message;
|
||||||
message.type = Dart_CObject_kArray;
|
message.type = Dart_CObject_kArray;
|
||||||
Dart_CObject* message_arr[] = {&tag,
|
Dart_CObject* message_arr[] = {&tag,
|
||||||
|
@ -718,7 +722,8 @@ class KernelCompilationRequest : public ValueObject {
|
||||||
&dills_object,
|
&dills_object,
|
||||||
&num_blob_loads,
|
&num_blob_loads,
|
||||||
&enable_asserts,
|
&enable_asserts,
|
||||||
&experimental_flags_object};
|
&experimental_flags_object,
|
||||||
|
&enable_mirrors};
|
||||||
message.value.as_array.values = message_arr;
|
message.value.as_array.values = message_arr;
|
||||||
message.value.as_array.length = ARRAY_SIZE(message_arr);
|
message.value.as_array.length = ARRAY_SIZE(message_arr);
|
||||||
|
|
||||||
|
@ -942,6 +947,10 @@ class KernelCompilationRequest : public ValueObject {
|
||||||
verbosity_str.value.as_string =
|
verbosity_str.value.as_string =
|
||||||
const_cast<char*>(KernelCompilationVerbosityLevelToString(verbosity));
|
const_cast<char*>(KernelCompilationVerbosityLevelToString(verbosity));
|
||||||
|
|
||||||
|
Dart_CObject enable_mirrors;
|
||||||
|
enable_mirrors.type = Dart_CObject_kBool;
|
||||||
|
enable_mirrors.value.as_bool = FLAG_enable_mirrors;
|
||||||
|
|
||||||
Dart_CObject* message_arr[] = {&tag,
|
Dart_CObject* message_arr[] = {&tag,
|
||||||
&send_port,
|
&send_port,
|
||||||
&uri,
|
&uri,
|
||||||
|
@ -957,7 +966,8 @@ class KernelCompilationRequest : public ValueObject {
|
||||||
&multiroot_filepaths_object,
|
&multiroot_filepaths_object,
|
||||||
&multiroot_scheme_object,
|
&multiroot_scheme_object,
|
||||||
&original_working_directory_object,
|
&original_working_directory_object,
|
||||||
&verbosity_str};
|
&verbosity_str,
|
||||||
|
&enable_mirrors};
|
||||||
message.value.as_array.values = message_arr;
|
message.value.as_array.values = message_arr;
|
||||||
message.value.as_array.length = ARRAY_SIZE(message_arr);
|
message.value.as_array.length = ARRAY_SIZE(message_arr);
|
||||||
// Send the message.
|
// Send the message.
|
||||||
|
|
Loading…
Reference in a new issue