Skip to content

Commit f581341

Browse files
rakudramaCommit Queue
authored andcommitted
[dart2js] Use static type refinement for getters in SSA
This helps with generic fields of classes that have contexts with concrete types, e.g Flutter's `IntTween extends Tween<int>` has `int?` fields `begin` and `end`. This helps remove some `HPrimitiveCheck` instructions. Bug: #60327 Change-Id: Ic2022cc15e024f596ad30f3134ec6c325c892dcf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426660 Commit-Queue: Stephen Adams <[email protected]> Reviewed-by: Mayank Patke <[email protected]>
1 parent cce62d3 commit f581341

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7031,7 +7031,9 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault<void>
70317031
}
70327032
}
70337033

7034-
if (node is ir.InstanceInvocation || node is ir.FunctionInvocation) {
7034+
if (node is ir.InstanceInvocation ||
7035+
node is ir.FunctionInvocation ||
7036+
node is ir.InstanceGet) {
70357037
final staticType =
70367038
_abstractValueDomain
70377039
.createFromStaticType(_getStaticType(node as ir.Expression))
@@ -7042,9 +7044,9 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault<void>
70427044
// here.
70437045
if (!_possiblyLegacyJavaScriptObject(selector, receiverType)) {
70447046
invoke.staticType = staticType;
7045-
invoke.instructionType = _abstractValueDomain.intersection(
7047+
invoke.instructionType = invoke.computeInstructionType(
70467048
resultType,
7047-
staticType,
7049+
_abstractValueDomain,
70487050
);
70497051
}
70507052
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,20 @@ abstract class HInvokeDynamic extends HInvoke implements InstructionContext {
19651965
);
19661966
}
19671967

1968+
/// Returns [value] narrowed by the [staticType].
1969+
AbstractValue computeInstructionType(
1970+
AbstractValue value,
1971+
AbstractValueDomain abstractValueDomain,
1972+
) {
1973+
if (staticType == null) return value;
1974+
final narrowed = abstractValueDomain.intersection(value, staticType!);
1975+
// Preserve the sentinel in [value] since the static type does not include
1976+
// a sentinel and the intersection would remove it.
1977+
return abstractValueDomain.isLateSentinel(value).isPotentiallyTrue
1978+
? abstractValueDomain.includeLateSentinel(narrowed)
1979+
: narrowed;
1980+
}
1981+
19681982
@override
19691983
String toString() => 'invoke dynamic: selector=$selector, mask=$receiverType';
19701984

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,7 @@ class SsaTypePropagator extends HBaseVisitor<AbstractValue>
446446
results,
447447
closedWorld,
448448
);
449-
if (node.staticType != null) {
450-
result = abstractValueDomain.intersection(result, node.staticType!);
451-
}
452-
return result;
449+
return node.computeInstructionType(result, abstractValueDomain);
453450
}
454451

455452
@override

0 commit comments

Comments
 (0)