Skip to content

[codex] refresh local scope naming#14

Merged
alvinwan merged 2 commits intomainfrom
dev/alvin/scope-local-refresh
Apr 5, 2026
Merged

[codex] refresh local scope naming#14
alvinwan merged 2 commits intomainfrom
dev/alvin/scope-local-refresh

Conversation

@alvinwan
Copy link
Copy Markdown
Owner

@alvinwan alvinwan commented Apr 5, 2026

Summary

  • refresh local name allocation so function-local bindings can reuse short names per scope while keeping cross-file/package renames on the shared allocator
  • address the actionable Codex review findings from the last compression PR around parameter assignments, local-instance method rewrites, constructor-call keyword rewrites, and import-alias callable metadata
  • regenerate the checked-in example outputs and update the top-level and benchmark README numbers to the new aggressive compression results

Why

The previous package-mode compression work still left a lot of gzip redundancy on the table because local names stayed unnecessarily unique across functions. Reusing short locals per scope improves both raw source size and compressed package size. Folding in the unresolved review fixes at the same time keeps the aggressive renaming path correct.

Impact

  • TexSoup raw Python source now goes from 98,181 bytes to 24,288 bytes (75.3% smaller)
  • TexSoup .tar.gz now goes from 23,101 bytes to 8,355 bytes (63.8% smaller)
  • the branch adds regression coverage for recursive functions, unrenamed parameter assignment stability, local-instance method rewrites, constructor-call keyword rewrites, and import-alias callable metadata

Validation

  • PYTHONPATH=. .venv/bin/python -m pytest
  • PYTHONPATH=. .venv/bin/python scripts/regenerate_examples.py --check
  • aggressive TexSoup package validation: upstream 78 tests passed

@alvinwan alvinwan marked this pull request as ready for review April 5, 2026 12:48
@alvinwan alvinwan merged commit 332272e into main Apr 5, 2026
10 checks passed
@alvinwan alvinwan deleted the dev/alvin/scope-local-refresh branch April 5, 2026 12:48
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 94d4b6bc0a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pymini/pymini.py
Comment on lines +163 to +165
):
if argument is not None and argument.annotation is not None:
self.visit(argument.annotation)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reserve nested function params before reusing outer local names

The new local-scope allocator only visits nested function argument annotations here, so nested parameter names themselves are never reserved. In rename_arguments=True mode this lets an outer binding be renamed to a nested parameter name, which breaks closures when the inner body references the outer variable (e.g. outer(long_value) with inner(a): return long_value + a is rewritten so both names become a, changing results). This regression is introduced by the new per-scope reuse logic and can silently alter runtime behavior.

Useful? React with 👍 / 👎.

Comment thread pymini/pymini.py
Comment on lines +185 to +186
def visit_Lambda(self, node):
return None
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include lambda/comprehension bindings in local-name reservation

By returning early for expression scopes, the collector ignores lambda/comprehension-local bindings when building used_names. That allows an enclosing variable to be renamed to the same identifier used inside a lambda/comprehension, which changes name resolution and output (for example, (lambda a: long_value + a) can become (lambda a: a + a)). This is a semantic regression triggered by local-name reuse in functions that contain these expressions.

Useful? React with 👍 / 👎.

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