mirror of
https://github.com/github/codeql.git
synced 2026-04-15 03:54:02 +02:00
Merge pull request #21706 from hvitved/rust/type-inference-perf-fixes
Rust: Improve performance of two type inference predicates
This commit is contained in:
@@ -1708,6 +1708,15 @@ private module AssocFunctionResolution {
|
||||
|
||||
predicate hasReceiverAtPos(FunctionPosition pos) { this.hasReceiver() and pos.asPosition() = 0 }
|
||||
|
||||
pragma[nomagic]
|
||||
private predicate hasIncompatibleArgsTarget(
|
||||
ImplOrTraitItemNode i, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
|
||||
AssocFunctionType selfType
|
||||
) {
|
||||
SelfArgIsInstantiationOf::argIsInstantiationOf(this, i, selfPos, derefChain, borrow, selfType) and
|
||||
OverloadedCallArgsAreInstantiationsOf::argsAreNotInstantiationsOf(this, i)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if the function inside `i` with matching name and arity can be ruled
|
||||
* out as a target of this call, because the candidate receiver type represented
|
||||
@@ -1722,16 +1731,11 @@ private module AssocFunctionResolution {
|
||||
ImplOrTraitItemNode i, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
|
||||
Type root
|
||||
) {
|
||||
exists(TypePath path |
|
||||
SelfArgIsInstantiationOf::argIsNotInstantiationOf(this, i, selfPos, derefChain, borrow, path) and
|
||||
path.isCons(root.getATypeParameter(), _)
|
||||
)
|
||||
or
|
||||
exists(AssocFunctionType selfType |
|
||||
SelfArgIsInstantiationOf::argIsInstantiationOf(this, i, selfPos, derefChain, borrow,
|
||||
selfType) and
|
||||
OverloadedCallArgsAreInstantiationsOf::argsAreNotInstantiationsOf(this, i) and
|
||||
root = selfType.getTypeAt(TypePath::nil())
|
||||
exists(AssocFunctionType selfType | root = selfType.getTypeAt(TypePath::nil()) |
|
||||
this.hasIncompatibleArgsTarget(i, selfPos, derefChain, borrow, selfType)
|
||||
or
|
||||
SelfArgIsInstantiationOf::argIsNotInstantiationOf(this, i, selfPos, derefChain, borrow,
|
||||
selfType)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2608,9 +2612,13 @@ private module AssocFunctionResolution {
|
||||
pragma[nomagic]
|
||||
predicate argIsNotInstantiationOf(
|
||||
AssocFunctionCall afc, ImplOrTraitItemNode i, FunctionPosition selfPos, DerefChain derefChain,
|
||||
BorrowKind borrow, TypePath path
|
||||
BorrowKind borrow, AssocFunctionType selfType
|
||||
) {
|
||||
argIsNotInstantiationOf(MkAssocFunctionCallCand(afc, selfPos, derefChain, borrow), i, _, path)
|
||||
exists(TypePath path |
|
||||
argIsNotInstantiationOf(MkAssocFunctionCallCand(afc, selfPos, derefChain, borrow), i,
|
||||
selfType, path) and
|
||||
not path.isEmpty()
|
||||
)
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
|
||||
@@ -566,15 +566,17 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
|
||||
)
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private predicate typeParametersEqual(
|
||||
App app, TypeAbstraction abs, Constraint constraint, TypeParameter tp
|
||||
App app, TypeAbstraction abs, Constraint constraint, int i
|
||||
) {
|
||||
satisfiesConcreteTypes(app, abs, constraint) and
|
||||
tp = getNthTypeParameter(abs, _) and
|
||||
(
|
||||
exists(TypeParameter tp |
|
||||
satisfiesConcreteTypes(app, abs, constraint) and
|
||||
tp = getNthTypeParameter(abs, i)
|
||||
|
|
||||
not exists(getNthTypeParameterPath(constraint, tp, _))
|
||||
or
|
||||
exists(int n | n = max(int i | exists(getNthTypeParameterPath(constraint, tp, i))) |
|
||||
exists(int n | n = max(int j | exists(getNthTypeParameterPath(constraint, tp, j))) |
|
||||
// If the largest index is 0, then there are no equalities to check as
|
||||
// the type parameter only occurs once.
|
||||
if n = 0 then any() else typeParametersEqualToIndex(app, abs, constraint, tp, _, n)
|
||||
@@ -585,12 +587,10 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
|
||||
private predicate typeParametersHaveEqualInstantiationToIndex(
|
||||
App app, TypeAbstraction abs, Constraint constraint, int i
|
||||
) {
|
||||
exists(TypeParameter tp | tp = getNthTypeParameter(abs, i) |
|
||||
typeParametersEqual(app, abs, constraint, tp) and
|
||||
if i = 0
|
||||
then any()
|
||||
else typeParametersHaveEqualInstantiationToIndex(app, abs, constraint, i - 1)
|
||||
)
|
||||
typeParametersEqual(app, abs, constraint, i) and
|
||||
if i = 0
|
||||
then any()
|
||||
else typeParametersHaveEqualInstantiationToIndex(app, abs, constraint, i - 1)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user