python / python/cpython

frozenset() created from a set literal is not untracked by the GC

Open
#155,181 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

gh-140232 made frozensets untracked by the GC when none of their elements can be tracked. However, the compiler's fast path for frozenset({...}) and frozenset({... for ...}) freezes the built set in place with _PySet_Freeze() (INTRINSIC_BUILD_FROZENSET), which skips that check, so the result stays tracked:

>>> import gc
>>> s = {1, 2}
>>> gc.is_tracked(frozenset(s))
False
>>> gc.is_tracked(frozenset({1, 2}))
True

I'm preparing a PR for this.

Linked PRs
  • gh-155182

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducer using gc.is_tracked, then inspect the compiler fast path named INTRINSIC_BUILD_FROZENSET and _PySet_Freeze(). Done means frozenset({...}) and frozenset({... for ...}) have the same tracking behavior as frozenset(s), with coverage for the reported cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.