Skip to content

Commit 77b2811

Browse files
committed
update key to just be cloned
1 parent db3754f commit 77b2811

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

mypy/build.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -993,11 +993,10 @@ def __init__(
993993
self.import_options: dict[str, bytes] = {}
994994
# Cache for transitive dependency check (expensive).
995995
self.transitive_deps_cache: dict[tuple[int, int], bool] = {}
996-
# Cache for options_snapshot() keyed by id() of the cloned Options.
997-
# Most modules share a handful of distinct configs. The keepalive
998-
# list keeps clones reachable so id() is stable for cache keys.
999-
self.options_snapshot_cache: dict[int, tuple[str, str]] = {}
1000-
self._options_snapshot_keepalive: list[Options] = []
996+
# Cache for options_snapshot() keyed by the cloned Options. Options is
997+
# hashed by identity, and most modules share a handful of distinct
998+
# configs, so this collapses ~all calls onto a few entries.
999+
self.options_snapshot_cache: dict[Options, tuple[str, str]] = {}
10011000
# Packages for which we know presence or absence of __getattr__().
10021001
self.known_partial_packages: dict[str, bool] = {}
10031002

@@ -1986,16 +1985,13 @@ def options_snapshot(module: str, manager: BuildManager) -> dict[str, object]:
19861985
result[key] = val
19871986
return result
19881987
cache = manager.options_snapshot_cache
1989-
key = id(cloned)
1990-
cached = cache.get(key)
1988+
cached = cache.get(cloned)
19911989
if cached is None:
19921990
platform_opt, values = cloned.select_options_affecting_cache()
19931991
buf = WriteBuffer()
19941992
write_json_value(buf, cast(JsonValue, values))
19951993
cached = (platform_opt, hash_digest(buf.getvalue()))
1996-
cache[key] = cached
1997-
# Keep cloned reachable so its id() is not reused by a later clone.
1998-
manager._options_snapshot_keepalive.append(cloned)
1994+
cache[cloned] = cached
19991995
return {"platform": cached[0], "other_options": cached[1]}
20001996

20011997

0 commit comments

Comments
 (0)