Skip to content

Commit 0aa3378

Browse files
committed
performance attempt
1 parent 1072977 commit 0aa3378

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

javascript/ql/lib/semmle/javascript/ApiGraphs.qll

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ module API {
105105
* For example, modules have an `exports` member representing their exports, and objects have
106106
* their properties as members.
107107
*/
108-
bindingset[m]
109-
bindingset[result]
110-
Node getMember(string m) { result = getASuccessor(Label::member(m)) }
108+
Node getMember(string m) { Impl::memberEdge(this, m, result) }
111109

112110
/**
113111
* Gets a node representing a member of this API component where the name of the member is
@@ -119,10 +117,7 @@ module API {
119117
* Gets a node representing a member of this API component where the name of the member may
120118
* or may not be known statically.
121119
*/
122-
Node getAMember() {
123-
result = getASuccessor(Label::member(_)) or
124-
result = getUnknownMember()
125-
}
120+
Node getAMember() { Impl::anyMemberEdge(this, result) }
126121

127122
/**
128123
* Gets a node representing an instance of this API component, that is, an object whose
@@ -812,6 +807,14 @@ module API {
812807
result = awaited(call, DataFlow::TypeTracker::end())
813808
}
814809

810+
cached
811+
predicate memberEdge(TApiNode pred, string member, TApiNode succ) {
812+
edge(pred, Label::member(member), succ)
813+
}
814+
815+
cached
816+
predicate anyMemberEdge(TApiNode pred, TApiNode succ) { memberEdge(pred, _, succ) }
817+
815818
/**
816819
* Holds if there is an edge from `pred` to `succ` in the API graph that is labeled with `lbl`.
817820
*/

javascript/ql/lib/semmle/javascript/dataflow/Configuration.qll

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,18 +1151,18 @@ private predicate reachableFromInput(
11511151
}
11521152

11531153
/**
1154-
* Holds if there is a level step from `pred` to `succ` under `cfg` that can be appended
1155-
* to a path represented by `oldSummary` yielding a path represented by `newSummary`.
1154+
* Holds if there is a level step from `mid` to `nd` under `cfg` that can be appended
1155+
* to a path represented by `oldSummary` yielding a path represented by `summary`.
11561156
*/
1157-
pragma[noinline]
1157+
pragma[noopt]
11581158
private predicate appendStep(
1159-
DataFlow::Node pred, DataFlow::Configuration cfg, PathSummary oldSummary, DataFlow::Node succ,
1160-
PathSummary newSummary
1159+
DataFlow::Node mid, DataFlow::Configuration cfg, PathSummary oldSummary, DataFlow::Node nd,
1160+
PathSummary summary
11611161
) {
11621162
exists(PathSummary stepSummary |
1163-
flowStep(pred, cfg, succ, stepSummary) and
1163+
flowStep(mid, cfg, nd, stepSummary) and
11641164
stepSummary.isLevel() and
1165-
newSummary = oldSummary.append(stepSummary)
1165+
summary = oldSummary.append(stepSummary)
11661166
)
11671167
}
11681168

@@ -1301,6 +1301,13 @@ private predicate reachesReturn(
13011301
summary = PathSummary::level() and
13021302
callInputStep(f, _, _, _, _) // check that a relevant result can exist.
13031303
or
1304+
reachesReturnRec(f, read, cfg, summary)
1305+
}
1306+
1307+
pragma[noopt]
1308+
private predicate reachesReturnRec(
1309+
Function f, DataFlow::Node read, DataFlow::Configuration cfg, PathSummary summary
1310+
) {
13041311
exists(DataFlow::Node mid, PathSummary oldSummary, PathSummary newSummary |
13051312
flowStep(read, cfg, mid, oldSummary) and
13061313
reachesReturn(f, mid, cfg, newSummary) and
@@ -1591,6 +1598,7 @@ private predicate flowIntoHigherOrderCall(
15911598
* Holds if there is a flow step from `pred` to `succ` described by `summary`
15921599
* under configuration `cfg`.
15931600
*/
1601+
pragma[noinline]
15941602
private predicate flowStep(
15951603
DataFlow::Node pred, DataFlow::Configuration cfg, DataFlow::Node succ, PathSummary summary
15961604
) {

0 commit comments

Comments
 (0)