[dart2js] Restrict instanceof is-test specializations to non-generic

types when SNS checks are enabled.

Change-Id: I759a4ba77b74f6e0ec7c7ec65ad3ca37ed8410a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372201
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
This commit is contained in:
Mayank Patke 2024-06-24 20:52:43 +00:00 committed by Commit Queue
parent 537737b190
commit 56851e50e2
2 changed files with 14 additions and 5 deletions

View file

@ -30,20 +30,24 @@ class InstanceOfIsTestSpecialization implements IsTestSpecialization {
class SpecializedChecks {
static IsTestSpecialization? findIsTestSpecialization(
DartType dartType, MemberEntity compiland, JClosedWorld closedWorld) {
DartType dartType, MemberEntity compiland, JClosedWorld closedWorld,
{required bool experimentNullSafetyChecks}) {
if (dartType is LegacyType) {
DartType base = dartType.baseType;
// `Never*` accepts only `null`.
if (base is NeverType) return SimpleIsTestSpecialization.isNull;
// `Object*` is top and should be handled by constant folding.
if (base.isObject) return null;
return _findIsTestSpecialization(base, compiland, closedWorld);
return _findIsTestSpecialization(base, compiland, closedWorld,
experimentNullSafetyChecks: experimentNullSafetyChecks);
}
return _findIsTestSpecialization(dartType, compiland, closedWorld);
return _findIsTestSpecialization(dartType, compiland, closedWorld,
experimentNullSafetyChecks: experimentNullSafetyChecks);
}
static IsTestSpecialization? _findIsTestSpecialization(
DartType dartType, MemberEntity compiland, JClosedWorld closedWorld) {
DartType dartType, MemberEntity compiland, JClosedWorld closedWorld,
{required bool experimentNullSafetyChecks}) {
if (dartType is InterfaceType) {
ClassEntity element = dartType.element;
JCommonElements commonElements = closedWorld.commonElements;
@ -98,6 +102,10 @@ class SpecializedChecks {
return SimpleIsTestSpecialization.isNotNull;
}
if (experimentNullSafetyChecks && dartType.typeArguments.isNotEmpty) {
return null;
}
ClassHierarchy classHierarchy = closedWorld.classHierarchy;
InterceptorData interceptorData = closedWorld.interceptorData;
OutputUnitData outputUnitData = closedWorld.outputUnitData;

View file

@ -2305,7 +2305,8 @@ class SsaInstructionSimplifier extends HBaseVisitor<HInstruction>
}
final specialization = SpecializedChecks.findIsTestSpecialization(
node.dartType, _graph.element, _closedWorld);
node.dartType, _graph.element, _closedWorld,
experimentNullSafetyChecks: _options.experimentNullSafetyChecks);
if (specialization == SimpleIsTestSpecialization.isNull ||
specialization == SimpleIsTestSpecialization.isNotNull) {