From b69f8532d03339a85acb95e1d1f9f04c74cea838 Mon Sep 17 00:00:00 2001 From: Asger F Date: Thu, 9 Oct 2025 15:17:36 +0200 Subject: [PATCH] JS: Moving 'cache' annotations outside the parameterised module --- .../ql/lib/semmle/javascript/ApiGraphs.qll | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/javascript/ql/lib/semmle/javascript/ApiGraphs.qll b/javascript/ql/lib/semmle/javascript/ApiGraphs.qll index 88e6218aa43..62ee4053561 100644 --- a/javascript/ql/lib/semmle/javascript/ApiGraphs.qll +++ b/javascript/ql/lib/semmle/javascript/ApiGraphs.qll @@ -818,7 +818,6 @@ module API { predicate inScope(DataFlow::Node node); } - cached private module Stage { /** * Holds if `rhs` is the right-hand side of a definition of a node that should have an @@ -1010,7 +1009,6 @@ module API { /** * Holds if `rhs` is the right-hand side of a definition of node `nd`. */ - cached predicate rhs(TApiNode nd, DataFlow::Node rhs) { (S::inScope(rhs) or S::isAdditionalDefRoot(nd)) and exists(string m | nd = MkModuleExport(m) | exports(m, rhs)) @@ -1258,7 +1256,6 @@ module API { /** * Holds if `ref` is a use of node `nd`. */ - cached predicate use(TApiNode nd, DataFlow::Node ref) { (S::inScope(ref) or S::isAdditionalUseRoot(nd)) and ( @@ -1380,7 +1377,6 @@ module API { /** * Gets a node that is inter-procedurally reachable from `nd`, which is a use of some node. */ - cached DataFlow::SourceNode trackUseNode(DataFlow::SourceNode nd) { result = trackUseNode(nd, false, 0, "") } @@ -1431,7 +1427,6 @@ module API { /** * Gets a node that inter-procedurally flows into `nd`, which is a definition of some node. */ - cached DataFlow::SourceNode trackDefNode(DataFlow::Node nd) { result = trackDefNode(nd, DataFlow::TypeBackTracker::end()) } @@ -1454,7 +1449,6 @@ module API { /** * Holds if there is an edge from `pred` to `succ` in the API graph that is labeled with `lbl`. */ - cached predicate edge(TApiNode pred, Label::ApiLabel lbl, TApiNode succ) { Stages::ApiStage::ref() and exists(string m | @@ -1520,7 +1514,6 @@ module API { * Gets a call to a promisified function represented by `callee` where * `bound` arguments have been bound. */ - cached DataFlow::InvokeNode getAPromisifiedInvocation(TApiNode callee, int bound, TApiNode succ) { exists(DataFlow::SourceNode src | use(callee, src) and @@ -1541,7 +1534,36 @@ module API { predicate inScope(DataFlow::Node node) { any() } } - import Stage + private module Stage1 = Stage; + + cached + private module Cached { + cached + predicate rhs(TApiNode nd, DataFlow::Node rhs) { Stage1::rhs(nd, rhs) } + + cached + predicate use(TApiNode nd, DataFlow::Node ref) { Stage1::use(nd, ref) } + + cached + DataFlow::SourceNode trackUseNode(DataFlow::SourceNode nd) { + result = Stage1::trackUseNode(nd) + } + + cached + DataFlow::SourceNode trackDefNode(DataFlow::Node nd) { result = Stage1::trackDefNode(nd) } + + cached + predicate edge(TApiNode pred, Label::ApiLabel lbl, TApiNode succ) { + Stage1::edge(pred, lbl, succ) + } + + cached + DataFlow::InvokeNode getAPromisifiedInvocation(TApiNode callee, int bound, TApiNode succ) { + result = Stage1::getAPromisifiedInvocation(callee, bound, succ) + } + } + + import Cached /** * Holds if there is an edge from `pred` to `succ` in the API graph.