Skip to content

Commit 8aa354c

Browse files
committed
QL: fix performance
1 parent 6f4370a commit 8aa354c

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

ql/src/codeql_ql/ast/Ast.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ class AstNode extends TAstNode {
7070
predicate hasAnnotation(string name) { this.getAnAnnotation().getName() = name }
7171

7272
/** Gets an annotation of this AST node. */
73-
Annotation getAnAnnotation() { toQL(this).getParent() = toQL(result).getParent() }
73+
cached
74+
Annotation getAnAnnotation() {
75+
toQL(this).getParent() = pragma[only_bind_out](toQL(result)).getParent()
76+
}
7477

7578
/**
7679
* Gets the predicate that contains this AST node.

ql/src/codeql_ql/ast/internal/Module.qll

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,16 @@ private predicate resolveSelectionName(Import imp, ContainerOrModule m, int i) {
148148

149149
cached
150150
private module Cached {
151-
// TODO: Use `AstNode::getParent` once it is total
152-
private QL::AstNode parent(QL::AstNode n) {
153-
result = n.getParent() and
154-
not n instanceof QL::Module
155-
}
156-
157151
private Module getEnclosingModule0(AstNode n) {
158-
AstNodes::toQL(result) = parent*(AstNodes::toQL(n).getParent())
152+
not n instanceof Module and
153+
(
154+
n = result.getAChild(_)
155+
or
156+
exists(AstNode prev |
157+
result = getEnclosingModule0(prev) and
158+
n = prev.getAChild(_)
159+
)
160+
)
159161
}
160162

161163
cached

0 commit comments

Comments
 (0)