-
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
Why so many lifetimes? #7342
Comments
I think the answer here is "Alex thought it was fun to avoid |
Is it something that can be easily fixed? If I submitted a PR would it get accepted? It does affect my code quite a lot, because many times I do want to store these structs and it bubble up in the code. |
To be honest it's not really something that's ever been considered I think. It would be a pretty massive and major refactoring of Cargo, so I suspect this would not be easily fixed. I would encourage discussing with the cargo team (e.g. not just me) about this before proceeding. |
Sure! Or trying to get more of them on this thread, it's sort of up to other folks if they want to respond. |
From my perspective, the cargo library is provided as-is. Although small changes to accommodate other users is occasionally done, I wouldn't want to do any large changes for that purpose. I also personally like the lifetime usage, as it works towards rust's strengths, and would not want to use more arc/mutex whenever possible. A more interesting question is why you need the cargo library at all? Most users are trying to move off it, and it is desired to provide command-based APIs to support most use cases. |
I don't understand why would anyone ... enjoy the lifetime usage. I avoid lifetimes like a plague, and only deal with them when I absolutely need to avoid some
How is that desired? It would mean that my Rust-related tool, instead of coming with the in built support for Rust, using code that was tested, etc. now will require user to install cargo, deal with the potential problems of spawning processes / shell commands, serializing and de-serializing input and output. And then I'll have to handle support issues for all the people for who something in that chain failed (serialization changed or had a bug is some version of cargo, cargo could not be found, etc). From my perspective, this has only downsides. Cargo library has actually quite OK API already, and these couple of warts and missing documentation (nice to have, not mandatory, really) are the only thing left to make it quite pleasant to use. I don't mind upgrading and fixing API breakage. At least it happens when I want it to, and can be tested and released when ready. |
Using cargo as a library has a big problem today: it means you need to closely track latest stable, and even then nightly-using projects will likely break often and be unusable with the cargo-library using tool. I personally deal with this quite a bit in my work on rust-lang/rust and similar so would really prefer that we moved tools to consuming e.g. As somewhat of an aside, I personally find lifetimes enormously helpful for determining whether, and how, an API is intended to be used; I haven't worked much with Cargo's API in particular but in both Cargo and other libraries (within rustc, for example) I find Mutex/RefCell more confusing than |
You might be thinking about lifetimes on arguments, which are usually OK. However lifetimes on whole structs are just a pain, binding lifetime of the struct to some other structs making it impossible to store them without some self-rental tricks etc. The I would be surprised if the lifetimes I'm pointing out, aren't making the internal code of cargo unnecessarily complex and difficult to work with. From what I can tell, some lifetimes already disappeared in few recent versions, because I remember some weird These couple of lifetimes in cargo API doesn't really seem to have a good reason to be there (from what I can tell, that's why opened this ticket), and |
If there's transformations that clearly make the code simpler, then I don't see why those would not be accepted. I disagree on "library is just dynamic vs static linking, dynamic vs static typing" -- cargo metadata is a intentionally stable (via |
I think the whole Now, not being able to resist being off topic... Whatever
However for a tool that is written in Rust, and can link to libcargo, serialization and deserialization are a drag, and shell as an API is inferior to a native Rust-API. With
My suggestion, would be to just handle more gracefully unsupported nightly features etc. and not just "blow up" as soon soon as unknown (and often irrelevant) feature have been spotted. AFAII, these sortfs of problems have already been kind of addressed, somewhat at least. I would also expect this to be less of a problem going forward, as everything matures. And in the very end ... if my tool can't work with a particular package... it's not the end of the world. |
Agreed on being off topic. I do think a PR here is a good way to move forward. |
What's the deal with interning? cargo/src/cargo/core/interning.rs Line 17 in 59f50ab
|
We don't just intern strings, we do the same for package_ids #6332 and source_ids #6342. The structure of interning has changed, but the justification is the same as when it was introduced #5121 (I used blame in the github UI to find that PR). There are 3 reasons interning is grate:
BTW, what project are you working on? |
Oh. So it's a perf optimization. I wonder if this really makes a difference. I mean... how many dependencies people have etc.? Anyway - thanks for answer. I am working on https://github.com/crev-dev |
Considering cargo-the-library is provided as-is, a major refactor like this would likely be driven by the needs of cargo-the-bin, rather than users of the API. It'll also likely be done opportunistically as other feature development is happening. As such, I'm going to go ahead and close this out. If there is a reason for us to reconsider, let us know! |
I'm sorry for bothering you, but I'm interacting with cargo library a lot and I can't help but wonder - why is there so many complications in the API? There are many lifetimes,
RefCell
s (that make stuff!Sync
etc.Like, why can't
Config
be taken by move so thatWorkspace
and bunch of other structs doesn't require lifetime? Why not justArc<Mutex<_>>
stuff instead of playing withRefCell
s? I don't think there's much performance wins to be had in the code that will always be blocked on IO anyway. Is there something I am missing here?The text was updated successfully, but these errors were encountered: