-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename Registry trait #3006
Comments
Looking at the code to try and derive inferences I came up with the following notes: // Desired:
// * a source is a place to find packages (specifically their source code)
// * a registry is a type of source which contains multiple released packages (not WIP packages)
//
// "perhaps both traits should be renamed to `RemoteSource: Source` or `CachedSource: Source`"
/// The source of information about a group of packages
trait Registry {}
/// A Source finds and downloads remote packages based on names and versions.
trait Source: Registry {}
// The following have both Registry and Source impls:
struct DirectorySource {}
struct GitSource {}
struct PathSource {}
struct RegistrySource {}
struct ReplacedSource {}
/// A registry of known packages.
/// Contains a collection of `Source`s, which are used to load a `Package` from.
struct PackageRegistry {}
impl Registry for PackageRegistry {} Note I think the "registry" referred to above only applies to Is the parallel of I've been thinking of names like "QuerySource", given "query" is effectively the defining method of Thoughts? |
Excellent! I think this is a core observation here! Note that we are not really using And that probably means that I think the path would be
|
Try & simplify Registry vs Source confusion Refs #3006. I tried to go further and replace references of `Registry` with `PackageRegistry`, but I ran into lifetime issue in `ops::resolve_with_previous` which I think has to do with no longer passing `PackageRegistry` as a `Registry` trait object (with a new and distinct lifetime).
Err so now neither is a supertrait of the other? That gives 2^2 = 4 combinations, are all 4 needed? |
They are disjoint now: each type is either only a source, or only a registry. I still think that rename is needed, because the term First of all, we have sources. a During resolution, Cargo works with packages from different sources, Registry the trait just bundles all those sources in a single struct, it does not have an identity. So a possible name for Registry trait would be SourceSet. However, I don't have a nice suggestion for Also, we have a thing called |
From #5432, I'm going to assume @alexcrichton might have an opinion about "naming things". 😉 |
Yes at the very least let's do that. Otherwise it's hard to even discuss the issues.
Err a type can implement both or neither in principle.
This would be the registry type, right?
I'd make a trait with all the methods, and a sub trait with just the identity part. A set of sources is also a source, but a set of "identified sources" doesn't itself have an identity. Right now we have identical methods in both traits which seems funny :). |
Wouldn't it be better to just remove the indirection of I tried to go about that, but ran into lifetime issues (see #5476 (comment)). |
@dwijnand I saw you tried to do that, and it seems reasonable, but what about the test that mocks it up? Also, I like the idea that sources (sans identification) compose. To me, composition like that is just a canary for a good design, and should be pursued even absent a concrete use-case. |
No idea, I didn't get to it as I got stuck trying to check the borrowing in the main code. 🙂 But (hand wavey) if PackageRegistry is a set of sources my hope was the tests could use real PackageRegistry with a singleton set of a replacement source. |
@dwijnand I guess think about this way: even if we did get rid of the trait, I rather |
I'm not that fussed, either way. If a consensus is reached and the work hasn't been done, I'm happy to (attempt to) do the grunt work. |
Sounds good. Thanks for getting the ball rolling :). |
The "lifetime issues" are so interesting, that I've even blogged about them! :) The TL;DR is that using a trait object here indeed simplifies lifetime management. This, and the presence of the mock suggests that we probably shouldn't try to replace registry trait object with a concrete struct.
@Ericson2314 the fact that methods have the same signature and name does not mean that their semantics is also identical :) It is wrong to pass bare sources to various resolve-related method. This has an interesting practical implication as well. Previously, one could see that resolve operates on So, my opinion here:
So, we should just rename the three "Registry"s. I personally can't think of a good name for them though :( Something along the lines of |
I'm...glad you have the ":)".
Why? Does it need to be wrong? :) |
AFIAK, the terminology we want is:
But right the
Registry
trait is a super-trait ofSource
. At the very leastRegistry
should get a new name, but perhaps both traits should be renamed likeRemoteSource: Source
orCachedSource: Source
.The text was updated successfully, but these errors were encountered: