Skip to content

Commit 0a94c7e

Browse files
committed
wip3
1 parent 756bfef commit 0a94c7e

1 file changed

Lines changed: 33 additions & 109 deletions

File tree

rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll

Lines changed: 33 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,48 +1821,14 @@ private module AssocFunctionResolution {
18211821
)
18221822
}
18231823

1824-
bindingset[derefChain, borrow, strippedTypePath, strippedType]
1825-
private predicate hasNoCompatibleNonBlanketLikeTargetCheck_(
1826-
FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow, TypePath strippedTypePath,
1827-
Type strippedType
1828-
) {
1829-
forall(ImplOrTraitItemNode i |
1830-
nonBlanketLikeCandidate(this, selfPos, i, _, strippedTypePath, strippedType)
1831-
|
1832-
this.hasIncompatibleTarget(i, selfPos, derefChain, borrow, strippedType)
1833-
)
1834-
}
1835-
1836-
// forex using recursion
1837-
pragma[nomagic]
1838-
private predicate hasNoCompatibleTargetNoBorrowToIndex(
1839-
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
1840-
int n
1841-
) {
1842-
Foo<hasNoCompatibleTargetNoBorrowToIndex/4>::hasNoCompatibleTargetCheck(this, selfPos,
1843-
derefChain, _, strippedTypePath, strippedType, n)
1844-
}
1845-
18461824
/**
18471825
* Holds if the candidate receiver type represented by `derefChain` does not
18481826
* have a matching call target at function-call adjusted position `selfPos`.
18491827
*/
18501828
pragma[nomagic]
18511829
predicate hasNoCompatibleTargetNoBorrow(FunctionPosition selfPos, DerefChain derefChain) {
1852-
exists(Type strippedType |
1853-
this.hasNoCompatibleTargetNoBorrowToIndex(selfPos, derefChain, _, strippedType,
1854-
getLastLookupTypeIndex(this, strippedType))
1855-
)
1856-
}
1857-
1858-
// forex using recursion
1859-
pragma[nomagic]
1860-
private predicate hasNoCompatibleNonBlanketTargetNoBorrowToIndex(
1861-
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
1862-
int n
1863-
) {
1864-
Foo<hasNoCompatibleNonBlanketTargetNoBorrowToIndex/4>::hasNoCompatibleNonBlanketTargetCheck(this,
1865-
selfPos, derefChain, _, strippedTypePath, strippedType, n)
1830+
Foo<hasNoCompatibleTargetNoBorrowToIndex/4>::hasNoCompatibleTargetCheck(this, selfPos,
1831+
derefChain, _)
18661832
}
18671833

18681834
/**
@@ -1873,22 +1839,8 @@ private module AssocFunctionResolution {
18731839
predicate hasNoCompatibleNonBlanketTargetNoBorrow(
18741840
FunctionPosition selfPos, DerefChain derefChain
18751841
) {
1876-
exists(Type strippedType |
1877-
this.hasNoCompatibleNonBlanketTargetNoBorrowToIndex(selfPos, derefChain, _, strippedType,
1878-
getLastLookupTypeIndex(this, strippedType))
1879-
)
1880-
}
1881-
1882-
// forex using recursion
1883-
pragma[nomagic]
1884-
private predicate hasNoCompatibleTargetSharedBorrowToIndex(
1885-
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
1886-
int n
1887-
) {
1888-
// hasNoCompatibleTargetSharedBorrowToIndex(this, selfPos, derefChain, _, strippedTypePath,
1889-
// strippedType, n)
1890-
Foo<hasNoCompatibleTargetSharedBorrowToIndex/4>::hasNoCompatibleNonBlanketLikeTargetCheck(this,
1891-
selfPos, derefChain, _, strippedTypePath, strippedType, n)
1842+
Foo<hasNoCompatibleNonBlanketTargetNoBorrowToIndex/4>::hasNoCompatibleNonBlanketTargetCheck(this,
1843+
selfPos, derefChain, _)
18921844
}
18931845

18941846
/**
@@ -1898,20 +1850,8 @@ private module AssocFunctionResolution {
18981850
*/
18991851
pragma[nomagic]
19001852
predicate hasNoCompatibleTargetSharedBorrow(FunctionPosition selfPos, DerefChain derefChain) {
1901-
exists(Type strippedType |
1902-
this.hasNoCompatibleTargetSharedBorrowToIndex(selfPos, derefChain, _, strippedType,
1903-
getLastLookupTypeIndex(this, strippedType))
1904-
)
1905-
}
1906-
1907-
// forex using recursion
1908-
pragma[nomagic]
1909-
private predicate hasNoCompatibleTargetMutBorrowToIndex(
1910-
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
1911-
int n
1912-
) {
1913-
Foo<hasNoCompatibleTargetMutBorrowToIndex/4>::hasNoCompatibleNonBlanketLikeTargetCheck(this,
1914-
selfPos, derefChain, _, strippedTypePath, strippedType, n)
1853+
Foo<hasNoCompatibleTargetSharedBorrowToIndex/4>::hasNoCompatibleNonBlanketLikeTargetCheck(this,
1854+
selfPos, derefChain, _)
19151855
}
19161856

19171857
/**
@@ -1921,20 +1861,8 @@ private module AssocFunctionResolution {
19211861
*/
19221862
pragma[nomagic]
19231863
predicate hasNoCompatibleTargetMutBorrow(FunctionPosition selfPos, DerefChain derefChain) {
1924-
exists(Type strippedType |
1925-
this.hasNoCompatibleTargetMutBorrowToIndex(selfPos, derefChain, _, strippedType,
1926-
getLastLookupTypeIndex(this, strippedType))
1927-
)
1928-
}
1929-
1930-
// forex using recursion
1931-
pragma[nomagic]
1932-
private predicate hasNoCompatibleNonBlanketTargetSharedBorrowToIndex(
1933-
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
1934-
int n
1935-
) {
1936-
Foo<hasNoCompatibleNonBlanketTargetSharedBorrowToIndex/4>::hasNoCompatibleNonBlanketTargetCheck(this,
1937-
selfPos, derefChain, _, strippedTypePath, strippedType, n)
1864+
Foo<hasNoCompatibleTargetMutBorrowToIndex/4>::hasNoCompatibleNonBlanketLikeTargetCheck(this,
1865+
selfPos, derefChain, _)
19381866
}
19391867

19401868
/**
@@ -1946,20 +1874,8 @@ private module AssocFunctionResolution {
19461874
predicate hasNoCompatibleNonBlanketTargetSharedBorrow(
19471875
FunctionPosition selfPos, DerefChain derefChain
19481876
) {
1949-
exists(Type strippedType |
1950-
this.hasNoCompatibleNonBlanketTargetSharedBorrowToIndex(selfPos, derefChain, _,
1951-
strippedType, getLastLookupTypeIndex(this, strippedType))
1952-
)
1953-
}
1954-
1955-
// forex using recursion
1956-
pragma[nomagic]
1957-
private predicate hasNoCompatibleNonBlanketTargetMutBorrowToIndex(
1958-
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
1959-
int n
1960-
) {
1961-
Foo<hasNoCompatibleNonBlanketTargetMutBorrowToIndex/4>::hasNoCompatibleNonBlanketTargetCheck(this,
1962-
selfPos, derefChain, _, strippedTypePath, strippedType, n)
1877+
Foo<hasNoCompatibleNonBlanketTargetSharedBorrowToIndex/4>::hasNoCompatibleNonBlanketTargetCheck(this,
1878+
selfPos, derefChain, _)
19631879
}
19641880

19651881
/**
@@ -1971,10 +1887,8 @@ private module AssocFunctionResolution {
19711887
predicate hasNoCompatibleNonBlanketTargetMutBorrow(
19721888
FunctionPosition selfPos, DerefChain derefChain
19731889
) {
1974-
exists(Type strippedType |
1975-
this.hasNoCompatibleNonBlanketTargetMutBorrowToIndex(selfPos, derefChain, _, strippedType,
1976-
getLastLookupTypeIndex(this, strippedType))
1977-
)
1890+
Foo<hasNoCompatibleNonBlanketTargetMutBorrowToIndex/4>::hasNoCompatibleNonBlanketTargetCheck(this,
1891+
selfPos, derefChain, _)
19781892
}
19791893

19801894
/**
@@ -2160,13 +2074,15 @@ private module AssocFunctionResolution {
21602074
) {
21612075
(
21622076
foo(afc, selfPos, derefChain, borrow, strippedTypePath, strippedType, n - 1) or
2163-
hasNoCompatibleNonBlanketLikeTargetCheck(afc, selfPos, derefChain, borrow, strippedTypePath,
2164-
strippedType, n - 1)
2077+
hasNoCompatibleNonBlanketLikeTargetCheckToIndex(afc, selfPos, derefChain, borrow,
2078+
strippedTypePath, strippedType, n - 1)
21652079
) and
21662080
t = getNthLookupType(afc, strippedType, n)
21672081
}
21682082

2169-
predicate hasNoCompatibleNonBlanketLikeTargetCheck(
2083+
// forex using recursion
2084+
pragma[nomagic]
2085+
private predicate hasNoCompatibleNonBlanketLikeTargetCheckToIndex(
21702086
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
21712087
TypePath strippedTypePath, Type strippedType, int n
21722088
) {
@@ -2180,23 +2096,31 @@ private module AssocFunctionResolution {
21802096
)
21812097
}
21822098

2099+
pragma[nomagic]
2100+
predicate hasNoCompatibleNonBlanketLikeTargetCheck(
2101+
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow
2102+
) {
2103+
exists(Type strippedType |
2104+
hasNoCompatibleNonBlanketLikeTargetCheckToIndex(afc, selfPos, derefChain, borrow, _,
2105+
strippedType, getLastLookupTypeIndex(afc, strippedType))
2106+
)
2107+
}
2108+
2109+
pragma[nomagic]
21832110
predicate hasNoCompatibleTargetCheck(
2184-
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
2185-
TypePath strippedTypePath, Type strippedType, int n
2111+
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow
21862112
) {
2187-
hasNoCompatibleNonBlanketLikeTargetCheck(afc, selfPos, derefChain, borrow, strippedTypePath,
2188-
strippedType, n) and
2113+
hasNoCompatibleNonBlanketLikeTargetCheck(afc, selfPos, derefChain, borrow) and
21892114
forall(ImplItemNode i | blanketLikeCandidate(afc, selfPos, i, _, _, _) |
21902115
afc.hasIncompatibleBlanketLikeTarget(i, selfPos, derefChain, borrow)
21912116
)
21922117
}
21932118

2119+
pragma[nomagic]
21942120
predicate hasNoCompatibleNonBlanketTargetCheck(
2195-
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
2196-
TypePath strippedTypePath, Type strippedType, int n
2121+
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow
21972122
) {
2198-
hasNoCompatibleNonBlanketLikeTargetCheck(afc, selfPos, derefChain, borrow, strippedTypePath,
2199-
strippedType, n) and
2123+
hasNoCompatibleNonBlanketLikeTargetCheck(afc, selfPos, derefChain, borrow) and
22002124
forall(ImplItemNode i |
22012125
blanketLikeCandidate(afc, selfPos, i, _, _, _) and
22022126
not i.isBlanketImplementation()

0 commit comments

Comments
 (0)