@@ -227,7 +227,7 @@ private module LogicInput implements GuardsImpl::LogicInputSig {
227227 e instanceof DereferenceableExpr and
228228 ct .getAnArgument ( ) = e and
229229 ct .getAnArgument ( ) = arg and
230- arg = any ( NullValue nv | nv . isNonNull ( ) ) . getAnExpr ( ) and
230+ nonNullValueImplied ( arg ) and
231231 ck = ct .getComparisonKind ( ) and
232232 e != arg and
233233 isNull = false and
@@ -314,7 +314,7 @@ class Guard extends Guards::Guard {
314314 * In case `cfn` or `sub` access an SSA variable in their left-most qualifier, then
315315 * so must the other (accessing the same SSA variable).
316316 */
317- predicate controlsNode ( ControlFlow:: Nodes:: ElementNode cfn , AccessOrCallExpr sub , AbstractValue v ) {
317+ predicate controlsNode ( ControlFlow:: Nodes:: ElementNode cfn , AccessOrCallExpr sub , GuardValue v ) {
318318 isGuardedByNode ( cfn , this , sub , v )
319319 }
320320
@@ -324,26 +324,31 @@ class Guard extends Guards::Guard {
324324 * Note: This predicate is inlined.
325325 */
326326 pragma [ inline]
327- predicate controlsNode ( ControlFlow:: Nodes:: ElementNode cfn , AbstractValue v ) {
327+ predicate controlsNode ( ControlFlow:: Nodes:: ElementNode cfn , GuardValue v ) {
328328 guardControls ( this , cfn .getBasicBlock ( ) , v )
329329 }
330330
331331 /**
332332 * Holds if basic block `bb` is guarded by this expression having value `v`.
333333 */
334- predicate controlsBasicBlock ( BasicBlock bb , AbstractValue v ) { guardControls ( this , bb , v ) }
334+ predicate controlsBasicBlock ( BasicBlock bb , GuardValue v ) { guardControls ( this , bb , v ) }
335335
336336 /**
337337 * Gets a valid value for this guard. For example, if this guard is a test, then
338338 * it can have Boolean values `true` and `false`.
339339 */
340- deprecated AbstractValue getAValue ( ) { isGuard ( this , result ) }
340+ deprecated GuardValue getAValue ( ) { isGuard ( this , result ) }
341341}
342342
343- class AbstractValue = GuardValue ;
343+ /** DEPRECATED: Use `GuardValue` instead. */
344+ deprecated class AbstractValue = GuardValue ;
344345
345- /** Provides different types of `AbstractValues`s. */
346- module AbstractValues {
346+ /**
347+ * DEPRECATED: Use `GuardValue` member predicates instead.
348+ *
349+ * Provides different types of `AbstractValues`s.
350+ */
351+ deprecated module AbstractValues {
347352 class BooleanValue extends AbstractValue {
348353 BooleanValue ( ) { exists ( this .asBooleanValue ( ) ) }
349354
@@ -369,8 +374,7 @@ module AbstractValues {
369374 }
370375}
371376
372- private import AbstractValues
373-
377+ // private import AbstractValues
374378/** Gets the value resulting from matching `null` against `pat`. */
375379private boolean patternMatchesNull ( PatternExpr pat ) {
376380 pat instanceof NullLiteral and result = true
@@ -431,22 +435,22 @@ class DereferenceableExpr extends Expr {
431435 /**
432436 * Gets an expression that tests via nullness whether this expression is `null`.
433437 *
434- * If the returned expression evaluates to `null` (`v.isNull ()`) or evaluates to
435- * non-`null` (`not v.isNull ()`), then this expression is guaranteed to be `null`
438+ * If the returned expression evaluates to `null` (`v.isNullValue ()`) or evaluates to
439+ * non-`null` (`not v.isNullValue ()`), then this expression is guaranteed to be `null`
436440 * if `isNull` is true, and non-`null` if `isNull` is false.
437441 *
438442 * For example, if `x` evaluates to `null` in `x ?? y` then `y` is evaluated, and
439443 * `x` is guaranteed to be `null`.
440444 */
441- private Expr getANullnessNullCheck ( NullValue v , boolean isNull ) {
445+ private Expr getANullnessNullCheck ( GuardValue v , boolean isNull ) {
442446 exists ( NullnessCompletion c | c .isValidFor ( this ) |
443447 result = this and
444448 if c .isNull ( )
445449 then (
446- v .isNull ( ) and
450+ v .isNullValue ( ) and
447451 isNull = true
448452 ) else (
449- v .isNonNull ( ) and
453+ v .isNonNullValue ( ) and
450454 isNull = false
451455 )
452456 )
@@ -513,8 +517,8 @@ class EnumerableCollectionExpr extends Expr {
513517 )
514518 }
515519
516- private Expr getABooleanEmptinessCheck ( BooleanValue v , boolean isEmpty ) {
517- exists ( boolean branch | branch = v .getValue ( ) |
520+ private Expr getABooleanEmptinessCheck ( GuardValue v , boolean isEmpty ) {
521+ exists ( boolean branch | branch = v .asBooleanValue ( ) |
518522 result =
519523 any ( ComparisonTest ct |
520524 exists ( boolean lowerBound |
@@ -578,7 +582,7 @@ class EnumerableCollectionExpr extends Expr {
578582 * For example, if the expression `x.Length != 0` evaluates to `true` then the
579583 * expression `x` is guaranteed to be non-empty.
580584 */
581- Expr getAnEmptinessCheck ( AbstractValue v , boolean isEmpty ) {
585+ Expr getAnEmptinessCheck ( GuardValue v , boolean isEmpty ) {
582586 result = this .getABooleanEmptinessCheck ( v , isEmpty )
583587 }
584588}
@@ -692,14 +696,14 @@ class GuardedExpr extends AccessOrCallExpr {
692696 * left-most qualifier, then so must the other (accessing the same SSA
693697 * variable).
694698 */
695- Guard getAGuard ( Expr sub , AbstractValue v ) { isGuardedByExpr ( this , result , sub , v ) }
699+ Guard getAGuard ( Expr sub , GuardValue v ) { isGuardedByExpr ( this , result , sub , v ) }
696700
697701 /**
698702 * Holds if this expression must have abstract value `v`. That is, this
699703 * expression is guarded by a structurally equal expression having abstract
700704 * value `v`.
701705 */
702- predicate mustHaveValue ( AbstractValue v ) {
706+ predicate mustHaveValue ( GuardValue v ) {
703707 exists ( Guard g | g = this .getAGuard ( g , v ) ) or ssaMustHaveValue ( this , v )
704708 }
705709
@@ -713,7 +717,7 @@ class GuardedExpr extends AccessOrCallExpr {
713717 * variable).
714718 */
715719 predicate isGuardedBy ( Expr cond , Expr sub , boolean b ) {
716- cond = this .getAGuard ( sub , any ( BooleanValue v | v .getValue ( ) = b ) )
720+ cond = this .getAGuard ( sub , any ( GuardValue v | v .asBooleanValue ( ) = b ) )
717721 }
718722}
719723
@@ -738,7 +742,7 @@ class GuardedExpr extends AccessOrCallExpr {
738742class GuardedControlFlowNode extends ControlFlow:: Nodes:: ElementNode {
739743 private Guard g ;
740744 private AccessOrCallExpr sub0 ;
741- private AbstractValue v0 ;
745+ private GuardValue v0 ;
742746
743747 GuardedControlFlowNode ( ) { g .controlsNode ( this , sub0 , v0 ) }
744748
@@ -753,7 +757,7 @@ class GuardedControlFlowNode extends ControlFlow::Nodes::ElementNode {
753757 * left-most qualifier, then so must the other (accessing the same SSA
754758 * variable).
755759 */
756- Guard getAGuard ( Expr sub , AbstractValue v ) {
760+ Guard getAGuard ( Expr sub , GuardValue v ) {
757761 result = g and
758762 sub = sub0 and
759763 v = v0
@@ -764,7 +768,7 @@ class GuardedControlFlowNode extends ControlFlow::Nodes::ElementNode {
764768 * control flow node is guarded by a structurally equal expression having
765769 * abstract value `v`.
766770 */
767- predicate mustHaveValue ( AbstractValue v ) { g = this .getAGuard ( g , v ) }
771+ predicate mustHaveValue ( GuardValue v ) { g = this .getAGuard ( g , v ) }
768772}
769773
770774/**
@@ -788,7 +792,7 @@ class GuardedControlFlowNode extends ControlFlow::Nodes::ElementNode {
788792class GuardedDataFlowNode extends DataFlow:: ExprNode {
789793 private Guard g ;
790794 private AccessOrCallExpr sub0 ;
791- private AbstractValue v0 ;
795+ private GuardValue v0 ;
792796
793797 GuardedDataFlowNode ( ) {
794798 exists ( ControlFlow:: Nodes:: ElementNode cfn | exists ( this .getExprAtNode ( cfn ) ) |
@@ -807,7 +811,7 @@ class GuardedDataFlowNode extends DataFlow::ExprNode {
807811 * left-most qualifier, then so must the other (accessing the same SSA
808812 * variable).
809813 */
810- Guard getAGuard ( Expr sub , AbstractValue v ) {
814+ Guard getAGuard ( Expr sub , GuardValue v ) {
811815 result = g and
812816 sub = sub0 and
813817 v = v0
@@ -818,17 +822,17 @@ class GuardedDataFlowNode extends DataFlow::ExprNode {
818822 * data flow node is guarded by a structurally equal expression having
819823 * abstract value `v`.
820824 */
821- predicate mustHaveValue ( AbstractValue v ) { g = this .getAGuard ( g , v ) }
825+ predicate mustHaveValue ( GuardValue v ) { g = this .getAGuard ( g , v ) }
822826}
823827
824828/** An expression guarded by a `null` check. */
825829class NullGuardedExpr extends GuardedExpr {
826- NullGuardedExpr ( ) { this .mustHaveValue ( any ( NullValue v | v .isNonNull ( ) ) ) }
830+ NullGuardedExpr ( ) { this .mustHaveValue ( any ( GuardValue v | v .isNonNullValue ( ) ) ) }
827831}
828832
829833/** A data flow node guarded by a `null` check. */
830834class NullGuardedDataFlowNode extends GuardedDataFlowNode {
831- NullGuardedDataFlowNode ( ) { this .mustHaveValue ( any ( NullValue v | v .isNonNull ( ) ) ) }
835+ NullGuardedDataFlowNode ( ) { this .mustHaveValue ( any ( GuardValue v | v .isNonNullValue ( ) ) ) }
832836}
833837
834838/** INTERNAL: Do not use. */
@@ -931,7 +935,7 @@ module Internal {
931935 bao .getAnOperand ( ) = o and
932936 // The other operand must be provably non-null in order
933937 // for `only if` to hold
934- o = any ( NullValue nv | nv . isNonNull ( ) ) . getAnExpr ( ) and
938+ nonNullValueImplied ( o ) and
935939 e != o
936940 )
937941 }
@@ -973,7 +977,7 @@ module Internal {
973977 nonEmptyValue ( def .getDefinition ( ) .getSource ( ) )
974978 }
975979
976- deprecated predicate isGuard ( Expr e , AbstractValue val ) {
980+ deprecated predicate isGuard ( Expr e , GuardValue val ) {
977981 (
978982 e .getType ( ) instanceof BoolType and
979983 not e instanceof BoolLiteral and
@@ -1207,7 +1211,7 @@ module Internal {
12071211 * Holds if basic block `bb` only is reached when guard `g` has abstract value `v`.
12081212 */
12091213 cached
1210- predicate guardControls ( Guard g , BasicBlock bb , AbstractValue v ) {
1214+ predicate guardControls ( Guard g , BasicBlock bb , GuardValue v ) {
12111215 g .( Guards:: Guard ) .valueControls ( bb , v )
12121216 }
12131217
@@ -1220,7 +1224,7 @@ module Internal {
12201224 pragma [ nomagic]
12211225 private predicate nodeIsGuardedBySameSubExpr0 (
12221226 ControlFlow:: Node guardedCfn , BasicBlock guardedBB , AccessOrCallExpr guarded , Guard g ,
1223- AccessOrCallExpr sub , AbstractValue v
1227+ AccessOrCallExpr sub , GuardValue v
12241228 ) {
12251229 Stages:: GuardsStage:: forceCachingInSameStage ( ) and
12261230 guardedCfn = guarded .getAControlFlowNode ( ) and
@@ -1233,7 +1237,7 @@ module Internal {
12331237 pragma [ nomagic]
12341238 private predicate nodeIsGuardedBySameSubExpr (
12351239 ControlFlow:: Node guardedCfn , BasicBlock guardedBB , AccessOrCallExpr guarded , Guard g ,
1236- AccessOrCallExpr sub , AbstractValue v
1240+ AccessOrCallExpr sub , GuardValue v
12371241 ) {
12381242 nodeIsGuardedBySameSubExpr0 ( guardedCfn , guardedBB , guarded , g , sub , v ) and
12391243 guardControlsSub ( g , guardedBB , sub )
@@ -1242,7 +1246,7 @@ module Internal {
12421246 pragma [ nomagic]
12431247 private predicate nodeIsGuardedBySameSubExprSsaDef0 (
12441248 ControlFlow:: Node cfn , BasicBlock guardedBB , AccessOrCallExpr guarded , Guard g ,
1245- ControlFlow:: Node subCfn , BasicBlock subCfnBB , AccessOrCallExpr sub , AbstractValue v ,
1249+ ControlFlow:: Node subCfn , BasicBlock subCfnBB , AccessOrCallExpr sub , GuardValue v ,
12461250 Ssa:: Definition def
12471251 ) {
12481252 nodeIsGuardedBySameSubExpr ( cfn , guardedBB , guarded , g , sub , v ) and
@@ -1253,7 +1257,7 @@ module Internal {
12531257 pragma [ nomagic]
12541258 private predicate nodeIsGuardedBySameSubExprSsaDef (
12551259 ControlFlow:: Node guardedCfn , AccessOrCallExpr guarded , Guard g , ControlFlow:: Node subCfn ,
1256- AccessOrCallExpr sub , AbstractValue v , Ssa:: Definition def
1260+ AccessOrCallExpr sub , GuardValue v , Ssa:: Definition def
12571261 ) {
12581262 exists ( BasicBlock guardedBB , BasicBlock subCfnBB |
12591263 nodeIsGuardedBySameSubExprSsaDef0 ( guardedCfn , guardedBB , guarded , g , subCfn , subCfnBB , sub ,
@@ -1264,17 +1268,15 @@ module Internal {
12641268
12651269 pragma [ noinline]
12661270 private predicate isGuardedByExpr0 (
1267- AccessOrCallExpr guarded , Guard g , AccessOrCallExpr sub , AbstractValue v
1271+ AccessOrCallExpr guarded , Guard g , AccessOrCallExpr sub , GuardValue v
12681272 ) {
12691273 forex ( ControlFlow:: Node cfn | cfn = guarded .getAControlFlowNode ( ) |
12701274 nodeIsGuardedBySameSubExpr ( cfn , _, guarded , g , sub , v )
12711275 )
12721276 }
12731277
12741278 cached
1275- predicate isGuardedByExpr (
1276- AccessOrCallExpr guarded , Guard g , AccessOrCallExpr sub , AbstractValue v
1277- ) {
1279+ predicate isGuardedByExpr ( AccessOrCallExpr guarded , Guard g , AccessOrCallExpr sub , GuardValue v ) {
12781280 isGuardedByExpr0 ( guarded , g , sub , v ) and
12791281 forall ( ControlFlow:: Node subCfn , Ssa:: Definition def |
12801282 nodeIsGuardedBySameSubExprSsaDef ( _, guarded , g , subCfn , sub , v , def )
@@ -1285,7 +1287,7 @@ module Internal {
12851287
12861288 cached
12871289 predicate isGuardedByNode (
1288- ControlFlow:: Nodes:: ElementNode guarded , Guard g , AccessOrCallExpr sub , AbstractValue v
1290+ ControlFlow:: Nodes:: ElementNode guarded , Guard g , AccessOrCallExpr sub , GuardValue v
12891291 ) {
12901292 nodeIsGuardedBySameSubExpr ( guarded , _, _, g , sub , v ) and
12911293 forall ( ControlFlow:: Node subCfn , Ssa:: Definition def |
0 commit comments