@@ -1283,8 +1283,9 @@ private Type testinferCallExprBaseType(
1283
1283
CallExprBaseMatchingInput:: Access a , string state , CallExprBaseMatchingInput:: AccessPosition apos ,
1284
1284
TypePath path
1285
1285
) {
1286
- a .getLocation ( ) .getStartLine ( ) = 73 and
1287
- a .fromSource ( ) and
1286
+ // a.getLocation().getStartLine() = 73 and
1287
+ // a.fromSource() and
1288
+ a = Debug:: getRelevantLocatable ( ) and
1288
1289
result = CallExprBaseMatching:: inferAccessType ( a , state , apos , path )
1289
1290
}
1290
1291
@@ -1302,6 +1303,7 @@ private Type inferCallExprBaseType0(
1302
1303
CallExprBaseMatchingInput:: Access a , CallExprBaseMatchingInput:: AccessPosition apos , AstNode n ,
1303
1304
string state , TypePath path
1304
1305
) {
1306
+ // a = Debug::getRelevantLocatable() and // todo: remove
1305
1307
exists ( TypePath path0 |
1306
1308
n = a .getNodeAt ( apos ) and
1307
1309
result = CallExprBaseMatching:: inferAccessType ( a , state , apos , path0 )
@@ -1320,8 +1322,7 @@ private Type inferCallExprBaseType0(
1320
1322
}
1321
1323
1322
1324
private Type testinferCallExprBaseType ( AstNode n , TypePath path ) {
1323
- n .getLocation ( ) .getStartLine ( ) = 1286 and
1324
- n .fromSource ( ) and
1325
+ n = Debug:: getRelevantLocatable ( ) and
1325
1326
result = inferCallExprBaseType ( n , path )
1326
1327
}
1327
1328
@@ -1343,7 +1344,7 @@ private Type inferCallExprBaseType(AstNode n, TypePath path) {
1343
1344
(
1344
1345
not apos .getArgumentPosition ( ) .isSelf ( )
1345
1346
or
1346
- state = [ "" , ";" , ".ref;ref" ]
1347
+ state = [ "" , ";" ]
1347
1348
) and
1348
1349
path = path0
1349
1350
or
@@ -2068,11 +2069,16 @@ final class MethodCall extends Call {
2068
2069
2069
2070
pragma [ nomagic]
2070
2071
private predicate isMethodCall0 ( Type rootType , string name , int arity , string derefChain ) {
2071
- rootType = this .getACandidateReceiverTypeAt ( TypePath:: nil ( ) , derefChain ) and //, mcd.getTypeAt(TypePath::singleton(TRefTypeParameter()))] and
2072
+ rootType = this .getACandidateReceiverTypeRefsAt ( TypePath:: nil ( ) , derefChain ) and //, mcd.getTypeAt(TypePath::singleton(TRefTypeParameter()))] and
2072
2073
name = this .getMethodName ( ) and
2073
2074
arity = this .getNumberOfArguments ( )
2074
2075
}
2075
2076
2077
+ private predicate testisMethodCall0 ( Type rootType , string name , int arity , string derefChain ) {
2078
+ this .isMethodCall0 ( rootType , name , arity , derefChain ) and
2079
+ this = Debug:: getRelevantLocatable ( )
2080
+ }
2081
+
2076
2082
/**
2077
2083
* Gets a [candidate receiver type][1] of this method call.
2078
2084
*
@@ -2119,12 +2125,27 @@ final class MethodCall extends Call {
2119
2125
this .fromSource ( )
2120
2126
}
2121
2127
2128
+ pragma [ nomagic]
2129
+ private Type foogetACandidateReceiverTypeAtNoMatch (
2130
+ TypePath path , string derefChain , Type rootType , string name , int arity , Impl impl
2131
+ ) {
2132
+ this = Debug:: getRelevantLocatable ( ) and
2133
+ this .receiverImplicitlyBorrowed ( ) and
2134
+ result = this .getACandidateReceiverTypeAt ( path , derefChain ) and
2135
+ this .isMethodCall0 ( rootType , name , arity , derefChain + ";" ) and
2136
+ not exists ( resolveNonImplMethodCallTarget ( rootType , name , arity ) ) and
2137
+ not exists ( this .getTrait ( ) ) and
2138
+ methodCandidate ( rootType , name , arity , impl ) and
2139
+ IsInstantiationOf< MethodCallDerefChainRef , IsInstantiationOfInput > :: isNotInstantiationOf ( MkMethodCallDerefChainRef ( this ,
2140
+ derefChain + ";" ) , impl , _)
2141
+ }
2142
+
2122
2143
pragma [ nomagic]
2123
2144
private Type getACandidateReceiverTypeAtNoMatch ( TypePath path , string derefChain ) {
2124
2145
this .receiverImplicitlyBorrowed ( ) and
2125
2146
result = this .getACandidateReceiverTypeAt ( path , derefChain ) and
2126
2147
exists ( Type rootType , string name , int arity |
2127
- this .isMethodCall0 ( rootType , name , arity , derefChain )
2148
+ this .isMethodCall0 ( rootType , name , arity , derefChain + ";" )
2128
2149
|
2129
2150
forall ( Impl impl |
2130
2151
methodCandidateTrait ( rootType , this .getTrait ( ) , name , arity , impl )
@@ -2134,15 +2155,15 @@ final class MethodCall extends Call {
2134
2155
|
2135
2156
IsInstantiationOf< MethodCallDerefChainRef , IsInstantiationOfInput > :: isNotInstantiationOf ( MkMethodCallDerefChainRef ( this ,
2136
2157
derefChain + ";" ) , impl , _)
2137
- )
2158
+ ) and
2159
+ not exists ( resolveNonImplMethodCallTarget ( rootType , name , arity ) )
2138
2160
)
2139
2161
}
2140
2162
2141
2163
pragma [ nomagic]
2142
- private Type testgetACandidateReceiverTypeAtNoMatch ( TypePath path , string derefChain ) {
2143
- result = this .getACandidateReceiverTypeAtNoMatch ( path , derefChain ) and
2144
- this .getLocation ( ) .getStartLine ( ) = 1286 and
2145
- this .fromSource ( )
2164
+ private Type testgetACandidateReceiverTypeAtRef ( TypePath path , string derefChain ) {
2165
+ result = this .getACandidateReceiverTypeAtRef ( path , derefChain ) and
2166
+ this = Debug:: getRelevantLocatable ( )
2146
2167
}
2147
2168
2148
2169
pragma [ nomagic]
@@ -2173,17 +2194,25 @@ final class MethodCall extends Call {
2173
2194
}
2174
2195
2175
2196
pragma [ nomagic]
2176
- private Type testgetACandidateReceiverTypeAtRef ( TypePath path , string derefChain ) {
2177
- result = this .getACandidateReceiverTypeAtRef ( path , derefChain ) and
2178
- this .getLocation ( ) .getStartLine ( ) = 1286 and
2179
- this .fromSource ( )
2197
+ private Type testgetACandidateReceiverTypeAtRefNoMatch ( TypePath path , string derefChain ) {
2198
+ result = this .getACandidateReceiverTypeAtRefNoMatch ( path , derefChain ) and
2199
+ this = Debug:: getRelevantLocatable ( )
2200
+ }
2201
+
2202
+ pragma [ nomagic]
2203
+ private Type testgetACandidateReceiverTypeAtRefNoMatch2 (
2204
+ TypePath path , string derefChain , Type rootType , string name , int arity
2205
+ ) {
2206
+ result = this .getACandidateReceiverTypeAtNoMatch ( path , derefChain ) and
2207
+ this .isMethodCall0 ( rootType , name , arity , derefChain ) and
2208
+ this = Debug:: getRelevantLocatable ( )
2180
2209
}
2181
2210
2182
2211
pragma [ nomagic]
2183
2212
private Type getACandidateReceiverTypeAtRefNoMatch ( TypePath path , string derefChain ) {
2184
2213
result = this .getACandidateReceiverTypeAtNoMatch ( path , derefChain ) and
2185
2214
exists ( Type rootType , string name , int arity |
2186
- this .isMethodCall0 ( rootType , name , arity , derefChain )
2215
+ this .isMethodCall0 ( rootType , name , arity , derefChain + ";ref" )
2187
2216
|
2188
2217
forall ( Impl impl |
2189
2218
methodCandidateTrait ( rootType , this .getTrait ( ) , name , arity , impl )
@@ -2193,7 +2222,8 @@ final class MethodCall extends Call {
2193
2222
|
2194
2223
IsInstantiationOf< MethodCallDerefChainRef , IsInstantiationOfInput > :: isNotInstantiationOf ( MkMethodCallDerefChainRef ( this ,
2195
2224
derefChain + ";ref" ) , impl , _)
2196
- )
2225
+ ) and
2226
+ not exists ( resolveNonImplMethodCallTarget ( rootType , name , arity ) )
2197
2227
)
2198
2228
}
2199
2229
@@ -2218,19 +2248,22 @@ final class MethodCall extends Call {
2218
2248
t0 = this .getACandidateReceiverTypeAtRef ( path0 , derefChain ) and
2219
2249
derefChainRef = derefChain + ";ref"
2220
2250
|
2221
- path .isEmpty ( ) and
2222
- result = TRefType ( )
2223
- or
2224
- path = TypePath:: cons ( TRefTypeParameter ( ) , path0 ) and
2251
+ // path.isEmpty() and
2252
+ // result = TRefType()
2253
+ // or
2254
+ // path = TypePath::cons(TRefTypeParameter(), path0) and
2255
+ // result = t0
2256
+ path = path0 and
2225
2257
result = t0
2226
2258
)
2227
2259
}
2228
2260
2229
2261
pragma [ nomagic]
2230
2262
private Type testgetACandidateReceiverTypeRefsAt ( TypePath path , string derefChain ) {
2231
2263
result = this .getACandidateReceiverTypeRefsAt ( path , derefChain ) and
2232
- this .getLocation ( ) .getStartLine ( ) = 1286 and
2233
- this .fromSource ( )
2264
+ this = Debug:: getRelevantLocatable ( )
2265
+ // this.getLocation().getStartLine() = 1286 and
2266
+ // this.fromSource()
2234
2267
}
2235
2268
// /** An alias for `getCandidateReceiverTypeAt`, needed to implement `HasTypeTreeSig`. */
2236
2269
// Type getTypeAt(TypePath path) { result = this.getACandidateReceiverTypeRefsAt(path) }
@@ -2295,6 +2328,7 @@ private module IsInstantiationOfInput implements IsInstantiationOfInputSig<Metho
2295
2328
predicate potentialInstantiationOf (
2296
2329
MethodCallDerefChainRef mc , TypeAbstraction impl , TypeMention constraint
2297
2330
) {
2331
+ // mc.getMethodCall() = Debug::getRelevantLocatable() and // todo
2298
2332
exists ( Type rootType , string name , int arity , MethodCall mc0 |
2299
2333
isMethodCall ( mc , mc0 , rootType , name , arity ) and
2300
2334
constraint = impl .( ImplTypeAbstraction ) .getSelfTy ( )
@@ -2521,24 +2555,37 @@ private Function getDynTraitMethod(DynTraitType traitObject, string name, int ar
2521
2555
result = getMethodSuccessor ( traitObject .getTrait ( ) , name , arity )
2522
2556
}
2523
2557
2558
+ bindingset [ t, name, arity]
2559
+ pragma [ inline_late]
2560
+ private Function resolveNonImplMethodCallTarget ( Type t , string name , int arity ) {
2561
+ // The type of the receiver is a type parameter and the method comes from a
2562
+ // trait bound on the type parameter.
2563
+ result = getTypeParameterMethod ( t , name , arity )
2564
+ or
2565
+ // The type of the receiver is an `impl Trait` type.
2566
+ result = getImplTraitMethod ( t , name , arity )
2567
+ or
2568
+ // The type of the receiver is a trait object `dyn Trait` type.
2569
+ result = getDynTraitMethod ( t , name , arity )
2570
+ }
2571
+
2524
2572
pragma [ nomagic]
2525
2573
private Function resolveMethodCallTarget ( MethodCallDerefChainRef mcd ) {
2526
2574
// The method comes from an `impl` block targeting the type of the receiver.
2527
2575
result = getMethodFromImpl ( mcd )
2528
2576
or
2529
- exists ( Type rootType , string name , int arity | isMethodCall ( mcd , _, rootType , name , arity ) |
2530
- // The type of the receiver is a type parameter and the method comes from a
2531
- // trait bound on the type parameter.
2532
- result = getTypeParameterMethod ( rootType , name , arity )
2533
- or
2534
- // The type of the receiver is an `impl Trait` type.
2535
- result = getImplTraitMethod ( rootType , name , arity )
2536
- or
2537
- // The type of the receiver is a trait object `dyn Trait` type.
2538
- result = getDynTraitMethod ( rootType , name , arity )
2577
+ exists ( Type rootType , string name , int arity |
2578
+ isMethodCall ( mcd , _, rootType , name , arity ) and
2579
+ result = resolveNonImplMethodCallTarget ( rootType , name , arity )
2539
2580
)
2540
2581
}
2541
2582
2583
+ private Function testresolveMethodCallTarget ( MethodCallDerefChainRef mcd ) {
2584
+ // result = resolveMethodCallTarget(mcd) and
2585
+ result = getMethodFromImpl ( mcd ) and
2586
+ mcd .getMethodCall ( ) = Debug:: getRelevantLocatable ( )
2587
+ }
2588
+
2542
2589
pragma [ nomagic]
2543
2590
private predicate assocFuncResolutionDependsOnArgument ( Function f , Impl impl , int pos ) {
2544
2591
functionResolutionDependsOnArgument ( impl , _, f , pos , _, _) and
@@ -2853,11 +2900,13 @@ Type inferType(AstNode n) { result = inferType(n, TypePath::nil()) }
2853
2900
2854
2901
/** Provides predicates for debugging the type inference implementation. */
2855
2902
private module Debug {
2856
- private Locatable getRelevantLocatable ( ) {
2903
+ Locatable getRelevantLocatable ( ) {
2857
2904
exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
2858
2905
result .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
2859
- filepath .matches ( "%/dereference.rs" ) and
2860
- startline = 171
2906
+ filepath .matches ( "%/crates/wdk-macros/src/lib.rs" ) and
2907
+ endline = [ 255 .. 256 ]
2908
+ // filepath.matches("%/main.rs") and
2909
+ // startline = 708
2861
2910
)
2862
2911
}
2863
2912
0 commit comments