Skip to content

Reintroduce local string hoisting#8

Merged
alvinwan merged 3 commits intomainfrom
dev/alvin/reintroduce-optimizations
Apr 4, 2026
Merged

Reintroduce local string hoisting#8
alvinwan merged 3 commits intomainfrom
dev/alvin/reintroduce-optimizations

Conversation

@alvinwan
Copy link
Copy Markdown
Owner

@alvinwan alvinwan commented Apr 4, 2026

What changed

  • reintroduced repeated string hoisting in the narrowest safe form: function-local only
  • added regression coverage for the new hoisting behavior and for the still-deferred class-body case
  • refreshed the checked-in examples/pyminify.py output and README compression comparisons

Why

String hoisting was one of the optimizations we had backed out during the TexSoup hardening pass. This brings part of it back without reopening the broader scope-ordering and public-surface problems from module and class scopes.

Validation

  • .venv/bin/python -m pytest
  • .venv/bin/python scripts/regenerate_examples.py --check
  • upstream TexSoup tests against the minified package tree: 78 passed

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: b9cb38ffbd

ℹ️ 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 Outdated
mapping = {}
repeated = self.repeated_strings_by_scope.get(id(node), ())
if repeated:
mapping = {value: next(self.generator) for value in repeated}
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 hoisted names against non-Name bindings

RepeatedStringRewriter allocates helper identifiers with next(self.generator), but that generator is seeded from VariableNameCollector.visit_Name, so bindings that are not ast.Name nodes (for example lambda/function parameters and names declared via global/nonlocal) are not reserved. When a collision occurs, hoisted literals can silently change runtime behavior (e.g. lambda b: ("hello", "hello") becomes (b, b)) or make valid input fail to compile (SyntaxError: name 'b' is assigned to before global declaration).

Useful? React with 👍 / 👎.

@alvinwan alvinwan merged commit 34b6c95 into main Apr 4, 2026
10 checks passed
@alvinwan alvinwan deleted the dev/alvin/reintroduce-optimizations branch April 4, 2026 12:26
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