-
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
Introduce FeatureValue type to represent features table values #5270
Conversation
b6b5958
to
f09576b
Compare
I am very looking forward to reviewing this. From the description it sounds like a good approach. With the holiday I have not yet had a chance to review it. |
I took a look at it and I think it looks correct. I think using |
@Eh2406 I've done another take using https://github.com/rust-lang/cargo/compare/master...djc:interned-feature-reqs?expand=1 You're right that |
That does look clearer! I'd be ok just moving forward, the only part that can be slow is |
@bors: delegate=Eh2406 |
✌️ @Eh2406 can now approve this pull request |
f09576b
to
4ba56f0
Compare
Okay, I've pushed the |
Unfortunately it is in the hot loop, but let's get it correct and clear before we think about performance. What do you see as the next step? Do you want that step to be in this PR, or in a separate one? Do you want all things that are storing |
☔ The latest upstream changes (presumably #5287) made this pull request unmergeable. Please resolve the merge conflicts. |
4ba56f0
to
8ed9299
Compare
I'd prefer to land this and do next steps in the next PR. The next step will be to introduce the What other areas of the code do you think are working with feature strings? The thing about |
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.
2 little nits.
src/cargo/core/interning.rs
Outdated
} | ||
} | ||
|
||
unsafe impl Send for InternedString {} |
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 think this is a rebase error, it was recently removedin https://github.com/rust-lang/cargo/pull/5287/files#diff-fc6e9b7a46297a8f6d7851cce9978683L94 as a &'static str
is already send and sync.
src/cargo/core/summary.rs
Outdated
/// * A feature in a depedency | ||
/// | ||
/// The selection between these 3 things happens as part of the construction of the FeatureValue. | ||
/// It stores a `Cow<str>`, so both `String` and `&str` can be used; typically, the former will |
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.
"It stores a Cow<str>
" this is a little out of date
Edit: Just notes that you had already changed a bunch of places to use I will happily r+ when the nits are addressed. I wanted to ask, instead of guessing, as I have seen this go wrong in both directions. I have seen PR's merged while I was still adding the rest of the big picture, and I have seen PR's waiting for approval because the PR was only for the first step. Thank you for adding abstraction to some of the most "stringly typed" parts of the resolver. It was desperately needed. |
8ed9299
to
7621108
Compare
Nits fixed, thanks for the review! |
@bors r+ |
📌 Commit 7621108 has been approved by |
⌛ Testing commit 7621108 with merge 61787c7a6733d5bf3dfd84c4865d0ca5d1f1b04b... |
💔 Test failed - status-travis |
@bors retry |
Introduce FeatureValue type to represent features table values This is the next step towards #1286 (after #5258). The goal here is to have a central place in the code where feature strings are interpreted as (a) a feature, (b) a dependency or (c) a dependency/feature combo, and anchor that interpretation in the type system as an enum. I've spent quite a bit of effort avoiding extra string allocations, complicating the code a bit; notice in particular the use of `Cow<str>` in `FeatureValue` variants, and the slight workaround in `Context::resolve_features()` and `build_requirements()`. I hope this is all okay. cc @Eh2406
☀️ Test successful - status-appveyor, status-travis |
"default_feat" | ||
{ | ||
"Feature": "default_feat" | ||
} | ||
], |
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 only just notest that this change, after the merge. I don't know why/if this change in structures is ok. Will this break things using metadata
?
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, this definitely will break consumers that look at the features
field. Could we preserve the old format here?
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.
Oops -- sorry, I thought that was only used for testing. Will follow up with a fix.
Intern more strings As pointed out in #5270 (comment), that clean up adds the mildly expensive `InternedString::new` to the hot path in the resolver. The process of this PR is: 1. Find a `InternedString::new` in the hot path. 2. replace the argument of type `&str` that is passed along to `InternedString::new` with the type `InternedString` 3. add an `InternedString::new` to the callers until it type checked. 4. Repeat from step 1. This stop if: - It was traced back to something that was already an `InternedString` - It was traced back to a `.to_string()` call - It was in a persistent object creation cc: - @djc this is building on your work, I don't want to get in your way. - @alexcrichton is this making things clearer and do you want to see a performance check?
use InternedString's ability to be a &'static str to appease the borrow checker This "slight workaround" was added in rust-lang#5270. So @djc dose this still look correct?
This is the next step towards #1286 (after #5258). The goal here is to have a central place in the code where feature strings are interpreted as (a) a feature, (b) a dependency or (c) a dependency/feature combo, and anchor that interpretation in the type system as an enum.
I've spent quite a bit of effort avoiding extra string allocations, complicating the code a bit; notice in particular the use of
Cow<str>
inFeatureValue
variants, and the slight workaround inContext::resolve_features()
andbuild_requirements()
. I hope this is all okay.cc @Eh2406