pathfinder: make LocatedHeaderDir immutable - #2647
Open
aryanputta wants to merge 1 commit into
Open
Conversation
locate_nvidia_header_directory() is functools.cache-backed and returns a mutable dataclass, so a caller that writes to the returned object changes what every later lookup of that libname returns for the life of the process. Freeze it, matching LocatedStaticLib and LocatedBitcodeLib, which are the other two public Located* return types. Signed-off-by: Aryan Putta <aryansputta@gmail.com>
Contributor
mdboom
approved these changes
Aug 20, 2026
Contributor
|
/ok to test 946d8b0 |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
closes #2646
locate_nvidia_header_directory()is@functools.cache-backed, so every caller gets the sameLocatedHeaderDirinstance. The dataclass was not frozen, so a write toabs_pathon a returned object changed what every later lookup of thatlibnamereturned for the rest of the process, including throughfind_nvidia_header_directory().This makes
LocatedHeaderDir@dataclass(frozen=True), matchingLocatedStaticLibandLocatedBitcodeLib, the other two publicLocated*return types. The__post_init__path normalization moves toobject.__setattr__, which is the standard frozen-dataclass form and keeps the normalization behavior identical. Freezing also makes the type hashable, which its two siblings already were.This is an intentional behavior change on a public type: code that previously mutated a returned
LocatedHeaderDirnow raisesdataclasses.FrozenInstanceErrorinstead of silently corrupting the shared cache entry. Nothing incuda_pathfinderor its test suite mutates one, and the two sibling types have always rejected it.Two tests are added: one drives the real cached lookup, asserts the write is rejected, and asserts a second lookup still returns the discovered directory; one pins hashability and value equality.
Checklist