[kernel] Remove NonNullableByDefaultCompiledMode
and TargetFlags.soundNullSafety TEST=existing Change-Id: I5e28d3d187b0f84fa23130c042fd3c55b89c687c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413460 Reviewed-by: Ömer Ağacan <omersa@google.com> Reviewed-by: Jens Johansen <jensj@google.com> Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Nate Biggs <natebiggs@google.com>
This commit is contained in:
committed by
Commit Queue
parent
4884112185
commit
06d938046f
@@ -310,13 +310,12 @@ class Compiler {
|
||||
irLibraries.add(irLibraryMap[library]!);
|
||||
}
|
||||
var mainMethod = component.mainMethodName;
|
||||
var componentMode = component.mode;
|
||||
final trimmedComponent = ir.Component(
|
||||
libraries: irLibraries,
|
||||
uriToSource: component.uriToSource,
|
||||
nameRoot: component.root,
|
||||
);
|
||||
trimmedComponent.setMainMethodAndMode(mainMethod, true, componentMode);
|
||||
trimmedComponent.setMainMethodAndMode(mainMethod, true);
|
||||
return trimmedComponent;
|
||||
}
|
||||
|
||||
|
||||
@@ -242,7 +242,7 @@ Future<_LoadFromKernelResult> _loadFromKernel(
|
||||
if (options.entryUri != null) {
|
||||
entryLibrary = _findEntryLibrary(component, options.entryUri!);
|
||||
var mainMethod = _findMainMethod(entryLibrary);
|
||||
component.setMainMethodAndMode(mainMethod, true, component.mode);
|
||||
component.setMainMethodAndMode(mainMethod, true);
|
||||
}
|
||||
|
||||
_doTransformsOnKernelLoad(component, options, reporter);
|
||||
|
||||
@@ -250,8 +250,7 @@ class DynamicModuleStrategy extends DefaultModuleStrategy with KernelNodes {
|
||||
if (hasPragma(coreTypes, library, _mainLibPragma)) {
|
||||
final mainMethod = library.procedures
|
||||
.firstWhere((m) => hasPragma(coreTypes, m, _mainMethodPragma));
|
||||
component.setMainMethodAndMode(
|
||||
mainMethod.reference, true, component.mode);
|
||||
component.setMainMethodAndMode(mainMethod.reference, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -839,13 +839,8 @@ ModuleSymbols _emitSymbols(Compiler compiler, String moduleName,
|
||||
|
||||
ModuleMetadata _emitMetadata(js_ast.Program program, Component component,
|
||||
String sourceMapUri, String moduleUri, String? fullDillUri) {
|
||||
var metadata = ModuleMetadata(
|
||||
program.name!,
|
||||
loadFunctionName(program.name!),
|
||||
sourceMapUri,
|
||||
moduleUri,
|
||||
fullDillUri,
|
||||
component.mode == NonNullableByDefaultCompiledMode.Strong);
|
||||
var metadata = ModuleMetadata(program.name!, loadFunctionName(program.name!),
|
||||
sourceMapUri, moduleUri, fullDillUri);
|
||||
|
||||
for (var lib in component.libraries) {
|
||||
metadata.addLibrary(LibraryMetadata(
|
||||
|
||||
@@ -429,8 +429,7 @@ class ExpressionCompilerWorker {
|
||||
libraries: libraries,
|
||||
nameRoot: originalComponent.root,
|
||||
uriToSource: originalComponent.uriToSource,
|
||||
)..setMainMethodAndMode(
|
||||
originalComponent.mainMethodName, true, originalComponent.mode);
|
||||
)..setMainMethodAndMode(originalComponent.mainMethodName, true);
|
||||
_processedOptions.ticker.logMs('Collected libraries for $moduleName');
|
||||
}
|
||||
|
||||
@@ -491,8 +490,7 @@ class ExpressionCompilerWorker {
|
||||
libraries: librariesToEmit,
|
||||
nameRoot: finalComponent.root,
|
||||
uriToSource: finalComponent.uriToSource)
|
||||
..setMainMethodAndMode(
|
||||
originalComponent.mainMethodName, true, originalComponent.mode);
|
||||
..setMainMethodAndMode(originalComponent.mainMethodName, true);
|
||||
|
||||
kernel2jsCompiler.emitModule(componentToEmit);
|
||||
_processedOptions.ticker.logMs('Emitted module for expression');
|
||||
|
||||
@@ -127,12 +127,8 @@ class ModuleMetadata {
|
||||
|
||||
final Map<String, LibraryMetadata> libraries = {};
|
||||
|
||||
/// True if the module corresponding to this metadata was compiled with sound
|
||||
/// null safety enabled.
|
||||
final bool soundNullSafety;
|
||||
|
||||
ModuleMetadata(this.name, this.closureName, this.sourceMapUri, this.moduleUri,
|
||||
this.fullDillUri, this.soundNullSafety,
|
||||
this.fullDillUri,
|
||||
{String? version})
|
||||
: version = version ??= ModuleMetadataVersion.current.version;
|
||||
|
||||
@@ -157,8 +153,7 @@ class ModuleMetadata {
|
||||
closureName = json['closureName'] as String,
|
||||
sourceMapUri = json['sourceMapUri'] as String,
|
||||
moduleUri = json['moduleUri'] as String,
|
||||
fullDillUri = json['fullDillUri'] as String,
|
||||
soundNullSafety = json['soundNullSafety'] as bool {
|
||||
fullDillUri = json['fullDillUri'] as String {
|
||||
if (!ModuleMetadataVersion.current.isCompatibleWith(version)) {
|
||||
throw Exception('Unsupported metadata version $version');
|
||||
}
|
||||
@@ -176,8 +171,7 @@ class ModuleMetadata {
|
||||
'sourceMapUri': sourceMapUri,
|
||||
'moduleUri': moduleUri,
|
||||
'fullDillUri': fullDillUri,
|
||||
'libraries': [for (var lib in libraries.values) lib.toJson()],
|
||||
'soundNullSafety': soundNullSafety
|
||||
'libraries': [for (var lib in libraries.values) lib.toJson()]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ void main() {
|
||||
}
|
||||
|
||||
ModuleMetadata createMetadata(String version) => ModuleMetadata(
|
||||
'module', 'closure', 'module.map', 'module.js', 'module.full.dill', true,
|
||||
'module', 'closure', 'module.map', 'module.js', 'module.full.dill',
|
||||
version: version)
|
||||
..addLibrary(LibraryMetadata('library', 'package:library/test.dart',
|
||||
'file:///source/library/lib/test.dart', ['src/test2.dart']));
|
||||
@@ -125,7 +125,6 @@ void testMetadataFields(ModuleMetadata module, String version) {
|
||||
expect(module.sourceMapUri, 'module.map');
|
||||
expect(module.moduleUri, 'module.js');
|
||||
expect(module.fullDillUri, 'module.full.dill');
|
||||
expect(module.soundNullSafety, true);
|
||||
|
||||
var libUri = module.libraries.keys.first;
|
||||
var lib = module.libraries[libUri]!;
|
||||
|
||||
@@ -80,7 +80,7 @@ class DdcResult {
|
||||
Component _computeCompiledLibraries() {
|
||||
Component compiledLibraries = new Component(
|
||||
nameRoot: component.root, uriToSource: component.uriToSource)
|
||||
..setMainMethodAndMode(null, false, component.mode);
|
||||
..setMainMethodAndMode(null, false);
|
||||
for (Library lib in component.libraries) {
|
||||
if (!librariesFromDill.contains(lib)) {
|
||||
compiledLibraries.libraries.add(lib);
|
||||
|
||||
@@ -14,8 +14,7 @@ import 'package:kernel/binary/ast_from_binary.dart'
|
||||
CompilationModeError,
|
||||
InvalidKernelSdkVersionError,
|
||||
InvalidKernelVersionError,
|
||||
SubComponentView,
|
||||
mergeCompilationModeOrThrow;
|
||||
SubComponentView;
|
||||
import 'package:kernel/canonical_name.dart'
|
||||
show CanonicalNameError, CanonicalNameSdkError;
|
||||
import 'package:kernel/class_hierarchy.dart'
|
||||
@@ -39,7 +38,6 @@ import 'package:kernel/kernel.dart'
|
||||
Name,
|
||||
NamedNode,
|
||||
Node,
|
||||
NonNullableByDefaultCompiledMode,
|
||||
Procedure,
|
||||
ProcedureKind,
|
||||
Reference,
|
||||
@@ -492,14 +490,9 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
|
||||
data.component?.mainMethod
|
||||
: componentWithDill.mainMethod;
|
||||
// ignore: unnecessary_null_comparison
|
||||
NonNullableByDefaultCompiledMode? compiledMode = componentWithDill == null
|
||||
?
|
||||
// Coverage-ignore(suite): Not run.
|
||||
data.component?.mode
|
||||
: componentWithDill.mode;
|
||||
Component result = context.options.target.configureComponent(
|
||||
new Component(libraries: outputLibraries, uriToSource: uriToSource))
|
||||
..setMainMethodAndMode(mainMethod?.reference, true, compiledMode!)
|
||||
..setMainMethodAndMode(mainMethod?.reference, true)
|
||||
..problemsAsJson = problemsAsJson;
|
||||
|
||||
// Copy the metadata *just created*. This will likely not contain metadata
|
||||
@@ -944,28 +937,9 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
|
||||
_dillLoadedData!.loader.currentSourceLoader = kernelTarget.loader;
|
||||
|
||||
// Re-use the libraries we've deemed re-usable.
|
||||
List<bool> seenModes = [false, false, false, false];
|
||||
for (DillLibraryBuilder library in reusedLibraries) {
|
||||
seenModes[library.library.nonNullableByDefaultCompiledMode.index] = true;
|
||||
kernelTarget.loader.registerLoadedDillLibraryBuilder(library);
|
||||
}
|
||||
// Check compilation mode up against what we've seen here and set
|
||||
// `hasInvalidNnbdModeLibrary` accordingly.
|
||||
if (c.options.globalFeatures.nonNullable.isEnabled) {
|
||||
// Don't expect weak or invalid.
|
||||
if (seenModes[NonNullableByDefaultCompiledMode.Weak.index] ||
|
||||
seenModes[NonNullableByDefaultCompiledMode.Invalid.index]) {
|
||||
// Coverage-ignore-block(suite): Not run.
|
||||
kernelTarget.loader.hasInvalidNnbdModeLibrary = true;
|
||||
}
|
||||
} else {
|
||||
// Coverage-ignore-block(suite): Not run.
|
||||
// Don't expect strong or invalid.
|
||||
if (seenModes[NonNullableByDefaultCompiledMode.Strong.index] ||
|
||||
seenModes[NonNullableByDefaultCompiledMode.Invalid.index]) {
|
||||
kernelTarget.loader.hasInvalidNnbdModeLibrary = true;
|
||||
}
|
||||
}
|
||||
|
||||
// The entry point(s) has to be set first for loader.firstUri to be setup
|
||||
// correctly.
|
||||
@@ -2491,8 +2465,7 @@ class _InitializationFromComponent extends _InitializationStrategy {
|
||||
.mainMethod
|
||||
// Coverage-ignore(suite): Not run.
|
||||
?.reference,
|
||||
true,
|
||||
componentToInitializeFrom.mode);
|
||||
true);
|
||||
componentProblems.saveComponentProblems(component);
|
||||
|
||||
bool foundDartCore = false;
|
||||
@@ -2621,10 +2594,6 @@ class _InitializationFromUri extends _InitializationFromSdkSummary {
|
||||
.readComponent(data.component!,
|
||||
checkCanonicalNames: true, createView: true)!;
|
||||
|
||||
// Compute "output nnbd mode".
|
||||
NonNullableByDefaultCompiledMode compiledMode =
|
||||
NonNullableByDefaultCompiledMode.Strong;
|
||||
|
||||
// Check the any package-urls still point to the same file
|
||||
// (e.g. the package still exists and hasn't been updated).
|
||||
// Also verify NNBD settings.
|
||||
@@ -2638,16 +2607,6 @@ class _InitializationFromUri extends _InitializationFromSdkSummary {
|
||||
// For now just don't initialize from this dill.
|
||||
throw const PackageChangedError();
|
||||
}
|
||||
// Note: If a library has a NonNullableByDefaultCompiledMode.invalid
|
||||
// we will throw and we won't initialize from it.
|
||||
// That's wanted behavior.
|
||||
if (compiledMode !=
|
||||
mergeCompilationModeOrThrow(
|
||||
compiledMode, lib.nonNullableByDefaultCompiledMode)) {
|
||||
throw new CompilationModeError(
|
||||
"Can't compile to $compiledMode with library with mode "
|
||||
"${lib.nonNullableByDefaultCompiledMode}.");
|
||||
}
|
||||
}
|
||||
|
||||
// Only initialize the incremental serializer when we know we'll
|
||||
|
||||
@@ -298,7 +298,7 @@ class IncrementalSerializer {
|
||||
libraries: libraries,
|
||||
uriToSource: component.uriToSource,
|
||||
nameRoot: component.root);
|
||||
singlePackageLibraries.setMainMethodAndMode(null, false, component.mode);
|
||||
singlePackageLibraries.setMainMethodAndMode(null, false);
|
||||
|
||||
// Copy all metadata. This should be okay (e.g. not result in a leak)
|
||||
// because we serialize now and then (implicitly) throw this component away.
|
||||
|
||||
@@ -13,12 +13,7 @@ import 'package:_fe_analyzer_shared/src/util/libraries_specification.dart'
|
||||
TargetLibrariesSpecification;
|
||||
import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;
|
||||
import 'package:kernel/kernel.dart'
|
||||
show
|
||||
CanonicalName,
|
||||
Component,
|
||||
Location,
|
||||
NonNullableByDefaultCompiledMode,
|
||||
Version;
|
||||
show CanonicalName, Component, Location, Version;
|
||||
import 'package:kernel/target/targets.dart'
|
||||
show NoneTarget, Target, TargetFlags;
|
||||
import 'package:package_config/package_config.dart';
|
||||
@@ -454,7 +449,7 @@ class ProcessedOptions {
|
||||
Target? _target;
|
||||
Target get target => _target ??= _raw.target ??
|
||||
// Coverage-ignore(suite): Not run.
|
||||
new NoneTarget(new TargetFlags(soundNullSafety: true));
|
||||
new NoneTarget(new TargetFlags());
|
||||
|
||||
/// Returns the global state of the experimental features.
|
||||
flags.GlobalFeatures get globalFeatures => _raw.globalFeatures;
|
||||
@@ -477,22 +472,6 @@ class ProcessedOptions {
|
||||
return _raw.isExperimentEnabledInLibraryByVersion(flag, importUri, version);
|
||||
}
|
||||
|
||||
Component _validateNullSafetyMode(Component component) {
|
||||
if (component.mode == NonNullableByDefaultCompiledMode.Invalid) {
|
||||
throw new FormatException(
|
||||
'Provided .dill file for the following libraries has an invalid null '
|
||||
'safety mode and does not support null safety:\n'
|
||||
'${component.libraries.join('\n')}');
|
||||
}
|
||||
if (component.mode != NonNullableByDefaultCompiledMode.Strong) {
|
||||
throw new FormatException(
|
||||
'Provided .dill file for the following libraries does not '
|
||||
'support sound null safety:\n'
|
||||
'${component.libraries.join('\n')}');
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
/// Get an outline component that summarizes the SDK, if any.
|
||||
// TODO(sigmund): move, this doesn't feel like an "option".
|
||||
Future<Component?> loadSdkSummary(CanonicalName? nameRoot) async {
|
||||
@@ -512,7 +491,6 @@ class ProcessedOptions {
|
||||
if (_sdkSummaryComponent != null) {
|
||||
throw new StateError("sdkSummary already loaded.");
|
||||
}
|
||||
_validateNullSafetyMode(platform);
|
||||
_sdkSummaryComponent = platform;
|
||||
}
|
||||
|
||||
@@ -550,7 +528,7 @@ class ProcessedOptions {
|
||||
disableLazyReading: false,
|
||||
alwaysCreateNewNamedNodes: alwaysCreateNewNamedNodes)
|
||||
.readComponent(component);
|
||||
return _validateNullSafetyMode(component);
|
||||
return component;
|
||||
}
|
||||
|
||||
/// Get the [UriTranslator] which resolves "package:" and "dart:" URIs.
|
||||
|
||||
@@ -760,12 +760,6 @@ class KernelTarget {
|
||||
Component component = backendTarget.configureComponent(new Component(
|
||||
nameRoot: nameRoot, libraries: libraries, uriToSource: uriToSource));
|
||||
|
||||
NonNullableByDefaultCompiledMode? compiledMode =
|
||||
NonNullableByDefaultCompiledMode.Strong;
|
||||
if (loader.hasInvalidNnbdModeLibrary) {
|
||||
compiledMode = NonNullableByDefaultCompiledMode.Invalid;
|
||||
}
|
||||
|
||||
Reference? mainReference;
|
||||
|
||||
LibraryBuilder? firstRoot = loader.rootLibrary;
|
||||
@@ -785,83 +779,12 @@ class KernelTarget {
|
||||
mainReference = declaration.invokeTarget.reference;
|
||||
}
|
||||
}
|
||||
component.setMainMethodAndMode(mainReference, true, compiledMode);
|
||||
|
||||
assert(_getLibraryNnbdModeError(component) == null,
|
||||
"Got error: ${_getLibraryNnbdModeError(component)}");
|
||||
component.setMainMethodAndMode(mainReference, true);
|
||||
|
||||
ticker.logMs("Linked component");
|
||||
return component;
|
||||
}
|
||||
|
||||
String? _getLibraryNnbdModeError(Component component) {
|
||||
if (loader.hasInvalidNnbdModeLibrary) {
|
||||
// Coverage-ignore-block(suite): Not run.
|
||||
// At least 1 library should be invalid or there should be a mix of strong
|
||||
// and weak. For libraries we've just compiled it will be marked as
|
||||
// invalid, but for libraries loaded from dill they have their original
|
||||
// value (i.e. either strong or weak).
|
||||
bool foundInvalid = false;
|
||||
bool foundStrong = false;
|
||||
bool foundWeak = false;
|
||||
for (Library library in component.libraries) {
|
||||
if (library.nonNullableByDefaultCompiledMode ==
|
||||
NonNullableByDefaultCompiledMode.Invalid) {
|
||||
foundInvalid = true;
|
||||
break;
|
||||
} else if (!foundWeak &&
|
||||
library.nonNullableByDefaultCompiledMode ==
|
||||
NonNullableByDefaultCompiledMode.Weak) {
|
||||
foundWeak = true;
|
||||
if (foundStrong) break;
|
||||
} else if (!foundStrong &&
|
||||
library.nonNullableByDefaultCompiledMode ==
|
||||
NonNullableByDefaultCompiledMode.Strong) {
|
||||
foundStrong = true;
|
||||
if (foundWeak) break;
|
||||
}
|
||||
}
|
||||
if (!foundInvalid && !(foundStrong && foundWeak)) {
|
||||
return "hasInvalidNnbdModeLibrary is true, but no library was invalid "
|
||||
"and there was no weak/strong mix.";
|
||||
}
|
||||
if (component.mode != NonNullableByDefaultCompiledMode.Invalid) {
|
||||
return "Component mode is not invalid as expected";
|
||||
}
|
||||
} else {
|
||||
// No libraries are allowed to be invalid, and should all be compatible
|
||||
// with the component nnbd mode setting.
|
||||
if (component.mode == NonNullableByDefaultCompiledMode.Invalid) {
|
||||
return "Component mode is invalid which was not expected";
|
||||
}
|
||||
if (component.modeRaw == null) {
|
||||
return "Component mode not set at all";
|
||||
}
|
||||
for (Library library in component.libraries) {
|
||||
if (component.mode == NonNullableByDefaultCompiledMode.Strong) {
|
||||
if (library.nonNullableByDefaultCompiledMode !=
|
||||
NonNullableByDefaultCompiledMode.Strong) {
|
||||
// Coverage-ignore-block(suite): Not run.
|
||||
return "Expected library ${library.importUri} to be strong, "
|
||||
"but was ${library.nonNullableByDefaultCompiledMode}";
|
||||
}
|
||||
}
|
||||
// Coverage-ignore(suite): Not run.
|
||||
else if (component.mode == NonNullableByDefaultCompiledMode.Weak) {
|
||||
if (library.nonNullableByDefaultCompiledMode !=
|
||||
NonNullableByDefaultCompiledMode.Weak) {
|
||||
return "Expected library ${library.importUri} to be weak, "
|
||||
"but was ${library.nonNullableByDefaultCompiledMode}";
|
||||
}
|
||||
} else {
|
||||
return "Expected component mode to be either strong, "
|
||||
"weak or agnostic but was ${component.mode}";
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void installDefaultSupertypes() {
|
||||
Class objectClass = this.objectClass;
|
||||
for (SourceLibraryBuilder library in loader.sourceLibraryBuilders) {
|
||||
|
||||
@@ -153,9 +153,7 @@ Component createExpressionEvaluationComponent(Procedure procedure) {
|
||||
|
||||
Uri uri = new Uri(scheme: 'evaluate', path: 'source');
|
||||
Library fakeLibrary = new Library(uri, fileUri: uri)
|
||||
..setLanguageVersion(realLibrary.languageVersion)
|
||||
..nonNullableByDefaultCompiledMode =
|
||||
realLibrary.nonNullableByDefaultCompiledMode;
|
||||
..setLanguageVersion(realLibrary.languageVersion);
|
||||
|
||||
// Add deferred library dependencies. They are needed for serializing
|
||||
// references to deferred libraries. We can just claim ownership of the ones
|
||||
@@ -209,8 +207,7 @@ Component createExpressionEvaluationComponent(Procedure procedure) {
|
||||
|
||||
// TODO(vegorov) find a way to preserve metadata.
|
||||
Component component = new Component(libraries: [fakeLibrary]);
|
||||
component.setMainMethodAndMode(
|
||||
null, false, fakeLibrary.nonNullableByDefaultCompiledMode);
|
||||
component.setMainMethodAndMode(null, false);
|
||||
return component;
|
||||
}
|
||||
|
||||
|
||||
@@ -186,14 +186,8 @@ Future<InternalCompilerResult> _buildInternal(CompilerContext compilerContext,
|
||||
trimmedSummaryComponent.metadata.addAll(summaryComponent.metadata);
|
||||
trimmedSummaryComponent.uriToSource.addAll(summaryComponent.uriToSource);
|
||||
|
||||
NonNullableByDefaultCompiledMode compiledMode =
|
||||
NonNullableByDefaultCompiledMode.Strong;
|
||||
if (kernelTarget.loader.hasInvalidNnbdModeLibrary) {
|
||||
compiledMode = NonNullableByDefaultCompiledMode.Invalid;
|
||||
}
|
||||
|
||||
trimmedSummaryComponent.setMainMethodAndMode(
|
||||
trimmedSummaryComponent.mainMethodName, false, compiledMode);
|
||||
trimmedSummaryComponent.mainMethodName, false);
|
||||
|
||||
// As documented, we only run outline transformations when we are building
|
||||
// summaries without building a full component (at this time, that's
|
||||
|
||||
@@ -984,8 +984,6 @@ class SourceCompilationUnitImpl implements SourceCompilationUnit {
|
||||
|
||||
@override
|
||||
void buildOutlineNode(Library library) {
|
||||
library.nonNullableByDefaultCompiledMode =
|
||||
NonNullableByDefaultCompiledMode.Strong;
|
||||
for (LibraryPart libraryPart in _builderFactoryResult.libraryParts) {
|
||||
library.addPart(libraryPart);
|
||||
}
|
||||
|
||||
@@ -602,28 +602,11 @@ class SourceLoader extends Loader {
|
||||
DillLibraryBuilder? libraryBuilder =
|
||||
target.dillTarget.loader.lookupLibraryBuilder(uri);
|
||||
if (libraryBuilder != null) {
|
||||
_checkDillLibraryBuilderNnbdMode(libraryBuilder);
|
||||
_checkForDartCore(uri, libraryBuilder.mainCompilationUnit);
|
||||
}
|
||||
return libraryBuilder;
|
||||
}
|
||||
|
||||
void _checkDillLibraryBuilderNnbdMode(DillLibraryBuilder libraryBuilder) {
|
||||
NonNullableByDefaultCompiledMode libraryMode =
|
||||
libraryBuilder.library.nonNullableByDefaultCompiledMode;
|
||||
if (libraryMode == NonNullableByDefaultCompiledMode.Invalid) {
|
||||
// Coverage-ignore-block(suite): Not run.
|
||||
registerNnbdMismatchLibrary(
|
||||
libraryBuilder, messageInvalidNnbdDillLibrary);
|
||||
} else {
|
||||
if (libraryMode != NonNullableByDefaultCompiledMode.Strong) {
|
||||
// Coverage-ignore-block(suite): Not run.
|
||||
registerNnbdMismatchLibrary(
|
||||
libraryBuilder, messageStrongWithWeakDillLibrary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _markDartLibraries(Uri uri, CompilationUnit compilationUnit) {
|
||||
if (uri.isScheme("dart")) {
|
||||
if (uri.path == "core") {
|
||||
@@ -1094,18 +1077,6 @@ severity: $severity
|
||||
});
|
||||
}
|
||||
|
||||
bool hasInvalidNnbdModeLibrary = false;
|
||||
|
||||
Map<LibraryBuilder, Message>? _nnbdMismatchLibraries;
|
||||
|
||||
// Coverage-ignore(suite): Not run.
|
||||
void registerNnbdMismatchLibrary(
|
||||
LibraryBuilder libraryBuilder, Message message) {
|
||||
_nnbdMismatchLibraries ??= {};
|
||||
_nnbdMismatchLibraries![libraryBuilder] = message;
|
||||
hasInvalidNnbdModeLibrary = true;
|
||||
}
|
||||
|
||||
void registerConstructorToBeInferred(InferableMember inferableMember) {
|
||||
_typeInferenceEngine!.toBeInferred[inferableMember.member] =
|
||||
inferableMember;
|
||||
@@ -1136,14 +1107,6 @@ severity: $severity
|
||||
}
|
||||
currentUriForCrashReporting = null;
|
||||
logSummary(outlineSummaryTemplate);
|
||||
if (_nnbdMismatchLibraries != null) {
|
||||
// Coverage-ignore-block(suite): Not run.
|
||||
for (MapEntry<LibraryBuilder, Message> entry
|
||||
in _nnbdMismatchLibraries!.entries) {
|
||||
addProblem(entry.value, -1, noLength, entry.key.fileUri);
|
||||
}
|
||||
_nnbdMismatchLibraries = null;
|
||||
}
|
||||
if (_unavailableDartLibraries.isNotEmpty) {
|
||||
CompilationUnit? rootLibrary = rootCompilationUnit;
|
||||
LoadedLibraries? loadedLibraries;
|
||||
|
||||
@@ -10,8 +10,6 @@ import 'package:compiler/src/kernel/dart2js_target.dart' show Dart2jsTarget;
|
||||
import 'package:dev_compiler/src/kernel/target.dart' show DevCompilerTarget;
|
||||
import 'package:front_end/src/api_prototype/compiler_options.dart'
|
||||
show CompilerOptions, DiagnosticMessage;
|
||||
import 'package:front_end/src/api_prototype/experimental_flags.dart'
|
||||
show ExperimentalFlag;
|
||||
import 'package:front_end/src/base/compiler_context.dart' show CompilerContext;
|
||||
import 'package:front_end/src/base/incremental_compiler.dart'
|
||||
show IncrementalCompiler;
|
||||
@@ -128,15 +126,12 @@ late IncrementalCompiler incrementalCompiler;
|
||||
Future<void> main(List<String> arguments) async {
|
||||
Uri? platformUri;
|
||||
Uri mainUri;
|
||||
bool nnbd = false;
|
||||
String targetString = "VM";
|
||||
|
||||
String? filename;
|
||||
for (String arg in arguments) {
|
||||
if (arg.startsWith("--")) {
|
||||
if (arg == "--nnbd") {
|
||||
nnbd = true;
|
||||
} else if (arg.startsWith("--platform=")) {
|
||||
if (arg.startsWith("--platform=")) {
|
||||
String platform = arg.substring("--platform=".length);
|
||||
platformUri = Uri.base.resolve(platform);
|
||||
} else if (arg == "--target=VM") {
|
||||
@@ -178,20 +173,16 @@ Future<void> main(List<String> arguments) async {
|
||||
mainUri = file.absolute.uri;
|
||||
|
||||
incrementalCompiler = new IncrementalCompiler(
|
||||
setupCompilerContext(nnbd, targetString, false, platformUri, mainUri));
|
||||
setupCompilerContext(targetString, false, platformUri, mainUri));
|
||||
await incrementalCompiler.computeDelta();
|
||||
}
|
||||
|
||||
CompilerContext setupCompilerContext(bool nnbd, String targetString,
|
||||
CompilerContext setupCompilerContext(String targetString,
|
||||
bool widgetTransformation, Uri platformUri, Uri mainUri) {
|
||||
CompilerOptions options = getOptions();
|
||||
|
||||
if (nnbd) {
|
||||
options.explicitExperimentalFlags = {ExperimentalFlag.nonNullable: true};
|
||||
}
|
||||
|
||||
TargetFlags targetFlags = new TargetFlags(
|
||||
soundNullSafety: nnbd, trackWidgetCreation: widgetTransformation);
|
||||
TargetFlags targetFlags =
|
||||
new TargetFlags(trackWidgetCreation: widgetTransformation);
|
||||
Target target;
|
||||
switch (targetString) {
|
||||
case "VM":
|
||||
|
||||
@@ -2075,7 +2075,6 @@ worlds:
|
||||
}
|
||||
|
||||
TargetFlags targetFlags = new TargetFlags(
|
||||
soundNullSafety: false,
|
||||
trackWidgetCreation: _settings.widgetTransformation);
|
||||
Target target;
|
||||
switch (_settings.targetString) {
|
||||
|
||||
@@ -751,7 +751,7 @@ Future<Map<String, Uint8List>> createModules(
|
||||
throw "Module probably not setup right.";
|
||||
}
|
||||
Component result = new Component(libraries: wantedLibs)
|
||||
..setMainMethodAndMode(null, false, c.mode);
|
||||
..setMainMethodAndMode(null, false);
|
||||
Uint8List resultBytes = util.postProcess(result);
|
||||
moduleResult[moduleName] = resultBytes;
|
||||
}
|
||||
@@ -1387,9 +1387,6 @@ class NewWorldTest {
|
||||
world, data, compilerResult.neededDillLibraries, base);
|
||||
if (result != null) return result;
|
||||
|
||||
Result? nnbdCheck = checkNNBDSettings(component!);
|
||||
if (nnbdCheck != null) return nnbdCheck.copyWithOutput(data);
|
||||
|
||||
if (!world.noFullComponent) {
|
||||
Set<Library> allLibraries = new Set<Library>();
|
||||
for (Library lib in component!.libraries) {
|
||||
@@ -1885,26 +1882,6 @@ class Strategy extends EquivalenceStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
Result? checkNNBDSettings(Component component) {
|
||||
NonNullableByDefaultCompiledMode mode = component.mode;
|
||||
if (mode == NonNullableByDefaultCompiledMode.Invalid) return null;
|
||||
for (Library lib in component.libraries) {
|
||||
if (mode == lib.nonNullableByDefaultCompiledMode) continue;
|
||||
|
||||
if (mode == NonNullableByDefaultCompiledMode.Strong ||
|
||||
lib.nonNullableByDefaultCompiledMode ==
|
||||
NonNullableByDefaultCompiledMode.Strong) {
|
||||
// Non agnostic and one (but not both) are strong => error.
|
||||
return new Result(
|
||||
null,
|
||||
NNBDModeMismatch,
|
||||
"Component mode was $mode but ${lib.importUri} had mode "
|
||||
"${lib.nonNullableByDefaultCompiledMode}.");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Result<TestData>? checkExpectFile(TestData data, int worldNum,
|
||||
String extraUriString, Context context, String actualSerialized) {
|
||||
Uri uri = data.loadedFrom.resolve(data.loadedFrom.pathSegments.last +
|
||||
@@ -2158,7 +2135,7 @@ Result<Uint8List?> checkIncrementalSerialization(
|
||||
World world) {
|
||||
if (incrementalSerialization == true) {
|
||||
Component c = new Component(nameRoot: component.root)
|
||||
..setMainMethodAndMode(null, false, component.mode);
|
||||
..setMainMethodAndMode(null, false);
|
||||
c.libraries.addAll(component.libraries);
|
||||
c.uriToSource.addAll(component.uriToSource);
|
||||
Map<String, Set<String>> originalContent = buildMapOfContent(c);
|
||||
@@ -2397,7 +2374,7 @@ String componentToStringSdkFiltered(Component component,
|
||||
c.libraries.add(lib);
|
||||
}
|
||||
}
|
||||
c.setMainMethodAndMode(component.mainMethodName, true, component.mode);
|
||||
c.setMainMethodAndMode(component.mainMethodName, true);
|
||||
c.problemsAsJson = component.problemsAsJson;
|
||||
|
||||
StringBuffer s = new StringBuffer();
|
||||
|
||||
@@ -19,7 +19,7 @@ Future<void> main() async {
|
||||
Stopwatch stopwatch = new Stopwatch()..start();
|
||||
Component component = await normalCompileToComponent(dart2jsUrl,
|
||||
options: getOptions()
|
||||
..target = new VmTarget(new TargetFlags(soundNullSafety: false))
|
||||
..target = new VmTarget(new TargetFlags())
|
||||
..omitPlatform = false);
|
||||
print("Compiled dart2js in ${stopwatch.elapsedMilliseconds} ms");
|
||||
|
||||
@@ -31,8 +31,7 @@ Future<void> main() async {
|
||||
Component libComponent = new Component(nameRoot: component.root);
|
||||
libComponent.libraries.add(lib);
|
||||
libComponent.uriToSource.addAll(component.uriToSource);
|
||||
libComponent.setMainMethodAndMode(
|
||||
component.mainMethodName, true, component.mode);
|
||||
libComponent.setMainMethodAndMode(component.mainMethodName, true);
|
||||
libComponents.add(serializeComponent(libComponent));
|
||||
}
|
||||
print("Serialized ${libComponents.length} separate library components "
|
||||
|
||||
@@ -12,12 +12,7 @@ import 'package:front_end/src/codes/cfe_codes.dart';
|
||||
import 'package:front_end/src/util/bytes_sink.dart' show BytesSink;
|
||||
import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
|
||||
import 'package:kernel/kernel.dart'
|
||||
show
|
||||
CanonicalName,
|
||||
Library,
|
||||
Component,
|
||||
loadComponentFromBytes,
|
||||
NonNullableByDefaultCompiledMode;
|
||||
show CanonicalName, Library, Component, loadComponentFromBytes;
|
||||
import 'package:package_config/package_config.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
@@ -75,8 +70,7 @@ class ProcessedOptionsTest {
|
||||
new Library(Uri.parse('org-dartlang-test:///a/b.dart'),
|
||||
fileUri: Uri.parse('org-dartlang-test:///a/b.dart'))
|
||||
])
|
||||
..setMainMethodAndMode(
|
||||
null, false, NonNullableByDefaultCompiledMode.Strong);
|
||||
..setMainMethodAndMode(null, false);
|
||||
|
||||
void test_compileSdk_false() {
|
||||
for (var value in [false, true]) {
|
||||
|
||||
@@ -68,7 +68,6 @@ import 'package:kernel/ast.dart'
|
||||
LibraryPart,
|
||||
Member,
|
||||
Node,
|
||||
NonNullableByDefaultCompiledMode,
|
||||
RecursiveVisitor,
|
||||
Reference,
|
||||
TreeNode,
|
||||
@@ -501,22 +500,6 @@ class Run extends Step<ComponentResult, ComponentResult, FastaContext> {
|
||||
await StdioProcess.run(context.vm.toFilePath(), args);
|
||||
print(process.output);
|
||||
Result<int> runResult = process.toResult();
|
||||
if (result.component.mode ==
|
||||
NonNullableByDefaultCompiledMode.Invalid) {
|
||||
// In this case we expect and want a runtime error.
|
||||
if (runResult.outcome ==
|
||||
ExpectationSet.defaultExpectations["RuntimeError"]) {
|
||||
// We convert this to pass because that's exactly what we'd
|
||||
// expect.
|
||||
return pass(result);
|
||||
} else {
|
||||
// Different outcome - that's a failure!
|
||||
return new Result<ComponentResult>(
|
||||
result,
|
||||
ExpectationSet.defaultExpectations["MissingRuntimeError"],
|
||||
runResult.error);
|
||||
}
|
||||
}
|
||||
return new Result<ComponentResult>(
|
||||
result, runResult.outcome, runResult.error);
|
||||
case "none":
|
||||
|
||||
@@ -475,7 +475,7 @@ class MatchExpectation
|
||||
ByteSink sink = new ByteSink();
|
||||
Component writeMe = new Component(
|
||||
libraries: component.libraries.where(result.isUserLibrary).toList())
|
||||
..setMainMethodAndMode(null, false, component.mode);
|
||||
..setMainMethodAndMode(null, false);
|
||||
writeMe.uriToSource.addAll(component.uriToSource);
|
||||
if (component.problemsAsJson != null) {
|
||||
writeMe.problemsAsJson =
|
||||
@@ -637,8 +637,7 @@ class WriteDill extends Step<ComponentResult, ComponentResult, ChainContext> {
|
||||
Component userCode = new Component(
|
||||
nameRoot: component.root,
|
||||
uriToSource: new Map<Uri, Source>.from(component.uriToSource));
|
||||
userCode.setMainMethodAndMode(
|
||||
component.mainMethodName, true, component.mode);
|
||||
userCode.setMainMethodAndMode(component.mainMethodName, true);
|
||||
List<Library> auxiliaryLibraries = [];
|
||||
for (Library library in component.libraries) {
|
||||
bool includeLibrary;
|
||||
|
||||
@@ -87,7 +87,6 @@ const Map<String?, Map<String, FieldRule?>> _fieldRuleMap = {
|
||||
'Component': {
|
||||
'root': null,
|
||||
'_mainMethodName': FieldRule(name: 'mainMethodName'),
|
||||
'_mode': FieldRule(name: 'mode'),
|
||||
},
|
||||
'Library': {
|
||||
'_languageVersion': FieldRule(name: 'languageVersion'),
|
||||
|
||||
@@ -394,8 +394,7 @@ Future<Uri> _emitComponent(ProcessedOptions options, Component component,
|
||||
Component userCode = new Component(
|
||||
nameRoot: component.root,
|
||||
uriToSource: new Map<Uri, Source>.from(component.uriToSource));
|
||||
userCode.setMainMethodAndMode(
|
||||
component.mainMethodName, true, component.mode);
|
||||
userCode.setMainMethodAndMode(component.mainMethodName, true);
|
||||
for (Library library in component.libraries) {
|
||||
if (!library.importUri.isScheme("dart")) {
|
||||
userCode.libraries.add(library);
|
||||
|
||||
@@ -421,8 +421,7 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
|
||||
if (summaryOnly) {
|
||||
incrementalComponent.uriToSource.clear();
|
||||
incrementalComponent.problemsAsJson = null;
|
||||
incrementalComponent.setMainMethodAndMode(
|
||||
null, true, incrementalComponent.mode);
|
||||
incrementalComponent.setMainMethodAndMode(null, true);
|
||||
target.performOutlineTransformations(incrementalComponent);
|
||||
makeStable(incrementalComponent);
|
||||
return new Future.value(fe.serializeComponent(incrementalComponent,
|
||||
|
||||
@@ -928,7 +928,6 @@ class FrontendCompiler implements CompilerInterface {
|
||||
final BinaryPrinter printer = new BinaryPrinter(sink);
|
||||
printer.writeComponentFile(new Component(
|
||||
libraries: [nativeAssetsLibrary],
|
||||
mode: nativeAssetsLibrary.nonNullableByDefaultCompiledMode,
|
||||
));
|
||||
}
|
||||
await sink.close();
|
||||
@@ -956,7 +955,6 @@ class FrontendCompiler implements CompilerInterface {
|
||||
final BinaryPrinter printer = new BinaryPrinter(sink);
|
||||
printer.writeComponentFile(new Component(
|
||||
libraries: [nativeAssetsLibrary],
|
||||
mode: nativeAssetsLibrary.nonNullableByDefaultCompiledMode,
|
||||
));
|
||||
await sink.close();
|
||||
}
|
||||
@@ -1254,7 +1252,7 @@ class FrontendCompiler implements CompilerInterface {
|
||||
libraries: libraries,
|
||||
uriToSource: deltaProgram.uriToSource,
|
||||
nameRoot: deltaProgram.root);
|
||||
singleLibrary.setMainMethodAndMode(null, false, deltaProgram.mode);
|
||||
singleLibrary.setMainMethodAndMode(null, false);
|
||||
ByteSink byteSink = new ByteSink();
|
||||
final BinaryPrinter printer = printerFactory.newBinaryPrinter(byteSink);
|
||||
printer.writeComponentFile(singleLibrary);
|
||||
|
||||
@@ -137,8 +137,7 @@ class IncrementalJavaScriptBundler {
|
||||
_lastFullComponent = new Component(
|
||||
libraries: combined.values.toList(),
|
||||
uriToSource: uriToSource,
|
||||
)..setMainMethodAndMode(
|
||||
candidate.mainMethod?.reference, true, candidate.mode);
|
||||
)..setMainMethodAndMode(candidate.mainMethod?.reference, true);
|
||||
for (final MetadataRepository repo in candidate.metadata.values) {
|
||||
_lastFullComponent.addMetadataRepository(repo);
|
||||
}
|
||||
@@ -155,8 +154,7 @@ class IncrementalJavaScriptBundler {
|
||||
nameRoot: _lastFullComponent.root,
|
||||
uriToSource: _lastFullComponent.uriToSource,
|
||||
);
|
||||
summaryComponent.setMainMethodAndMode(
|
||||
null, false, _currentComponent.mode);
|
||||
summaryComponent.setMainMethodAndMode(null, false);
|
||||
|
||||
String baseName = urlForComponentUri(uri, packageConfig);
|
||||
_summaryToLibraryBundleJSPath[uri] = '$baseName.lib.js';
|
||||
|
||||
@@ -101,8 +101,6 @@ void main() {
|
||||
final Library firstLib = component.libraries.first;
|
||||
expect(firstLib.importUri != _nativeAssetsLibraryUri, true);
|
||||
expect(nativeAssetsLibrary!.nonNullable, firstLib.nonNullable);
|
||||
expect(nativeAssetsLibrary.nonNullableByDefaultCompiledMode,
|
||||
firstLib.nonNullableByDefaultCompiledMode);
|
||||
|
||||
await mainFile.writeAsString('''
|
||||
void main() {
|
||||
|
||||
@@ -147,7 +147,7 @@ type CanonicalName {
|
||||
|
||||
type ComponentFile {
|
||||
UInt32 magic = 0x90ABCDEF;
|
||||
UInt32 formatVersion = 122;
|
||||
UInt32 formatVersion = 123;
|
||||
Byte[10] shortSdkHash;
|
||||
List<String> problemsAsJson; // Described in problems.md.
|
||||
Library[] libraries;
|
||||
@@ -188,7 +188,7 @@ type ComponentIndex {
|
||||
UInt32 binaryOffsetForStringTable;
|
||||
UInt32 binaryOffsetForStartOfComponentIndex;
|
||||
UInt32 mainMethodReference; // This is a ProcedureReference with a fixed-size integer.
|
||||
UInt32 compilationMode; // enum NonNullableByDefaultCompiledMode { Disabled = 0, Weak = 1, Strong = 2, Agnostic = 3 } with a fixed-size integer.
|
||||
UInt32 _dummy; // TODO(jensj): Previously the component mode. Remove this.
|
||||
UInt32[libraryCount + 1] libraryOffsets;
|
||||
UInt32 libraryCount;
|
||||
UInt32 componentFileSizeInBytes;
|
||||
|
||||
@@ -78,7 +78,6 @@ class _ComponentIndex {
|
||||
final int binaryOffsetForConstantTableIndex;
|
||||
final int binaryOffsetForStartOfComponentIndex;
|
||||
final int mainMethodReference;
|
||||
final NonNullableByDefaultCompiledMode compiledMode;
|
||||
final List<int> libraryOffsets;
|
||||
final int libraryCount;
|
||||
final int componentFileSizeInBytes;
|
||||
@@ -93,7 +92,6 @@ class _ComponentIndex {
|
||||
required this.binaryOffsetForConstantTableIndex,
|
||||
required this.binaryOffsetForStartOfComponentIndex,
|
||||
required this.mainMethodReference,
|
||||
required this.compiledMode,
|
||||
required this.libraryOffsets,
|
||||
required this.libraryCount,
|
||||
required this.componentFileSizeInBytes});
|
||||
@@ -155,7 +153,6 @@ class BinaryBuilder {
|
||||
int _transformerFlags = 0;
|
||||
Library? _currentLibrary;
|
||||
int _componentStartOffset = 0;
|
||||
NonNullableByDefaultCompiledMode? compilationMode;
|
||||
|
||||
// If something goes wrong, this list should indicate what library,
|
||||
// class, and member was being built.
|
||||
@@ -808,8 +805,8 @@ class BinaryBuilder {
|
||||
int binaryOffsetForStartOfComponentIndex =
|
||||
_componentStartOffset + readUint32();
|
||||
int mainMethodReference = readUint32();
|
||||
NonNullableByDefaultCompiledMode compiledMode =
|
||||
NonNullableByDefaultCompiledMode.values[readUint32()];
|
||||
// TODO(jensj): Previously the component mode. Remove this.
|
||||
readUint32();
|
||||
for (int i = 0; i < libraryCount + 1; ++i) {
|
||||
libraryOffsets[i] = _componentStartOffset + readUint32();
|
||||
}
|
||||
@@ -829,8 +826,7 @@ class BinaryBuilder {
|
||||
binaryOffsetForConstantTableIndex: binaryOffsetForConstantTableIndex,
|
||||
binaryOffsetForStartOfComponentIndex:
|
||||
binaryOffsetForStartOfComponentIndex,
|
||||
mainMethodReference: mainMethodReference,
|
||||
compiledMode: compiledMode);
|
||||
mainMethodReference: mainMethodReference);
|
||||
}
|
||||
|
||||
void _readOneComponentSource(Component component, int componentFileSize) {
|
||||
@@ -892,11 +888,6 @@ class BinaryBuilder {
|
||||
|
||||
// Read component index from the end of this ComponentFiles serialized data.
|
||||
_ComponentIndex index = _readComponentIndex(componentFileSize);
|
||||
if (compilationMode == null) {
|
||||
compilationMode = component.modeRaw;
|
||||
}
|
||||
compilationMode =
|
||||
mergeCompilationModeOrThrow(compilationMode, index.compiledMode);
|
||||
|
||||
_byteOffset = index.binaryOffsetForStringTable;
|
||||
readStringTable();
|
||||
@@ -938,7 +929,7 @@ class BinaryBuilder {
|
||||
|
||||
Reference? mainMethod =
|
||||
getNullableMemberReferenceFromInt(index.mainMethodReference);
|
||||
component.setMainMethodAndMode(mainMethod, false, compilationMode!);
|
||||
component.setMainMethodAndMode(mainMethod, false);
|
||||
|
||||
_byteOffset = _componentStartOffset + componentFileSize;
|
||||
|
||||
@@ -1244,13 +1235,6 @@ class BinaryBuilder {
|
||||
library.fileUri = fileUri;
|
||||
library.problemsAsJson = problemsAsJson;
|
||||
|
||||
assert(
|
||||
mergeCompilationModeOrThrow(
|
||||
compilationMode, library.nonNullableByDefaultCompiledMode) ==
|
||||
compilationMode,
|
||||
"Cannot load ${library.nonNullableByDefaultCompiledMode} "
|
||||
"into component with mode $compilationMode");
|
||||
|
||||
assert(() {
|
||||
debugPath.add(library!.name ?? library.importUri.toString());
|
||||
return true;
|
||||
@@ -4482,21 +4466,3 @@ class _MetadataSubsection {
|
||||
|
||||
_MetadataSubsection(this.repository, this.mapping);
|
||||
}
|
||||
|
||||
/// Merges two compilation modes or throws if they are not compatible.
|
||||
NonNullableByDefaultCompiledMode mergeCompilationModeOrThrow(
|
||||
NonNullableByDefaultCompiledMode? a, NonNullableByDefaultCompiledMode b) {
|
||||
if (a == null || a == b) {
|
||||
return b;
|
||||
}
|
||||
|
||||
// If something is invalid, it should always merge as invalid.
|
||||
if (a == NonNullableByDefaultCompiledMode.Invalid) {
|
||||
return a;
|
||||
}
|
||||
if (b == NonNullableByDefaultCompiledMode.Invalid) {
|
||||
return b;
|
||||
}
|
||||
|
||||
throw new CompilationModeError("Mixed compilation mode found: $a and $b");
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import 'dart:developer';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import '../ast.dart';
|
||||
import 'ast_from_binary.dart' show mergeCompilationModeOrThrow;
|
||||
import 'tag.dart';
|
||||
|
||||
/// Writes to a binary file.
|
||||
@@ -30,7 +29,6 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
|
||||
final List<bool?> _sourcesUsedInLibrary = <bool?>[];
|
||||
Map<LibraryDependency, int> _libraryDependencyIndex =
|
||||
<LibraryDependency, int>{};
|
||||
NonNullableByDefaultCompiledMode? compilationMode;
|
||||
|
||||
List<_MetadataSubsection>? _metadataSubsections;
|
||||
|
||||
@@ -586,7 +584,6 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
|
||||
|
||||
void writeComponentFile(Component component) {
|
||||
Timeline.timeSync("BinaryPrinter.writeComponentFile", () {
|
||||
compilationMode = component.mode;
|
||||
_computeCanonicalNames(component);
|
||||
final int componentOffset = getBufferOffset();
|
||||
writeUInt32(Tag.ComponentFile);
|
||||
@@ -846,8 +843,8 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
|
||||
_ensureCanonicalName(getNonNullableMemberReferenceGetter(mainMethod));
|
||||
writeUInt32(main.index + 1);
|
||||
}
|
||||
assert(component.modeRaw != null, "Component mode not set.");
|
||||
writeUInt32(component.mode.index);
|
||||
// TODO(jensj): Previously the component mode. Remove this.
|
||||
writeUInt32(0);
|
||||
|
||||
assert(libraryOffsets.length == libraries.length);
|
||||
for (int offset in libraryOffsets) {
|
||||
@@ -1088,13 +1085,6 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
|
||||
libraryOffsets.add(getBufferOffset());
|
||||
writeByte(node.flags);
|
||||
|
||||
assert(
|
||||
mergeCompilationModeOrThrow(
|
||||
compilationMode, node.nonNullableByDefaultCompiledMode) ==
|
||||
compilationMode,
|
||||
"Cannot have ${node.nonNullableByDefaultCompiledMode} "
|
||||
"in component with mode $compilationMode");
|
||||
|
||||
writeUInt30(node.languageVersion.major);
|
||||
writeUInt30(node.languageVersion.minor);
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ class Tag {
|
||||
/// Internal version of kernel binary format.
|
||||
/// Bump it when making incompatible changes in kernel binaries.
|
||||
/// Keep in sync with runtime/vm/kernel_binary.h, pkg/kernel/binary.md.
|
||||
static const int BinaryFormatVersion = 122;
|
||||
static const int BinaryFormatVersion = 123;
|
||||
}
|
||||
|
||||
abstract class ConstantTag {
|
||||
|
||||
@@ -33,22 +33,14 @@ class Component extends TreeNode {
|
||||
/// Reference to the main method in one of the libraries.
|
||||
Reference? _mainMethodName;
|
||||
Reference? get mainMethodName => _mainMethodName;
|
||||
NonNullableByDefaultCompiledMode? _mode;
|
||||
NonNullableByDefaultCompiledMode get mode {
|
||||
return _mode ?? NonNullableByDefaultCompiledMode.Strong;
|
||||
}
|
||||
|
||||
NonNullableByDefaultCompiledMode? get modeRaw => _mode;
|
||||
|
||||
Component(
|
||||
{CanonicalName? nameRoot,
|
||||
List<Library>? libraries,
|
||||
Map<Uri, Source>? uriToSource,
|
||||
NonNullableByDefaultCompiledMode? mode})
|
||||
Map<Uri, Source>? uriToSource})
|
||||
: root = nameRoot ?? new CanonicalName.root(),
|
||||
libraries = libraries ?? <Library>[],
|
||||
uriToSource = uriToSource ?? <Uri, Source>{},
|
||||
_mode = mode {
|
||||
uriToSource = uriToSource ?? <Uri, Source>{} {
|
||||
adoptChildren();
|
||||
}
|
||||
|
||||
@@ -121,12 +113,10 @@ class Component extends TreeNode {
|
||||
|
||||
Procedure? get mainMethod => mainMethodName?.asProcedure;
|
||||
|
||||
void setMainMethodAndMode(Reference? main, bool overwriteMainIfSet,
|
||||
NonNullableByDefaultCompiledMode mode) {
|
||||
void setMainMethodAndMode(Reference? main, bool overwriteMainIfSet) {
|
||||
if (_mainMethodName == null || overwriteMainIfSet) {
|
||||
_mainMethodName = main;
|
||||
}
|
||||
_mode = mode;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -8,8 +8,6 @@ part of '../../ast.dart';
|
||||
// LIBRARIES and CLASSES
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
enum NonNullableByDefaultCompiledMode { Strong, Weak, Invalid }
|
||||
|
||||
class Library extends NamedNode
|
||||
implements Annotatable, Comparable<Library>, FileUriNode {
|
||||
/// An import path to this library.
|
||||
@@ -31,10 +29,7 @@ class Library extends NamedNode
|
||||
}
|
||||
|
||||
static const int SyntheticFlag = 1 << 0;
|
||||
|
||||
static const int NonNullableByDefaultModeBit1 = 1 << 1;
|
||||
static const int NonNullableByDefaultModeBit2 = 1 << 2;
|
||||
static const int IsUnsupportedFlag = 1 << 3;
|
||||
static const int IsUnsupportedFlag = 1 << 1;
|
||||
|
||||
int flags = 0;
|
||||
|
||||
@@ -45,33 +40,6 @@ class Library extends NamedNode
|
||||
flags = value ? (flags | SyntheticFlag) : (flags & ~SyntheticFlag);
|
||||
}
|
||||
|
||||
NonNullableByDefaultCompiledMode get nonNullableByDefaultCompiledMode {
|
||||
bool bit1 = (flags & NonNullableByDefaultModeBit1) != 0;
|
||||
bool bit2 = (flags & NonNullableByDefaultModeBit2) != 0;
|
||||
if (!bit1 && !bit2) return NonNullableByDefaultCompiledMode.Strong;
|
||||
if (bit1 && !bit2) return NonNullableByDefaultCompiledMode.Weak;
|
||||
if (!bit1 && bit2) return NonNullableByDefaultCompiledMode.Invalid;
|
||||
throw new StateError("Unused bit-pattern for compilation mode");
|
||||
}
|
||||
|
||||
void set nonNullableByDefaultCompiledMode(
|
||||
NonNullableByDefaultCompiledMode mode) {
|
||||
switch (mode) {
|
||||
case NonNullableByDefaultCompiledMode.Strong:
|
||||
flags = (flags & ~NonNullableByDefaultModeBit1) &
|
||||
~NonNullableByDefaultModeBit2;
|
||||
break;
|
||||
case NonNullableByDefaultCompiledMode.Weak:
|
||||
flags = (flags | NonNullableByDefaultModeBit1) &
|
||||
~NonNullableByDefaultModeBit2;
|
||||
break;
|
||||
case NonNullableByDefaultCompiledMode.Invalid:
|
||||
flags = (flags & ~NonNullableByDefaultModeBit1) |
|
||||
NonNullableByDefaultModeBit2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// If true, the library is not supported through the 'dart.library.*' value
|
||||
/// used in conditional imports and `bool.fromEnvironment` constants.
|
||||
bool get isUnsupported => flags & IsUnsupportedFlag != 0;
|
||||
|
||||
@@ -1810,9 +1810,6 @@ class EquivalenceStrategy {
|
||||
if (!checkComponent_mainMethodName(visitor, node, other)) {
|
||||
result = visitor.resultOnInequivalence;
|
||||
}
|
||||
if (!checkComponent_mode(visitor, node, other)) {
|
||||
result = visitor.resultOnInequivalence;
|
||||
}
|
||||
if (!checkComponent_fileOffset(visitor, node, other)) {
|
||||
result = visitor.resultOnInequivalence;
|
||||
}
|
||||
@@ -5920,11 +5917,6 @@ class EquivalenceStrategy {
|
||||
node.mainMethodName, other.mainMethodName, 'mainMethodName');
|
||||
}
|
||||
|
||||
bool checkComponent_mode(
|
||||
EquivalenceVisitor visitor, Component node, Component other) {
|
||||
return visitor.checkValues(node.mode, other.mode, 'mode');
|
||||
}
|
||||
|
||||
bool checkTreeNode_fileOffset(
|
||||
EquivalenceVisitor visitor, TreeNode node, TreeNode other) {
|
||||
return visitor.checkValues(node.fileOffset, other.fileOffset, 'fileOffset');
|
||||
|
||||
@@ -13,12 +13,10 @@ import 'changed_structure_notifier.dart';
|
||||
|
||||
class TargetFlags {
|
||||
final bool trackWidgetCreation;
|
||||
final bool soundNullSafety;
|
||||
final bool supportMirrors;
|
||||
|
||||
const TargetFlags(
|
||||
{this.trackWidgetCreation = false,
|
||||
this.soundNullSafety = true,
|
||||
this.supportMirrors = true});
|
||||
|
||||
@override
|
||||
@@ -26,7 +24,6 @@ class TargetFlags {
|
||||
if (identical(this, other)) return true;
|
||||
return other is TargetFlags &&
|
||||
trackWidgetCreation == other.trackWidgetCreation &&
|
||||
soundNullSafety == other.soundNullSafety &&
|
||||
supportMirrors == other.supportMirrors;
|
||||
}
|
||||
|
||||
@@ -34,7 +31,6 @@ class TargetFlags {
|
||||
int get hashCode {
|
||||
int hash = 485786;
|
||||
hash = 0x3fffffff & (hash * 31 + (hash ^ trackWidgetCreation.hashCode));
|
||||
hash = 0x3fffffff & (hash * 31 + (hash ^ soundNullSafety.hashCode));
|
||||
hash = 0x3fffffff & (hash * 31 + (hash ^ supportMirrors.hashCode));
|
||||
return hash;
|
||||
}
|
||||
|
||||
@@ -875,9 +875,6 @@ abstract class StaticTypeContext {
|
||||
/// For opt out libraries this is [Nullability.legacy].
|
||||
Nullability get nullable;
|
||||
|
||||
/// Returns the mode under which the current library was compiled.
|
||||
NonNullableByDefaultCompiledMode get nonNullableByDefaultCompiledMode;
|
||||
|
||||
/// Returns the static type of [node].
|
||||
DartType getExpressionType(Expression node);
|
||||
|
||||
@@ -941,11 +938,6 @@ class StaticTypeContextImpl implements StaticTypeContext {
|
||||
@override
|
||||
Nullability get nullable => _library.nullable;
|
||||
|
||||
/// Returns the mode under which the current library was compiled.
|
||||
@override
|
||||
NonNullableByDefaultCompiledMode get nonNullableByDefaultCompiledMode =>
|
||||
_library.nonNullableByDefaultCompiledMode;
|
||||
|
||||
@override
|
||||
DartType getExpressionType(Expression node) {
|
||||
if (_cache != null) {
|
||||
@@ -1053,10 +1045,6 @@ class _FlatStatefulStaticTypeContext extends StatefulStaticTypeContext {
|
||||
@override
|
||||
Nullability get nullable => _library.nullable;
|
||||
|
||||
@override
|
||||
NonNullableByDefaultCompiledMode get nonNullableByDefaultCompiledMode =>
|
||||
_library.nonNullableByDefaultCompiledMode;
|
||||
|
||||
/// Updates the [nonNullable] and [thisType] to match static type context for
|
||||
/// the member [node].
|
||||
///
|
||||
@@ -1155,10 +1143,6 @@ class _StackedStatefulStaticTypeContext extends StatefulStaticTypeContext {
|
||||
@override
|
||||
Nullability get nullable => _library.nullable;
|
||||
|
||||
@override
|
||||
NonNullableByDefaultCompiledMode get nonNullableByDefaultCompiledMode =>
|
||||
_library.nonNullableByDefaultCompiledMode;
|
||||
|
||||
/// Updates the [library] and [thisType] to match static type context for
|
||||
/// the member [node].
|
||||
///
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
// Copyright (c) 2020, 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.
|
||||
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:kernel/binary/ast_from_binary.dart';
|
||||
|
||||
import 'utils.dart';
|
||||
|
||||
void main() {
|
||||
void setCompileMode(Component c, NonNullableByDefaultCompiledMode mode) {
|
||||
c.setMainMethodAndMode(null, true, mode);
|
||||
}
|
||||
|
||||
void verifyMode(Component c, NonNullableByDefaultCompiledMode mode) {
|
||||
if (c.mode != mode) {
|
||||
throw "Serialized and re-read component had change in mode: "
|
||||
"Expected $mode got ${c.mode}.";
|
||||
}
|
||||
}
|
||||
|
||||
const List<NonNullableByDefaultCompiledMode> modes = const [
|
||||
NonNullableByDefaultCompiledMode.Weak,
|
||||
NonNullableByDefaultCompiledMode.Strong,
|
||||
];
|
||||
|
||||
int combination = 0;
|
||||
for (NonNullableByDefaultCompiledMode c1Mode in modes) {
|
||||
for (NonNullableByDefaultCompiledMode c2Mode in modes) {
|
||||
combination++;
|
||||
print("Checking combination #$combination ("
|
||||
"c1Mode: $c1Mode; "
|
||||
"c2Mode: $c2Mode; "
|
||||
")");
|
||||
|
||||
// Try individually.
|
||||
Uint8List c1Serialized;
|
||||
{
|
||||
Uri uri = Uri.parse("foo://bar.dart");
|
||||
Library lib1 = new Library(uri, fileUri: uri)
|
||||
..nonNullableByDefaultCompiledMode = c1Mode;
|
||||
Component c1 = new Component(libraries: [lib1]);
|
||||
setCompileMode(c1, c1Mode);
|
||||
c1Serialized = serializeComponent(c1);
|
||||
Component c1RoundTrip = loadComponentFromBytes(c1Serialized);
|
||||
verifyMode(c1RoundTrip, c1Mode);
|
||||
}
|
||||
|
||||
Uint8List c2Serialized;
|
||||
{
|
||||
Uri uri = Uri.parse("foo://baz.dart");
|
||||
Library lib2 = new Library(uri, fileUri: uri)
|
||||
..nonNullableByDefaultCompiledMode = c2Mode;
|
||||
Component c2 = new Component(libraries: [lib2]);
|
||||
setCompileMode(c2, c2Mode);
|
||||
c2Serialized = serializeComponent(c2);
|
||||
Component c2RoundTrip = loadComponentFromBytes(c2Serialized);
|
||||
verifyMode(c2RoundTrip, c2Mode);
|
||||
}
|
||||
|
||||
// Try with combined binary.
|
||||
try {
|
||||
Uint8List combined =
|
||||
Uint8List.fromList([...c1Serialized, ...c2Serialized]);
|
||||
Component combinedRoundTrip = loadComponentFromBytes(combined);
|
||||
verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode));
|
||||
print(" -> OK with $c1Mode and $c2Mode");
|
||||
} on CompilationModeError catch (e) {
|
||||
print(" -> Got $e with $c1Mode and $c2Mode");
|
||||
verifyError(c1Mode, c2Mode);
|
||||
}
|
||||
// Try other order.
|
||||
try {
|
||||
Uint8List combined =
|
||||
Uint8List.fromList([...c2Serialized, ...c1Serialized]);
|
||||
Component combinedRoundTrip = loadComponentFromBytes(combined);
|
||||
verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode));
|
||||
print(" -> OK with $c1Mode and $c2Mode");
|
||||
} on CompilationModeError catch (e) {
|
||||
print(" -> Got $e with $c1Mode and $c2Mode");
|
||||
verifyError(c1Mode, c2Mode);
|
||||
}
|
||||
|
||||
// Try with individual binary, but loaded into same component.
|
||||
try {
|
||||
Component combinedRoundTrip = loadComponentFromBytes(c1Serialized);
|
||||
combinedRoundTrip =
|
||||
loadComponentFromBytes(c2Serialized, combinedRoundTrip);
|
||||
verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode));
|
||||
print(" -> OK with $c1Mode and $c2Mode");
|
||||
} on CompilationModeError catch (e) {
|
||||
print(" -> Got $e with $c1Mode and $c2Mode");
|
||||
verifyError(c1Mode, c2Mode);
|
||||
}
|
||||
// Try other order.
|
||||
try {
|
||||
Component combinedRoundTrip = loadComponentFromBytes(c2Serialized);
|
||||
combinedRoundTrip =
|
||||
loadComponentFromBytes(c1Serialized, combinedRoundTrip);
|
||||
verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode));
|
||||
print(" -> OK with $c1Mode and $c2Mode");
|
||||
} on CompilationModeError catch (e) {
|
||||
print(" -> Got $e with $c1Mode and $c2Mode");
|
||||
verifyError(c1Mode, c2Mode);
|
||||
}
|
||||
|
||||
// Try with individual binary, but loaded into same component where
|
||||
// component initially does not have a mode.
|
||||
try {
|
||||
Component combinedRoundTrip = new Component();
|
||||
combinedRoundTrip =
|
||||
loadComponentFromBytes(c1Serialized, combinedRoundTrip);
|
||||
combinedRoundTrip =
|
||||
loadComponentFromBytes(c2Serialized, combinedRoundTrip);
|
||||
verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode));
|
||||
print(" -> OK with $c1Mode and $c2Mode");
|
||||
} on CompilationModeError catch (e) {
|
||||
print(" -> Got $e with $c1Mode and $c2Mode");
|
||||
verifyError(c1Mode, c2Mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print("Done: Everything looks good.");
|
||||
}
|
||||
|
||||
bool isOK(NonNullableByDefaultCompiledMode c1Mode,
|
||||
NonNullableByDefaultCompiledMode c2Mode) {
|
||||
return c1Mode == c2Mode;
|
||||
}
|
||||
|
||||
NonNullableByDefaultCompiledMode verifyOK(
|
||||
NonNullableByDefaultCompiledMode c1Mode,
|
||||
NonNullableByDefaultCompiledMode c2Mode) {
|
||||
if (isOK(c1Mode, c2Mode)) {
|
||||
return c1Mode;
|
||||
}
|
||||
throw "Not OK combination: $c1Mode and $c2Mode";
|
||||
}
|
||||
|
||||
void verifyError(NonNullableByDefaultCompiledMode c1Mode,
|
||||
NonNullableByDefaultCompiledMode c2Mode) {
|
||||
if (isOK(c1Mode, c2Mode)) {
|
||||
throw "Unexpected error for $c1Mode and $c2Mode";
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ void main() {
|
||||
classA.addConstructor(classAConstructor);
|
||||
}
|
||||
Component c = new Component(libraries: [lib]);
|
||||
c.setMainMethodAndMode(null, false, NonNullableByDefaultCompiledMode.Strong);
|
||||
c.setMainMethodAndMode(null, false);
|
||||
Uint8List loadMe = serializeComponent(c);
|
||||
|
||||
// Load and make sure we can get at class B from class A (i.e. that it's
|
||||
|
||||
@@ -16,41 +16,16 @@ void main() {
|
||||
}
|
||||
}
|
||||
|
||||
void setNonNullableByDefaultCompiledMode(Library lib,
|
||||
NonNullableByDefaultCompiledMode nonNullableByDefaultCompiledMode) {
|
||||
lib.nonNullableByDefaultCompiledMode = nonNullableByDefaultCompiledMode;
|
||||
}
|
||||
|
||||
void verifyNonNullableByDefaultCompiledMode(Library lib,
|
||||
NonNullableByDefaultCompiledMode nonNullableByDefaultCompiledMode) {
|
||||
if (lib.nonNullableByDefaultCompiledMode !=
|
||||
nonNullableByDefaultCompiledMode) {
|
||||
throw "Serialized and re-read library had change in "
|
||||
"nonNullableByDefaultCompiledMode flag.";
|
||||
}
|
||||
}
|
||||
|
||||
int combination = 0;
|
||||
for (bool isSynthetic in [true, false]) {
|
||||
for (NonNullableByDefaultCompiledMode nonNullableByDefaultCompiledMode in [
|
||||
NonNullableByDefaultCompiledMode.Weak,
|
||||
NonNullableByDefaultCompiledMode.Strong,
|
||||
]) {
|
||||
combination++;
|
||||
print("Checking combination #$combination ("
|
||||
"isSynthetic: $isSynthetic; "
|
||||
"nonNullableByDefaultCompiledMode:"
|
||||
" $nonNullableByDefaultCompiledMode");
|
||||
Uri uri = Uri.parse("foo://bar.dart");
|
||||
Library lib = new Library(uri, fileUri: uri);
|
||||
setSynthetic(lib, isSynthetic);
|
||||
setNonNullableByDefaultCompiledMode(
|
||||
lib, nonNullableByDefaultCompiledMode);
|
||||
Library lib2 = libRoundTrip(lib);
|
||||
verifySynthetic(lib2, isSynthetic);
|
||||
verifyNonNullableByDefaultCompiledMode(
|
||||
lib2, nonNullableByDefaultCompiledMode);
|
||||
}
|
||||
combination++;
|
||||
print("Checking combination #$combination ("
|
||||
"isSynthetic: $isSynthetic");
|
||||
Uri uri = Uri.parse("foo://bar.dart");
|
||||
Library lib = new Library(uri, fileUri: uri);
|
||||
setSynthetic(lib, isSynthetic);
|
||||
Library lib2 = libRoundTrip(lib);
|
||||
verifySynthetic(lib2, isSynthetic);
|
||||
}
|
||||
|
||||
print("Done: Everything looks good.");
|
||||
|
||||
@@ -14,8 +14,7 @@ Library libRoundTrip(Library lib) {
|
||||
|
||||
List<Library> serializationRoundTrip(List<Library> libraries) {
|
||||
Component c = new Component(libraries: libraries)
|
||||
..setMainMethodAndMode(
|
||||
null, false, libraries.first.nonNullableByDefaultCompiledMode);
|
||||
..setMainMethodAndMode(null, false);
|
||||
Uint8List bytes = serializeComponent(c);
|
||||
Component c2 = loadComponentFromBytes(bytes);
|
||||
return c2.libraries;
|
||||
|
||||
@@ -188,8 +188,7 @@ void verifyTargets(Procedure libProcedure, Procedure lib2Procedure,
|
||||
|
||||
Uint8List serialize(Library lib1, Library lib2) {
|
||||
Component component = new Component(libraries: [lib1, lib2])
|
||||
..setMainMethodAndMode(
|
||||
null, false, NonNullableByDefaultCompiledMode.Strong);
|
||||
..setMainMethodAndMode(null, false);
|
||||
ByteSink sink = new ByteSink();
|
||||
new BinaryPrinter(sink).writeComponentFile(component);
|
||||
return sink.builder.takeBytes();
|
||||
|
||||
@@ -27,8 +27,7 @@ void main() {
|
||||
library2.addProcedure(p2);
|
||||
|
||||
Component component = new Component(libraries: [library1, library2])
|
||||
..setMainMethodAndMode(
|
||||
null, false, NonNullableByDefaultCompiledMode.Strong);
|
||||
..setMainMethodAndMode(null, false);
|
||||
component.uriToSource[uri1] =
|
||||
new Source([42, 2 * 42], utf8.encode("source #1"), uri1, uri1);
|
||||
component.uriToSource[uri2] =
|
||||
@@ -36,7 +35,7 @@ void main() {
|
||||
expectSource(serialize(component), true, true);
|
||||
|
||||
Component cPartial1 = new Component(nameRoot: component.root)
|
||||
..setMainMethodAndMode(null, false, NonNullableByDefaultCompiledMode.Strong)
|
||||
..setMainMethodAndMode(null, false)
|
||||
..libraries.add(library1);
|
||||
cPartial1.uriToSource[uri1] =
|
||||
new Source([42, 2 * 42], utf8.encode("source #1"), uri1, uri1);
|
||||
@@ -46,7 +45,7 @@ void main() {
|
||||
expectSource(partial1Serialized, true, false);
|
||||
|
||||
Component cPartial2 = new Component(nameRoot: component.root)
|
||||
..setMainMethodAndMode(null, false, NonNullableByDefaultCompiledMode.Strong)
|
||||
..setMainMethodAndMode(null, false)
|
||||
..libraries.add(library2);
|
||||
cPartial2.uriToSource[uri1] =
|
||||
new Source.emptySource([42, 2 * 42], uri1, uri1);
|
||||
|
||||
@@ -61,8 +61,7 @@ void expect(dynamic actual, dynamic expected) {
|
||||
|
||||
Uint8List serialize(Library lib1) {
|
||||
Component component = new Component(libraries: [lib1])
|
||||
..setMainMethodAndMode(
|
||||
null, false, NonNullableByDefaultCompiledMode.Strong);
|
||||
..setMainMethodAndMode(null, false);
|
||||
ByteSink sink = new ByteSink();
|
||||
new BinaryPrinter(sink).writeComponentFile(component);
|
||||
return sink.builder.takeBytes();
|
||||
|
||||
@@ -198,6 +198,5 @@ Component createComponent(int literal) {
|
||||
fileUri: mainUri);
|
||||
main.addProcedure(mainProcedure);
|
||||
return new Component(libraries: [main, lib])
|
||||
..setMainMethodAndMode(
|
||||
null, false, NonNullableByDefaultCompiledMode.Strong);
|
||||
..setMainMethodAndMode(null, false);
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ import 'package:front_end/src/api_prototype/front_end.dart'
|
||||
show CompilerResult;
|
||||
import 'package:front_end/src/api_prototype/memory_file_system.dart';
|
||||
import 'package:front_end/src/api_unstable/vm.dart';
|
||||
import 'package:kernel/ast.dart'
|
||||
show Component, Library, NonNullableByDefaultCompiledMode, Procedure;
|
||||
import 'package:kernel/ast.dart' show Component, Library, Procedure;
|
||||
import 'package:kernel/binary/ast_from_binary.dart'
|
||||
show BinaryBuilderWithMetadata;
|
||||
import 'package:kernel/binary/ast_to_binary.dart';
|
||||
@@ -1010,10 +1009,7 @@ Future _processLoadRequest(request) async {
|
||||
pragmaClass: compilerResult.coreTypes?.pragmaClass,
|
||||
);
|
||||
if (nativeAssetsLibrary != null) {
|
||||
nativeAssetsComponent = Component(
|
||||
libraries: [nativeAssetsLibrary],
|
||||
mode: NonNullableByDefaultCompiledMode.Strong,
|
||||
);
|
||||
nativeAssetsComponent = Component(libraries: [nativeAssetsLibrary]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,10 +128,6 @@ Future main(List<String> args) async {
|
||||
bytes = concatenate(File(platformFile).readAsBytesSync(), bytes);
|
||||
}
|
||||
final component = loadComponentFromBytes(bytes);
|
||||
if (component.mode != NonNullableByDefaultCompiledMode.Strong) {
|
||||
print('Input kernel file should be compiled with sound null safety.');
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
installAdditionalTargets();
|
||||
|
||||
|
||||
@@ -99,8 +99,6 @@ class IncrementalCompiler {
|
||||
IncrementalCompilerResult _combinePendingDeltas(bool includePlatform) {
|
||||
assert(_pendingDeltas.isNotEmpty);
|
||||
Procedure? mainMethod;
|
||||
NonNullableByDefaultCompiledMode compilationMode =
|
||||
NonNullableByDefaultCompiledMode.Invalid;
|
||||
Map<Uri, Library> combined = <Uri, Library>{};
|
||||
Map<Uri, Source> uriToSource = new Map<Uri, Source>();
|
||||
ClassHierarchy classHierarchy = _pendingDeltas.last.classHierarchy;
|
||||
@@ -110,7 +108,6 @@ class IncrementalCompiler {
|
||||
if (delta.mainMethod != null) {
|
||||
mainMethod = delta.mainMethod;
|
||||
}
|
||||
compilationMode = delta.mode;
|
||||
uriToSource.addAll(delta.uriToSource);
|
||||
for (Library library in delta.libraries) {
|
||||
bool isPlatform =
|
||||
@@ -125,7 +122,7 @@ class IncrementalCompiler {
|
||||
new Component(
|
||||
libraries: combined.values.toList(),
|
||||
uriToSource: uriToSource,
|
||||
)..setMainMethodAndMode(mainMethod?.reference, true, compilationMode),
|
||||
)..setMainMethodAndMode(mainMethod?.reference, true),
|
||||
classHierarchy: classHierarchy,
|
||||
coreTypes: coreTypes,
|
||||
);
|
||||
@@ -174,11 +171,7 @@ class IncrementalCompiler {
|
||||
new Component(
|
||||
libraries: combined.values.toList(),
|
||||
uriToSource: uriToSource,
|
||||
)..setMainMethodAndMode(
|
||||
candidate.mainMethod?.reference,
|
||||
true,
|
||||
candidate.mode,
|
||||
),
|
||||
)..setMainMethodAndMode(candidate.mainMethod?.reference, true),
|
||||
classHierarchy: result.classHierarchy,
|
||||
coreTypes: result.coreTypes,
|
||||
);
|
||||
|
||||
@@ -34,8 +34,7 @@ import 'package:front_end/src/api_unstable/vm.dart'
|
||||
parseExperimentalFlags,
|
||||
printDiagnosticMessage,
|
||||
resolveInputUri;
|
||||
import 'package:kernel/ast.dart'
|
||||
show Component, Library, NonNullableByDefaultCompiledMode;
|
||||
import 'package:kernel/ast.dart' show Component, Library;
|
||||
import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
|
||||
import 'package:kernel/class_hierarchy.dart' show ClassHierarchy;
|
||||
import 'package:kernel/core_types.dart' show CoreTypes;
|
||||
@@ -482,12 +481,7 @@ Future<int> runCompiler(ArgResults options, String usage) async {
|
||||
// If Dart component in JIT, write as concatenated dill, to not mess with
|
||||
// the incremental compiler.
|
||||
final BinaryPrinter printer = new BinaryPrinter(sink);
|
||||
printer.writeComponentFile(
|
||||
Component(
|
||||
libraries: [nativeAssetsLibrary],
|
||||
mode: NonNullableByDefaultCompiledMode.Strong,
|
||||
),
|
||||
);
|
||||
printer.writeComponentFile(Component(libraries: [nativeAssetsLibrary]));
|
||||
}
|
||||
await sink.close();
|
||||
|
||||
@@ -1116,13 +1110,12 @@ Future<void> forEachPackage(
|
||||
|
||||
final mainMethod = component.mainMethod;
|
||||
final problemsAsJson = component.problemsAsJson;
|
||||
final compilationMode = component.mode;
|
||||
component.setMainMethodAndMode(null, true, compilationMode);
|
||||
component.setMainMethodAndMode(null, true);
|
||||
component.problemsAsJson = null;
|
||||
for (String package in packages.keys) {
|
||||
await action(package, packages[package]!);
|
||||
}
|
||||
component.setMainMethodAndMode(mainMethod?.reference, true, compilationMode);
|
||||
component.setMainMethodAndMode(mainMethod?.reference, true);
|
||||
component.problemsAsJson = problemsAsJson;
|
||||
|
||||
if (!mainFirst) {
|
||||
|
||||
@@ -26,7 +26,6 @@ native-assets:
|
||||
NativeAssetsValidator(errorDetector).parseAndValidate(yamlString)!;
|
||||
final component = Component(
|
||||
libraries: [NativeAssetsSynthesizer.synthesizeLibrary(validatedYaml)],
|
||||
mode: NonNullableByDefaultCompiledMode.Strong,
|
||||
);
|
||||
final libraryToString = kernelLibraryToString(component.libraries.single);
|
||||
final expectedKernel = '''@#C3
|
||||
|
||||
@@ -874,15 +874,6 @@ class LibraryHelper {
|
||||
void SetJustRead(Field field) { next_read_ = field + 1; }
|
||||
|
||||
bool IsSynthetic() const { return (flags_ & kSynthetic) != 0; }
|
||||
NNBDCompiledMode GetNonNullableByDefaultCompiledMode() const {
|
||||
bool bit1 = (flags_ & kNonNullableByDefaultCompiledModeBit1) != 0;
|
||||
bool bit2 = (flags_ & kNonNullableByDefaultCompiledModeBit2) != 0;
|
||||
if (!bit1 && !bit2) return NNBDCompiledMode::kStrong;
|
||||
if (bit1 && !bit2) return NNBDCompiledMode::kWeak;
|
||||
if (bit1 && bit2) return NNBDCompiledMode::kAgnostic;
|
||||
if (!bit1 && bit2) return NNBDCompiledMode::kInvalid;
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
uint8_t flags_ = 0;
|
||||
NameIndex canonical_name_;
|
||||
|
||||
@@ -174,6 +174,7 @@ std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
|
||||
program->component_index_offset_ = reader->ReadUInt32();
|
||||
|
||||
program->main_method_reference_ = NameIndex(reader->ReadUInt32() - 1);
|
||||
// TODO(jensj): Remove this.
|
||||
reader->ReadUInt32(); // Read and ignore NNBD compilation mode.
|
||||
|
||||
return program;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace kernel {
|
||||
// package:kernel/binary.md.
|
||||
|
||||
static const uint32_t kMagicProgramFile = 0x90ABCDEFu;
|
||||
static const uint32_t kSupportedKernelFormatVersion = 122;
|
||||
static const uint32_t kSupportedKernelFormatVersion = 123;
|
||||
|
||||
// Keep in sync with package:kernel/lib/binary/tag.dart
|
||||
#define KERNEL_TAG_LIST(V) \
|
||||
|
||||
@@ -828,21 +828,6 @@ LibraryPtr KernelLoader::LoadLibrary(intptr_t index) {
|
||||
|
||||
if (library.Loaded()) return library.ptr();
|
||||
|
||||
const NNBDCompiledMode mode =
|
||||
library_helper.GetNonNullableByDefaultCompiledMode();
|
||||
if (mode == NNBDCompiledMode::kInvalid) {
|
||||
H.ReportError(
|
||||
"Library '%s' was compiled in an unsupported mixed mode between sound "
|
||||
"null safety and not sound null safety.",
|
||||
String::Handle(library.url()).ToCString());
|
||||
}
|
||||
if (mode == NNBDCompiledMode::kWeak) {
|
||||
H.ReportError(
|
||||
"Library '%s' was compiled without sound null safety (in weak mode) "
|
||||
"and it cannot be used at runtime",
|
||||
String::Handle(library.url()).ToCString());
|
||||
}
|
||||
|
||||
library_kernel_data_ = helper_.reader_.ViewFromTo(
|
||||
library_kernel_offset_, library_kernel_offset_ + library_size);
|
||||
library.set_kernel_library_index(index);
|
||||
|
||||
@@ -1145,15 +1145,6 @@ enum class TypeEquality {
|
||||
kInSubtypeTest = 2,
|
||||
};
|
||||
|
||||
// The NNBDCompiledMode reflects the mode in which constants of the library were
|
||||
// compiled by CFE.
|
||||
enum class NNBDCompiledMode {
|
||||
kStrong = 0,
|
||||
kWeak = 1,
|
||||
kAgnostic = 2,
|
||||
kInvalid = 3,
|
||||
};
|
||||
|
||||
class Class : public Object {
|
||||
public:
|
||||
enum InvocationDispatcherEntry {
|
||||
|
||||
Reference in New Issue
Block a user