Skip to content

feat: control-flow syntax pass - #53

Merged
SizzleUnrlsd merged 2 commits into
mainfrom
feat/syntax-control-flow
Sep 4, 2026
Merged

SizzleUnrlsd merged 2 commits into
mainfrom
feat/syntax-control-flow

Conversation

@SizzleUnrlsd

Copy link
Copy Markdown
Contributor

Summary

Second syntax pass, driven by the twelve repositories under tests-project/: the constructs that add control flow or a scope inside an expression, plus the last statement forms they used.

  • Acceptance tests first (test: define conditional expressions, comprehensions, lambdas, sets, globals and chained assignments), implementation follows.
  • PyHIR stays faithful: Conditional, Lambda, Set, dictionary comprehensions (Comprehension.key) and tuple comprehension targets; scopes give lambdas a function scope and comprehensions keep their own, as before. A chained assignment becomes one hidden local assigned once and every target assigned from it.
  • The CFG builder lays expression-level control flow out as real blocks: a conditional expression becomes a branch writing a synthetic local, a comprehension becomes nested loops and ifs filling a synthetic list, set or dict through append, add or an item store, with comprehension variables renamed to synthetic locals so they do not leak into the function. The CFG carries synthetic_locals and the lowering treats them as locals; everything downstream, SSA, taint, heap, refutation, sees ordinary control flow, so taint through comprehensions comes from the existing container rules. A conditional or comprehension inside a while condition is reported as unsupported rather than mislaid.
  • Lowering: lambdas and nested function definitions become MakeFunction values bound to their name, their bodies not analysed yet, and calls to them stay conservative; assignments to global names become SetGlobal; set literals build BuildSet.
  • Call graph names are made unique when a module defines the same qualified name twice, a property and its setter for instance, which crashed the analysis of one repository.
  • Existing tests that used a nested function as the canonical unsupported construct now use a class defined inside a function.

Measured on the twelve repositories: ten analyse with no syntax note at all; the last two use a match statement and a del statement.

@SizzleUnrlsd SizzleUnrlsd self-assigned this Sep 4, 2026
@SizzleUnrlsd
SizzleUnrlsd merged commit 3c5c336 into main Sep 4, 2026
6 checks passed
@SizzleUnrlsd
SizzleUnrlsd deleted the feat/syntax-control-flow branch September 4, 2026 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant