Skip to content

Fix Reduction.inames_set to return frozenset instead of mutable set#998

Merged
inducer merged 2 commits intomainfrom
copilot/fix-redn-inames-set-return-type
Mar 29, 2026
Merged

Fix Reduction.inames_set to return frozenset instead of mutable set#998
inducer merged 2 commits intomainfrom
copilot/fix-redn-inames-set-return-type

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 29, 2026

Reduction.inames_set was a cached_property returning a mutable set, allowing callers to silently corrupt the cached value and affect all subsequent accesses.

expr = parse("sum(i, i**2)")
frozenset(expr.inames_set)          # frozenset({'i'})
expr.inames_set.add("bug")          # mutates the cache!
tuple(sorted(expr.inames_set))      # ('bug', 'i') — corrupted

Change

  • Reduction.inames_set now returns frozenset[str] instead of set[str], making the cached value immutable. All existing call sites using set operations (&, -, etc.) are unaffected since frozenset supports them.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI linked an issue Mar 29, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix lp.Reduction.inames_set to return frozenset Fix Reduction.inames_set to return frozenset instead of mutable set Mar 29, 2026
Copilot AI requested a review from inducer March 29, 2026 18:18
@inducer inducer marked this pull request as ready for review March 29, 2026 18:23
Copilot AI review requested due to automatic review settings March 29, 2026 18:23
@inducer inducer enabled auto-merge (squash) March 29, 2026 18:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a mutability hazard in Reduction.inames_set by ensuring the cached value cannot be modified by callers, preventing silent corruption of subsequent accesses.

Changes:

  • Change Reduction.inames_set (a cached_property) to return frozenset[str] instead of set[str].

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@inducer inducer merged commit 47c8999 into main Mar 29, 2026
21 checks passed
@inducer inducer deleted the copilot/fix-redn-inames-set-return-type branch March 29, 2026 19:00
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.

lp.Reduction.inames_set must return frozenset

3 participants