Skip to content

Commit d789aa3

Browse files
owen-mcCopilot
andcommitted
Go: stabilize build constraint predicate evaluation
Evaluate the small set of build-constrained files bottom-up while keeping the public predicate demand-specialized. This avoids a large, schedule-dependent location join without changing query results. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 59bd591 commit d789aa3

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎go/ql/lib/semmle/go/Files.qll‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ class Folder extends Container, Impl::Folder {
4848
Folder getASubFolder() { result = this.getAChildContainer() }
4949
}
5050

51+
/**
52+
* Holds if `file` contains at least one build constraint.
53+
*
54+
* This is evaluated bottom-up to avoid propagating bound-file demands through location predicates.
55+
*/
56+
pragma[nomagic]
57+
private predicate buildConstrainedFile(ExtractedOrExternalFile file) {
58+
exists(BuildConstraintComment bc | file = bc.getFile())
59+
}
60+
5161
/** A file, including files that have not been extracted but are referred to as locations for errors. */
5262
class ExtractedOrExternalFile extends Container, Impl::File, Documentable, ExprParent,
5363
GoModExprParent, DeclParent, ScopeNode
@@ -69,7 +79,7 @@ class ExtractedOrExternalFile extends Container, Impl::File, Documentable, ExprP
6979

7080
/** Holds if this file contains at least one build constraint. */
7181
pragma[noinline]
72-
predicate hasBuildConstraints() { exists(BuildConstraintComment bc | this = bc.getFile()) }
82+
predicate hasBuildConstraints() { buildConstrainedFile(this) }
7383

7484
/**
7585
* Holds if this file contains build constraints that ensure that it

0 commit comments

Comments
 (0)