@@ -608,7 +608,7 @@ module LocalFlow {
608608 *
609609 * TODO: Remove once library code is extracted.
610610 */
611- private module VariantLib {
611+ private module VariantInLib {
612612 private import codeql.util.Option
613613
614614 private class CrateOrigin extends string {
@@ -619,8 +619,8 @@ private module VariantLib {
619619
620620 private CrateOriginOption langCoreCrate ( ) { result .asSome ( ) = "lang:core" }
621621
622- private newtype TVariantLib =
623- MkVariantLib ( CrateOriginOption crate , string path , string name ) {
622+ private newtype TVariantInLib =
623+ MkVariantInLib ( CrateOriginOption crate , string path , string name ) {
624624 crate = langCoreCrate ( ) and
625625 (
626626 path = "crate::option::Option" and
@@ -631,43 +631,43 @@ private module VariantLib {
631631 )
632632 }
633633
634- /** A canonical path pointing to an enum variant . */
635- class VariantLib extends MkVariantLib {
634+ /** An enum variant from library code, represented by its canonical path . */
635+ class VariantInLib extends MkVariantInLib {
636636 CrateOriginOption crate ;
637637 string path ;
638638 string name ;
639639
640- VariantLib ( ) { this = MkVariantLib ( crate , path , name ) }
640+ VariantInLib ( ) { this = MkVariantInLib ( crate , path , name ) }
641+
642+ int getAPosition ( ) {
643+ this = MkVariantInLib ( langCoreCrate ( ) , "crate::option::Option" , "Some" ) and
644+ result = 0
645+ or
646+ this = MkVariantInLib ( langCoreCrate ( ) , "crate::result::Result" , [ "Ok" , "Err" ] ) and
647+ result = 0
648+ }
641649
642650 string getExtendedCanonicalPath ( ) { result = path + "::" + name }
643651
644652 string toString ( ) { result = name }
645653 }
646654
647- predicate variantLibPos ( VariantLib:: VariantLib v , int pos ) {
648- v = MkVariantLib ( langCoreCrate ( ) , "crate::option::Option" , "Some" ) and
649- pos = 0
650- or
651- v = MkVariantLib ( langCoreCrate ( ) , "crate::result::Result" , [ "Ok" , "Err" ] ) and
652- pos = 0
653- }
654-
655655 /** A tuple variant from library code. */
656- class VariantLibTupleFieldContent extends VariantContent , TVariantLibTupleFieldContent {
657- private VariantLib :: VariantLib v ;
656+ class VariantInLibTupleFieldContent extends VariantContent , TVariantInLibTupleFieldContent {
657+ private VariantInLib :: VariantInLib v ;
658658 private int pos_ ;
659659
660- VariantLibTupleFieldContent ( ) { this = TVariantLibTupleFieldContent ( v , pos_ ) }
660+ VariantInLibTupleFieldContent ( ) { this = TVariantInLibTupleFieldContent ( v , pos_ ) }
661661
662- VariantLib :: VariantLib getVariantLib ( int pos ) { result = v and pos = pos_ }
662+ VariantInLib :: VariantInLib getVariantInLib ( int pos ) { result = v and pos = pos_ }
663663
664664 string getExtendedCanonicalPath ( ) { result = v .getExtendedCanonicalPath ( ) }
665665
666666 int getPosition ( ) { result = pos_ }
667667
668668 final override string toString ( ) {
669669 // only print indices when the arity is > 1
670- if exists ( TVariantLibTupleFieldContent ( v , 1 ) )
670+ if exists ( TVariantInLibTupleFieldContent ( v , 1 ) )
671671 then result = v .toString ( ) + "(" + pos_ + ")"
672672 else result = v .toString ( )
673673 }
@@ -687,39 +687,39 @@ private module VariantLib {
687687 }
688688
689689 /** Holds if path `p` resolves to variant `v`. */
690- private predicate pathResolveToVariantLib ( PathAstNode p , VariantLib v ) {
690+ private predicate pathResolveToVariantInLib ( PathAstNode p , VariantInLib v ) {
691691 exists ( CrateOriginOption crate , string path , string name |
692692 resolveExtendedCanonicalPath ( p , pragma [ only_bind_into ] ( crate ) , path + "::" + name ) and
693- v = MkVariantLib ( pragma [ only_bind_into ] ( crate ) , path , name )
693+ v = MkVariantInLib ( pragma [ only_bind_into ] ( crate ) , path , name )
694694 )
695695 }
696696
697697 /** Holds if `p` destructs an enum variant `v`. */
698698 pragma [ nomagic]
699- private predicate tupleVariantCanonicalDestruction ( TupleStructPat p , VariantLib v ) {
700- pathResolveToVariantLib ( p , v )
699+ private predicate tupleVariantCanonicalDestruction ( TupleStructPat p , VariantInLib v ) {
700+ pathResolveToVariantInLib ( p , v )
701701 }
702702
703703 bindingset [ pos]
704704 predicate tupleVariantCanonicalDestruction (
705- TupleStructPat pat , VariantLibTupleFieldContent c , int pos
705+ TupleStructPat pat , VariantInLibTupleFieldContent c , int pos
706706 ) {
707- tupleVariantCanonicalDestruction ( pat , c .getVariantLib ( pos ) )
707+ tupleVariantCanonicalDestruction ( pat , c .getVariantInLib ( pos ) )
708708 }
709709
710710 /** Holds if `ce` constructs an enum value of type `v`. */
711711 pragma [ nomagic]
712- private predicate tupleVariantCanonicalConstruction ( CallExpr ce , VariantLib v ) {
713- pathResolveToVariantLib ( ce .getFunction ( ) .( PathExpr ) , v )
712+ private predicate tupleVariantCanonicalConstruction ( CallExpr ce , VariantInLib v ) {
713+ pathResolveToVariantInLib ( ce .getFunction ( ) .( PathExpr ) , v )
714714 }
715715
716716 bindingset [ pos]
717- predicate tupleVariantCanonicalConstruction ( CallExpr ce , VariantLibTupleFieldContent c , int pos ) {
718- tupleVariantCanonicalConstruction ( ce , c .getVariantLib ( pos ) )
717+ predicate tupleVariantCanonicalConstruction ( CallExpr ce , VariantInLibTupleFieldContent c , int pos ) {
718+ tupleVariantCanonicalConstruction ( ce , c .getVariantInLib ( pos ) )
719719 }
720720}
721721
722- class VariantLibTupleFieldContent = VariantLib :: VariantLibTupleFieldContent ;
722+ class VariantInLibTupleFieldContent = VariantInLib :: VariantInLibTupleFieldContent ;
723723
724724/**
725725 * A path to a value contained in an object. For example a field name of a struct.
@@ -1087,29 +1087,22 @@ module RustDataFlow implements InputSig<Location> {
10871087 node2 .( Node:: FlowSummaryNode ) .getSummaryNode ( ) )
10881088 }
10891089
1090- /** Holds if path `p` resolves to struct `s`. */
1091- private predicate pathResolveToStruct ( PathAstNode p , Struct s ) {
1092- s = PathResolution:: resolvePath ( p .getPath ( ) )
1093- }
1094-
1095- /** Holds if path `p` resolves to variant `v`. */
1096- private predicate pathResolveToVariant ( PathAstNode p , Variant v ) {
1097- v = PathResolution:: resolvePath ( p .getPath ( ) )
1090+ /** Gets the item that `p` resolves to, if any. */
1091+ private PathResolution:: ItemNode resolvePath ( PathAstNode p ) {
1092+ result = PathResolution:: resolvePath ( p .getPath ( ) )
10981093 }
10991094
11001095 /** Holds if `p` destructs an enum variant `v`. */
11011096 pragma [ nomagic]
1102- private predicate tupleVariantDestruction ( TupleStructPat p , Variant v ) {
1103- pathResolveToVariant ( p , v )
1104- }
1097+ private predicate tupleVariantDestruction ( TupleStructPat p , Variant v ) { v = resolvePath ( p ) }
11051098
11061099 /** Holds if `p` destructs an enum variant `v`. */
11071100 pragma [ nomagic]
1108- private predicate recordVariantDestruction ( RecordPat p , Variant v ) { pathResolveToVariant ( p , v ) }
1101+ private predicate recordVariantDestruction ( RecordPat p , Variant v ) { v = resolvePath ( p ) }
11091102
11101103 /** Holds if `p` destructs a struct `s`. */
11111104 pragma [ nomagic]
1112- private predicate structDestruction ( RecordPat p , Struct s ) { pathResolveToStruct ( p , s ) }
1105+ private predicate structDestruction ( RecordPat p , Struct s ) { s = resolvePath ( p ) }
11131106
11141107 /**
11151108 * Holds if data can flow from `node1` to `node2` via a read of `c`. Thus,
@@ -1124,7 +1117,7 @@ module RustDataFlow implements InputSig<Location> {
11241117 |
11251118 tupleVariantDestruction ( pat .getPat ( ) , c .( VariantTupleFieldContent ) .getVariant ( pos ) )
11261119 or
1127- VariantLib :: tupleVariantCanonicalDestruction ( pat .getPat ( ) , c , pos )
1120+ VariantInLib :: tupleVariantCanonicalDestruction ( pat .getPat ( ) , c , pos )
11281121 )
11291122 or
11301123 exists ( TuplePatCfgNode pat , int pos |
@@ -1177,7 +1170,7 @@ module RustDataFlow implements InputSig<Location> {
11771170 exists ( TryExprCfgNode try |
11781171 node1 .asExpr ( ) = try .getExpr ( ) and
11791172 node2 .asExpr ( ) = try and
1180- c .( VariantLibTupleFieldContent ) . getVariantLib ( 0 ) .getExtendedCanonicalPath ( ) =
1173+ c .( VariantInLibTupleFieldContent ) . getVariantInLib ( 0 ) .getExtendedCanonicalPath ( ) =
11811174 [ "crate::option::Option::Some" , "crate::result::Result::Ok" ]
11821175 )
11831176 or
@@ -1198,18 +1191,16 @@ module RustDataFlow implements InputSig<Location> {
11981191 /** Holds if `ce` constructs an enum value of type `v`. */
11991192 pragma [ nomagic]
12001193 private predicate tupleVariantConstruction ( CallExpr ce , Variant v ) {
1201- pathResolveToVariant ( ce .getFunction ( ) .( PathExpr ) , v )
1194+ v = resolvePath ( ce .getFunction ( ) .( PathExpr ) )
12021195 }
12031196
12041197 /** Holds if `re` constructs an enum value of type `v`. */
12051198 pragma [ nomagic]
1206- private predicate recordVariantConstruction ( RecordExpr re , Variant v ) {
1207- pathResolveToVariant ( re , v )
1208- }
1199+ private predicate recordVariantConstruction ( RecordExpr re , Variant v ) { v = resolvePath ( re ) }
12091200
12101201 /** Holds if `re` constructs a struct value of type `s`. */
12111202 pragma [ nomagic]
1212- private predicate structConstruction ( RecordExpr re , Struct s ) { pathResolveToStruct ( re , s ) }
1203+ private predicate structConstruction ( RecordExpr re , Struct s ) { s = resolvePath ( re ) }
12131204
12141205 private predicate tupleAssignment ( Node node1 , Node node2 , TuplePositionContent c ) {
12151206 exists ( AssignmentExprCfgNode assignment , FieldExprCfgNode access |
@@ -1228,7 +1219,7 @@ module RustDataFlow implements InputSig<Location> {
12281219 |
12291220 tupleVariantConstruction ( call .getCallExpr ( ) , c .( VariantTupleFieldContent ) .getVariant ( pos ) )
12301221 or
1231- VariantLib :: tupleVariantCanonicalConstruction ( call .getCallExpr ( ) , c , pos )
1222+ VariantInLib :: tupleVariantCanonicalConstruction ( call .getCallExpr ( ) , c , pos )
12321223 )
12331224 or
12341225 exists ( RecordExprCfgNode re , string field |
@@ -1600,9 +1591,7 @@ private module Cached {
16001591 newtype TContent =
16011592 TVariantTupleFieldContent ( Variant v , int pos ) { exists ( getVariantTupleField ( v , pos ) ) } or
16021593 // TODO: Remove once library types are extracted
1603- TVariantLibTupleFieldContent ( VariantLib:: VariantLib v , int pos ) {
1604- VariantLib:: variantLibPos ( v , pos )
1605- } or
1594+ TVariantInLibTupleFieldContent ( VariantInLib:: VariantInLib v , int pos ) { pos = v .getAPosition ( ) } or
16061595 TVariantRecordFieldContent ( Variant v , string field ) { exists ( getVariantRecordField ( v , field ) ) } or
16071596 TElementContent ( ) or
16081597 TTuplePositionContent ( int pos ) {
0 commit comments