This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Removes unnecessary Accounts constructors #34471
Merged
brooksprumo
merged 4 commits into
solana-labs:master
from
brooksprumo:accounts/ctor-refactor2
Dec 15, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost all of the cases you've touched look something like this one:
Wondering if we should make
Accounts::new()
take anAccountsDb
instead ofArc<AccountsDb>
, and then we can shift the repeatedArc::new()
insideAccounts::new()
?Also, @apfitzge had a clever suggestion on one of my PR's the other day that might be applicable here if we want to accept
Arc<AccountsDb>
orAccountsDb
: #34449 (comment)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd prefer if
Accounts::new()
tookAccountsDb
instead ofArc<AccountsDb>
. But,Bank::_new_from_parent()
clones the AccountsDb into the new bank's Accounts, so there must be a ctor that takes anArc<AccountsDb>
.solana/runtime/src/bank.rs
Line 1274 in aaccbdd
We could keep a second ctor around, but I'm really trying to reduce ctors where possible.
Clever, indeed! Since Arc already has implements
From<T> for Arc<T>
, this allows the caller to use.into()
already. This still requires the caller to do something special. I understand theInto<Arc<AccountsDb>>
as a function parameter would remove the burden from the caller, which may be nice. I'm on the fence. Want me to do theInto
way? I'll do basically anything to avoid adding more constructors heh.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆 😆 😆
I'm a little on the fence as well ha and don't have too strong of an option; I just saw the repeated code so figured I'd mention it.
That being said, I think this PR is still valuable as-is;
Arc::new()
is pretty simple and having some of these repeated is probably better than someone having to choose from a handful of constructors. So, I think we could defer a decision to another PR and ship this one as-isThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've come around to the Into<> idea. Here's a PR for it: #34476.
(I'm going to merge this PR as-is, since it feels like a complete thought, and the Into<> one is a different thought.)