Skip to content

Commit

Permalink
[cfe] Move checks for all sound Components from .dill
Browse files Browse the repository at this point in the history
Moving here allows the checks to cover more code paths including
the mode used in google3 where the no mixed .dills in sound mode
was not being enforced for ddc targets.

Change-Id: I1af1d63f96dd23f56d637bffd4eef397d4deb167
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162823
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Nicholas Shahan <[email protected]>
  • Loading branch information
nshahan authored and [email protected] committed Sep 16, 2020
1 parent 4b30c91 commit 8cc4a12
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
27 changes: 24 additions & 3 deletions pkg/front_end/lib/src/base/processed_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import 'package:_fe_analyzer_shared/src/messages/severity.dart' show Severity;
import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;

import 'package:kernel/kernel.dart'
show CanonicalName, Component, Location, Version;
show
CanonicalName,
Component,
Location,
NonNullableByDefaultCompiledMode,
Version;

import 'package:kernel/target/targets.dart'
show NoneTarget, Target, TargetFlags;
Expand Down Expand Up @@ -357,6 +362,18 @@ class ProcessedOptions {
_raw.experimentReleasedVersionForTesting);
}

Component _validateNullSafetyMode(Component component) {
if (nnbdMode == NnbdMode.Strong &&
!(component.mode == NonNullableByDefaultCompiledMode.Strong ||
component.mode == NonNullableByDefaultCompiledMode.Agnostic)) {
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 {
Expand All @@ -365,6 +382,7 @@ class ProcessedOptions {
List<int> bytes = await loadSdkSummaryBytes();
if (bytes != null && bytes.isNotEmpty) {
_sdkSummaryComponent = loadComponent(bytes, nameRoot);
_validateNullSafetyMode(_sdkSummaryComponent);
}
}
return _sdkSummaryComponent;
Expand All @@ -374,6 +392,7 @@ class ProcessedOptions {
if (_sdkSummaryComponent != null) {
throw new StateError("sdkSummary already loaded.");
}
_validateNullSafetyMode(platform);
_sdkSummaryComponent = platform;
}

Expand All @@ -389,7 +408,8 @@ class ProcessedOptions {
uris.map((uri) => _readAsBytes(fileSystem.entityForUri(uri))));
_additionalDillComponents = allBytes
.where((bytes) => bytes != null)
.map((bytes) => loadComponent(bytes, nameRoot))
.map((bytes) =>
_validateNullSafetyMode(loadComponent(bytes, nameRoot)))
.toList();
}
return _additionalDillComponents;
Expand All @@ -399,6 +419,7 @@ class ProcessedOptions {
if (_additionalDillComponents != null) {
throw new StateError("inputAdditionalDillsComponents already loaded.");
}
components.forEach(_validateNullSafetyMode);
_additionalDillComponents = components;
}

Expand All @@ -414,7 +435,7 @@ class ProcessedOptions {
disableLazyReading: false,
alwaysCreateNewNamedNodes: alwaysCreateNewNamedNodes)
.readComponent(component);
return component;
return _validateNullSafetyMode(component);
}

/// Get the [UriTranslator] which resolves "package:" and "dart:" URIs.
Expand Down
17 changes: 0 additions & 17 deletions pkg/front_end/lib/src/kernel_generator_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,11 @@ Future<CompilerResult> generateKernelInternal(
// sdkSummary between multiple invocations.
CanonicalName nameRoot = sdkSummary?.root ?? new CanonicalName.root();
if (sdkSummary != null) {
if (options.nnbdMode == NnbdMode.Strong &&
!(sdkSummary.mode == NonNullableByDefaultCompiledMode.Strong ||
sdkSummary.mode == NonNullableByDefaultCompiledMode.Agnostic)) {
throw new FormatException(
'Provided SDK .dill does not support sound null safety.');
}
dillTarget.loader.appendLibraries(sdkSummary);
}

for (Component additionalDill
in await options.loadAdditionalDills(nameRoot)) {
if (options.nnbdMode == NnbdMode.Strong &&
!(additionalDill.mode == NonNullableByDefaultCompiledMode.Strong ||
// In some VM tests the SDK dill appears as an additionalDill so
// allow agnostic here as well.
additionalDill.mode ==
NonNullableByDefaultCompiledMode.Agnostic)) {
throw new FormatException(
'Provided .dill file for the following libraries does not support '
'sound null safety:\n'
'${additionalDill.libraries.join('\n')}');
}
loadedComponents.add(additionalDill);
dillTarget.loader.appendLibraries(additionalDill);
}
Expand Down

0 comments on commit 8cc4a12

Please sign in to comment.