Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Co-locate retained definition usage state#26019

Merged
charliermarsh merged 3 commits into
mainfrom
charlie/codex-retained-definition-used-state
Jun 25, 2026
Merged

[ty] Co-locate retained definition usage state#26019
charliermarsh merged 3 commits into
mainfrom
charlie/codex-retained-definition-used-state

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Jun 15, 2026

Copy link
Copy Markdown
Member

Summary

We now encode whether each retained definition is used directly in RetainedDefinitionState, instead of retaining a separate parallel boolean vector in UseDefMap.

The mutable builder continues to keep all_definitions and used_bindings separate, then combines them only when freezing the immutable map. This keeps mutation straightforward while removing one allocation and one byte per definition from the retained representation. A compile-time size assertion guarantees that the combined enum remains the same size as DefinitionState.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 15, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 94.47%. The percentage of expected errors that received a diagnostic held steady at 89.19%. The number of fully passing files held steady at 95/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
flake8 29.15MB 29.03MB -0.41% (122.58kB) ⬇️
trio 70.61MB 70.39MB -0.32% (228.52kB) ⬇️
sphinx 167.31MB 166.91MB -0.24% (407.02kB) ⬇️
prefect 450.62MB 449.53MB -0.24% (1.09MB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
semantic_index 8.03MB 7.91MB -1.49% (122.58kB) ⬇️

trio

Name Old New Diff Outcome
semantic_index 18.00MB 17.78MB -1.24% (228.52kB) ⬇️

sphinx

Name Old New Diff Outcome
semantic_index 37.89MB 37.49MB -1.05% (407.02kB) ⬇️

prefect

Name Old New Diff Outcome
semantic_index 115.48MB 114.39MB -0.94% (1.09MB) ⬇️

@astral-sh-bot

astral-sh-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh force-pushed the charlie/codex-retained-definition-used-state branch from 1e02913 to 7a60dc2 Compare June 17, 2026 01:24
@charliermarsh charliermarsh force-pushed the charlie/codex-retained-definition-used-state branch from 7a60dc2 to 74278e8 Compare June 25, 2026 00:16
@charliermarsh charliermarsh marked this pull request as ready for review June 25, 2026 00:44
@charliermarsh charliermarsh requested a review from a team as a code owner June 25, 2026 00:44
@charliermarsh charliermarsh added the performance Potential performance improvement label Jun 25, 2026
@astral-sh-bot astral-sh-bot Bot requested a review from carljm June 25, 2026 00:45
@charliermarsh charliermarsh removed the request for review from carljm June 25, 2026 00:46
@charliermarsh charliermarsh merged commit e61a540 into main Jun 25, 2026
63 checks passed
@charliermarsh charliermarsh deleted the charlie/codex-retained-definition-used-state branch June 25, 2026 01:05
charliermarsh added a commit that referenced this pull request Jun 25, 2026
## Summary

Stacked on #26019.

We reserve `ScopedDefinitionId` zero for the implicit unbound or
undeclared definition. The mutable use-def builder needs that sentinel
while constructing its indexed flow state, but retaining an explicit
`Undefined` entry in every frozen `UseDefMap` is unnecessary.

This introduces a small retained-definition wrapper that omits the
sentinel when freezing the map and synthesizes it for lookup and
enumeration. Definition IDs and the builder representation remain
unchanged. Coverage for an empty scope verifies that the implicit
definition remains observable through both APIs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Potential performance improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant