Skip to content

Commit 617b78a

Browse files
sigmundchcommit-bot@chromium.org
authored andcommitted
[ddc] do not add null checks for parameters marked as @NotNull
Unlike non-nullable types, the purpose of the annotation in our runtime is to ensure we don't generate extra checks. This should remove a few nullFailed calls in the generated sdk. Change-Id: I7b8ac012a6cfa5f8baf2667d89185e7540320ec2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138783 Reviewed-by: Nicholas Shahan <[email protected]>
1 parent 2ae10b1 commit 617b78a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pkg/dev_compiler/lib/src/kernel/compiler.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3173,7 +3173,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
31733173
body.add(js.statement('if (# == null) return false;', [jsParam]));
31743174
} else if (_annotatedNullCheck(p.annotations)) {
31753175
body.add(_nullParameterCheck(jsParam));
3176-
} else if (_mustBeNonNullable(p.type)) {
3176+
} else if (_mustBeNonNullable(p.type) &&
3177+
!_annotatedNotNull(p.annotations)) {
31773178
// TODO(vsm): Remove if / when CFE does this:
31783179
// https://github.com/dart-lang/sdk/issues/40597
31793180
// The check on `p.type` is per:
@@ -3229,6 +3230,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
32293230
bool _annotatedNullCheck(List<Expression> annotations) =>
32303231
annotations.any(_nullableInference.isNullCheckAnnotation);
32313232

3233+
bool _annotatedNotNull(List<Expression> annotations) =>
3234+
annotations.any(_nullableInference.isNotNullAnnotation);
3235+
32323236
bool _reifyGenericFunction(Member m) =>
32333237
m == null ||
32343238
m.enclosingLibrary.importUri.scheme != 'dart' ||

0 commit comments

Comments
 (0)