-
Notifications
You must be signed in to change notification settings - Fork 36
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
Don't require a clone in Solver's methods #18
Comments
We are mostly interested in the iterating over versions to pick one, which is done in Otherwise, I opted for |
As an example: |
Doesn't sound like a good thing XD |
However, the nice thing about having an actual Regarding PS: caching is probably a concern for another issue, but directly related to this one so I wanted to add it here |
We can change resolve to only use iterators. So I started with returning pub trait DependencyProvider<P: Package, V: Version> {
type IV: IntoIterator<Item = V>;
...
fn list_available_versions(&self, package: &P) -> Result<Self::IV, Box<dyn Error>>;
type ID: IntoIterator<Item = (P, Range<V>)>;
...
fn get_dependencies(
&self,
package: &P,
version: &V,
) -> Result<Option<Self::ID>, Box<dyn Error>>;
...
} This works for Looking back, I may just have rediscovered @mpizenberg's point:
So if impl does not work lets try using pub trait DependencyProvider<P: Package, V: Version> {
...
fn list_available_versions<'s>(
&'s self,
package: &P,
) -> Result<Box<dyn Iterator<Item = V> + 's>, Box<dyn Error>>;
...
fn get_dependencies<'s>(
&'s self,
package: &P,
version: &V,
) -> Result<Option<Box<dyn Iterator<Item = (P, Range<V>)> + 's>>, Box<dyn Error>>;
...
} This lets us do all kinds of fancy things, but we have an allocation anyway. Is it better to have a Looking back, I may just have rediscovered @mpizenberg's point:
So not having found a good api, I am leaning toward leaving things alone. |
What is the usage of such API? What would returning for example a Vec look like?
What about RC like the original post suggested? |
For versions, the algorithm needs to pick one from those provided. The code to pick one only needs references and will only clone the picked version. So avoiding to clone the whole vec of versions thanks to For dependencies, the code using those ( |
This will be stabilized in a few weeks. We could now have Another stable way to get this Vantage is to use |
Co-authored-by: Zanie Blue <[email protected]> Otherwise, it's not possible to implement custom formatting of `Range` types. This seems generally useful to expose. Example usages: https://github.com/astral-sh/uv/blob/8d721830db8ad75b8b7ef38edc0e346696c52e3d/crates/uv-resolver/src/pubgrub/report.rs#L97-L112 https://github.com/astral-sh/uv/blob/8d721830db8ad75b8b7ef38edc0e346696c52e3d/crates/uv-resolver/src/pubgrub/report.rs#L549-L560 https://github.com/astral-sh/uv/blob/8d721830db8ad75b8b7ef38edc0e346696c52e3d/crates/uv-resolver/src/pubgrub/report.rs#L568-L605 Upstream port of astral-sh#18, but `impl Iterator<Item = (&Bound<V>, &Bound<V>)>` instead of `impl Iterator<Item = &(Bound<V>, Bound<V>)>` to avoid constraining it to a tuple. Co-authored-by: Zanie Blue <[email protected]>
Is there a way to avoid the clones and allocation in https://github.com/mpizenberg/elm-test-rs/blob/31596f874a6e9340350de3e7c783a5cde9ca396b/src/solver.rs#L439? In Cargo we use
Rc<Vec<Summary>>
https://github.com/rust-lang/cargo/blob/07162dbaa84aaad97d6f3be5069265e784179bcd/src/cargo/core/resolver/dep_cache.rs#L35, so that a cache hit is and Rc clone instead of a Vec clone. I wonder if there is a trate bound that works for the algorithm and allows returningVec<>
,Rc<Vec<_>>
,im::Vector<_>
, or even a leaked&'static [_]
?Originally brought up in #15 (comment)
The text was updated successfully, but these errors were encountered: