Skip to content

Commit 0bb3adb

Browse files
rakudramaCommit Queue
authored andcommitted
[dart2js] Remove receiver-not-null strengthening
Adding the inference that, after `x.foo()`, `x` cannot be null used to make sense, but with sound null safety means this is only applicable when `x` is `dynamic`. Removing the `knownType` update logic makes it easier to reason about type propagation. There are very few regressions for removing this now (huge app had half a dozen minor regressions, several other apps had none). If we decide to add something like this in the future, I think it should be added as part of SsaTypeConversionInserter, and be extended to add other post-conditions (e.g. the runtime helper `checkString(s)` ensures `s` is a String). Change-Id: I27a7fcbc13873867713c439c062ecf9bd71d644d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420504 Commit-Queue: Stephen Adams <[email protected]> Reviewed-by: Mayank Patke <[email protected]>
1 parent 1568027 commit 0bb3adb

File tree

2 files changed

+1
-35
lines changed

2 files changed

+1
-35
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4045,7 +4045,7 @@ class HLateInitializeOnceCheck extends HLateCheck {
40454045

40464046
/// The [HTypeKnown] instruction marks a value with a refined type.
40474047
class HTypeKnown extends HCheck {
4048-
AbstractValue knownType;
4048+
final AbstractValue knownType;
40494049
final bool _isMovable;
40504050

40514051
HTypeKnown.pinned(this.knownType, HInstruction input)

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

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -441,40 +441,6 @@ class SsaTypePropagator extends HBaseVisitor<AbstractValue>
441441
AbstractValue receiverType = receiver.instructionType;
442442
node.updateReceiverType(abstractValueDomain, receiverType);
443443

444-
// Try to refine that the receiver is not null after this call by inserting
445-
// a refinement node (HTypeKnown).
446-
var selector = node.selector;
447-
if (!selector.isMaybeClosureCall && !selector.appliesToNullWithoutThrow()) {
448-
var next = node.next;
449-
if (next is HTypeKnown && next.checkedInput == receiver) {
450-
// On a previous pass or iteration we already refined [receiver] by
451-
// inserting a [HTypeKnown] instruction. That replaced several dominated
452-
// uses with the refinement. We update the type of the [HTypeKnown]
453-
// instruction because it may have been refined with a correct type at
454-
// the time, but incorrect now.
455-
AbstractValue newType = abstractValueDomain.excludeNull(receiverType);
456-
if (next.instructionType != newType) {
457-
next.knownType = next.instructionType = newType;
458-
addDependentInstructionsToWorkList(next);
459-
}
460-
} else if (abstractValueDomain.isNull(receiverType).isPotentiallyTrue) {
461-
DominatedUses uses = DominatedUses.of(
462-
receiver,
463-
node,
464-
excludeDominator: true,
465-
);
466-
if (uses.isNotEmpty) {
467-
// Insert a refinement node after the call and update all users
468-
// dominated by the call to use that node instead of [receiver].
469-
AbstractValue newType = abstractValueDomain.excludeNull(receiverType);
470-
HTypeKnown converted = HTypeKnown.witnessed(newType, receiver, node);
471-
node.block!.addBefore(node.next, converted);
472-
uses.replaceWith(converted);
473-
addDependentInstructionsToWorkList(converted);
474-
}
475-
}
476-
}
477-
478444
var result = node.specializer.computeTypeFromInputTypes(
479445
node,
480446
results,

0 commit comments

Comments
 (0)