@@ -19,16 +19,6 @@ private module Input1 implements InputSig1<Location> {
19
19
20
20
class TypeParameter = T:: TypeParameter ;
21
21
22
- /**
23
- * A type abstraction. I.e., a place in the program where type variables are
24
- * introduced.
25
- *
26
- * Example:
27
- * ```rust
28
- * impl<A, B> Foo<A, B> { }
29
- * // ^^^^^^ a type abstraction
30
- * ```
31
- */
32
22
class TypeAbstraction = T:: TypeAbstraction ;
33
23
34
24
private newtype TTypeArgumentPosition =
@@ -156,7 +146,7 @@ private module Input2 implements InputSig2 {
156
146
exists ( TypeParam param |
157
147
abs = param .getTypeBoundList ( ) .getABound ( ) and
158
148
condition = param and
159
- constraint = param . getTypeBoundList ( ) . getABound ( ) .getTypeRepr ( )
149
+ constraint = abs . ( TypeBound ) .getTypeRepr ( )
160
150
)
161
151
or
162
152
// the implicit `Self` type parameter satisfies the trait
@@ -968,22 +958,6 @@ private module Cached {
968
958
)
969
959
}
970
960
971
- pragma [ nomagic]
972
- private Type receiverRootType ( Expr e ) {
973
- any ( MethodCallExpr mce ) .getReceiver ( ) = e and
974
- result = inferType ( e )
975
- }
976
-
977
- pragma [ nomagic]
978
- private Type inferReceiverType ( Expr e , TypePath path ) {
979
- exists ( Type root | root = receiverRootType ( e ) |
980
- // for reference types, lookup members in the type being referenced
981
- if root = TRefType ( )
982
- then result = inferType ( e , TypePath:: cons ( TRefTypeParameter ( ) , path ) )
983
- else result = inferType ( e , path )
984
- )
985
- }
986
-
987
961
private class ReceiverExpr extends Expr {
988
962
MethodCallExpr mce ;
989
963
@@ -993,13 +967,22 @@ private module Cached {
993
967
994
968
int getNumberOfArgs ( ) { result = mce .getArgList ( ) .getNumberOfArgs ( ) }
995
969
996
- Type resolveTypeAt ( TypePath path ) { result = inferReceiverType ( this , path ) }
970
+ pragma [ nomagic]
971
+ Type getTypeAt ( TypePath path ) {
972
+ exists ( TypePath path0 | result = inferType ( this , path0 ) |
973
+ path0 = TypePath:: cons ( TRefTypeParameter ( ) , path )
974
+ or
975
+ not path0 .isCons ( TRefTypeParameter ( ) , _) and
976
+ not ( path0 .isEmpty ( ) and result = TRefType ( ) ) and
977
+ path = path0
978
+ )
979
+ }
997
980
}
998
981
999
982
/** Holds if a method for `type` with the name `name` and the arity `arity` exists in `impl`. */
1000
983
pragma [ nomagic]
1001
984
private predicate methodCandidate ( Type type , string name , int arity , Impl impl ) {
1002
- type = impl .( ImplTypeAbstraction ) . getSelfTy ( ) .( TypeReprMention ) .resolveType ( ) and
985
+ type = impl .getSelfTy ( ) .( TypeReprMention ) .resolveType ( ) and
1003
986
exists ( Function f |
1004
987
f = impl .( ImplItemNode ) .getASuccessor ( name ) and
1005
988
f .getParamList ( ) .hasSelfParam ( ) and
@@ -1009,17 +992,16 @@ private module Cached {
1009
992
1010
993
private module IsInstantiationOfInput implements IsInstantiationOfInputSig< ReceiverExpr > {
1011
994
pragma [ nomagic]
1012
- predicate potentialInstantiationOf ( ReceiverExpr receiver , TypeAbstraction impl , TypeMention sub ) {
1013
- methodCandidate ( receiver .resolveTypeAt ( TypePath:: nil ( ) ) , receiver .getField ( ) ,
995
+ predicate potentialInstantiationOf (
996
+ ReceiverExpr receiver , TypeAbstraction impl , TypeMention constraint
997
+ ) {
998
+ methodCandidate ( receiver .getTypeAt ( TypePath:: nil ( ) ) , receiver .getField ( ) ,
1014
999
receiver .getNumberOfArgs ( ) , impl ) and
1015
- sub = impl .( ImplTypeAbstraction ) .getSelfTy ( )
1000
+ constraint = impl .( ImplTypeAbstraction ) .getSelfTy ( )
1016
1001
}
1017
1002
1018
- predicate relevantTypeMention ( TypeMention sub ) {
1019
- exists ( TypeAbstraction impl |
1020
- methodCandidate ( _, _, _, impl ) and
1021
- sub = impl .( ImplTypeAbstraction ) .getSelfTy ( )
1022
- )
1003
+ predicate relevantTypeMention ( TypeMention constraint ) {
1004
+ exists ( Impl impl | methodCandidate ( _, _, _, impl ) and constraint = impl .getSelfTy ( ) )
1023
1005
}
1024
1006
}
1025
1007
@@ -1044,8 +1026,7 @@ private module Cached {
1044
1026
*/
1045
1027
private Function getMethodFromImpl ( ReceiverExpr receiver ) {
1046
1028
exists ( Impl impl |
1047
- IsInstantiationOf< ReceiverExpr , IsInstantiationOfInput > :: isInstantiationOf ( receiver , impl ,
1048
- impl .( ImplTypeAbstraction ) .getSelfTy ( ) .( TypeReprMention ) ) and
1029
+ IsInstantiationOf< ReceiverExpr , IsInstantiationOfInput > :: isInstantiationOf ( receiver , impl , _) and
1049
1030
result = getMethodSuccessor ( impl , receiver .getField ( ) )
1050
1031
)
1051
1032
}
@@ -1059,19 +1040,17 @@ private module Cached {
1059
1040
or
1060
1041
// The type of `receiver` is a type parameter and the method comes from a
1061
1042
// trait bound on the type parameter.
1062
- result = getTypeParameterMethod ( receiver .resolveTypeAt ( TypePath:: nil ( ) ) , receiver .getField ( ) )
1043
+ result = getTypeParameterMethod ( receiver .getTypeAt ( TypePath:: nil ( ) ) , receiver .getField ( ) )
1063
1044
)
1064
1045
}
1065
1046
1066
1047
pragma [ inline]
1067
1048
private Type inferRootTypeDeref ( AstNode n ) {
1068
- exists ( Type t |
1069
- t = inferType ( n ) and
1070
- // for reference types, lookup members in the type being referenced
1071
- if t = TRefType ( )
1072
- then result = inferType ( n , TypePath:: singleton ( TRefTypeParameter ( ) ) )
1073
- else result = t
1074
- )
1049
+ result = inferType ( n ) and
1050
+ result != TRefType ( )
1051
+ or
1052
+ // for reference types, lookup members in the type being referenced
1053
+ result = inferType ( n , TypePath:: singleton ( TRefTypeParameter ( ) ) )
1075
1054
}
1076
1055
1077
1056
pragma [ nomagic]
0 commit comments