@@ -108,6 +108,7 @@ abstract class HVisitor<R> {
108108 // Instructions for 'dart:_rti'.
109109 R visitIsTest (HIsTest node);
110110 R visitAsCheck (HAsCheck node);
111+ R visitAsCheckSimple (HAsCheckSimple node);
111112 R visitSubtypeCheck (HSubtypeCheck node);
112113 R visitLoadType (HLoadType node);
113114 R visitInstanceEnvironment (HInstanceEnvironment node);
@@ -603,6 +604,8 @@ class HBaseVisitor extends HGraphVisitor implements HVisitor {
603604 @override
604605 visitAsCheck (HAsCheck node) => visitCheck (node);
605606 @override
607+ visitAsCheckSimple (HAsCheckSimple node) => visitCheck (node);
608+ @override
606609 visitSubtypeCheck (HSubtypeCheck node) => visitCheck (node);
607610 @override
608611 visitLoadType (HLoadType node) => visitInstruction (node);
@@ -1092,11 +1095,12 @@ abstract class HInstruction implements Spannable {
10921095
10931096 static const int IS_TEST_TYPECODE = 47 ;
10941097 static const int AS_CHECK_TYPECODE = 48 ;
1095- static const int SUBTYPE_CHECK_TYPECODE = 49 ;
1096- static const int LOAD_TYPE_TYPECODE = 50 ;
1097- static const int INSTANCE_ENVIRONMENT_TYPECODE = 51 ;
1098- static const int TYPE_EVAL_TYPECODE = 52 ;
1099- static const int TYPE_BIND_TYPECODE = 53 ;
1098+ static const int AS_CHECK_SIMPLE_TYPECODE = 49 ;
1099+ static const int SUBTYPE_CHECK_TYPECODE = 50 ;
1100+ static const int LOAD_TYPE_TYPECODE = 51 ;
1101+ static const int INSTANCE_ENVIRONMENT_TYPECODE = 52 ;
1102+ static const int TYPE_EVAL_TYPECODE = 53 ;
1103+ static const int TYPE_BIND_TYPECODE = 54 ;
11001104
11011105 HInstruction (this .inputs, this .instructionType)
11021106 : id = idCounter++ ,
@@ -4430,6 +4434,55 @@ class HAsCheck extends HCheck {
44304434 }
44314435}
44324436
4437+ /// Type cast or type check for simple known types that are achieved via a
4438+ /// simple static call.
4439+ class HAsCheckSimple extends HCheck {
4440+ final DartType dartType;
4441+ final AbstractValueWithPrecision checkedType;
4442+ final bool isTypeError;
4443+ final MemberEntity method;
4444+
4445+ HAsCheckSimple (HInstruction checked, this .dartType, this .checkedType,
4446+ this .isTypeError, this .method, AbstractValue type)
4447+ : assert (isTypeError != null ),
4448+ super ([checked], type);
4449+
4450+ @override
4451+ HInstruction get checkedInput => inputs[0 ];
4452+
4453+ @override
4454+ bool isJsStatement () => false ;
4455+
4456+ @override
4457+ accept (HVisitor visitor) => visitor.visitAsCheckSimple (this );
4458+
4459+ bool isRedundant (JClosedWorld closedWorld) {
4460+ if (! checkedType.isPrecise) return false ;
4461+ AbstractValueDomain abstractValueDomain = closedWorld.abstractValueDomain;
4462+ AbstractValue inputType = checkedInput.instructionType;
4463+ return abstractValueDomain
4464+ .isIn (inputType, checkedType.abstractValue)
4465+ .isDefinitelyTrue;
4466+ }
4467+
4468+ @override
4469+ int typeCode () => HInstruction .AS_CHECK_SIMPLE_TYPECODE ;
4470+
4471+ @override
4472+ bool typeEquals (HInstruction other) => other is HAsCheckSimple ;
4473+
4474+ @override
4475+ bool dataEquals (HAsCheckSimple other) {
4476+ return isTypeError == other.isTypeError && dartType == other.dartType;
4477+ }
4478+
4479+ @override
4480+ String toString () {
4481+ String error = isTypeError ? 'TypeError' : 'CastError' ;
4482+ return 'HAsCheck($error )' ;
4483+ }
4484+ }
4485+
44334486/// Subtype check comparing two Rti types.
44344487class HSubtypeCheck extends HCheck {
44354488 HSubtypeCheck (
0 commit comments