Skip to content

Python: bind captured type-tracking jumps from source - #22407

Draft
yoff wants to merge 2 commits into
github:yoff/python-shared-cfg-dataflow-flipfrom
yoff:yoff-python-dispatch-plan-cost
Draft

Python: bind captured type-tracking jumps from source#22407
yoff wants to merge 2 commits into
github:yoff/python-shared-cfg-dataflow-flipfrom
yoff:yoff-python-dispatch-plan-cost

Conversation

@yoff

@yoff yoff commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Depends on #21925.

Summary

This rewrites the captured-scope type-tracking jump so the scope-entry definition binds the source variable before the source CFG node is matched. The relation is unchanged, but the evaluator no longer materializes the high-duplication store/variable cross product induced by the previous join shape.

The old constraints introduced an independent Cfg::DefinitionNode def, related def to var.getVariable().getAStore(), and only then constrained nodeFrom = def. The new form binds e from nodeTo, derives var from e, and directly applies the same DefinitionNode.getNode() = store constraint to nodeFrom. This is existential elimination with the same type and scope restrictions, not a semantic change.

Diagnostic commit

Commit 1 is intentionally a semantic call-target invariant diagnostic, not an inline MISSING/SPURIOUS red-state. It records the valid captured-callable targets produced for decorator wrappers and captured type parameters in comprehensions, including the mechanism behind Airflow's legitimate _RegexpIgnoreRule.compile and _GlobIgnoreRule.compile targets. It passes before and after the optimization so that commit 2 must preserve the relation exactly. An annotation that failed before the fix would assert an artificial semantic delta and would not test this behavior-preserving plan optimization.

Exact Airflow measurement

Measured with CodeQL 2.26.2 on Airflow a9da0f7fb48dc7526b2745be3e8fe64e1c775da2, comparing exact #21925 head 1a8e317b4a328bea1059453a2ab3ba6eada09e3f to this branch:

  • Call-target diagnostic: identical 59,732-edge sets; tuples joined 1,032,403,207 -> 66,969,953 (-93.5%); maximum duplication 1,473,981 -> 4,053; evaluator wall time 59.9s -> 6.2s.
  • py/clear-text-logging-sensitive-data: every result tuple is preserved (130 alerts, 256,708 path edges, 102,385 path nodes, 116,976 subpaths); tuples joined 1,329,594,809 -> 242,111,554 (-81.8%); evaluator wall time 94s -> 14.4s.

No valid call target is suppressed.

Limitations

These measurements cover one exact substantial Airflow database and two query shapes. The fix does not reduce legitimate semantic call-graph or path growth, and fleet-wide performance remains to be confirmed. No DCA was launched.

Tests

  • captured-call-targets/CallTargets.ql
  • typetracking/tracked.ql
  • QL formatting check for the changed library and diagnostic query

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The previous capturedJumpStep shape introduced an independent
Cfg::DefinitionNode and related it to the captured variable before nodeTo
bound the relevant scope-entry definition. On substantial databases, the
evaluator chose a plan that materialized a high-duplication store/variable
join before applying the target entry and source-node constraints.

Bind the scope-entry definition from nodeTo first, derive its source variable,
and then match nodeFrom's DefinitionNode directly to that variable's store.
This is relation-equivalent existential elimination: the old
nodeFrom.asCfgNode() = def and def.getNode() = store constraints become
nodeFrom.asCfgNode().(Cfg::DefinitionNode).getNode() = store, preserving the
DefinitionNode type restriction and the unchanged enclosing-scope condition.

On Airflow a9da0f7 with CodeQL 2.26.2, against exact github#21925 head
1a8e317:

* The call-target diagnostic retains the identical 59,732-edge set while
  tuples joined fall from 1,032,403,207 to 66,969,953 (-93.5%), maximum
  duplication falls from 1,473,981 to 4,053, and evaluator wall time falls
  from 59.9s to 6.2s.
* py/clear-text-logging-sensitive-data retains every result tuple (130 alerts,
  256,708 path edges, 102,385 path nodes, and 116,976 subpaths) while tuples
  joined fall from 1,329,594,809 to 242,111,554 (-81.8%) and evaluator wall
  time falls from 94s to 14.4s.

The preceding commit is intentionally a semantic call-target invariant
diagnostic that passes on the unoptimized relation and after this rewrite. An
inline MISSING/SPURIOUS red-state would assert an artificial semantic delta;
this optimization must preserve every valid captured call target.

These measurements cover one exact substantial Airflow database and two query
shapes. No DCA was run, the fix does not reduce legitimate call-graph or path
growth, and broader fleet performance remains to be confirmed separately.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5dfda5f5-08c8-481b-9ecb-299018701497
@yoff
yoff force-pushed the yoff-python-dispatch-plan-cost branch from f2a75c8 to d7066b7 Compare August 21, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant