Skip to content

Commit ac5fa62

Browse files
yoffCopilot
andcommitted
Python: inline init_module_submodule_defn into ImportResolution
The new-dataflow ImportResolution module only used semmle.python.essa.SsaDefinitions for the 5-line helper predicate SsaSource::init_module_submodule_defn. Inline it locally and drop the dependency on legacy SsaDefinitions. This is the only remaining direct import of semmle.python.essa.* in the new dataflow stack, so dropping it makes the layering cleaner. Semantic noop on the current SSA: SsaSourceVariable.getName() and GlobalVariable.getId() both project the same DB column (variable(_,_,result)), and the old call's 'init.getEntryNode() = f' join was just constraining init = package via Scope.getEntryNode()'s functional uniqueness. RA dump of accesses.ql confirms only the expected predicate-rename shuffle; all 70 dataflow + ApiGraphs library tests pass. This factors out commit 8cab5a2 from the larger shared-CFG migration #21925. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5fb75ac commit ac5fa62

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

python/ql/lib/semmle/python/dataflow/new/internal/ImportResolution.qll

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,19 @@ private import semmle.python.dataflow.new.DataFlow
99
private import semmle.python.dataflow.new.internal.ImportStar
1010
private import semmle.python.dataflow.new.TypeTracking
1111
private import semmle.python.dataflow.new.internal.DataFlowPrivate
12-
private import semmle.python.essa.SsaDefinitions
12+
13+
/**
14+
* Holds if `init` is a package's `__init__.py` and `var` is a global variable in
15+
* `init` whose name matches a submodule of the package.
16+
*
17+
* Inlined from `SsaSource::init_module_submodule_defn` to avoid pulling
18+
* `semmle.python.essa.SsaDefinitions` into the new dataflow stack.
19+
*/
20+
private predicate initModuleSubmoduleDefn(GlobalVariable var, Module init) {
21+
init.isPackageInit() and
22+
exists(init.getPackage().getSubModule(var.getId())) and
23+
var.getScope() = init
24+
}
1325

1426
/**
1527
* Python modules and the way imports are resolved are... complicated. Here's a crash course in how
@@ -326,7 +338,7 @@ module ImportResolution {
326338
// imported yet.
327339
exists(string submodule, Module package, EssaVariable var |
328340
submodule = var.getName() and
329-
SsaSource::init_module_submodule_defn(var.getSourceVariable(), package.getEntryNode()) and
341+
initModuleSubmoduleDefn(var.getSourceVariable(), package) and
330342
m = getModuleFromName(package.getPackageName() + "." + submodule) and
331343
result.asCfgNode() = var.getDefinition().(EssaNodeDefinition).getDefiningNode()
332344
)

0 commit comments

Comments
 (0)