@@ -210,6 +210,19 @@ private TypeMention getTypeAnnotation(AstNode n) {
210210 )
211211}
212212
213+ private predicate hasKnownType ( AstNode n ) {
214+ none ( )
215+ // exists(TypeMention tm |
216+ // tm = getTypeAnnotation(n) and
217+ // not tm = any(InferTypeRepr itr).getParentNode*()
218+ // )
219+ // or
220+ // n instanceof SelfParam
221+ // or
222+ // n.getLocation().getStartLine() in [1495 .. 1499] and
223+ // n.getFile().getBaseName() = "ordered_float.rs"
224+ }
225+
213226/** Gets the type of `n`, which has an explicit type annotation. */
214227pragma [ nomagic]
215228private Type inferAnnotatedType ( AstNode n , TypePath path ) {
@@ -302,7 +315,8 @@ pragma[nomagic]
302315private Type inferTypeEquality ( AstNode n , TypePath path ) {
303316 exists ( TypePath prefix1 , AstNode n2 , TypePath prefix2 , TypePath suffix |
304317 result = inferType ( n2 , prefix2 .appendInverse ( suffix ) ) and
305- path = prefix1 .append ( suffix )
318+ path = prefix1 .append ( suffix ) and
319+ not hasKnownType ( n )
306320 |
307321 typeEquality ( n , prefix1 , n2 , prefix2 )
308322 or
@@ -482,7 +496,8 @@ pragma[nomagic]
482496private Type inferStructExprType ( AstNode n , TypePath path ) {
483497 exists ( StructExprMatchingInput:: Access a , StructExprMatchingInput:: AccessPosition apos |
484498 n = a .getNodeAt ( apos ) and
485- result = StructExprMatching:: inferAccessType ( a , apos , path )
499+ result = StructExprMatching:: inferAccessType ( a , apos , path ) and
500+ not hasKnownType ( n )
486501 )
487502}
488503
@@ -526,12 +541,25 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
526541 }
527542 }
528543
544+ private Locatable getRelevantLocatable ( ) {
545+ exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
546+ result .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
547+ filepath .matches ( "%/common/hashtable/src/hashtable.rs" ) and
548+ startline = [ 128 , 156 ]
549+ )
550+ }
551+
529552 abstract class Declaration extends AstNode {
530553 abstract TypeParameter getTypeParameter ( TypeParameterPosition ppos ) ;
531554
532555 pragma [ nomagic]
533556 abstract Type getParameterType ( DeclarationPosition dpos , TypePath path ) ;
534557
558+ private Type dbggetDeclaredType ( DeclarationPosition dpos , TypePath path ) {
559+ this = getRelevantLocatable ( ) and
560+ result = this .getDeclaredType ( dpos , path )
561+ }
562+
535563 abstract Type getReturnType ( TypePath path ) ;
536564
537565 Type getDeclaredType ( DeclarationPosition dpos , TypePath path ) {
@@ -749,6 +777,13 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
749777 or
750778 result = CallExprImpl:: getResolvedFunction ( this )
751779 }
780+
781+ private Declaration dbggetTarget ( ) {
782+ this = getRelevantLocatable ( ) and
783+ result = resolveMethodCallTarget ( this ) // mutual recursion; resolving method calls requires resolving types and vice versa
784+ // or
785+ // result = CallExprImpl::getResolvedFunction(this)
786+ }
752787 }
753788
754789 predicate accessDeclarationPositionMatch ( AccessPosition apos , DeclarationPosition dpos ) {
@@ -826,7 +861,8 @@ private Type inferCallExprBaseType(AstNode n, TypePath path) {
826861 TypePath path0
827862 |
828863 n = a .getNodeAt ( apos ) and
829- result = CallExprBaseMatching:: inferAccessType ( a , apos , path0 )
864+ result = CallExprBaseMatching:: inferAccessType ( a , apos , path0 ) and
865+ not hasKnownType ( n )
830866 |
831867 if
832868 apos .isBorrowed ( true )
@@ -987,7 +1023,8 @@ private Type inferFieldExprType(AstNode n, TypePath path) {
9871023 FieldExprMatchingInput:: Access a , FieldExprMatchingInput:: AccessPosition apos , TypePath path0
9881024 |
9891025 n = a .getNodeAt ( apos ) and
990- result = FieldExprMatching:: inferAccessType ( a , apos , path0 )
1026+ result = FieldExprMatching:: inferAccessType ( a , apos , path0 ) and
1027+ not hasKnownType ( n )
9911028 |
9921029 if apos .isSelf ( )
9931030 then
@@ -1592,8 +1629,8 @@ private module Debug {
15921629 private Locatable getRelevantLocatable ( ) {
15931630 exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
15941631 result .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
1595- filepath .matches ( "%/sqlx .rs" ) and
1596- startline = [ 56 .. 60 ]
1632+ filepath .matches ( "%/expression/src/utils/arithmetics_type .rs" ) and
1633+ startline = 1049
15971634 )
15981635 }
15991636
@@ -1607,19 +1644,52 @@ private module Debug {
16071644 result = resolveMethodCallTarget ( mce )
16081645 }
16091646
1647+ predicate debugInferImplicitSelfType ( SelfParam self , TypePath path , Type t ) {
1648+ self = getRelevantLocatable ( ) and
1649+ t = inferImplicitSelfType ( self , path )
1650+ }
1651+
1652+ predicate debugInferCallExprBaseType ( AstNode n , TypePath path , Type t ) {
1653+ n = getRelevantLocatable ( ) and
1654+ t = inferCallExprBaseType ( n , path )
1655+ }
1656+
16101657 predicate debugTypeMention ( TypeMention tm , TypePath path , Type type ) {
16111658 tm = getRelevantLocatable ( ) and
16121659 tm .resolveTypeAt ( path ) = type
16131660 }
16141661
16151662 pragma [ nomagic]
1616- private int countTypes ( AstNode n , TypePath path , Type t ) {
1663+ private int countTypesAtPath ( AstNode n , TypePath path , Type t ) {
16171664 t = inferType ( n , path ) and
16181665 result = strictcount ( Type t0 | t0 = inferType ( n , path ) )
16191666 }
16201667
16211668 predicate maxTypes ( AstNode n , TypePath path , Type t , int c ) {
1622- c = countTypes ( n , path , t ) and
1623- c = max ( countTypes ( _, _, _) )
1669+ c = countTypesAtPath ( n , path , t ) and
1670+ c = max ( countTypesAtPath ( _, _, _) )
1671+ }
1672+
1673+ pragma [ nomagic]
1674+ private predicate typePathLength ( AstNode n , TypePath path , Type t , int len ) {
1675+ t = inferType ( n , path ) and
1676+ len = path .length ( ) and
1677+ not n .getFile ( ) .getBaseName ( ) = "ordered_float.rs"
1678+ }
1679+
1680+ predicate maxTypePath ( AstNode n , TypePath path , Type t , int len ) {
1681+ typePathLength ( n , path , t , len ) and
1682+ len = max ( int i | typePathLength ( _, _, _, i ) )
1683+ }
1684+
1685+ pragma [ nomagic]
1686+ private int countTypePaths ( AstNode n , TypePath path , Type t ) {
1687+ t = inferType ( n , path ) and
1688+ result = strictcount ( TypePath path0 , Type t0 | t0 = inferType ( n , path0 ) )
1689+ }
1690+
1691+ predicate maxTypePaths ( AstNode n , TypePath path , Type t , int c ) {
1692+ c = countTypePaths ( n , path , t ) and
1693+ c = max ( countTypePaths ( _, _, _) )
16241694 }
16251695}
0 commit comments