@@ -1283,8 +1283,9 @@ private Type testinferCallExprBaseType(
12831283 CallExprBaseMatchingInput:: Access a , string state , CallExprBaseMatchingInput:: AccessPosition apos ,
12841284 TypePath path
12851285) {
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
12881289 result = CallExprBaseMatching:: inferAccessType ( a , state , apos , path )
12891290}
12901291
@@ -1302,6 +1303,7 @@ private Type inferCallExprBaseType0(
13021303 CallExprBaseMatchingInput:: Access a , CallExprBaseMatchingInput:: AccessPosition apos , AstNode n ,
13031304 string state , TypePath path
13041305) {
1306+ // a = Debug::getRelevantLocatable() and // todo: remove
13051307 exists ( TypePath path0 |
13061308 n = a .getNodeAt ( apos ) and
13071309 result = CallExprBaseMatching:: inferAccessType ( a , state , apos , path0 )
@@ -1320,8 +1322,7 @@ private Type inferCallExprBaseType0(
13201322}
13211323
13221324private Type testinferCallExprBaseType ( AstNode n , TypePath path ) {
1323- n .getLocation ( ) .getStartLine ( ) = 1286 and
1324- n .fromSource ( ) and
1325+ n = Debug:: getRelevantLocatable ( ) and
13251326 result = inferCallExprBaseType ( n , path )
13261327}
13271328
@@ -1343,7 +1344,7 @@ private Type inferCallExprBaseType(AstNode n, TypePath path) {
13431344 (
13441345 not apos .getArgumentPosition ( ) .isSelf ( )
13451346 or
1346- state = [ "" , ";" , ".ref;ref" ]
1347+ state = [ "" , ";" ]
13471348 ) and
13481349 path = path0
13491350 or
@@ -2068,11 +2069,16 @@ final class MethodCall extends Call {
20682069
20692070 pragma [ nomagic]
20702071 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
20722073 name = this .getMethodName ( ) and
20732074 arity = this .getNumberOfArguments ( )
20742075 }
20752076
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+
20762082 /**
20772083 * Gets a [candidate receiver type][1] of this method call.
20782084 *
@@ -2119,12 +2125,27 @@ final class MethodCall extends Call {
21192125 this .fromSource ( )
21202126 }
21212127
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+
21222143 pragma [ nomagic]
21232144 private Type getACandidateReceiverTypeAtNoMatch ( TypePath path , string derefChain ) {
21242145 this .receiverImplicitlyBorrowed ( ) and
21252146 result = this .getACandidateReceiverTypeAt ( path , derefChain ) and
21262147 exists ( Type rootType , string name , int arity |
2127- this .isMethodCall0 ( rootType , name , arity , derefChain )
2148+ this .isMethodCall0 ( rootType , name , arity , derefChain + ";" )
21282149 |
21292150 forall ( Impl impl |
21302151 methodCandidateTrait ( rootType , this .getTrait ( ) , name , arity , impl )
@@ -2134,15 +2155,15 @@ final class MethodCall extends Call {
21342155 |
21352156 IsInstantiationOf< MethodCallDerefChainRef , IsInstantiationOfInput > :: isNotInstantiationOf ( MkMethodCallDerefChainRef ( this ,
21362157 derefChain + ";" ) , impl , _)
2137- )
2158+ ) and
2159+ not exists ( resolveNonImplMethodCallTarget ( rootType , name , arity ) )
21382160 )
21392161 }
21402162
21412163 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 ( )
21462167 }
21472168
21482169 pragma [ nomagic]
@@ -2173,17 +2194,25 @@ final class MethodCall extends Call {
21732194 }
21742195
21752196 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 ( )
21802209 }
21812210
21822211 pragma [ nomagic]
21832212 private Type getACandidateReceiverTypeAtRefNoMatch ( TypePath path , string derefChain ) {
21842213 result = this .getACandidateReceiverTypeAtNoMatch ( path , derefChain ) and
21852214 exists ( Type rootType , string name , int arity |
2186- this .isMethodCall0 ( rootType , name , arity , derefChain )
2215+ this .isMethodCall0 ( rootType , name , arity , derefChain + ";ref" )
21872216 |
21882217 forall ( Impl impl |
21892218 methodCandidateTrait ( rootType , this .getTrait ( ) , name , arity , impl )
@@ -2193,7 +2222,8 @@ final class MethodCall extends Call {
21932222 |
21942223 IsInstantiationOf< MethodCallDerefChainRef , IsInstantiationOfInput > :: isNotInstantiationOf ( MkMethodCallDerefChainRef ( this ,
21952224 derefChain + ";ref" ) , impl , _)
2196- )
2225+ ) and
2226+ not exists ( resolveNonImplMethodCallTarget ( rootType , name , arity ) )
21972227 )
21982228 }
21992229
@@ -2218,19 +2248,22 @@ final class MethodCall extends Call {
22182248 t0 = this .getACandidateReceiverTypeAtRef ( path0 , derefChain ) and
22192249 derefChainRef = derefChain + ";ref"
22202250 |
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
22252257 result = t0
22262258 )
22272259 }
22282260
22292261 pragma [ nomagic]
22302262 private Type testgetACandidateReceiverTypeRefsAt ( TypePath path , string derefChain ) {
22312263 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()
22342267 }
22352268 // /** An alias for `getCandidateReceiverTypeAt`, needed to implement `HasTypeTreeSig`. */
22362269 // Type getTypeAt(TypePath path) { result = this.getACandidateReceiverTypeRefsAt(path) }
@@ -2295,6 +2328,7 @@ private module IsInstantiationOfInput implements IsInstantiationOfInputSig<Metho
22952328 predicate potentialInstantiationOf (
22962329 MethodCallDerefChainRef mc , TypeAbstraction impl , TypeMention constraint
22972330 ) {
2331+ // mc.getMethodCall() = Debug::getRelevantLocatable() and // todo
22982332 exists ( Type rootType , string name , int arity , MethodCall mc0 |
22992333 isMethodCall ( mc , mc0 , rootType , name , arity ) and
23002334 constraint = impl .( ImplTypeAbstraction ) .getSelfTy ( )
@@ -2521,24 +2555,37 @@ private Function getDynTraitMethod(DynTraitType traitObject, string name, int ar
25212555 result = getMethodSuccessor ( traitObject .getTrait ( ) , name , arity )
25222556}
25232557
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+
25242572pragma [ nomagic]
25252573private Function resolveMethodCallTarget ( MethodCallDerefChainRef mcd ) {
25262574 // The method comes from an `impl` block targeting the type of the receiver.
25272575 result = getMethodFromImpl ( mcd )
25282576 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 )
25392580 )
25402581}
25412582
2583+ private Function testresolveMethodCallTarget ( MethodCallDerefChainRef mcd ) {
2584+ // result = resolveMethodCallTarget(mcd) and
2585+ result = getMethodFromImpl ( mcd ) and
2586+ mcd .getMethodCall ( ) = Debug:: getRelevantLocatable ( )
2587+ }
2588+
25422589pragma [ nomagic]
25432590private predicate assocFuncResolutionDependsOnArgument ( Function f , Impl impl , int pos ) {
25442591 functionResolutionDependsOnArgument ( impl , _, f , pos , _, _) and
@@ -2853,11 +2900,13 @@ Type inferType(AstNode n) { result = inferType(n, TypePath::nil()) }
28532900
28542901/** Provides predicates for debugging the type inference implementation. */
28552902private module Debug {
2856- private Locatable getRelevantLocatable ( ) {
2903+ Locatable getRelevantLocatable ( ) {
28572904 exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
28582905 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
28612910 )
28622911 }
28632912
0 commit comments