Python: further restrict LibraryLambdaMethod

On the small test project, this reduces the number
of instances from 285 to 22.
This commit is contained in:
Rasmus Lerchedahl Petersen
2023-12-06 09:24:49 +01:00
parent 453ab9ca7b
commit 061fd014a6

View File

@@ -92,12 +92,30 @@ abstract class SummarizedCallable extends LibraryCallable, Impl::Public::Summari
class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack;
private module LibraryCallbackSummaries {
private predicate libraryCall(CallCfgNode call) {
not exists(NormalCall normalCall | call.getNode() = normalCall.getNode())
}
private DataFlow::LocalSourceNode trackLambdaCreation(TypeTracker t) {
t.start() and
lambdaCreation(result, _, _)
or
exists(TypeTracker t2 | result = trackLambdaCreation(t2).track(t2, t)) and
not result.(ParameterNode).getParameter().isSelf()
}
private predicate libraryCallHasLambdaArg(CallCfgNode call, int i) {
exists(CfgNode arg |
arg = call.getArg(i) and
arg.getALocalSource() = trackLambdaCreation(TypeTracker::end()) and
libraryCall(call)
)
}
private class LibraryLambdaMethod extends SummarizedCallable {
LibraryLambdaMethod() { this = "<library method accepting a callback>" }
final override CallCfgNode getACall() {
not exists(NormalCall call | result.getNode() = call.getNode())
}
final override CallCfgNode getACall() { libraryCallHasLambdaArg(result, _) }
final override ArgumentNode getACallback() { none() }