outline callee computation - to avoid many joins on getACall

This commit is contained in:
Erik Krogh Kristensen
2021-02-22 17:40:00 +01:00
parent aa6cde2fe0
commit b3aa358177

View File

@@ -65,6 +65,53 @@ module PropertyProjection {
deprecated class CustomPropertyProjection = PropertyProjection::Range;
/**
* Gets a callee of a simple property projection call.
* This predicate is used exclusively in `SimplePropertyProjection`.
*/
pragma[noinline]
private DataFlow::SourceNode getASimplePropertyProjectionCallee(
boolean singleton, int selectorIndex, int objectIndex
) {
singleton = false and
(
result = LodashUnderscore::member("pick") and
objectIndex = 0 and
selectorIndex = [1 .. max(result.getACall().getNumArgument())]
or
result = LodashUnderscore::member("pickBy") and
objectIndex = 0 and
selectorIndex = 1
or
result = DataFlow::moduleMember("ramda", ["pick", "pickAll", "pickBy"]) and
objectIndex = 1 and
selectorIndex = 0
or
result = DataFlow::moduleMember("dotty", "search") and
objectIndex = 0 and
selectorIndex = 1
)
or
singleton = true and
(
result = LodashUnderscore::member("get") and
objectIndex = 0 and
selectorIndex = 1
or
result = DataFlow::moduleMember("ramda", "path") and
objectIndex = 1 and
selectorIndex = 0
or
result = DataFlow::moduleMember("dottie", "get") and
objectIndex = 0 and
selectorIndex = 1
or
result = DataFlow::moduleMember("dotty", "get") and
objectIndex = 0 and
selectorIndex = 1
)
}
/**
* A simple model of common property projection functions.
*/
@@ -74,51 +121,7 @@ private class SimplePropertyProjection extends PropertyProjection::Range {
boolean singleton;
SimplePropertyProjection() {
exists(DataFlow::SourceNode callee | this = callee.getACall() |
singleton = false and
(
callee = LodashUnderscore::member("pick") and
objectIndex = 0 and
selectorIndex = [1 .. getNumArgument()]
or
callee = LodashUnderscore::member("pickBy") and
objectIndex = 0 and
selectorIndex = 1
or
exists(string name |
name = "pick" or
name = "pickAll" or
name = "pickBy"
|
callee = DataFlow::moduleMember("ramda", name) and
objectIndex = 1 and
selectorIndex = 0
)
or
callee = DataFlow::moduleMember("dotty", "search") and
objectIndex = 0 and
selectorIndex = 1
)
or
singleton = true and
(
callee = LodashUnderscore::member("get") and
objectIndex = 0 and
selectorIndex = 1
or
callee = DataFlow::moduleMember("ramda", "path") and
objectIndex = 1 and
selectorIndex = 0
or
callee = DataFlow::moduleMember("dottie", "get") and
objectIndex = 0 and
selectorIndex = 1
or
callee = DataFlow::moduleMember("dotty", "get") and
objectIndex = 0 and
selectorIndex = 1
)
)
this = getASimplePropertyProjectionCallee(singleton, selectorIndex, objectIndex).getACall()
}
override DataFlow::Node getObject() { result = getArgument(objectIndex) }