cask/config: define instance variables in a consistent order - #23388
Merged
Conversation
Signed-off-by: Patrick Linnane <patrick@linnane.io>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Cask::Config to eagerly define all instance variables in #initialize (in a consistent order) to avoid Ruby “shape variation” performance warnings and ensure all instances share the same object shape.
Changes:
- Eagerly defines
@defaultand@env(asnilwhen not provided) and predeclares memoized directory ivars asnilin#initialize. - Simplifies directory accessors by removing inline
T.let(...)inside||=now that ivars are declared up-front. - Adds an RSpec example intended to lock the instance variable list/order for regression detection.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Library/Homebrew/cask/config.rb | Predeclares all Cask::Config ivars in #initialize and simplifies memoized directory accessors. |
| Library/Homebrew/test/cask/config_spec.rb | Adds a spec asserting consistent instance variable definition ordering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Follows #22362 by defining all of
Cask::Config's instance variables up front in#initialize, in a consistent order, so every instance shares one object shape. OneConfigis built perCask, plus more via.from_args,.from_jsonand#merge.@defaultand@envwere only assigned when the matching keyword argument was passed, and the five directory accessors created their ivars lazily on first read, so instances took different shape transitions depending on which arguments were given and which accessor was hit first. Onmain:That is silent with this change.
The accessors keep their
||=memoization and the ivars are predeclared asnil, so nothing is computed any earlier than before. Evaluation order in#initializeis unchanged, so an invaliddefault:still raises before an invalidexplicit:.A
config_spec.rbexample locks the ivar list and its order so a new lazy ivar added without predeclaring it is caught in CI.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Claude Code (Opus 5) drafted the implementation and tests; I reviewed the diff, verified the new spec fails against the old initializer and passes with it, confirmed the warning reproduces on
mainand is silent here, and ranbrew lgtmlocally.