Skip to content

fix(rewriter): preserve scoped nested renames - #339

Closed
fischeti wants to merge 2 commits into
masterfrom
pickle-scoped-rename-fix
Closed

fix(rewriter): preserve scoped nested renames#339
fischeti wants to merge 2 commits into
masterfrom
pickle-scoped-rename-fix

Conversation

@fischeti

@fischeti fischeti commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #338

Rewritting recursively with slang is a bit difficult with slang, since it does not persist for nested scoped names when replacing the syntax node. There is a helper functionrewrite_scoped_names_inplace which solves this, but it was simply missing for this particular case. I added some regression tests as well.

@fischeti

fischeti commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #342, which fixes this at the root instead of adding another manual re-walk.

The underlying issue is that replace() makes the replaced subtree opaque to the clone walk, so rewrite_scoped_names_inplace has to be remembered at every replacement site — this PR is what happens when it isn't, and VirtualInterfaceTypeSyntax and PackageImportItemSyntax are two more sites on master that are still missing it. #342 switches every rename to a token-level edit (keyed by owning node + child index, applied during the clone walk), so nested names are picked up by the ordinary visitor traversal and the helper goes away entirely.

@fischeti fischeti closed this Aug 3, 2026
fischeti added a commit that referenced this pull request Aug 4, 2026
…ments

Every rename the pickler performs is a single identifier token, but the
rewriter was replacing whole syntax nodes via deepClone + replace(). In
slang, replace() records a change keyed by the old node pointer and the
tree cloner stops descending as soon as it hits one, so any change queued
on a descendant is silently dropped. Nested scoped names therefore had to
be re-walked by hand (rewrite_scoped_names_inplace) at every replacement
site, which is easy to forget: the packed-dimension case in #338 was one
such missed site, and VirtualInterfaceTypeSyntax and PackageImportItemSyntax
were two more latent ones.

Token changes are keyed by (owning node, child index) and are applied
during the clone walk, so they compose with edits at any other depth.
Switching every handler to replaceToken() plus an unconditional
visitDefault() removes the whole category of bug rather than patching one
more site, and lets rewrite_scoped_names_inplace and every deepClone go.

Renaming a scoped name also no longer skips visitDefault, so the right
subtree of a renamed scoped name is now visited.

The regression test and fixtures are taken unchanged from #339, which this
supersedes. Pickled output is byte-identical to before for the existing
test project.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

bender pickle does not properly rename scoped name in packed dimensions

2 participants