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

Introduce ptr::hash for references #56250

Merged
merged 11 commits into from
Dec 7, 2018
Merged

Introduce ptr::hash for references #56250

merged 11 commits into from
Dec 7, 2018

Conversation

dwijnand
Copy link
Member

The RHS is what I used, which wasn't as convenient as ptr::eq, so I wondered: should ptr::hash exist?

My first Rust PR, so I'm going to need some guidance. :)

@rust-highfive
Copy link
Collaborator

r? @aidanhs

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 26, 2018
@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

src/libcore/ptr.rs Outdated Show resolved Hide resolved
src/libcore/ptr.rs Outdated Show resolved Hide resolved
src/libcore/ptr.rs Outdated Show resolved Hide resolved
@dwijnand dwijnand changed the title [WIP] Introduce ptr::hash for references Introduce ptr::hash for references Nov 27, 2018
@Centril
Copy link
Contributor

Centril commented Nov 27, 2018

Code looks good imo; assigning over to someone on T-libs for review.

r? @sfackler

@rust-highfive rust-highfive assigned sfackler and unassigned aidanhs Nov 27, 2018
@rust-highfive

This comment has been minimized.

@dwijnand
Copy link
Member Author

dwijnand commented Dec 1, 2018

CC @alexcrichton this would've made that interning code in Cargo look more symmetric :)

@alexcrichton
Copy link
Member

This seems like it's fine to me to add, but to align with ptr::eq should this perhaps take a raw pointer as well?

@dwijnand
Copy link
Member Author

dwijnand commented Dec 4, 2018

My hesitation on a raw pointer was to avoid having to make a decision on whether a null pointer should be hashed or not. But I guess if ptr::eq is happy to compare any raw pointer then I guess ptr::hash can hash any raw pointer, and the user can guard against passing it null pointers if need be.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:03752b1b:start=1543909813110345578,finish=1543909868985148801,duration=55874803223
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---
184272 ./obj/build/cache/2018-10-30
153272 ./src/tools/clang
150332 ./obj/build/bootstrap/debug/incremental
134740 ./obj/build/bootstrap/debug/incremental/bootstrap-1plb86h2refwc
134736 ./obj/build/bootstrap/debug/incremental/bootstrap-1plb86h2refwc/s-f79qgjj7ni-1l6t9lv-4qyniat88vxc
134060 ./.git/modules/src
115340 ./src/llvm/test/CodeGen
107892 ./obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends
107416 ./src/tools/lldb
---
travis_time:end:25f9ff50:start=1543910111560666043,finish=1543910111565902426,duration=5236383
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:1eddb1e6
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:044559c0
travis_time:start:044559c0
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:12bf5050
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

kennytm added a commit to GuillaumeGomez/rust that referenced this pull request Dec 5, 2018
Introduce ptr::hash for references

The RHS is what I used, which wasn't as convenient as `ptr::eq`, so I wondered: should `ptr::hash` exist?

My first Rust PR, so I'm going to need some guidance. :)
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Dec 5, 2018
Introduce ptr::hash for references

The RHS is what I used, which wasn't as convenient as `ptr::eq`, so I wondered: should `ptr::hash` exist?

My first Rust PR, so I'm going to need some guidance. :)
@@ -2509,6 +2509,36 @@ pub fn eq<T: ?Sized>(a: *const T, b: *const T) -> bool {
a == b
}

/// Hash the raw pointer address behind a reference, rather than the value
Copy link
Contributor

Choose a reason for hiding this comment

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

As now it's taking a pointer, "behind a reference" may need to be removed.

@bors
Copy link
Contributor

bors commented Dec 6, 2018

⌛ Testing commit ad76569 with merge 786b54f...

bors added a commit that referenced this pull request Dec 6, 2018
Introduce ptr::hash for references

The RHS is what I used, which wasn't as convenient as `ptr::eq`, so I wondered: should `ptr::hash` exist?

My first Rust PR, so I'm going to need some guidance. :)
@bors
Copy link
Contributor

bors commented Dec 6, 2018

💔 Test failed - status-travis

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 6, 2018
@rust-highfive
Copy link
Collaborator

The job dist-aarch64-linux of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
Building stage2 tool cargo (aarch64-unknown-linux-gnu)
[01:08:28]  Downloading crates ...
[01:08:48] warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates.io)
[01:09:08] warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates.io)
[01:09:28] error: failed to download from `https://crates.io/api/v1/crates/openssl-src/111.0.1+1.1.1/download`
[01:09:28] Caused by:
[01:09:28]   [6] Couldn't resolve host name (Could not resolve host: crates.io)
[01:09:28] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "aarch64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--manifest-path" "/checkout/src/tools/cargo/Cargo.toml" "--features" "rustc-workspace-hack/all-static" "--message-format" "json"
[01:09:28] expected success, got: exit code: 101
---
travis_time:end:1057ba42:start=1544077771498342503,finish=1544077771506399975,duration=8057472
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:132101c7
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:1ed83885
travis_time:start:1ed83885
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0da61ed0
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@kennytm
Copy link
Member

kennytm commented Dec 6, 2018

@bors retry rollup travis-ci/travis-ci#9696

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 6, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Dec 7, 2018
Introduce ptr::hash for references

The RHS is what I used, which wasn't as convenient as `ptr::eq`, so I wondered: should `ptr::hash` exist?

My first Rust PR, so I'm going to need some guidance. :)
bors added a commit that referenced this pull request Dec 7, 2018
Rollup of 7 pull requests

Successful merges:

 - #56000 (Add Armv8-M Mainline targets)
 - #56250 (Introduce ptr::hash for references)
 - #56434 (Improve query cycle errors for parallel queries)
 - #56516 (Replace usages of `..i + 1` ranges with `..=i`.)
 - #56555 (Send textual profile data to stderr, not stdout)
 - #56561 (Fix bug in from_key_hashed_nocheck)
 - #56574 (Fix a stutter in the docs for slice::exact_chunks)

Failed merges:

r? @ghost
@dwijnand
Copy link
Member Author

dwijnand commented Dec 7, 2018

As now it's taking a pointer, "behind a reference" may need to be removed.

@sinkuu you're right, well spotted. But I'm holding back on pushing a commit as I don't want to mess up any rollup efforts. I'm happy to push a fix either in this PR or a follow-up when it's best to.

@bors bors merged commit ad76569 into rust-lang:master Dec 7, 2018
@dwijnand dwijnand deleted the ptr-hash branch December 7, 2018 16:15
@dwijnand
Copy link
Member Author

dwijnand commented Dec 7, 2018

Followed up in #56602.

Centril added a commit to Centril/rust that referenced this pull request Dec 8, 2018
Fix the just-introduced ptr::hash docs

Follow-up to rust-lang#56250.
kennytm added a commit to kennytm/rust that referenced this pull request Dec 14, 2018
Allow ptr::hash to accept fat pointers

Fat pointers implement Hash since rust-lang#45483.  This is a follow-up to rust-lang#56250.
kennytm added a commit to kennytm/rust that referenced this pull request Dec 14, 2018
Allow ptr::hash to accept fat pointers

Fat pointers implement Hash since rust-lang#45483.  This is a follow-up to rust-lang#56250.
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Dec 14, 2018
Allow ptr::hash to accept fat pointers

Fat pointers implement Hash since rust-lang#45483.  This is a follow-up to rust-lang#56250.
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Dec 15, 2018
Allow ptr::hash to accept fat pointers

Fat pointers implement Hash since rust-lang#45483.  This is a follow-up to rust-lang#56250.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants