Skip to content
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

[Draft] Switch to libsolv port #236

Closed
wants to merge 17 commits into from
Closed

Conversation

aochagavia
Copy link
Contributor

No description provided.

Copy link
Collaborator

@baszalmstra baszalmstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First part of my review!

crates/libsolv_rs/src/id.rs Show resolved Hide resolved
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct StringId {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to turn this into a tuple struct like the other ids?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

crates/libsolv_rs/src/id.rs Show resolved Hide resolved
crates/libsolv_rs/src/id.rs Show resolved Hide resolved
use std::str::FromStr;

pub struct Pool<'a> {
pub(crate) solvables: Vec<Solvable<'a>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this usecase a lot in the code. You have a Vec<T> where you intern Ts and return a TId. Accessing the T is done through a TId. This is a typical Arena pattern. It would be nice to have a type to make that more explicit.

You could optimize this by not using a Vec but allocating large chunks on the fly.

See https://github.com/mun-lang/mun/blob/main/crates/mun_hir/src/arena.rs for a simple example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea! I'll look into it (using a Vec until we have benchmarks, though)


/// Returns a string describing the last error associated to this pool, or "no error" if there
/// were no errors
pub fn last_error(&self) -> String {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assume this function to return an Option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just removed it, since it turns out we weren't even using it (it was a remnant of libsolv)

"no error".to_string()
}

/// Resolves the id to a solvable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns the solvable right? not an Id? Same for resolve_solvable_mut

Copy link
Contributor Author

@aochagavia aochagavia Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the wording is confusing... What I mean here is that the function resolves the id into a solvable. I'll reword it in a way that is clearer, something like "returns the solvable associated to the provided id"

crates/libsolv_rs/src/solvable.rs Show resolved Hide resolved
crates/libsolv_rs/src/solvable.rs Show resolved Hide resolved
/// = 0: undecided
/// > 0: level of decision when the solvable is set to true
/// < 0: level of decision when the solvable is set to false
map: Vec<i64>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a mapping from a SolvableId to an i64? Might be nice to make a newtype of that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

use std::marker::PhantomData;
use std::ops::{Index, IndexMut};

/// An `Arena<TValue>` holds a collection of `TValue`s that can be addressed by `TId`s. You can
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// An `Arena<TValue>` holds a collection of `TValue`s that can be addressed by `TId`s. You can
/// An `Mapping<TId, TValue>` holds a collection of `TValue`s that can be addressed by `TId`s. You can

@aochagavia
Copy link
Contributor Author

Closing in favor of #243

@aochagavia aochagavia closed this Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants