Skip to content

Commit baf2c5b

Browse files
committed
wip2
1 parent b4f23c7 commit baf2c5b

File tree

4 files changed

+23
-90
lines changed

4 files changed

+23
-90
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private predicate functionResolutionDependsOnArgumentCand(
128128
)
129129
}
130130

131-
private predicate functionResolutionDependsOnPositionalArgument(
131+
private predicate functionResolutionDependsOnPositionalArgumentCand(
132132
ImplItemNode impl, Function f, string functionName, TypeParameter traitTp
133133
) {
134134
exists(FunctionPosition pos |
@@ -164,13 +164,13 @@ private predicate hasEquivalentPositionalSibling(
164164
|
165165
forall(TypePath path0, Type t |
166166
t = getAssocFunctionNonTypeParameterTypeAt(impl, f, pos, path0) and
167-
(path = path0.getAPrefix() or path = path0)
167+
path = path0.getAPrefixOrSelf()
168168
|
169169
t = getAssocFunctionNonTypeParameterTypeAt(sibling, f1, pos, path0)
170170
) and
171171
forall(TypePath path0, Type t |
172172
t = getAssocFunctionNonTypeParameterTypeAt(sibling, f1, pos, path0) and
173-
(path = path0.getAPrefix() or path = path0)
173+
path = path0.getAPrefixOrSelf()
174174
|
175175
t = getAssocFunctionNonTypeParameterTypeAt(impl, f, pos, path0)
176176
)
@@ -217,13 +217,13 @@ predicate functionResolutionDependsOnArgument(
217217
exists(string functionName, TypePath path |
218218
functionResolutionDependsOnArgumentCand(impl, f, functionName, traitTp, pos, path)
219219
|
220-
if functionResolutionDependsOnPositionalArgument(impl, f, functionName, traitTp)
220+
if functionResolutionDependsOnPositionalArgumentCand(impl, f, functionName, traitTp)
221221
then any()
222222
else
223223
exists(ImplItemNode sibling |
224224
implSiblings(_, impl, sibling) and
225225
forall(TypeParameter otherTraitTp |
226-
functionResolutionDependsOnPositionalArgument(impl, f, functionName, otherTraitTp)
226+
functionResolutionDependsOnPositionalArgumentCand(impl, f, functionName, otherTraitTp)
227227
|
228228
hasEquivalentPositionalSibling(impl, sibling, f, otherTraitTp)
229229
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ private module ContextTyping {
11751175
private Type inferCallTypeFromContextCand(AstNode n, TypePath prefix, TypePath path) {
11761176
result = inferCallType(n, false, path) and
11771177
hasUnknownType(n) and
1178-
prefix = [path, path.getPrefix(_)]
1178+
prefix = path.getAPrefixOrSelf()
11791179
}
11801180

11811181
pragma[nomagic]
@@ -2947,7 +2947,7 @@ private module NonMethodResolution {
29472947
predicate hasTargetCand(ImplOrTraitItemNode i, Function f) {
29482948
hasTraitResolvedCand(this, i, f) and
29492949
BlanketImplementation::isBlanketLike(i, _, _) and
2950-
this.hasNoCompatibleNonBlanketTarget() // todo: removing this line makes the pred below work
2950+
(this.hasNoCompatibleNonBlanketTarget() or not i.(ImplItemNode).isBlanketImplementation()) // todo: removing this line makes the pred below work
29512951
}
29522952
}
29532953
}

shared/typeinference/codeql/typeinference/internal/TypeInference.qll

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,22 +1443,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
14431443
)
14441444
}
14451445

1446-
pragma[nomagic]
1447-
private predicate typeParameterConstraintHasTypeParameter2(
1448-
Declaration target, AccessPosition apos, TypePath pathToConstrained, Type constraint,
1449-
TypePath pathToTp, TypeParameter tp, TypeParameter constrainedTp
1450-
) {
1451-
exists(DeclarationPosition dpos |
1452-
accessDeclarationPositionMatch(apos, dpos) and
1453-
constrainedTp = target.getTypeParameter(_) and
1454-
tp = target.getTypeParameter(_) and
1455-
tp = getATypeParameterConstraint(constrainedTp, pathToTp) and
1456-
constrainedTp != tp and
1457-
constrainedTp = target.getDeclaredType(dpos, pathToConstrained) and
1458-
constraint = getATypeParameterConstraint(constrainedTp, TypePath::nil())
1459-
)
1460-
}
1461-
14621446
pragma[nomagic]
14631447
private predicate typeConstraintBaseTypeMatch(
14641448
Access a, AccessEnvironment e, Declaration target, TypePath path, Type t, TypeParameter tp
@@ -1471,19 +1455,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
14711455
)
14721456
}
14731457

1474-
pragma[nomagic]
1475-
private predicate typeConstraintBaseTypeMatch2(
1476-
Access a, AccessEnvironment e, Declaration target, TypePath path, Type t, TypeParameter tp,
1477-
Type constraint, AccessPosition apos, TypePath pathToTp, TypePath pathToTp2,
1478-
TypeParameter constrainedTp
1479-
) {
1480-
not exists(getTypeArgument(a, target, tp, _)) and
1481-
typeParameterConstraintHasTypeParameter2(target, apos, pathToTp2, constraint, pathToTp, tp,
1482-
constrainedTp) and
1483-
AccessConstraint::satisfiesConstraintType(a, e, target, apos, pathToTp2, constraint,
1484-
pathToTp.appendInverse(path), t)
1485-
}
1486-
14871458
pragma[inline]
14881459
private predicate typeMatch(
14891460
Access a, AccessEnvironment e, Declaration target, TypePath path, Type t, TypeParameter tp
@@ -1558,52 +1529,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
15581529
)
15591530
)
15601531
}
1561-
1562-
pragma[nomagic]
1563-
Type inferAccessType2(
1564-
Declaration target, Access a, AccessEnvironment e, AccessPosition apos, TypePath path,
1565-
TypePath prefix, TypeParameter tp, TypePath suffix, Type constraint, AccessPosition apos2,
1566-
TypePath pathToTp, TypePath pathToTp2, TypeParameter constrainedTp
1567-
) {
1568-
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
1569-
a.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1570-
|
1571-
// filepath.matches("%/examples/manual-routing/src/main.rs") and
1572-
// startline = [33, 81]
1573-
// or
1574-
// filepath.matches("%/connection.rs") and
1575-
// startline = [838, 953]
1576-
// or
1577-
filepath.matches("%/main.rs") and
1578-
startline = 2930
1579-
) and
1580-
exists(DeclarationPosition dpos |
1581-
accessDeclarationPositionMatch(apos, dpos) and
1582-
// A suffix of `path` leads to a type parameter in the target
1583-
tp = target.getDeclaredType(dpos, prefix) and
1584-
path = prefix.append(suffix)
1585-
|
1586-
// // A type given at the access corresponds directly to the type parameter
1587-
// // at the target.
1588-
// explicitTypeMatch(a, e, target, suffix, result, tp)
1589-
// or
1590-
// // We can infer the type of `tp` from one of the access positions
1591-
// directTypeMatch(a, e, target, suffix, result, tp)
1592-
// or
1593-
// // We can infer the type of `tp` by going up the type hiearchy
1594-
// baseTypeMatch(a, e, target, suffix, result, tp)
1595-
// or
1596-
// We can infer the type of `tp` by a type constraint
1597-
typeConstraintBaseTypeMatch2(a, e, target, suffix, result, tp, constraint, apos2,
1598-
pathToTp, pathToTp2, constrainedTp)
1599-
// typeMatch(a, e, target, suffix, result, tp)
1600-
// or
1601-
// // `path` corresponds directly to a concrete type in the declaration
1602-
// result = target.getDeclaredType(dpos, path) and
1603-
// target = a.getTarget(e) and
1604-
// not result instanceof TypeParameter
1605-
)
1606-
}
16071532
}
16081533

16091534
/** Provides the input to `Matching`. */
@@ -1722,12 +1647,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
17221647
Type inferAccessType(Input::Access a, Input::AccessPosition apos, TypePath path) {
17231648
result = M::inferAccessType(a, _, apos, path)
17241649
}
1725-
1726-
Type inferAccessType2(
1727-
Input::Declaration target, Input::Access a, Input::AccessPosition apos, TypePath path
1728-
) {
1729-
result = M::inferAccessType2(target, a, _, apos, path, _, _, _, _, _, _, _, _)
1730-
}
17311650
}
17321651

17331652
/** Provides consistency checks. */

shared/util/codeql/util/UnboundList.qll

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ module Make<LocationSig Location, InputSig<Location> Input> {
134134
bindingset[this]
135135
Element getHead() { result = this.getElement(0) }
136136

137-
/** Gets the `i`th prefix of this list, if any. */
137+
/**
138+
* Gets the `i`th prefix of this list, if any.
139+
*
140+
* Only holds when this list is non-empty, and only returns proper prefixes.
141+
*/
138142
bindingset[this]
139143
UnboundList getPrefix(int i) {
140144
exists(string regexp, int occurrenceOffset | regexp = "[0-9]+\\." |
@@ -143,9 +147,19 @@ module Make<LocationSig Location, InputSig<Location> Input> {
143147
)
144148
}
145149

146-
/** Gets a prefix of this list, if any. */
150+
/**
151+
* Gets a prefix of this list, if any.
152+
*
153+
* Only holds when this list is non-empty, and only returns proper prefixes.
154+
*/
147155
bindingset[this]
148156
UnboundList getAPrefix() { result = this.getPrefix(_) }
157+
158+
/**
159+
* Gets a prefix of this list, including the list itself.
160+
*/
161+
bindingset[this]
162+
UnboundList getAPrefixOrSelf() { result = [this, this.getAPrefix()] }
149163
}
150164

151165
/** Provides predicates for constructing `UnboundList`s. */

0 commit comments

Comments
 (0)