mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:31:58 +00:00
[dart2js] Replace references to NNBD with null safety.
Change-Id: Id23dce928425c99770ced629f866cee01fa2ef0c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212240 Reviewed-by: Joshua Litt <joshualitt@google.com> Commit-Queue: Mayank Patke <fishythefish@google.com>
This commit is contained in:
parent
1795c2c804
commit
74fa14a4c5
|
@ -1707,7 +1707,7 @@ abstract class DartTypes {
|
|||
|
||||
DartType nullableType(DartType baseType) {
|
||||
bool _isNullable(DartType t) =>
|
||||
// Note that we can assume NNBD is enabled here.
|
||||
// Note that we can assume null safety is enabled here.
|
||||
t.isNull ||
|
||||
t is NullableType ||
|
||||
t is LegacyType && _isNullable(t.baseType) ||
|
||||
|
|
|
@ -72,8 +72,8 @@ class SpecializedChecks {
|
|||
}
|
||||
|
||||
DartTypes dartTypes = closedWorld.dartTypes;
|
||||
// Top types (here it could be Object in non-NNBD mode) should be constant
|
||||
// folded outside the specializer. This test protects logic below.
|
||||
// Top types should be constant folded outside the specializer. This test
|
||||
// protects logic below.
|
||||
if (dartTypes.isTopType(dartType)) return null;
|
||||
ElementEnvironment elementEnvironment = closedWorld.elementEnvironment;
|
||||
if (!dartTypes.isSubtype(
|
||||
|
|
|
@ -61,7 +61,8 @@ class KernelLoaderTask extends CompilerTask {
|
|||
String targetName =
|
||||
_options.compileForServer ? "dart2js_server" : "dart2js";
|
||||
|
||||
// We defer selecting the platform until we've resolved the NNBD mode.
|
||||
// We defer selecting the platform until we've resolved the null safety
|
||||
// mode.
|
||||
String getPlatformFilename() {
|
||||
String platform = targetName;
|
||||
if (!_options.useLegacySubtyping) {
|
||||
|
|
|
@ -838,7 +838,7 @@ abstract class BehaviorBuilder {
|
|||
_behavior.typesReturned.add(type.withoutNullability);
|
||||
|
||||
// Breakdown nullable type into TypeWithoutNullability|Null.
|
||||
// Pre-nnbd Declared types are nullable, so we also add null in that case.
|
||||
// Unsound declared types are nullable, so we also add null in that case.
|
||||
// TODO(41960): Remove check for legacy subtyping. This was added as a
|
||||
// temporary workaround to unblock the null-safe unfork. At this time some
|
||||
// native APIs are typed unsoundly because they don't consider browser
|
||||
|
|
|
@ -708,7 +708,7 @@ class CompilerOptions implements DiagnosticOptions {
|
|||
|
||||
if (benchmarkingExperiment) {
|
||||
// Set flags implied by '--benchmarking-x'.
|
||||
// TODO(sra): Use this for some NNBD variant.
|
||||
// TODO(sra): Use this for some null safety variant.
|
||||
useContentSecurityPolicy = true;
|
||||
features.forceCanary();
|
||||
}
|
||||
|
|
|
@ -3517,10 +3517,10 @@ class HLateValue extends HLateInstruction {
|
|||
/// Check for receiver or argument type when lowering operation to a primitive,
|
||||
/// e.g. lowering `+` to [HAdd].
|
||||
///
|
||||
/// After NNBD, `a + b` will require `a` and `b` are non-nullable and these
|
||||
/// checks will become explicit in the source (e.g. `a! + b!`). At that time,
|
||||
/// this check should be removed. If needed, the `!` check can be optimized
|
||||
/// give the same signals to the JavaScript VM.
|
||||
/// With sound null safety, `a + b` will require `a` and `b` to be non-nullable
|
||||
/// and these checks will become explicit in the source (e.g. `a! + b!`). At
|
||||
/// that time, this check should be removed. If needed, the `!` check can be
|
||||
/// optimized to give the same signals to the JavaScript VM.
|
||||
class HPrimitiveCheck extends HCheck {
|
||||
// Values for [kind].
|
||||
static const int ARGUMENT_TYPE_CHECK = 1;
|
||||
|
@ -3590,8 +3590,8 @@ class HPrimitiveCheck extends HCheck {
|
|||
}
|
||||
|
||||
/// A check that the input to a condition (if, ?:, while, etc) is non-null. The
|
||||
/// front-end generates 'as bool' checks, but until the transition to NNBD is
|
||||
/// complete, this allows `null` to be passed to the condition.
|
||||
/// front-end generates 'as bool' checks, but until the transition to null
|
||||
/// safety is complete, this allows `null` to be passed to the condition.
|
||||
///
|
||||
// TODO(sra): Once NNDB is far enough along that the front-end can generate `as
|
||||
// bool!` checks and the backend checks them correctly, this instruction will
|
||||
|
|
|
@ -1926,8 +1926,8 @@ class SsaInstructionSimplifier extends HBaseVisitor
|
|||
@override
|
||||
HInstruction visitAsCheck(HAsCheck node) {
|
||||
// TODO(fishythefish): Correctly constant fold `null as T` (also in
|
||||
// [visitAsCheckSimple]) when running with strong NNBD. We might get this
|
||||
// for free if nullability is precisely propagated to the typemasks.
|
||||
// [visitAsCheckSimple]) when running with sound null safety. We might get
|
||||
// this for free if nullability is precisely propagated to the typemasks.
|
||||
|
||||
HInstruction typeInput = node.typeInput;
|
||||
if (typeInput is HLoadType) {
|
||||
|
|
|
@ -33,7 +33,7 @@ class Class2<T> {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// Implicit as-cast is only required in spec:nnbd-off mode.
|
||||
/// Implicit as-cast is only required in spec mode.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*member: Class3.:hasThis*/
|
||||
|
|
|
@ -27,7 +27,7 @@ method2<T>(dynamic o) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// Implicit as-cast is only required in spec:nnbd-off mode.
|
||||
/// Implicit as-cast is only required in spec mode.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*member: method3:*/
|
||||
|
|
|
@ -43,7 +43,7 @@ class Class1b<T> {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// A local function parameter type is only captured in spec:nnbd-off mode.
|
||||
/// A local function parameter type is only captured in spec mode.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*member: Class2.:hasThis*/
|
||||
|
@ -58,7 +58,7 @@ class Class2<T> {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// A local function return type is only captured in spec:nnbd-off mode.
|
||||
/// A local function return type is only captured in spec mode.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*member: Class3.:hasThis*/
|
||||
|
|
|
@ -19,7 +19,7 @@ method1<T>(T o) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// A local function parameter type is captured in spec:nnbd-off mode.
|
||||
/// A local function parameter type is captured in spec mode.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
method2<T>() {
|
||||
|
@ -29,7 +29,7 @@ method2<T>() {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// A local function return type is captured in spec:nnbd-off mode.
|
||||
/// A local function return type is captured in spec mode.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
method3<T>(dynamic o) {
|
||||
|
|
|
@ -11,7 +11,7 @@ import 'package:async_helper/async_helper.dart';
|
|||
import '../helpers/compiler_helper.dart';
|
||||
|
||||
// 'N' tests all have a nullable input so should not reduce is-test.
|
||||
// TODO(NNBD): Add tests with non-nullable input types.
|
||||
// TODO(sra): Add tests with non-nullable input types.
|
||||
|
||||
const TEST1N = r"""
|
||||
foo(int a) {
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
import 'dart:typed_data';
|
||||
|
||||
// TODO(johnniwinther): Fix inference for spec:nnbd-off mode. List elements should not
|
||||
// be [empty].
|
||||
// TODO(johnniwinther): Fix inference for spec mode. List elements should not be
|
||||
// [empty].
|
||||
|
||||
/*member: myList:Container([null|exact=NativeFloat32List], element: [subclass=JSNumber], length: 42)*/
|
||||
var myList = new Float32List(42);
|
||||
|
|
|
@ -14,9 +14,9 @@ import 'common_test_utils.dart';
|
|||
final String testRootDir = Platform.script.resolve('.').toFilePath();
|
||||
|
||||
runTestCase(
|
||||
Uri source, List<String> experimentalFlags, bool enableNullSafety) async {
|
||||
Uri source, List<String> experimentalFlags, bool soundNullSafety) async {
|
||||
final target =
|
||||
TestingDart2jsTarget(TargetFlags(enableNullSafety: enableNullSafety));
|
||||
TestingDart2jsTarget(TargetFlags(enableNullSafety: soundNullSafety));
|
||||
Component component = await compileTestCaseToKernelProgram(source,
|
||||
target: target, experimentalFlags: experimentalFlags);
|
||||
|
||||
|
@ -33,13 +33,11 @@ main() {
|
|||
in testCasesDir.listSync(recursive: true, followLinks: false)) {
|
||||
final path = entry.path;
|
||||
if (path.endsWith('.dart')) {
|
||||
final bool enableNullSafety = path.endsWith('_nnbd_strong.dart');
|
||||
final bool enableNNBD = enableNullSafety || path.endsWith('_nnbd.dart');
|
||||
final List<String> experimentalFlags = [
|
||||
if (enableNNBD) 'non-nullable',
|
||||
];
|
||||
test(path,
|
||||
() => runTestCase(entry.uri, experimentalFlags, enableNullSafety));
|
||||
final bool unsoundNullSafety = path.endsWith('_unsound.dart');
|
||||
test(
|
||||
path,
|
||||
() => runTestCase(
|
||||
entry.uri, const ['non-nullable'], !unsoundNullSafety));
|
||||
}
|
||||
}
|
||||
}, timeout: Timeout.none);
|
||||
|
|
Loading…
Reference in a new issue