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

Intern PackageId #6332

Merged
merged 8 commits into from
Nov 26, 2018
Merged

Intern PackageId #6332

merged 8 commits into from
Nov 26, 2018

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Nov 18, 2018

Refs #6207

@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@dwijnand dwijnand changed the title Intern PackageId & SourceId Intern PackageId Nov 19, 2018
@dwijnand
Copy link
Member Author

Interning SourceId broke some tests in the git source test suite (updating git precise revision). I don't know why it's happening and whether it's just a test artefact or not, so I just pulled that commit out for now (it's in a separate branch of mine).

Copy link
Contributor

@Eh2406 Eh2406 left a comment

Choose a reason for hiding this comment

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

Thank you for doing this! I don't know why the test are failing. It doesn't look to be the hash problems we found in #5153 and #5287, but I could be wrong.

src/cargo/core/package_id.rs Outdated Show resolved Hide resolved
src/cargo/core/package_id.rs Show resolved Hide resolved
src/cargo/core/package_id.rs Show resolved Hide resolved
@dwijnand
Copy link
Member Author

Damn, it's the same tests that failed. Well at least I know where to look now.

@alexcrichton
Copy link
Member

FWIW this looks good to me so far!

@dwijnand dwijnand mentioned this pull request Nov 21, 2018
bors added a commit that referenced this pull request Nov 25, 2018
@dwijnand
Copy link
Member Author

@alexcrichton / @Eh2406 Could you help me understand the failure here, please?

I've been studying and debugging git::two_deps_only_update_one for a number of hours today, and I think it's down to these log entries, right?

