Skip to content

Commit d707c52

Browse files
committed
Ruby: Avoid computing full fastTC for AstNode::getParent
DIL before ``` /* AST::AstNode */ AST#87953007::Cached::TAstNode result) = fastTC(Module#fe82a56b::parent#1#ff/2) . Module#fe82a56b::enclosingModule#1#ff(/* AST::AstNode */ AST#87953007::Cached::TAstNode node, /* Module::ModuleBase */ AST#87953007::Cached::TAstNode result) :- exists(/* AST::AstNode */ AST#87953007::Cached::TAstNode call_result#2 | Module#2a43f566::ModuleBase#f(result), project#AST#a6718388::AstNode::getAChild#1#dispred(result, call_result#2), ( node = call_result#2; #Module#fe82a56b::parent#1Plus#ff(node, call_result#2) ) ) . ``` DIL after ``` incremental Module#fe82a56b::enclosingModule#1#ff(/* AST::AstNode */ AST#87953007::Cached::TAstNode node, /* Module::ModuleBase */ AST#87953007::Cached::TAstNode result) :- ( Module#2a43f566::ModuleBase#f(result), exists(cached dontcare string _ | AST#a6718388::AstNode::getAChild#1#dispred(result, _, node) ) ); exists(/* AST::AstNode */ AST#87953007::Cached::TAstNode mid | Module#2a43f566::ModuleBase#f(result), rec Module#fe82a56b::enclosingModule#1#ff(mid, result), not(Module#2a43f566::ModuleBase#f(mid)), not(Method#8b49e67f::Block#f(mid)), exists(cached dontcare string _ | AST#a6718388::AstNode::getAChild#1#dispred(mid, _, node) ) ) | [base_case] Module#2a43f566::ModuleBase#f(result), project#AST#a6718388::AstNode::getAChild#1#dispred(result, node) | [delta_order] exists(/* AST::AstNode */ AST#87953007::Cached::TAstNode mid | Module#2a43f566::ModuleBase#f(result), delta previous rec Module#fe82a56b::enclosingModule#1#ff(mid, result), not(Module#2a43f566::ModuleBase#f(mid)), not(Method#8b49e67f::Block#f(mid)), project#AST#a6718388::AstNode::getAChild#1#dispred(mid, node) ), not(previous rec Module#fe82a56b::enclosingModule#1#ff(node, result)) | [delta_order_up_to_500000] exists(/* AST::AstNode */ AST#87953007::Cached::TAstNode mid | delta previous rec Module#fe82a56b::enclosingModule#1#ff(mid, result), Module#2a43f566::ModuleBase#f(result), not(Module#2a43f566::ModuleBase#f(mid)), not(Method#8b49e67f::Block#f(mid)), project#AST#a6718388::AstNode::getAChild#1#dispred(mid, node) ), not(previous rec Module#fe82a56b::enclosingModule#1#ff(node, result)) . ```
1 parent 5cadd3c commit d707c52

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

ruby/ql/lib/codeql/ruby/ast/internal/Module.qll

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,15 @@ private import ResolveImpl
486486
* methods evaluate the block in the context of some other module/class instead of
487487
* the enclosing one.
488488
*/
489-
private ModuleBase enclosingModule(AstNode node) { result = parent*(node).getParent() }
490-
491-
private AstNode parent(AstNode n) {
492-
result = n.getParent() and
493-
not result instanceof ModuleBase and
494-
not result instanceof Block
489+
private ModuleBase enclosingModule(AstNode node) {
490+
result = node.getParent()
491+
or
492+
exists(AstNode mid |
493+
result = enclosingModule(mid) and
494+
mid = node.getParent() and
495+
not mid instanceof ModuleBase and
496+
not mid instanceof Block
497+
)
495498
}
496499

497500
private Module getAncestors(Module m) {

0 commit comments

Comments
 (0)