mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:45:06 +00:00
Migrate pkg/vm to null safety, part 5
TEST=ci Issue: https://github.com/dart-lang/sdk/issues/46620 Change-Id: Ifc5fe377b5dd8273a45ca0c28fcd27527baae146 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208021 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Siva Annamalai <asiva@google.com> Reviewed-by: Alexander Aprelev <aam@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
4911f0968e
commit
730ab0583d
|
@ -279,7 +279,7 @@ class DiagnosticMessageFromJson implements DiagnosticMessage {
|
|||
this.severity, this.uri, this.involvedFiles, this.codeName);
|
||||
|
||||
factory DiagnosticMessageFromJson.fromJson(String jsonString) {
|
||||
Map<String, Object> decoded = json.decode(jsonString);
|
||||
Map<String, Object?> decoded = json.decode(jsonString);
|
||||
List<String> ansiFormatted =
|
||||
new List<String>.from(_asListOfString(decoded["ansiFormatted"]));
|
||||
List<String> plainTextFormatted =
|
||||
|
|
|
@ -2823,7 +2823,7 @@ class ConstantEvaluator implements ExpressionVisitor<Constant> {
|
|||
for (int i = 0; i < node.expressions.length; i++) {
|
||||
Constant constant = _evaluateSubexpression(node.expressions[i]);
|
||||
if (constant is AbortConstant) return constant;
|
||||
if (constant is PrimitiveConstant<Object>) {
|
||||
if (constant is PrimitiveConstant) {
|
||||
String value;
|
||||
if (constant is DoubleConstant && intFolder.isInt(constant)) {
|
||||
value = new BigInt.from(constant.value).toString();
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io' as io;
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
/// This is an interface to the Dart Kernel parser and Kernel binary generator.
|
||||
///
|
||||
/// It is used by the kernel-isolate to load Dart source code and generate
|
||||
|
@ -20,7 +18,6 @@
|
|||
/// dart pkg/vm/bin/kernel_service.dart --train <source-file>
|
||||
///
|
||||
///
|
||||
library runtime.tools.kernel_service;
|
||||
|
||||
import 'dart:async' show Future, ZoneSpecification, runZoned;
|
||||
import 'dart:collection' show UnmodifiableMapBase;
|
||||
|
@ -90,11 +87,11 @@ const int kNullSafetyOptionStrong = 2;
|
|||
|
||||
CompilerOptions setupCompilerOptions(
|
||||
FileSystem fileSystem,
|
||||
Uri platformKernelPath,
|
||||
Uri? platformKernelPath,
|
||||
bool enableAsserts,
|
||||
int nullSafety,
|
||||
List<String> experimentalFlags,
|
||||
Uri packagesUri,
|
||||
List<String>? experimentalFlags,
|
||||
Uri? packagesUri,
|
||||
List<String> errorsPlain,
|
||||
List<String> errorsColorized,
|
||||
String invocationModes,
|
||||
|
@ -161,11 +158,11 @@ CompilerOptions setupCompilerOptions(
|
|||
abstract class Compiler {
|
||||
final int isolateGroupId;
|
||||
final FileSystem fileSystem;
|
||||
final Uri platformKernelPath;
|
||||
final Uri? platformKernelPath;
|
||||
final bool enableAsserts;
|
||||
final int nullSafety;
|
||||
final List<String> experimentalFlags;
|
||||
final String packageConfig;
|
||||
final List<String>? experimentalFlags;
|
||||
final String? packageConfig;
|
||||
final String invocationModes;
|
||||
final String verbosityLevel;
|
||||
|
||||
|
@ -177,7 +174,7 @@ abstract class Compiler {
|
|||
final List<String> errorsPlain = <String>[];
|
||||
final List<String> errorsColorized = <String>[];
|
||||
|
||||
CompilerOptions options;
|
||||
late final CompilerOptions options;
|
||||
|
||||
Compiler(this.isolateGroupId, this.fileSystem, this.platformKernelPath,
|
||||
{this.enableAsserts: false,
|
||||
|
@ -188,11 +185,10 @@ abstract class Compiler {
|
|||
this.packageConfig: null,
|
||||
this.invocationModes: '',
|
||||
this.verbosityLevel: Verbosity.defaultValue}) {
|
||||
Uri packagesUri = null;
|
||||
Uri? packagesUri = null;
|
||||
final packageConfig = this.packageConfig ?? Platform.packageConfig;
|
||||
if (packageConfig != null) {
|
||||
packagesUri = Uri.parse(packageConfig);
|
||||
} else if (Platform.packageConfig != null) {
|
||||
packagesUri = Uri.parse(Platform.packageConfig);
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
|
@ -218,7 +214,7 @@ abstract class Compiler {
|
|||
Future<CompilerResult> compile(Uri script) {
|
||||
return runWithPrintToStderr(() async {
|
||||
final CompilerResult compilerResult = await compileInternal(script);
|
||||
final Component component = compilerResult.component;
|
||||
final Component? component = compilerResult.component;
|
||||
|
||||
if (errorsPlain.isEmpty) {
|
||||
// Record dependencies only if compilation was error free.
|
||||
|
@ -233,20 +229,16 @@ abstract class Compiler {
|
|||
}
|
||||
|
||||
class CompilerResult {
|
||||
final Component component;
|
||||
final Component? component;
|
||||
|
||||
/// Set of libraries loaded from .dill, with or without the SDK depending on
|
||||
/// the compilation settings.
|
||||
final Set<Library> loadedLibraries;
|
||||
final ClassHierarchy classHierarchy;
|
||||
final CoreTypes coreTypes;
|
||||
final ClassHierarchy? classHierarchy;
|
||||
final CoreTypes? coreTypes;
|
||||
|
||||
CompilerResult(
|
||||
this.component, this.loadedLibraries, this.classHierarchy, this.coreTypes)
|
||||
: assert(component != null),
|
||||
assert(loadedLibraries != null),
|
||||
assert(classHierarchy != null),
|
||||
assert(coreTypes != null);
|
||||
CompilerResult(this.component, this.loadedLibraries, this.classHierarchy,
|
||||
this.coreTypes);
|
||||
}
|
||||
|
||||
// Environment map which looks up environment defines in the VM environment
|
||||
|
@ -257,17 +249,17 @@ class CompilerResult {
|
|||
// the full (isolate specific) environment as a finite, static map.
|
||||
class EnvironmentMap extends UnmodifiableMapBase<String, String> {
|
||||
@override
|
||||
bool containsKey(Object key) {
|
||||
return new bool.hasEnvironment(key);
|
||||
bool containsKey(Object? key) {
|
||||
return key is String && new bool.hasEnvironment(key);
|
||||
}
|
||||
|
||||
@override
|
||||
String operator [](Object key) {
|
||||
String? operator [](Object? key) {
|
||||
// The fromEnvironment constructor is specified to throw when called using
|
||||
// new. However, the VM implementation actually looks up the given name in
|
||||
// the environment.
|
||||
if (containsKey(key)) {
|
||||
return new String.fromEnvironment(key);
|
||||
return new String.fromEnvironment(key as String);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -294,14 +286,14 @@ class FileSink implements Sink<List<int>> {
|
|||
}
|
||||
|
||||
class IncrementalCompilerWrapper extends Compiler {
|
||||
IncrementalCompiler generator;
|
||||
IncrementalCompiler? generator;
|
||||
|
||||
IncrementalCompilerWrapper(
|
||||
int isolateGroupId, FileSystem fileSystem, Uri platformKernelPath,
|
||||
int isolateGroupId, FileSystem fileSystem, Uri? platformKernelPath,
|
||||
{bool enableAsserts: false,
|
||||
int nullSafety: kNullSafetyOptionUnspecified,
|
||||
List<String> experimentalFlags: null,
|
||||
String packageConfig: null,
|
||||
List<String>? experimentalFlags,
|
||||
String? packageConfig,
|
||||
String invocationModes: '',
|
||||
String verbosityLevel: Verbosity.defaultValue})
|
||||
: super(isolateGroupId, fileSystem, platformKernelPath,
|
||||
|
@ -318,10 +310,10 @@ class IncrementalCompilerWrapper extends Compiler {
|
|||
Component component,
|
||||
int isolateGroupId,
|
||||
FileSystem fileSystem,
|
||||
Uri platformKernelPath,
|
||||
Uri? platformKernelPath,
|
||||
{bool enableAsserts: false,
|
||||
List<String> experimentalFlags: null,
|
||||
String packageConfig: null,
|
||||
List<String>? experimentalFlags,
|
||||
String? packageConfig,
|
||||
String invocationModes: ''}) {
|
||||
IncrementalCompilerWrapper result = IncrementalCompilerWrapper(
|
||||
isolateGroupId, fileSystem, platformKernelPath,
|
||||
|
@ -332,15 +324,13 @@ class IncrementalCompilerWrapper extends Compiler {
|
|||
result.generator = new IncrementalCompiler.forExpressionCompilationOnly(
|
||||
component,
|
||||
result.options,
|
||||
component.mainMethod?.enclosingLibrary?.fileUri);
|
||||
component.mainMethod!.enclosingLibrary.fileUri);
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<CompilerResult> compileInternal(Uri script) async {
|
||||
if (generator == null) {
|
||||
generator = new IncrementalCompiler(options, script);
|
||||
}
|
||||
final generator = this.generator ??= IncrementalCompiler(options, script);
|
||||
errorsPlain.clear();
|
||||
errorsColorized.clear();
|
||||
final component = await generator.compile(entryPoint: script);
|
||||
|
@ -348,8 +338,8 @@ class IncrementalCompilerWrapper extends Compiler {
|
|||
generator.getClassHierarchy(), generator.getCoreTypes());
|
||||
}
|
||||
|
||||
void accept() => generator.accept();
|
||||
void invalidate(Uri uri) => generator.invalidate(uri);
|
||||
void accept() => generator!.accept();
|
||||
void invalidate(Uri uri) => generator!.invalidate(uri);
|
||||
|
||||
Future<IncrementalCompilerWrapper> clone(int isolateGroupId) async {
|
||||
IncrementalCompilerWrapper clone = IncrementalCompilerWrapper(
|
||||
|
@ -359,6 +349,7 @@ class IncrementalCompilerWrapper extends Compiler {
|
|||
experimentalFlags: experimentalFlags,
|
||||
packageConfig: packageConfig,
|
||||
invocationModes: invocationModes);
|
||||
final generator = this.generator!;
|
||||
// TODO(VM TEAM): This does not seem safe. What if cloning while having
|
||||
// pending deltas for instance?
|
||||
generator.resetDeltaState();
|
||||
|
@ -369,9 +360,10 @@ class IncrementalCompilerWrapper extends Compiler {
|
|||
MemoryFileSystem memoryFileSystem = (fileSystem as HybridFileSystem).memory;
|
||||
|
||||
String filename = 'full-component-$isolateGroupId.dill';
|
||||
Sink sink = FileSink(memoryFileSystem.entityForUri(Uri.file(filename)));
|
||||
Sink<List<int>> sink =
|
||||
FileSink(memoryFileSystem.entityForUri(Uri.file(filename)));
|
||||
new BinaryPrinter(sink).writeComponentFile(fullComponent);
|
||||
await sink.close();
|
||||
sink.close();
|
||||
|
||||
clone.generator = new IncrementalCompiler(options, generator.entryPoint,
|
||||
initializeFromDillUri: Uri.file(filename));
|
||||
|
@ -387,8 +379,8 @@ class SingleShotCompilerWrapper extends Compiler {
|
|||
{this.requireMain: false,
|
||||
bool enableAsserts: false,
|
||||
int nullSafety: kNullSafetyOptionUnspecified,
|
||||
List<String> experimentalFlags: null,
|
||||
String packageConfig: null,
|
||||
List<String>? experimentalFlags,
|
||||
String? packageConfig,
|
||||
String invocationModes: '',
|
||||
String verbosityLevel: Verbosity.defaultValue})
|
||||
: super(isolateGroupId, fileSystem, platformKernelPath,
|
||||
|
@ -401,12 +393,15 @@ class SingleShotCompilerWrapper extends Compiler {
|
|||
|
||||
@override
|
||||
Future<CompilerResult> compileInternal(Uri script) async {
|
||||
fe.CompilerResult compilerResult = requireMain
|
||||
final fe.CompilerResult? compilerResult = requireMain
|
||||
? await kernelForProgram(script, options)
|
||||
: await kernelForModule([script], options);
|
||||
if (compilerResult == null) {
|
||||
return CompilerResult(null, const {}, null, null);
|
||||
}
|
||||
|
||||
Set<Library> loadedLibraries = createLoadedLibrariesSet(
|
||||
compilerResult?.loadedComponents, compilerResult?.sdkComponent,
|
||||
compilerResult.loadedComponents, compilerResult.sdkComponent,
|
||||
includePlatform: !options.omitPlatform);
|
||||
|
||||
return new CompilerResult(compilerResult.component, loadedLibraries,
|
||||
|
@ -418,21 +413,21 @@ final Map<int, IncrementalCompilerWrapper> isolateCompilers = {};
|
|||
final Map<int, List<Uri>> isolateDependencies = {};
|
||||
final Map<int, _ExpressionCompilationFromDillSettings> isolateLoadNotifies = {};
|
||||
|
||||
IncrementalCompilerWrapper lookupIncrementalCompiler(int isolateGroupId) {
|
||||
IncrementalCompilerWrapper? lookupIncrementalCompiler(int isolateGroupId) {
|
||||
return isolateCompilers[isolateGroupId];
|
||||
}
|
||||
|
||||
Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateGroupId,
|
||||
List sourceFiles, Uri platformKernelPath, List<int> platformKernel,
|
||||
List sourceFiles, Uri platformKernelPath, List<int>? platformKernel,
|
||||
{bool enableAsserts: false,
|
||||
int nullSafety: kNullSafetyOptionUnspecified,
|
||||
List<String> experimentalFlags: null,
|
||||
String packageConfig: null,
|
||||
String multirootFilepaths,
|
||||
String multirootScheme,
|
||||
List<String>? experimentalFlags,
|
||||
String? packageConfig,
|
||||
String? multirootFilepaths,
|
||||
String? multirootScheme,
|
||||
String invocationModes: '',
|
||||
String verbosityLevel: Verbosity.defaultValue}) async {
|
||||
IncrementalCompilerWrapper compiler =
|
||||
IncrementalCompilerWrapper? compiler =
|
||||
lookupIncrementalCompiler(isolateGroupId);
|
||||
if (compiler != null) {
|
||||
updateSources(compiler, sourceFiles);
|
||||
|
@ -441,9 +436,7 @@ Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateGroupId,
|
|||
// This is how identify scenario where child isolate hot reload requests
|
||||
// requires setting up actual compiler first: non-empty sourceFiles list has
|
||||
// no actual content specified for the source file.
|
||||
if (sourceFiles != null &&
|
||||
sourceFiles.length > 0 &&
|
||||
sourceFiles[1] == null) {
|
||||
if (sourceFiles.isNotEmpty && sourceFiles[1] == null) {
|
||||
// Just use first compiler that should represent main isolate as a source for cloning.
|
||||
var source = isolateCompilers.entries.first;
|
||||
compiler = await source.value.clone(isolateGroupId);
|
||||
|
@ -475,7 +468,7 @@ void updateSources(IncrementalCompilerWrapper compiler, List sourceFiles) {
|
|||
final FileSystem fs = compiler.fileSystem;
|
||||
for (int i = 0; i < sourceFiles.length ~/ 2; i++) {
|
||||
Uri uri = Uri.parse(sourceFiles[i * 2]);
|
||||
List<int> source = sourceFiles[i * 2 + 1];
|
||||
List<int>? source = sourceFiles[i * 2 + 1];
|
||||
// The source is only provided by unit tests and is normally empty.
|
||||
// Don't add an entry for the uri so the compiler will fallback to the
|
||||
// real file system for the updated source.
|
||||
|
@ -507,23 +500,24 @@ Future _processExpressionCompilationRequest(request) async {
|
|||
final List<String> definitions = request[5].cast<String>();
|
||||
final List<String> typeDefinitions = request[6].cast<String>();
|
||||
final String libraryUri = request[7];
|
||||
final String klass = request[8]; // might be null
|
||||
final String? klass = request[8];
|
||||
final bool isStatic = request[9];
|
||||
final List dillData = request[10];
|
||||
final List<List<int>> dillData = request[10].cast<List<int>>();
|
||||
final int blobLoadCount = request[11];
|
||||
final bool enableAsserts = request[12];
|
||||
final List<String> experimentalFlags =
|
||||
final List<String>? experimentalFlags =
|
||||
request[13] != null ? request[13].cast<String>() : null;
|
||||
|
||||
IncrementalCompilerWrapper compiler = isolateCompilers[isolateGroupId];
|
||||
IncrementalCompilerWrapper? compiler = isolateCompilers[isolateGroupId];
|
||||
|
||||
_ExpressionCompilationFromDillSettings isolateLoadDillData =
|
||||
_ExpressionCompilationFromDillSettings? isolateLoadDillData =
|
||||
isolateLoadNotifies[isolateGroupId];
|
||||
if (isolateLoadDillData != null) {
|
||||
// Check if we can reuse the compiler.
|
||||
if (isolateLoadDillData.blobLoadCount != blobLoadCount ||
|
||||
isolateLoadDillData.prevDillCount != dillData.length) {
|
||||
compiler = isolateCompilers[isolateGroupId] = null;
|
||||
isolateCompilers.remove(isolateGroupId);
|
||||
compiler = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -560,7 +554,7 @@ Future _processExpressionCompilationRequest(request) async {
|
|||
}
|
||||
}
|
||||
if (!foundDartCore) {
|
||||
List<int> platformKernel = null;
|
||||
List<int> platformKernel;
|
||||
if (dart_platform_kernel is List<int>) {
|
||||
platformKernel = dart_platform_kernel;
|
||||
} else {
|
||||
|
@ -598,7 +592,7 @@ Future _processExpressionCompilationRequest(request) async {
|
|||
packageConfig: dotPackagesFile);
|
||||
isolateCompilers[isolateGroupId] = compiler;
|
||||
await compiler.compile(
|
||||
component.mainMethod?.enclosingLibrary?.importUri ??
|
||||
component.mainMethod?.enclosingLibrary.importUri ??
|
||||
component.libraries.last.importUri);
|
||||
} catch (e) {
|
||||
port.send(new CompilationResult.errors([
|
||||
|
@ -623,7 +617,7 @@ Future _processExpressionCompilationRequest(request) async {
|
|||
|
||||
CompilationResult result;
|
||||
try {
|
||||
Procedure procedure = await compiler.generator.compileExpression(
|
||||
Procedure? procedure = await compiler.generator!.compileExpression(
|
||||
expression, definitions, typeDefinitions, libraryUri, klass, isStatic);
|
||||
|
||||
if (procedure == null) {
|
||||
|
@ -651,7 +645,7 @@ Future _processExpressionCompilationRequest(request) async {
|
|||
}
|
||||
|
||||
void _recordDependencies(
|
||||
int isolateGroupId, Component component, Uri packageConfig) {
|
||||
int isolateGroupId, Component? component, Uri? packageConfig) {
|
||||
final dependencies = isolateDependencies[isolateGroupId] ??= <Uri>[];
|
||||
|
||||
if (component != null) {
|
||||
|
@ -680,8 +674,8 @@ String _escapeDependency(Uri uri) {
|
|||
return uri.toFilePath().replaceAll("\\", "\\\\").replaceAll(" ", "\\ ");
|
||||
}
|
||||
|
||||
List<int> _serializeDependencies(List<Uri> uris) {
|
||||
return utf8.encode(uris.map(_escapeDependency).join(" "));
|
||||
Uint8List _serializeDependencies(List<Uri> uris) {
|
||||
return utf8.encode(uris.map(_escapeDependency).join(" ")) as Uint8List;
|
||||
}
|
||||
|
||||
Future _processListDependenciesRequest(
|
||||
|
@ -752,23 +746,23 @@ Future _processLoadRequest(request) async {
|
|||
return;
|
||||
}
|
||||
|
||||
final String inputFileUri = request[2];
|
||||
final Uri script =
|
||||
final String? inputFileUri = request[2];
|
||||
final Uri? script =
|
||||
inputFileUri != null ? Uri.base.resolve(inputFileUri) : null;
|
||||
final bool incremental = request[4];
|
||||
final bool snapshot = request[5];
|
||||
final int nullSafety = request[6];
|
||||
final List sourceFiles = request[8];
|
||||
final bool enableAsserts = request[9];
|
||||
final List<String> experimentalFlags =
|
||||
final List<String>? experimentalFlags =
|
||||
request[10] != null ? request[10].cast<String>() : null;
|
||||
final String packageConfig = request[11];
|
||||
final String multirootFilepaths = request[12];
|
||||
final String multirootScheme = request[13];
|
||||
final String workingDirectory = request[14];
|
||||
final String? packageConfig = request[11];
|
||||
final String? multirootFilepaths = request[12];
|
||||
final String? multirootScheme = request[13];
|
||||
final String? workingDirectory = request[14];
|
||||
final String verbosityLevel = request[15];
|
||||
Uri platformKernelPath = null;
|
||||
List<int> platformKernel = null;
|
||||
Uri platformKernelPath;
|
||||
List<int>? platformKernel = null;
|
||||
if (request[3] is String) {
|
||||
platformKernelPath = Uri.base.resolveUri(new Uri.file(request[3]));
|
||||
} else if (request[3] is List<int>) {
|
||||
|
@ -781,7 +775,7 @@ Future _processLoadRequest(request) async {
|
|||
|
||||
final String invocationModes = snapshot ? 'compile' : '';
|
||||
|
||||
Compiler compiler;
|
||||
Compiler? compiler;
|
||||
|
||||
// Update the in-memory file system with the provided sources. Currently, only
|
||||
// unit tests compile sources that are not on the file system, so this can only
|
||||
|
@ -796,7 +790,7 @@ Future _processLoadRequest(request) async {
|
|||
.toResponse());
|
||||
return;
|
||||
}
|
||||
updateSources(compiler, sourceFiles);
|
||||
updateSources(compiler as IncrementalCompilerWrapper, sourceFiles);
|
||||
port.send(new CompilationResult.ok(null).toResponse());
|
||||
return;
|
||||
} else if (tag == kAcceptTag) {
|
||||
|
@ -813,16 +807,15 @@ Future _processLoadRequest(request) async {
|
|||
} else if (tag == kDetectNullabilityTag) {
|
||||
FileSystem fileSystem = _buildFileSystem(
|
||||
sourceFiles, platformKernel, multirootFilepaths, multirootScheme);
|
||||
Uri packagesUri = null;
|
||||
if (packageConfig != null) {
|
||||
packagesUri = Uri.parse(packageConfig);
|
||||
} else if (Platform.packageConfig != null) {
|
||||
packagesUri = Uri.parse(Platform.packageConfig);
|
||||
Uri? packagesUri = null;
|
||||
final packageConfigWithDefault = packageConfig ?? Platform.packageConfig;
|
||||
if (packageConfigWithDefault != null) {
|
||||
packagesUri = Uri.parse(packageConfigWithDefault);
|
||||
}
|
||||
if (packagesUri != null && packagesUri.scheme == '') {
|
||||
// Script does not have a scheme, assume that it is a path,
|
||||
// resolve it against the working directory.
|
||||
packagesUri = Uri.directory(workingDirectory).resolveUri(packagesUri);
|
||||
packagesUri = Uri.directory(workingDirectory!).resolveUri(packagesUri);
|
||||
}
|
||||
final List<String> errorsPlain = <String>[];
|
||||
final List<String> errorsColorized = <String>[];
|
||||
|
@ -839,8 +832,7 @@ Future _processLoadRequest(request) async {
|
|||
verbosityLevel);
|
||||
|
||||
// script should only be null for kUpdateSourcesTag.
|
||||
assert(script != null);
|
||||
await autoDetectNullSafetyMode(script, options);
|
||||
await autoDetectNullSafetyMode(script!, options);
|
||||
bool value = options.nnbdMode == NnbdMode.Strong;
|
||||
port.send(new CompilationResult.nullSafety(value).toResponse());
|
||||
return;
|
||||
|
@ -884,7 +876,7 @@ Future _processLoadRequest(request) async {
|
|||
print("DFE: scriptUri: ${script}");
|
||||
}
|
||||
|
||||
CompilerResult compilerResult = await compiler.compile(script);
|
||||
CompilerResult compilerResult = await compiler.compile(script!);
|
||||
Set<Library> loadedLibraries = compilerResult.loadedLibraries;
|
||||
|
||||
assert(compiler.errorsPlain.length == compiler.errorsColorized.length);
|
||||
|
@ -896,10 +888,11 @@ Future _processLoadRequest(request) async {
|
|||
if (compiler.errorsColorized.isNotEmpty) {
|
||||
final List<String> errors =
|
||||
(enableColors) ? compiler.errorsColorized : compiler.errorsPlain;
|
||||
if (compilerResult.component != null) {
|
||||
final component = compilerResult.component;
|
||||
if (component != null) {
|
||||
result = new CompilationResult.errors(
|
||||
errors,
|
||||
serializeComponent(compilerResult.component,
|
||||
serializeComponent(component,
|
||||
filter: (lib) => !loadedLibraries.contains(lib)));
|
||||
} else {
|
||||
result = new CompilationResult.errors(errors, null);
|
||||
|
@ -910,7 +903,7 @@ Future _processLoadRequest(request) async {
|
|||
// [kernelForProgram] is marked `external`, so we can use that bit to
|
||||
// decide what to exclude.
|
||||
result = new CompilationResult.ok(serializeComponent(
|
||||
compilerResult.component,
|
||||
compilerResult.component!,
|
||||
filter: (lib) => !loadedLibraries.contains(lib)));
|
||||
}
|
||||
} catch (error, stack) {
|
||||
|
@ -922,7 +915,7 @@ Future _processLoadRequest(request) async {
|
|||
if (tag == kTrainTag) {
|
||||
// In training mode make sure to read the sdk a few more times...
|
||||
ProcessedOptions p = new ProcessedOptions(options: compiler.options);
|
||||
var bytes = await p.loadSdkSummaryBytes();
|
||||
final bytes = (await p.loadSdkSummaryBytes())!;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
p.loadComponent(bytes, null);
|
||||
}
|
||||
|
@ -951,19 +944,17 @@ Future _processLoadRequest(request) async {
|
|||
///
|
||||
/// The result can be used instead of StandardFileSystem.instance by the
|
||||
/// frontend.
|
||||
FileSystem _buildFileSystem(List sourceFiles, List<int> platformKernel,
|
||||
String multirootFilepaths, String multirootScheme) {
|
||||
FileSystem _buildFileSystem(List sourceFiles, List<int>? platformKernel,
|
||||
String? multirootFilepaths, String? multirootScheme) {
|
||||
FileSystem fileSystem = new HttpAwareFileSystem(StandardFileSystem.instance);
|
||||
|
||||
if (!sourceFiles.isEmpty || platformKernel != null) {
|
||||
MemoryFileSystem memoryFileSystem =
|
||||
new MemoryFileSystem(Uri.parse('file:///'));
|
||||
if (sourceFiles != null) {
|
||||
for (int i = 0; i < sourceFiles.length ~/ 2; i++) {
|
||||
memoryFileSystem
|
||||
.entityForUri(Uri.parse(sourceFiles[i * 2]))
|
||||
.writeAsBytesSync(sourceFiles[i * 2 + 1]);
|
||||
}
|
||||
for (int i = 0; i < sourceFiles.length ~/ 2; i++) {
|
||||
memoryFileSystem
|
||||
.entityForUri(Uri.parse(sourceFiles[i * 2]))
|
||||
.writeAsBytesSync(sourceFiles[i * 2 + 1]);
|
||||
}
|
||||
if (platformKernel != null) {
|
||||
memoryFileSystem
|
||||
|
@ -984,7 +975,7 @@ FileSystem _buildFileSystem(List sourceFiles, List<int> platformKernel,
|
|||
return fileSystem;
|
||||
}
|
||||
|
||||
train(String scriptUri, String platformKernelPath) async {
|
||||
train(String scriptUri, String? platformKernelPath) async {
|
||||
// Train on program asked to train on.
|
||||
await trainInternal(scriptUri, platformKernelPath);
|
||||
|
||||
|
@ -1007,7 +998,7 @@ train(String scriptUri, String platformKernelPath) async {
|
|||
}
|
||||
}
|
||||
|
||||
Future trainInternal(String scriptUri, String platformKernelPath) async {
|
||||
Future trainInternal(String scriptUri, String? platformKernelPath) async {
|
||||
var tag = kTrainTag;
|
||||
var responsePort = new RawReceivePort();
|
||||
responsePort.handler = (response) {
|
||||
|
@ -1050,7 +1041,7 @@ main([args]) {
|
|||
// 2) Optional platform kernel path.
|
||||
int argIndex = 1;
|
||||
final String script = args[argIndex++];
|
||||
final String platform = (argIndex < args.length) ? args[argIndex] : null;
|
||||
final String? platform = (argIndex < args.length) ? args[argIndex] : null;
|
||||
train(script, platform);
|
||||
} else {
|
||||
// Entry point for the Kernel isolate.
|
||||
|
@ -1077,11 +1068,11 @@ enum Status {
|
|||
abstract class CompilationResult {
|
||||
CompilationResult._();
|
||||
|
||||
factory CompilationResult.ok(Uint8List bytes) = _CompilationOk;
|
||||
factory CompilationResult.ok(Uint8List? bytes) = _CompilationOk;
|
||||
|
||||
factory CompilationResult.nullSafety(bool val) = _CompilationNullSafety;
|
||||
|
||||
factory CompilationResult.errors(List<String> errors, Uint8List bytes) =
|
||||
factory CompilationResult.errors(List<String> errors, Uint8List? bytes) =
|
||||
_CompilationError;
|
||||
|
||||
factory CompilationResult.crash(Object exception, StackTrace stack) =
|
||||
|
@ -1095,11 +1086,14 @@ abstract class CompilationResult {
|
|||
}
|
||||
|
||||
class _CompilationOk extends CompilationResult {
|
||||
final Uint8List bytes;
|
||||
final Uint8List? bytes;
|
||||
|
||||
_CompilationOk(this.bytes) : super._() {
|
||||
if (dumpKernel && bytes != null) {
|
||||
_debugDumpKernel(bytes);
|
||||
if (dumpKernel) {
|
||||
final bytes = this.bytes;
|
||||
if (bytes != null) {
|
||||
_debugDumpKernel(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1109,7 +1103,7 @@ class _CompilationOk extends CompilationResult {
|
|||
@override
|
||||
get payload => bytes;
|
||||
|
||||
String toString() => "_CompilationOk(${bytes.length} bytes)";
|
||||
String toString() => "_CompilationOk(${bytes?.length ?? 0} bytes)";
|
||||
}
|
||||
|
||||
class _CompilationNullSafety extends CompilationResult {
|
||||
|
@ -1136,7 +1130,7 @@ abstract class _CompilationFail extends CompilationResult {
|
|||
}
|
||||
|
||||
class _CompilationError extends _CompilationFail {
|
||||
final Uint8List bytes;
|
||||
final Uint8List? bytes;
|
||||
final List<String> errors;
|
||||
|
||||
_CompilationError(this.errors, this.bytes);
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
/// This program will take a .dill file and do a protobuf aware tree-shaking.
|
||||
///
|
||||
/// All fields of GeneratedMessage subclasses that are not accessed with their
|
||||
|
@ -36,7 +34,6 @@ import 'package:kernel/core_types.dart' show CoreTypes;
|
|||
import 'package:vm/kernel_front_end.dart'
|
||||
show runGlobalTransformations, ErrorDetector;
|
||||
import 'package:kernel/target/targets.dart' show TargetFlags, getTarget;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:vm/target/install.dart' show installAdditionalTargets;
|
||||
import 'package:vm/transformations/type_flow/transformer.dart' as globalTypeFlow
|
||||
show transformComponent;
|
||||
|
@ -71,7 +68,7 @@ ArgResults parseArgs(List<String> args) {
|
|||
help: 'Write to stdout about what classes and fields where remeoved')
|
||||
..addFlag('help', help: 'Prints this help', negatable: false);
|
||||
|
||||
ArgResults argResults;
|
||||
ArgResults? argResults;
|
||||
try {
|
||||
argResults = argParser.parse(args);
|
||||
} on FormatException catch (e) {
|
||||
|
@ -111,7 +108,7 @@ Future main(List<String> args) async {
|
|||
|
||||
installAdditionalTargets();
|
||||
|
||||
final target = getTarget(argResults['target'], TargetFlags());
|
||||
final target = getTarget(argResults['target'], TargetFlags())!;
|
||||
|
||||
// The [component] is treeshaken and has TFA annotations. Write output.
|
||||
if (argResults['aot']) {
|
||||
|
@ -158,7 +155,7 @@ Uint8List concatenate(Uint8List a, Uint8List b) {
|
|||
}
|
||||
|
||||
Future writeComponent(Component component, String filename,
|
||||
{@required bool removeCoreLibs, @required bool removeSource}) async {
|
||||
{required bool removeCoreLibs, required bool removeSource}) async {
|
||||
if (removeSource) {
|
||||
component.uriToSource.clear();
|
||||
}
|
||||
|
|
|
@ -15,8 +15,6 @@ dependencies:
|
|||
path: ../front_end
|
||||
kernel:
|
||||
path: ../kernel
|
||||
meta:
|
||||
path: ../meta
|
||||
package_config: any
|
||||
collection: ^1.15.0
|
||||
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:collection/collection.dart' show IterableExtension;
|
||||
import 'package:front_end/src/api_unstable/vm.dart'
|
||||
show
|
||||
CompilerOptions,
|
||||
|
@ -47,8 +46,8 @@ main() {
|
|||
final options = getFreshOptions();
|
||||
|
||||
group('basic', () {
|
||||
Directory mytest;
|
||||
File main;
|
||||
late Directory mytest;
|
||||
late File main;
|
||||
|
||||
setUpAll(() {
|
||||
mytest = Directory.systemTemp.createTempSync('incremental');
|
||||
|
@ -70,7 +69,7 @@ main() {
|
|||
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
new Printer(buffer, showMetadata: true)
|
||||
.writeLibraryFile(component.mainMethod.enclosingLibrary);
|
||||
.writeLibraryFile(component.mainMethod!.enclosingLibrary);
|
||||
expect(
|
||||
buffer.toString(),
|
||||
equals('library /*isNonNullableByDefault*/;\n'
|
||||
|
@ -92,7 +91,7 @@ main() {
|
|||
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
new Printer(buffer, showMetadata: true)
|
||||
.writeLibraryFile(component.mainMethod.enclosingLibrary);
|
||||
.writeLibraryFile(component.mainMethod!.enclosingLibrary);
|
||||
expect(
|
||||
buffer.toString(),
|
||||
equals('library /*isNonNullableByDefault*/;\n'
|
||||
|
@ -113,13 +112,13 @@ main() {
|
|||
await compiler.compile();
|
||||
compiler.accept();
|
||||
{
|
||||
Procedure procedure = await compiler.compileExpression(
|
||||
Procedure? procedure = await compiler.compileExpression(
|
||||
'main', <String>[], <String>[], main.uri.toString(), null, true);
|
||||
expect(procedure, isNotNull);
|
||||
expect(errorsReported, equals(0));
|
||||
}
|
||||
{
|
||||
Procedure procedure = await compiler.compileExpression(
|
||||
Procedure? procedure = await compiler.compileExpression(
|
||||
'main1', <String>[], <String>[], main.uri.toString(), null, true);
|
||||
expect(procedure, isNotNull);
|
||||
expect(errorsReported, equals(1));
|
||||
|
@ -138,7 +137,7 @@ main() {
|
|||
Future<Set<int>> collectAndCheckCoverageData(int port, bool getAllSources,
|
||||
{bool resume: true,
|
||||
bool onGetAllVerifyCount: true,
|
||||
Set<int> coverageForLines}) async {
|
||||
Set<int>? coverageForLines}) async {
|
||||
RemoteVm remoteVm = new RemoteVm(port);
|
||||
|
||||
// Wait for the script to have finished.
|
||||
|
@ -177,7 +176,7 @@ main() {
|
|||
// Ensure that we can get a line and column number for all reported
|
||||
// positions in the scripts we care about.
|
||||
for (Map sourceReport in sourceReports) {
|
||||
List scripts = sourceReport["scripts"];
|
||||
List<Map> scripts = sourceReport["scripts"].cast<Map>();
|
||||
Map<String, int> scriptIdToIndex = new Map<String, int>();
|
||||
Set<int> lib1scriptIndices = new Set<int>();
|
||||
int i = 0;
|
||||
|
@ -201,9 +200,9 @@ main() {
|
|||
Map<int, Map> scriptIndexToScript = new Map<int, Map>();
|
||||
for (String scriptId in scriptIdToIndex.keys) {
|
||||
Map script = await remoteVm.getObject(scriptId);
|
||||
int scriptIdx = scriptIdToIndex[scriptId];
|
||||
int scriptIdx = scriptIdToIndex[scriptId]!;
|
||||
scriptIndexToScript[scriptIdx] = script;
|
||||
List tokenPosTable = script["tokenPosTable"];
|
||||
List? tokenPosTable = script["tokenPosTable"];
|
||||
if (tokenPosTable == null) {
|
||||
errorMessages.add("Script with uri ${script['uri']} "
|
||||
"and id ${script['id']} "
|
||||
|
@ -215,7 +214,7 @@ main() {
|
|||
}
|
||||
}
|
||||
|
||||
List ranges = sourceReport["ranges"];
|
||||
List<Map> ranges = sourceReport["ranges"].cast<Map>();
|
||||
Set<int> scriptIndexesSet = new Set<int>.from(scriptIndexToScript.keys);
|
||||
for (Map range in ranges) {
|
||||
if (scriptIndexesSet.contains(range["scriptIndex"])) {
|
||||
|
@ -233,7 +232,7 @@ main() {
|
|||
if (range["possibleBreakpoints"] != null) {
|
||||
for (int pos in range["possibleBreakpoints"]) positions.add(pos);
|
||||
}
|
||||
Map script = scriptIndexToScript[range["scriptIndex"]];
|
||||
Map script = scriptIndexToScript[range["scriptIndex"]]!;
|
||||
Set<int> knownPositions = new Set<int>();
|
||||
Map<int, int> tokenPosToLine = {};
|
||||
if (script["tokenPosTable"] != null) {
|
||||
|
@ -256,7 +255,7 @@ main() {
|
|||
if (coverageForLines != null) {
|
||||
for (int pos in coverage["hits"]) {
|
||||
if (lib1scriptIndices.contains(range["scriptIndex"])) {
|
||||
coverageForLines.add(tokenPosToLine[pos]);
|
||||
coverageForLines.add(tokenPosToLine[pos]!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -271,10 +270,10 @@ main() {
|
|||
}
|
||||
|
||||
group('multiple kernels', () {
|
||||
Directory mytest;
|
||||
File main;
|
||||
File lib;
|
||||
Process vm;
|
||||
late Directory mytest;
|
||||
late File main;
|
||||
late File lib;
|
||||
late Process vm;
|
||||
setUpAll(() {
|
||||
mytest = Directory.systemTemp.createTempSync('incremental');
|
||||
main = new File('${mytest.path}/main.dart')..createSync();
|
||||
|
@ -485,8 +484,8 @@ main() {
|
|||
.listen((String s) async {
|
||||
if (s.startsWith(kObservatoryListening)) {
|
||||
expect(observatoryPortRegExp.hasMatch(s), isTrue);
|
||||
final match = observatoryPortRegExp.firstMatch(s);
|
||||
port = int.parse(match.group(1));
|
||||
final match = observatoryPortRegExp.firstMatch(s)!;
|
||||
port = int.parse(match.group(1)!);
|
||||
await collectAndCheckCoverageData(port, true);
|
||||
if (!portLineCompleter.isCompleted) {
|
||||
portLineCompleter.complete("done");
|
||||
|
@ -503,12 +502,12 @@ main() {
|
|||
});
|
||||
|
||||
group('multiple kernels constant coverage', () {
|
||||
Directory mytest;
|
||||
File main;
|
||||
File lib1;
|
||||
int lineForUnnamedConstructor;
|
||||
int lineForNamedConstructor;
|
||||
Process vm;
|
||||
late Directory mytest;
|
||||
late File main;
|
||||
late File lib1;
|
||||
late int lineForUnnamedConstructor;
|
||||
late int lineForNamedConstructor;
|
||||
late Process vm;
|
||||
setUpAll(() {
|
||||
mytest = Directory.systemTemp.createTempSync('incremental');
|
||||
main = new File('${mytest.path}/main.dart')..createSync();
|
||||
|
@ -594,8 +593,8 @@ main() {
|
|||
}
|
||||
if (s.startsWith(kObservatoryListening)) {
|
||||
expect(observatoryPortRegExp.hasMatch(s), isTrue);
|
||||
final match = observatoryPortRegExp.firstMatch(s);
|
||||
port = int.parse(match.group(1));
|
||||
final match = observatoryPortRegExp.firstMatch(s)!;
|
||||
port = int.parse(match.group(1)!);
|
||||
await collectAndCheckCoverageData(port, true,
|
||||
onGetAllVerifyCount: false, coverageForLines: coverageLines);
|
||||
if (!portLineCompleter.isCompleted) {
|
||||
|
@ -740,11 +739,11 @@ main() {
|
|||
});
|
||||
|
||||
group('multiple kernels 2', () {
|
||||
Directory mytest;
|
||||
File main;
|
||||
File lib1;
|
||||
File lib2;
|
||||
Process vm;
|
||||
late Directory mytest;
|
||||
late File main;
|
||||
late File lib1;
|
||||
late File lib2;
|
||||
late Process vm;
|
||||
setUpAll(() {
|
||||
mytest = Directory.systemTemp.createTempSync('incremental');
|
||||
main = new File('${mytest.path}/main.dart')..createSync();
|
||||
|
@ -849,8 +848,8 @@ main() {
|
|||
.listen((String s) async {
|
||||
if (s.startsWith(kObservatoryListening)) {
|
||||
expect(observatoryPortRegExp.hasMatch(s), isTrue);
|
||||
final match = observatoryPortRegExp.firstMatch(s);
|
||||
port = int.parse(match.group(1));
|
||||
final match = observatoryPortRegExp.firstMatch(s)!;
|
||||
port = int.parse(match.group(1)!);
|
||||
Set<int> hits1 =
|
||||
await collectAndCheckCoverageData(port, true, resume: false);
|
||||
Set<int> hits2 =
|
||||
|
@ -871,7 +870,7 @@ main() {
|
|||
});
|
||||
|
||||
group('reload', () {
|
||||
Directory mytest;
|
||||
late Directory mytest;
|
||||
|
||||
setUpAll(() {
|
||||
mytest = Directory.systemTemp.createTempSync('incremental');
|
||||
|
@ -941,8 +940,8 @@ main() {
|
|||
final RegExp observatoryPortRegExp =
|
||||
new RegExp("Observatory listening on http://127.0.0.1:\([0-9]*\)");
|
||||
expect(observatoryPortRegExp.hasMatch(portLine), isTrue);
|
||||
final match = observatoryPortRegExp.firstMatch(portLine);
|
||||
final port = int.parse(match.group(1));
|
||||
final match = observatoryPortRegExp.firstMatch(portLine)!;
|
||||
final port = int.parse(match.group(1)!);
|
||||
|
||||
var remoteVm = new RemoteVm(port);
|
||||
await remoteVm.resume();
|
||||
|
@ -978,7 +977,7 @@ main() {
|
|||
});
|
||||
|
||||
group('reject', () {
|
||||
Directory mytest;
|
||||
late Directory mytest;
|
||||
setUpAll(() {
|
||||
mytest = Directory.systemTemp.createTempSync('incremental_reject');
|
||||
});
|
||||
|
@ -1025,7 +1024,7 @@ main() {
|
|||
}
|
||||
compiler.accept();
|
||||
{
|
||||
Procedure procedure = await compiler.compileExpression(
|
||||
Procedure? procedure = await compiler.compileExpression(
|
||||
'a', <String>[], <String>[], 'package:foo/bar.dart', 'A', true);
|
||||
expect(procedure, isNotNull);
|
||||
}
|
||||
|
@ -1040,7 +1039,7 @@ main() {
|
|||
}
|
||||
await compiler.reject();
|
||||
{
|
||||
Procedure procedure = await compiler.compileExpression(
|
||||
Procedure? procedure = await compiler.compileExpression(
|
||||
'a', <String>[], <String>[], 'package:foo/bar.dart', 'A', true);
|
||||
expect(procedure, isNotNull);
|
||||
}
|
||||
|
@ -1088,9 +1087,8 @@ main() {
|
|||
}
|
||||
compiler.accept();
|
||||
{
|
||||
final Procedure procedure = await compiler.compileExpression(
|
||||
'a', <String>[], <String>[], barUri.toString(), 'A', true);
|
||||
expect(procedure, isNotNull);
|
||||
final Procedure procedure = (await compiler.compileExpression(
|
||||
'a', <String>[], <String>[], barUri.toString(), 'A', true))!;
|
||||
// Verify that the expression only has links to the only bar we know
|
||||
// about.
|
||||
final LibraryReferenceCollector lrc = new LibraryReferenceCollector();
|
||||
|
@ -1107,8 +1105,8 @@ main() {
|
|||
compiler.invalidate(barUri);
|
||||
{
|
||||
final Component component = await compiler.compile(entryPoint: fooUri);
|
||||
final Library fooLib2 = component.libraries
|
||||
.firstWhere((lib) => lib.fileUri == fooUri, orElse: () => null);
|
||||
final Library? fooLib2 = component.libraries
|
||||
.firstWhereOrNull((lib) => lib.fileUri == fooUri);
|
||||
expect(fooLib2, isNull);
|
||||
final Library barLib2 =
|
||||
component.libraries.firstWhere((lib) => lib.fileUri == barUri);
|
||||
|
@ -1130,13 +1128,12 @@ main() {
|
|||
// Verify that the saved "last known good" compnent only contains links
|
||||
// to the original 'foo' and 'bar' libraries.
|
||||
final LibraryReferenceCollector lrc = new LibraryReferenceCollector();
|
||||
compiler.lastKnownGoodComponent.accept(lrc);
|
||||
compiler.lastKnownGoodComponent!.accept(lrc);
|
||||
expect(lrc.librariesReferenced, equals(<Library>{fooLib, barLib}));
|
||||
}
|
||||
{
|
||||
final Procedure procedure = await compiler.compileExpression(
|
||||
'a', <String>[], <String>[], barUri.toString(), 'A', true);
|
||||
expect(procedure, isNotNull);
|
||||
final Procedure procedure = (await compiler.compileExpression(
|
||||
'a', <String>[], <String>[], barUri.toString(), 'A', true))!;
|
||||
// Verify that the expression only has links to the original bar.
|
||||
final LibraryReferenceCollector lrc = new LibraryReferenceCollector();
|
||||
procedure.accept(lrc);
|
||||
|
@ -1146,8 +1143,8 @@ main() {
|
|||
});
|
||||
|
||||
group('expression evaluation', () {
|
||||
Directory mytest;
|
||||
Process vm;
|
||||
late Directory mytest;
|
||||
late Process vm;
|
||||
|
||||
setUpAll(() {
|
||||
mytest = Directory.systemTemp.createTempSync('expression_evaluation');
|
||||
|
@ -1168,7 +1165,7 @@ main() {
|
|||
|
||||
launchBreakAndEvaluate(File scriptOrDill, String scriptUriToBreakIn,
|
||||
int lineToBreakAt, List<String> expressionsAndExpectedResults,
|
||||
{Future Function(RemoteVm remoteVm) callback}) async {
|
||||
{Future Function(RemoteVm remoteVm)? callback}) async {
|
||||
vm = await Process.start(Platform.resolvedExecutable, <String>[
|
||||
"--pause-isolates-on-start",
|
||||
"--enable-vm-service:0",
|
||||
|
@ -1190,8 +1187,8 @@ main() {
|
|||
print("vm stdout: $s");
|
||||
if (s.startsWith(kObservatoryListening)) {
|
||||
expect(observatoryPortRegExp.hasMatch(s), isTrue);
|
||||
final match = observatoryPortRegExp.firstMatch(s);
|
||||
port = int.parse(match.group(1));
|
||||
final match = observatoryPortRegExp.firstMatch(s)!;
|
||||
port = int.parse(match.group(1)!);
|
||||
RemoteVm remoteVm = new RemoteVm(port);
|
||||
|
||||
// Wait for the script to have loaded.
|
||||
|
@ -1591,7 +1588,7 @@ Future findScriptAndBreak(
|
|||
RemoteVm remoteVm, String scriptUriToBreakIn, int lineToBreakAt) async {
|
||||
Map scriptsMap = await remoteVm.getScripts();
|
||||
List scripts = scriptsMap["scripts"];
|
||||
String scriptId;
|
||||
String? scriptId;
|
||||
for (int i = 0; i < scripts.length; i++) {
|
||||
Map script = scripts[i];
|
||||
String scriptUri = script["uri"];
|
||||
|
@ -1602,7 +1599,7 @@ Future findScriptAndBreak(
|
|||
}
|
||||
expect(scriptId, isNotNull);
|
||||
|
||||
return await remoteVm.addBreakpoint(scriptId, lineToBreakAt);
|
||||
return await remoteVm.addBreakpoint(scriptId!, lineToBreakAt);
|
||||
}
|
||||
|
||||
Future deletePossibleBreakpoint(
|
||||
|
@ -1643,12 +1640,12 @@ class RemoteVm {
|
|||
/// An peer point used to send service protocol messages. The service
|
||||
/// protocol uses JSON rpc on top of web-sockets.
|
||||
json_rpc.Peer get rpc => _rpc ??= _createPeer();
|
||||
json_rpc.Peer _rpc;
|
||||
json_rpc.Peer? _rpc;
|
||||
|
||||
/// The main isolate ID of the running VM. Needed to indicate to the VM which
|
||||
/// isolate to reload.
|
||||
FutureOr<String> get mainId async => _mainId ??= await _computeMainId();
|
||||
String _mainId;
|
||||
String? _mainId;
|
||||
|
||||
RemoteVm([this.port = 8181]);
|
||||
|
||||
|
@ -1701,41 +1698,34 @@ class RemoteVm {
|
|||
await rpc.sendRequest('resume', {'isolateId': id});
|
||||
}
|
||||
|
||||
Future getIsolate() async {
|
||||
Future<Map> getIsolate() async {
|
||||
var id = await mainId;
|
||||
return await rpc.sendRequest('getIsolate', {'isolateId': id});
|
||||
return (await rpc.sendRequest('getIsolate', {'isolateId': id})) as Map;
|
||||
}
|
||||
|
||||
Future getScripts() async {
|
||||
Future<Map> getScripts() async {
|
||||
var id = await mainId;
|
||||
return await rpc.sendRequest('getScripts', {
|
||||
return (await rpc.sendRequest('getScripts', {
|
||||
'isolateId': id,
|
||||
});
|
||||
})) as Map;
|
||||
}
|
||||
|
||||
Future getSourceReport([String scriptId]) async {
|
||||
Future<Map> getSourceReport([String? scriptId]) async {
|
||||
var id = await mainId;
|
||||
if (scriptId != null) {
|
||||
return await rpc.sendRequest('getSourceReport', {
|
||||
'isolateId': id,
|
||||
'scriptId': scriptId,
|
||||
'reports': ['Coverage', 'PossibleBreakpoints'],
|
||||
'forceCompile': true
|
||||
});
|
||||
}
|
||||
return await rpc.sendRequest('getSourceReport', {
|
||||
return (await rpc.sendRequest('getSourceReport', {
|
||||
'isolateId': id,
|
||||
if (scriptId != null) 'scriptId': scriptId,
|
||||
'reports': ['Coverage', 'PossibleBreakpoints'],
|
||||
'forceCompile': true
|
||||
});
|
||||
'forceCompile': true,
|
||||
})) as Map;
|
||||
}
|
||||
|
||||
Future getObject(String objectId) async {
|
||||
Future<Map> getObject(String objectId) async {
|
||||
var id = await mainId;
|
||||
return await rpc.sendRequest('getObject', {
|
||||
return (await rpc.sendRequest('getObject', {
|
||||
'isolateId': id,
|
||||
'objectId': objectId,
|
||||
});
|
||||
})) as Map;
|
||||
}
|
||||
|
||||
Future addBreakpoint(String scriptId, int line) async {
|
||||
|
@ -1769,21 +1759,22 @@ class RemoteVm {
|
|||
int expectGcAfter = new DateTime.now().millisecondsSinceEpoch;
|
||||
while (true) {
|
||||
var id = await mainId;
|
||||
Map result = await rpc.sendRequest('getAllocationProfile', {
|
||||
Map result = (await rpc.sendRequest('getAllocationProfile', {
|
||||
'isolateId': id,
|
||||
"gc": true,
|
||||
});
|
||||
String lastGc = result["dateLastServiceGC"];
|
||||
})) as Map;
|
||||
String? lastGc = result["dateLastServiceGC"];
|
||||
if (lastGc != null && int.parse(lastGc) >= expectGcAfter) return;
|
||||
}
|
||||
}
|
||||
|
||||
/// Close any connections used to communicate with the VM.
|
||||
Future disconnect() async {
|
||||
if (_rpc == null) return null;
|
||||
final rpc = this._rpc;
|
||||
if (rpc == null) return null;
|
||||
this._mainId = null;
|
||||
if (!_rpc.isClosed) {
|
||||
var future = _rpc.close();
|
||||
if (!rpc.isClosed) {
|
||||
var future = rpc.close();
|
||||
_rpc = null;
|
||||
return future;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:front_end/src/api_unstable/vm.dart'
|
||||
|
@ -22,14 +20,14 @@ const String mainScriptPackageUri = 'package:vm/kernel_front_end.dart';
|
|||
const String packagesFile = '.packages';
|
||||
const String packageConfigFile = '.dart_tool/package_config.json';
|
||||
|
||||
void testCompile(List<String> args) async {
|
||||
Future<void> testCompile(List<String> args) async {
|
||||
final compilerExitCode =
|
||||
await runCompiler(createCompilerArgParser().parse(args), '');
|
||||
expect(compilerExitCode, successExitCode);
|
||||
}
|
||||
|
||||
main() {
|
||||
Directory tempDir;
|
||||
late Directory tempDir;
|
||||
setUp(() {
|
||||
var systemTempDir = Directory.systemTemp;
|
||||
tempDir = systemTempDir.createTempSync('kernel_front_end_test');
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
@ -35,14 +33,14 @@ main() async {
|
|||
await withTempDirectory((Uri uri) async {
|
||||
final mixinFilename = uri.resolve('mixin.dart');
|
||||
final mixinDillFilename = uri.resolve('mixin.dart.dill');
|
||||
await File.fromUri(mixinFilename).writeAsStringSync(mixinFile);
|
||||
File.fromUri(mixinFilename).writeAsStringSync(mixinFile);
|
||||
|
||||
await compileToKernel(vmTarget, librariesFile, sdkSummary, packagesFile,
|
||||
mixinDillFilename, <Uri>[mixinFilename], <Uri>[]);
|
||||
|
||||
final mainFilename = uri.resolve('main.dart');
|
||||
final mainDillFilename = uri.resolve('main.dart.dill');
|
||||
await File.fromUri(mainFilename).writeAsStringSync(mainFile);
|
||||
File.fromUri(mainFilename).writeAsStringSync(mainFile);
|
||||
|
||||
await compileToKernel(vmTarget, librariesFile, sdkSummary, packagesFile,
|
||||
mainDillFilename, <Uri>[mainFilename], <Uri>[mixinDillFilename]);
|
||||
|
@ -98,9 +96,9 @@ Future compileToKernel(
|
|||
message.plainTextFormatted.forEach(print);
|
||||
}
|
||||
|
||||
final Component component =
|
||||
final Component? component =
|
||||
await fe.compileComponent(state, sources, onDiagnostic);
|
||||
final Uint8List kernel = fe.serializeComponent(component,
|
||||
final Uint8List kernel = fe.serializeComponent(component!,
|
||||
filter: (library) => sources.contains(library.importUri));
|
||||
await File(outputFile.toFilePath()).writeAsBytes(kernel);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:kernel/target/targets.dart';
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:kernel/target/targets.dart';
|
||||
|
@ -38,7 +36,7 @@ Future<void> shakeAndRun(Uri source) async {
|
|||
.expand(
|
||||
(lib) => lib.classes.where((klass) =>
|
||||
klass.superclass != null &&
|
||||
klass.superclass.name == "GeneratedMessage"),
|
||||
klass.superclass!.name == "GeneratedMessage"),
|
||||
)
|
||||
.toList();
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:kernel/ast.dart';
|
||||
|
@ -29,7 +27,7 @@ runTestCase(List<String> packageUris, String expectationName) async {
|
|||
transformComponent(component, packageUris);
|
||||
verifyComponent(component);
|
||||
|
||||
final actual = kernelLibraryToString(component.mainMethod.enclosingLibrary);
|
||||
final actual = kernelLibraryToString(component.mainMethod!.enclosingLibrary);
|
||||
|
||||
compareResultWithExpectationsFile(
|
||||
testCasesUri.resolve(expectationName), actual);
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:kernel/ast.dart';
|
||||
|
@ -64,7 +62,7 @@ class FakeEntryPointsListener implements EntryPointsListener {
|
|||
}
|
||||
|
||||
class PrintSummaries extends RecursiveVisitor {
|
||||
SummaryCollector _summaryCollector;
|
||||
late SummaryCollector _summaryCollector;
|
||||
final StringBuffer _buf = new StringBuffer();
|
||||
|
||||
PrintSummaries(Target target, TypeEnvironment environment,
|
||||
|
@ -77,12 +75,12 @@ class PrintSummaries extends RecursiveVisitor {
|
|||
new FakeEntryPointsListener(typesBuilder),
|
||||
typesBuilder,
|
||||
new NativeCodeOracle(
|
||||
null, new ConstantPragmaAnnotationParser(coreTypes)),
|
||||
coreTypes.index, new ConstantPragmaAnnotationParser(coreTypes)),
|
||||
new GenericInterfacesInfoImpl(coreTypes, hierarchy),
|
||||
/*_protobufHandler=*/ null);
|
||||
}
|
||||
|
||||
String print(TreeNode node) {
|
||||
String print(Library node) {
|
||||
visitLibrary(node);
|
||||
return _buf.toString();
|
||||
}
|
||||
|
@ -101,10 +99,11 @@ class PrintSummaries extends RecursiveVisitor {
|
|||
runTestCase(Uri source) async {
|
||||
final Target target = new TestingVmTarget(new TargetFlags());
|
||||
final Component component = await compileTestCaseToKernelProgram(source);
|
||||
final Library library = component.mainMethod.enclosingLibrary;
|
||||
final Library library = component.mainMethod!.enclosingLibrary;
|
||||
final CoreTypes coreTypes = new CoreTypes(component);
|
||||
|
||||
final ClassHierarchy hierarchy = new ClassHierarchy(component, coreTypes);
|
||||
final ClosedWorldClassHierarchy hierarchy =
|
||||
new ClassHierarchy(component, coreTypes) as ClosedWorldClassHierarchy;
|
||||
final typeEnvironment = new TypeEnvironment(coreTypes, hierarchy);
|
||||
|
||||
final actual =
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:kernel/target/targets.dart';
|
||||
|
@ -33,7 +31,7 @@ runTestCase(
|
|||
matcher: new ConstantPragmaAnnotationParser(coreTypes),
|
||||
treeShakeProtobufs: true);
|
||||
|
||||
String actual = kernelLibraryToString(component.mainMethod.enclosingLibrary);
|
||||
String actual = kernelLibraryToString(component.mainMethod!.enclosingLibrary);
|
||||
|
||||
// Tests in /protobuf_handler consist of multiple libraries.
|
||||
// Include libraries with protobuf generated messages into the result.
|
||||
|
@ -55,7 +53,7 @@ runTestCase(
|
|||
ensureKernelCanBeSerializedToBinary(component);
|
||||
}
|
||||
|
||||
String argsTestName(List<String> args) {
|
||||
String? argsTestName(List<String> args) {
|
||||
if (args.length > 0) {
|
||||
return args.last;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:core' hide Type;
|
||||
|
||||
import 'package:kernel/ast.dart';
|
||||
|
@ -23,15 +21,12 @@ class TestTypeHierarchy extends TypeHierarchy {
|
|||
|
||||
@override
|
||||
bool isSubtype(Class sub, Class sup) {
|
||||
return subtypes[sup].contains(sub);
|
||||
return subtypes[sup]!.contains(sub);
|
||||
}
|
||||
|
||||
@override
|
||||
Type specializeTypeCone(TFClass base, {bool allowWideCone = false}) {
|
||||
Type result = specializations[base.classNode];
|
||||
expect(result, isNotNull,
|
||||
reason: "specializeTypeCone($base) is not defined");
|
||||
return result;
|
||||
return specializations[base.classNode]!;
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -104,10 +99,10 @@ main() {
|
|||
test('union-intersection', () {
|
||||
// T1 <: T3, T2 <: T3
|
||||
|
||||
final c1 = new Class(name: 'T1', fileUri: dummyUri);
|
||||
final c2 = new Class(name: 'T2', fileUri: dummyUri);
|
||||
final c3 = new Class(name: 'T3', fileUri: dummyUri);
|
||||
final c4 = new Class(name: 'T4', fileUri: dummyUri);
|
||||
final c1 = new Class(name: 'T1', fileUri: dummyUri)..parent = dummyLibrary;
|
||||
final c2 = new Class(name: 'T2', fileUri: dummyUri)..parent = dummyLibrary;
|
||||
final c3 = new Class(name: 'T3', fileUri: dummyUri)..parent = dummyLibrary;
|
||||
final c4 = new Class(name: 'T4', fileUri: dummyUri)..parent = dummyLibrary;
|
||||
|
||||
final tfc1 = new TFClass(1, c1);
|
||||
final tfc2 = new TFClass(2, c2);
|
||||
|
@ -295,9 +290,9 @@ main() {
|
|||
});
|
||||
|
||||
test('hashcode-equals', () {
|
||||
final c1 = new Class(name: 'C1', fileUri: dummyUri);
|
||||
final c2 = new Class(name: 'C2', fileUri: dummyUri);
|
||||
final c3 = new Class(name: 'C3', fileUri: dummyUri);
|
||||
final c1 = new Class(name: 'C1', fileUri: dummyUri)..parent = dummyLibrary;
|
||||
final c2 = new Class(name: 'C2', fileUri: dummyUri)..parent = dummyLibrary;
|
||||
final c3 = new Class(name: 'C3', fileUri: dummyUri)..parent = dummyLibrary;
|
||||
|
||||
final tfc1 = new TFClass(1, c1);
|
||||
final tfc2 = new TFClass(2, c2);
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:kernel/target/targets.dart';
|
||||
|
@ -30,7 +28,7 @@ runTestCase(Uri source) async {
|
|||
component = transformComponent(component, /* enableAsserts = */ false);
|
||||
verifyComponent(component);
|
||||
|
||||
final actual = kernelLibraryToString(component.mainMethod.enclosingLibrary);
|
||||
final actual = kernelLibraryToString(component.mainMethod!.enclosingLibrary);
|
||||
|
||||
compareResultWithExpectationsFile(source, actual);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
|
|
|
@ -256,8 +256,8 @@ static Dart_NativeFunction NativeResolver(Dart_Handle name,
|
|||
// Measure compile of all kernel Service(CFE) functions.
|
||||
//
|
||||
BENCHMARK(KernelServiceCompileAll) {
|
||||
if (FLAG_sound_null_safety == kNullSafetyOptionStrong) {
|
||||
// TODO(bkonyi): remove this check when we build the CFE in strong mode.
|
||||
// kernel_service.dill is built with sound null safety.
|
||||
if (FLAG_sound_null_safety != kNullSafetyOptionStrong) {
|
||||
return;
|
||||
}
|
||||
bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary);
|
||||
|
|
|
@ -88,6 +88,7 @@ class RunKernelTask : public ThreadPool::Task {
|
|||
Dart_IsolateFlags api_flags;
|
||||
Isolate::FlagsInitialize(&api_flags);
|
||||
api_flags.enable_asserts = false;
|
||||
api_flags.null_safety = true;
|
||||
api_flags.is_system_isolate = true;
|
||||
#if !defined(DART_PRECOMPILER)
|
||||
api_flags.use_field_guards = true;
|
||||
|
|
Loading…
Reference in a new issue