Skip to content

feat: package layout alignment and lexical scope analysis - #4

Merged
SizzleUnrlsd merged 7 commits into
mainfrom
feat/semantic-scopes
Sep 3, 2026
Merged

SizzleUnrlsd merged 7 commits into
mainfrom
feat/semantic-scopes

Conversation

@SizzleUnrlsd

@SizzleUnrlsd SizzleUnrlsd commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Opens Phase 2 of docs/architecture.md (§4.1 ScopeAnalysis) and closes the Phase 1 repository-layout item (§37).

  • Acceptance tests first: architectural boundaries, PyHIR scoping nodes, scope analysis contract, --emit-ir integration.
  • semantic/ package: import binding and canonical symbols move out of frontend; HIR→PyIR lowering moves into ir; frontend.build_hir is the only public frontend entry point, so no ast object crosses the CLI.
  • PyHIR gains Global, Nonlocal, Class and Comprehension nodes.
  • semantic/scopes.py: immutable scope tree with Python resolution rules (whole-function locality, global/nonlocal, class bodies skipped by nested functions, comprehension scopes).
  • Lowering resolves names through the ScopeAnalysis. A name read before a later assignment is now a local instead of the module import it shadowed.

Roadmap

Verification

python -m mypy && python -m ruff check . && python -m pytest — 74 passed.

Not lowered yet, with a source-located diagnostic: free variables in nested functions, assignment to global/nonlocal names, classes and comprehensions inside functions. They wait on the Phase 3 CFG and PyIR instructions.

🤖 Generated with Claude Code

SizzleUnrlsd and others added 5 commits September 3, 2026 04:56
Move import binding and canonical symbols into semantic/, HIR-to-PyIR lowering
into ir/, and expose frontend.build_hir as the only public frontend entry point
so parser objects never leave the frontend.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Represent global and nonlocal declarations, class definitions and list, set
and generator comprehensions so scope analysis can be built from PyHIR.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Build an immutable scope tree from PyHIR with Python resolution rules: whole-function
locality, global and nonlocal redirection, class bodies skipped by nested functions,
and comprehension scopes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Lowering no longer tracks locals itself: names are classified by the semantic
ScopeAnalysis, so a name assigned anywhere in a function is local for the whole
function and only module-level bindings can resolve to canonical import symbols.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@SizzleUnrlsd SizzleUnrlsd self-assigned this Sep 3, 2026
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@SizzleUnrlsd SizzleUnrlsd changed the title feat/semantic scopes feat: package layout alignment and lexical scope analysis Sep 3, 2026
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@SizzleUnrlsd
SizzleUnrlsd merged commit 7d73899 into main Sep 3, 2026
6 checks passed
@SizzleUnrlsd
SizzleUnrlsd deleted the feat/semantic-scopes branch September 3, 2026 03:44
@SizzleUnrlsd SizzleUnrlsd mentioned this pull request Sep 3, 2026
6 tasks done
SizzleUnrlsd added a commit that referenced this pull request Sep 3, 2026
feat: package layout alignment and lexical scope analysis
@SizzleUnrlsd SizzleUnrlsd mentioned this pull request Sep 3, 2026
8 tasks done
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