@@ -1136,13 +1136,19 @@ private module MethodCallResolution {
1136
1136
*/
1137
1137
pragma [ nomagic]
1138
1138
predicate methodInfo (
1139
- Function f , string name , int arity , ImplOrTraitItemNode i , FunctionType selfType , Type rootType ,
1140
- TypePath selfRootPath , Type selfRootType
1139
+ Function f , string name , int arity , ImplOrTraitItemNode i , FunctionType selfType ,
1140
+ TypePath rootTypePath , Type rootType , TypePath selfRootPath , Type selfRootType
1141
1141
) {
1142
1142
exists ( FunctionTypePosition pos |
1143
1143
f = i .getASuccessor ( name ) and
1144
1144
arity = f .getParamList ( ) .getNumberOfParams ( ) and
1145
- rootType = selfType .getTypeAt ( TypePath:: nil ( ) ) and
1145
+ rootType = selfType .getTypeAt ( rootTypePath ) and
1146
+ (
1147
+ rootTypePath .isEmpty ( ) and
1148
+ rootType != TRefType ( )
1149
+ or
1150
+ rootTypePath = TypePath:: singleton ( TRefTypeParameter ( ) )
1151
+ ) and
1146
1152
selfType .appliesTo ( f , pos , i ) and
1147
1153
pos .isSelf ( ) and
1148
1154
selfType .getTypeAt ( selfRootPath ) = selfRootType and
@@ -1157,7 +1163,7 @@ private module MethodCallResolution {
1157
1163
pragma [ nomagic]
1158
1164
private predicate traitMethodInfo ( string name , int arity , Trait trait ) {
1159
1165
exists ( ImplItemNode i |
1160
- methodInfo ( _, name , arity , i , _, _, _, _) and
1166
+ methodInfo ( _, name , arity , i , _, _, _, _, _ ) and
1161
1167
trait = i .resolveTraitTy ( )
1162
1168
)
1163
1169
}
@@ -1167,7 +1173,7 @@ private module MethodCallResolution {
1167
1173
exists ( string name , int arity | mc .( MethodCall ) .isMethodCall ( name , arity ) |
1168
1174
traitMethodInfo ( name , arity , trait )
1169
1175
or
1170
- methodInfo ( _, name , arity , trait , _, _, _, _)
1176
+ methodInfo ( _, name , arity , trait , _, _, _, _, _ )
1171
1177
)
1172
1178
}
1173
1179
@@ -1196,12 +1202,12 @@ private module MethodCallResolution {
1196
1202
*/
1197
1203
pragma [ inline]
1198
1204
private predicate methodCallCandidate (
1199
- MethodCall mc , ImplOrTraitItemNode i , FunctionType self , Type rootType , TypePath selfRootPath ,
1200
- Type selfRootType
1205
+ MethodCall mc , ImplOrTraitItemNode i , FunctionType self , TypePath rootTypePath , Type rootType ,
1206
+ TypePath selfRootPath , Type selfRootType
1201
1207
) {
1202
1208
exists ( string name , int arity |
1203
1209
mc .isMethodCall ( name , arity ) and
1204
- methodInfo ( _, name , arity , i , self , rootType , selfRootPath , selfRootType )
1210
+ methodInfo ( _, name , arity , i , self , rootTypePath , rootType , selfRootPath , selfRootType )
1205
1211
|
1206
1212
i =
1207
1213
any ( Impl impl |
@@ -1218,11 +1224,11 @@ private module MethodCallResolution {
1218
1224
}
1219
1225
1220
1226
private int countmethodCallCandidate ( MethodCall mc ) {
1221
- result = strictcount ( ImplOrTraitItemNode i | methodCallCandidate ( mc , i , _, _, _, _) )
1227
+ result = strictcount ( ImplOrTraitItemNode i | methodCallCandidate ( mc , i , _, _, _, _, _ ) )
1222
1228
}
1223
1229
1224
1230
private predicate countmethodCallMaxCandidate ( MethodCall mc , ImplOrTraitItemNode i ) {
1225
- methodCallCandidate ( mc , i , _, _, _, _) and
1231
+ methodCallCandidate ( mc , i , _, _, _, _, _ ) and
1226
1232
countmethodCallCandidate ( mc ) = max ( countmethodCallCandidate ( _) )
1227
1233
}
1228
1234
@@ -1289,9 +1295,10 @@ private module MethodCallResolution {
1289
1295
IsInstantiationOf< MethodCallCand , FunctionType , MethodCallIsInstantiationOfInput > :: isNotInstantiationOf ( MkMethodCallCand ( this ,
1290
1296
derefChainBorrow ) , i , _)
1291
1297
or
1292
- exists ( Type rootType , TypePath selfRootPath , Type selfRootType |
1293
- rootType = this .getACandidateReceiverTypeAtSubstituteTraitBounds ( derefChainBorrow ) and
1294
- methodCallCandidate ( this , i , _, rootType , selfRootPath , selfRootType ) and
1298
+ exists ( TypePath rootTypePath , Type rootType , TypePath selfRootPath , Type selfRootType |
1299
+ rootType =
1300
+ this .getACandidateReceiverTypeAtSubstituteTraitBounds ( rootTypePath , derefChainBorrow ) and
1301
+ methodCallCandidate ( this , i , _, rootTypePath , rootType , selfRootPath , selfRootType ) and
1295
1302
selfRootType !=
1296
1303
this .getACandidateReceiverTypeAtSubstituteTraitBounds ( selfRootPath , derefChainBorrow )
1297
1304
)
@@ -1303,33 +1310,46 @@ private module MethodCallResolution {
1303
1310
*/
1304
1311
pragma [ nomagic]
1305
1312
private predicate noCandidateReceiverTypeAtNoBorrow ( string derefChain ) {
1306
- exists ( Type rootType , string derefChainBorrow |
1313
+ exists ( TypePath rootTypePath , Type rootType , string derefChainBorrow |
1307
1314
derefChainBorrow = derefChain + ";" and
1308
1315
not derefChain .matches ( "%.ref" ) and // no need to try a borrow if the last thing we did was a deref
1309
- rootType = this .getACandidateReceiverTypeAtSubstituteTraitBounds ( derefChainBorrow )
1316
+ rootType =
1317
+ this .getACandidateReceiverTypeAtSubstituteTraitBounds ( rootTypePath , derefChainBorrow ) and
1318
+ (
1319
+ rootTypePath .isEmpty ( ) and
1320
+ rootType != TRefType ( )
1321
+ or
1322
+ rootTypePath = TypePath:: singleton ( TRefTypeParameter ( ) )
1323
+ )
1310
1324
|
1311
- forall ( ImplOrTraitItemNode i | methodCallCandidate ( this , i , _, rootType , _, _) |
1325
+ forall ( ImplOrTraitItemNode i |
1326
+ methodCallCandidate ( this , i , _, rootTypePath , rootType , _, _)
1327
+ |
1312
1328
this .isNotCandidate ( i , derefChainBorrow )
1313
1329
)
1314
1330
)
1315
1331
}
1316
1332
1317
- pragma [ nomagic]
1318
- private predicate hasRefCandidate ( ImplOrTraitItemNode i ) {
1319
- methodCallCandidate ( this , i , _, TRefType ( ) , _, _)
1320
- }
1321
-
1333
+ // pragma[nomagic]
1334
+ // private predicate hasRefCandidate(ImplOrTraitItemNode i) {
1335
+ // methodCallCandidate(this, i, _, TRefType(), _, _)
1336
+ // }
1322
1337
/**
1323
1338
* Holds if the candidate receiver type represented by `derefChain;borrow` does not
1324
1339
* have a matching method target.
1325
1340
*/
1326
1341
pragma [ nomagic]
1327
1342
private predicate noCandidateReceiverTypeAt ( string derefChain ) {
1328
- exists ( string derefChainBorrow |
1343
+ exists ( TypePath rootTypePath , Type rootType , string derefChainBorrow |
1329
1344
derefChainBorrow = derefChain + ";borrow" and
1330
- this .noCandidateReceiverTypeAtNoBorrow ( derefChain )
1345
+ this .noCandidateReceiverTypeAtNoBorrow ( derefChain ) and
1346
+ rootType =
1347
+ this .getACandidateReceiverTypeAtSubstituteTraitBounds ( rootTypePath , derefChainBorrow ) and
1348
+ rootTypePath = TypePath:: singleton ( TRefTypeParameter ( ) )
1331
1349
|
1332
- forall ( ImplOrTraitItemNode i | this .hasRefCandidate ( i ) |
1350
+ forall ( ImplOrTraitItemNode i |
1351
+ methodCallCandidate ( this , i , _, rootTypePath , rootType , _, _)
1352
+ |
1333
1353
this .isNotCandidate ( i , derefChainBorrow )
1334
1354
)
1335
1355
)
@@ -1475,10 +1495,16 @@ private module MethodCallResolution {
1475
1495
*/
1476
1496
pragma [ nomagic]
1477
1497
private predicate hasNoInherentTarget ( ) {
1478
- exists ( Type rootType , string name , int arity |
1479
- this .isMethodCall ( _, TypePath:: nil ( ) , rootType , name , arity ) and
1498
+ exists ( TypePath rootTypePath , Type rootType , string name , int arity |
1499
+ this .isMethodCall ( _, rootTypePath , rootType , name , arity ) and
1500
+ (
1501
+ rootTypePath .isEmpty ( ) and
1502
+ rootType != TRefType ( )
1503
+ or
1504
+ rootTypePath = TypePath:: singleton ( TRefTypeParameter ( ) )
1505
+ ) and
1480
1506
forall ( Impl i , FunctionType self , TypePath selfRootPath , Type selfRootType |
1481
- methodInfo ( _, name , arity , i , self , rootType , selfRootPath , selfRootType ) and
1507
+ methodInfo ( _, name , arity , i , self , rootTypePath , rootType , selfRootPath , selfRootType ) and
1482
1508
not i .hasTrait ( )
1483
1509
|
1484
1510
this .isNotInherentCandidate ( i )
@@ -1553,12 +1579,12 @@ private module MethodCallResolution {
1553
1579
) {
1554
1580
exists ( MethodCall mc , string name , int arity , TypePath selfRootPath , Type selfRootType |
1555
1581
mcc .isMethodCall ( mc , selfRootPath , selfRootType , name , arity ) and
1556
- methodCallCandidate ( mc , abs , constraint , _, selfRootPath , selfRootType )
1582
+ methodCallCandidate ( mc , abs , constraint , _, _ , selfRootPath , selfRootType )
1557
1583
)
1558
1584
}
1559
1585
1560
1586
predicate relevantTypeMention ( FunctionType constraint ) {
1561
- methodInfo ( _, _, _, _, constraint , _, _, _)
1587
+ methodInfo ( _, _, _, _, constraint , _, _, _, _ )
1562
1588
}
1563
1589
}
1564
1590
@@ -1574,14 +1600,14 @@ private module MethodCallResolution {
1574
1600
MethodCallCand mcc , TypeAbstraction abs , FunctionType constraint
1575
1601
) {
1576
1602
abs = any ( Impl i | not i .hasTrait ( ) ) and
1577
- exists ( MethodCall mc , string name , int arity , Type rootType |
1578
- mcc .isMethodCall ( mc , TypePath :: nil ( ) , rootType , name , arity ) and
1579
- methodCallCandidate ( mc , abs , constraint , rootType , _, _)
1603
+ exists ( MethodCall mc , string name , int arity , TypePath rootTypePath , Type rootType |
1604
+ mcc .isMethodCall ( mc , rootTypePath , rootType , name , arity ) and
1605
+ methodCallCandidate ( mc , abs , constraint , rootTypePath , rootType , _, _)
1580
1606
)
1581
1607
}
1582
1608
1583
1609
predicate relevantTypeMention ( FunctionType constraint ) {
1584
- methodInfo ( _, _, _, _, constraint , _, _, _)
1610
+ methodInfo ( _, _, _, _, constraint , _, _, _, _ )
1585
1611
}
1586
1612
}
1587
1613
}
@@ -1892,7 +1918,7 @@ private module FunctionCallResolution {
1892
1918
exists ( TypePath selfRootPath , Type selfRootType |
1893
1919
f = call .getPathResolutionResolvedFunctionOrImplementation ( resolved ) and
1894
1920
trait = call .( Call ) .getTrait ( ) and
1895
- MethodCallResolution:: methodInfo ( f , _, _, i , self , _, selfRootPath , selfRootType ) and
1921
+ MethodCallResolution:: methodInfo ( f , _, _, i , self , _, _ , selfRootPath , selfRootType ) and
1896
1922
call .getTypeAt ( selfRootPath ) = selfRootType
1897
1923
)
1898
1924
}
@@ -1905,7 +1931,7 @@ private module FunctionCallResolution {
1905
1931
}
1906
1932
1907
1933
predicate relevantTypeMention ( FunctionType constraint ) {
1908
- MethodCallResolution:: methodInfo ( _, _, _, _, constraint , _, _, _)
1934
+ MethodCallResolution:: methodInfo ( _, _, _, _, constraint , _, _, _, _ )
1909
1935
}
1910
1936
}
1911
1937
}
@@ -2192,7 +2218,7 @@ private module OperationResolution {
2192
2218
TypeAbstraction abs , FunctionType constraint , Trait trait , string name , int arity ,
2193
2219
TypePath selfRootPath , Type selfRootType
2194
2220
) {
2195
- MethodCallResolution:: methodInfo ( _, name , arity , abs , constraint , _, selfRootPath ,
2221
+ MethodCallResolution:: methodInfo ( _, name , arity , abs , constraint , _, _ , selfRootPath ,
2196
2222
selfRootType ) and
2197
2223
(
2198
2224
trait = abs .( ImplItemNode ) .resolveTraitTy ( )
@@ -2210,7 +2236,7 @@ private module OperationResolution {
2210
2236
}
2211
2237
2212
2238
predicate relevantTypeMention ( FunctionType constraint ) {
2213
- MethodCallResolution:: methodInfo ( _, _, _, _, constraint , _, _, _)
2239
+ MethodCallResolution:: methodInfo ( _, _, _, _, constraint , _, _, _, _ )
2214
2240
}
2215
2241
}
2216
2242
}
0 commit comments