dep1 head sha: 41927a80
running `/d/cargo/target/debug/cargo update -p dep1`
    Updating git repository `file:///d/cargo/target/cit/t0/dep1`
 TRACE cargo::ops::resolve > previous: graph: Graph {
  - foo v0.5.0 (/d/cargo/target/cit/t0/foo)
    - dep1 v0.5.0 (file:///d/cargo/target/cit/t0/dep1#fb979dad)
  - dep1 v0.5.0 (file:///d/cargo/target/cit/t0/dep1#fb979dad)
}

features: {
}
 DEBUG cargo::ops::resolve > ignoring any lock pointing directly at dep1 v0.5.0 (file:///d/cargo/target/cit/t0/dep1#fb979dad)
 DEBUG cargo::ops::resolve > attempting to prefer foo v0.5.0 (/d/cargo/target/cit/t0/foo)
 DEBUG cargo::core::resolver > initial activation: foo v0.5.0 (/d/cargo/target/cit/t0/foo)
 TRACE cargo::core::resolver > activating foo v0.5.0 (/d/cargo/target/cit/t0/foo)
 TRACE cargo::core::resolver > foo[0]>dep1 1 candidates
 TRACE cargo::core::resolver > foo[0]>dep1 0 prev activations
 TRACE cargo::core::resolver > foo[0]>dep1 trying 0.5.0
 TRACE cargo::core::resolver > activating dep1 v0.5.0 (file:///d/cargo/target/cit/t0/dep1#fb979dad)
 TRACE cargo::core::resolver > resolved: graph: Graph {
  - dep1 v0.5.0 (file:///d/cargo/target/cit/t0/dep1#fb979dad)
  - foo v0.5.0 (/d/cargo/target/cit/t0/foo)
    - dep1 v0.5.0 (file:///d/cargo/target/cit/t0/dep1#fb979dad)
}

features: {
}

(RUST_LOG=cargo::ops::cargo_generate_lockfile=debug,cargo::core::resolver=trace,cargo::ops::resolve=trace,cargo::ops::resolvers::context=trace cargo test git::two_deps_only_update_one

The new sha for the HEAD of the dep1 dependency is at the top (41927a80) but the resolver reuses the source id from the lock file. Does that seem wrong?

@dwijnand
Copy link
Member Author

Indeed, the same thing on master show the sha changing:

    Updating git repository `file:///d/cargo-master/target/cit/t0/dep1`
 TRACE cargo::ops::resolve > previous: graph: Graph {
  - dep1 v0.5.0 (file:///d/cargo-master/target/cit/t0/dep1#4ac9593f)
  - foo v0.5.0 (/d/cargo-master/target/cit/t0/foo)
    - dep1 v0.5.0 (file:///d/cargo-master/target/cit/t0/dep1#4ac9593f)
}

features: {
}
 DEBUG cargo::ops::resolve > ignoring any lock pointing directly at dep1 v0.5.0 (file:///d/cargo-master/target/cit/t0/dep1#4ac9593f)
 DEBUG cargo::ops::resolve > attempting to prefer foo v0.5.0 (/d/cargo-master/target/cit/t0/foo)
 DEBUG cargo::core::resolver > initial activation: foo v0.5.0 (/d/cargo-master/target/cit/t0/foo)
 TRACE cargo::core::resolver > activating foo v0.5.0 (/d/cargo-master/target/cit/t0/foo)
 TRACE cargo::core::resolver > foo[0]>dep1 1 candidates
 TRACE cargo::core::resolver > foo[0]>dep1 0 prev activations
 TRACE cargo::core::resolver > foo[0]>dep1 trying 0.5.0
 TRACE cargo::core::resolver > activating dep1 v0.5.0 (file:///d/cargo-master/target/cit/t0/dep1#666d8cf3)
 TRACE cargo::core::resolver > resolved: graph: Graph {
  - foo v0.5.0 (/d/cargo-master/target/cit/t0/foo)
    - dep1 v0.5.0 (file:///d/cargo-master/target/cit/t0/dep1#666d8cf3)
  - dep1 v0.5.0 (file:///d/cargo-master/target/cit/t0/dep1#666d8cf3)
}

features: {
}

@Eh2406
Copy link
Contributor

Eh2406 commented Nov 26, 2018

So I think what is going on is that we end up with the two different PackageId one for 4ac9593f and one for 666d8cf3. The only difference is the source_id, but the two source_id's only differ by the sha. But the two source_id's Hash to the same value, and they eq with each other. So the interning decides that they are exchangeable.

I don't know how we solve this. Is there some way to let the interning know the "real" hash/eq for the source_id? I don't see how. I wish we had a cleaner way to separate all the different hacks for the different uses of hash/eq. I don't see a cleaner design without specialization.

I do have one (probably bad) idea. A PackageId is just a SourceId, a InternedString, and a semver::Version. If we intern the semver::Version then all of them are copy. Maybe we can decide that 3 pointers don't need to be interned, and just be declared copy.

@bors
Copy link
Collaborator

bors commented Nov 26, 2018

☔ The latest upstream changes (presumably #6347) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton
Copy link
Member

@Eh2406 is right in that these are two SourceId instances that hash to the same value / are equal, but we rely on the fact that they behave differently at runtime to do various operations.

I think the PackageId interning could perhaps take this into account though? It won't be as bland as #[derive(Hash)] but with some handwritten impls I think we can get the same result?

@dwijnand
Copy link
Member Author

dwijnand commented Nov 26, 2018

That fixed the git tests, but now random other tests are failing:

    lockfile_compat::listed_checksum_bad_if_we_cannot_compute
    overrides::override_adds_some_deps
    update::conservative
    update::transitive_minor_update

I think this needs a rethink. This "sometimes equals, sometimes not" strategy is bound to leave holes. Can we not have distinct types for the different use cases?

Copy link
Contributor

@Eh2406 Eh2406 left a comment

Choose a reason for hiding this comment

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

I love the idea of getting away from "sometimes equals, sometimes not" mess. I don't know how infectious a new type would be, how many things have a PackageId as a field and sow would also need a new type, I honestly don't know. Worth a try as a separate PR, or at least a tracking issue.

src/cargo/core/source/source_id.rs Outdated Show resolved Hide resolved
src/cargo/core/source/source_id.rs Outdated Show resolved Hide resolved
tests/testsuite/git.rs Show resolved Hide resolved
src/cargo/core/package_id.rs Outdated Show resolved Hide resolved
@dwijnand
Copy link
Member Author

Nice one, @Eh2406! The test suite now passes.

@Eh2406
Copy link
Contributor

Eh2406 commented Nov 26, 2018

Looks correct. The test pass, and Alex said (on the other PR) to trust the tests. So:
@bors: r+

@bors
Copy link
Collaborator

bors commented Nov 26, 2018

📌 Commit efd03bd has been approved by Eh2406

@bors
Copy link
Collaborator

bors commented Nov 26, 2018

⌛ Testing commit efd03bd with merge 151c225...

bors added a commit that referenced this pull request Nov 26, 2018
@bors
Copy link
Collaborator

bors commented Nov 26, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: Eh2406
Pushing 151c225 to master...

@bors bors merged commit efd03bd into rust-lang:master Nov 26, 2018
@dwijnand dwijnand deleted the intern-more branch November 26, 2018 21:28
bors added a commit that referenced this pull request Nov 28, 2018
remove clones made redundant by Intern PackageId

This is a follow up to #6332. I used clippy to find all the places we called `.clone()`  on a `PackageId` or where we passed `&PackageId`. Yes that touches 44 files and 400+ lines, that is way we wanted `PackageId` to be `copy`.
bors added a commit to rust-lang/rust that referenced this pull request Dec 4, 2018
Update cargo, rls

26 commits in b3d0b2e545b61d4cd08096911724b7d49d213f73..5e85ba14aaa20f8133863373404cb0af69eeef2c
2018-11-15 19:13:04 +0000 to 2018-12-02 14:37:25 +0000
- ConflictStoreTrie: Faster filtered search (rust-lang/cargo#6366)
- Remove `cmake` as a requirement (rust-lang/cargo#6368)
- progress: display "Downloading 1 crate" instead of "Downloading 1 crates" (rust-lang/cargo#6369)
- Use expect over unwrap, for panic-in-panic aborts (rust-lang/cargo#6364)
- Switch to pretty_env_logger, under --features pretty-env-logger (rust-lang/cargo#6362)
- use allow-dirty option in `cargo package` to skip vcs checks (rust-lang/cargo#6280)
- remove clones made redundant by Intern PackageId (rust-lang/cargo#6352)
- docs: correct profile usage of `cargo test --release` (rust-lang/cargo#6345)
- Improve doc for `cargo install` (rust-lang/cargo#6354)
- Intern PackageId (rust-lang/cargo#6332)
- Clean only release artifacts if --release option is set (rust-lang/cargo#6349)
- remove clones made redundant by Intern SourceId (rust-lang/cargo#6347)
- Intern SourceId (rust-lang/cargo#6342)
- Tweak Layout to allow for non json file targets with internal "." (rust-lang/cargo#6255)
- Correct Target Directory command-line option (rust-lang/cargo#6343)
- Persistent data structures by im-rs (rust-lang/cargo#6336)
- Move command prelude into main library (rust-lang/cargo#6335)
- Distinguish custom build invocations (rust-lang/cargo#6331)
- Allow crate_type=bin examples to run (rust-lang/cargo#6330)
- Make verify-project honour unstable features (rust-lang/cargo#6326)
- Make autodiscovery disable inferred targets (rust-lang/cargo#6329)
- Add `c` alias for `check` (rust-lang/cargo#6218)
- Allow user aliases to override built-in aliases (rust-lang/cargo#6259)
- Fix renaming directory project using build scripts with cross-compiling. (rust-lang/cargo#6328)
- Fix add_plugin_deps-related tests. (rust-lang/cargo#6327)
- Add a glossary. (rust-lang/cargo#6321)
@Eh2406 Eh2406 mentioned this pull request Sep 17, 2019
@ehuss ehuss added this to the 1.32.0 milestone Feb 6, 2022
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.

6 participants