Skip to content

Commit a42401a

Browse files
rakudramaCommit Queue
authored andcommitted
[dart2js] Remove checks to support migration with mixed null safety
`_potentiallyAssertNotNull` would insert null checks to catch issues from mixing libraries sound and unsound null safety. The null checks are now always optimized away so we might as well never insert them. Bug: #60327 Change-Id: I092a4fb336e46bf33b9b3cd9867dd7b6d8f9c65e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427569 Reviewed-by: Mayank Patke <[email protected]> Commit-Queue: Stephen Adams <[email protected]> Reviewed-by: Jake Macdonald <[email protected]>
1 parent 40ffa5a commit a42401a

File tree

2 files changed

+5
-58
lines changed

2 files changed

+5
-58
lines changed

pkg/compiler/lib/src/ssa/builder.dart

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,6 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault<void>
670670
// TODO(sra): The source information should indicate the field and
671671
// possibly its type but not the initializer.
672672
value.sourceInformation ??= _sourceInformationBuilder.buildSet(node);
673-
value = _potentiallyAssertNotNull(field, node, value, type);
674673
if (!_fieldAnalysis.getFieldData(field).isElided) {
675674
add(HFieldSet(field, thisInstruction, value));
676675
}
@@ -1999,13 +1998,6 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault<void>
19991998
type,
20001999
);
20012000
}
2002-
// TODO(sra): Hoist out of loop.
2003-
newParameter = _potentiallyAssertNotNull(
2004-
member,
2005-
variable,
2006-
newParameter,
2007-
type,
2008-
);
20092001
localsHandler.updateLocal(local, newParameter);
20102002
}
20112003

@@ -2036,49 +2028,6 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault<void>
20362028
}
20372029
}
20382030

2039-
/// In mixed mode, inserts an assertion of the form `assert(x != null)` for
2040-
/// parameters in opt-in libraries that have a static type that cannot be
2041-
/// nullable under a strong interpretation.
2042-
HInstruction _potentiallyAssertNotNull(
2043-
MemberEntity member,
2044-
ir.TreeNode context,
2045-
HInstruction value,
2046-
DartType type,
2047-
) {
2048-
if (!dartTypes.isNonNullable(type)) return value;
2049-
2050-
// `operator==` is usually augmented to handle a `null`-argument before this
2051-
// test would be inserted. There are a few exceptions (Object,
2052-
// Interceptor), where the body of the `==` method is designed to handle a
2053-
// `null` argument. In the usual case the null assertion is unnecessary and
2054-
// will be optimized away. In the exception cases a null assertion would be
2055-
// incorrect. Either way we should not do a null-assertion on the parameter
2056-
// of any `operator==` method.
2057-
if (member.name == '==') return value;
2058-
2059-
if (options.enableUserAssertions) {
2060-
pushCheckNull(value);
2061-
push(HNot(pop(), _abstractValueDomain.boolType));
2062-
var sourceInformation = _sourceInformationBuilder.buildAssert(context);
2063-
_pushStaticInvocation(
2064-
_commonElements.assertHelper,
2065-
[pop()],
2066-
_typeInferenceMap.getReturnTypeOf(_commonElements.assertHelper),
2067-
const <DartType>[],
2068-
sourceInformation: sourceInformation,
2069-
);
2070-
pop();
2071-
return value;
2072-
} else {
2073-
HInstruction nullCheck = HNullCheck(
2074-
value,
2075-
_abstractValueDomain.excludeNull(value.instructionType),
2076-
)..sourceInformation = value.sourceInformation;
2077-
add(nullCheck);
2078-
return nullCheck;
2079-
}
2080-
}
2081-
20822031
/// Builds an SSA graph for FunctionNodes of external methods.
20832032
void _buildExternalFunctionNode(
20842033
FunctionEntity function,
@@ -8595,12 +8544,6 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault<void>
85958544
type,
85968545
);
85978546
}
8598-
checkedOrTrusted = _potentiallyAssertNotNull(
8599-
function,
8600-
variable,
8601-
checkedOrTrusted,
8602-
type,
8603-
);
86048547
localsHandler.updateLocal(parameter, checkedOrTrusted);
86058548
});
86068549
}

tests/language/function_subtype/regress41680_strong_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Requirements=nnbd-strong
66

77
import "package:expect/expect.dart";
8+
import 'package:expect/variations.dart' as v;
89

910
typedef dynamicToDynamic = dynamic Function(dynamic);
1011

@@ -22,5 +23,8 @@ main() {
2223
Expect.throwsTypeError(() => dynamicNull as dynamicToDynamic);
2324
Expect.throwsTypeError(() => cast<dynamic Function(dynamic)>(dynamicNull));
2425
Expect.throwsTypeError(() => dynamicNull as voidToT);
25-
Expect.throwsTypeError(() => allowsArgument(dynamicNull));
26+
Expect.throwsTypeErrorWhen(
27+
v.checkedParameters,
28+
() => allowsArgument(dynamicNull),
29+
);
2630
}

0 commit comments

Comments
 (0)