-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
add note on comparing vtables / function pointers #120880
Conversation
/// pointers to the same function can compare inequal (because functions are duplicated in multiple | ||
/// codegen units), and pointers to *different* functions can compare equal (since identical | ||
/// functions can be deduplicated within a codegen unit). | ||
/// | ||
/// [`Hash`]: hash::Hash |
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 hadn't considered before -- are we then violating the Hash
-Eq
contract? Or is it ok because the separate origins of pointers to the "same" function will at least be self-consistent in hashing, and pointers to different deduplicated functions will also hash the same.
That is, if you use function pointers as a HashMap
key, they will behave correctly with respect to the address of actual codegen functions, but not their original function in the source code.
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.
Hash and PartialEq use the same source data, so that contract is maintained.
That is, if you use function pointers as a HashMap key, they will behave correctly with respect to the address of actual codegen functions, but not their original function in the source code.
Correct.
@bors r+ rollup |
@bors r- |
@rustbot review |
This comment was marked as duplicate.
This comment was marked as duplicate.
Sure, sounds good. @bors r+ |
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#110483 (Create try_new function for ThinBox) - rust-lang#120740 (Make cmath.rs a single file) - rust-lang#120872 (hir: Refactor getters for HIR parents) - rust-lang#120880 (add note on comparing vtables / function pointers) - rust-lang#120885 (interpret/visitor: ensure we only see normalized types) - rust-lang#120888 (assert_unsafe_precondition cleanup) - rust-lang#120897 (Encode `coroutine_for_closure` for foreign crates) - rust-lang#120937 ([docs] Update armv6k-nintendo-3ds platform docs for outdated info) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#120880 - RalfJung:vtable-fnptr-partialeq, r=cuviper add note on comparing vtables / function pointers Fixes rust-lang#99388 Fixes rust-lang#117047
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#110483 (Create try_new function for ThinBox) - rust-lang#120740 (Make cmath.rs a single file) - rust-lang#120872 (hir: Refactor getters for HIR parents) - rust-lang#120880 (add note on comparing vtables / function pointers) - rust-lang#120885 (interpret/visitor: ensure we only see normalized types) - rust-lang#120888 (assert_unsafe_precondition cleanup) - rust-lang#120897 (Encode `coroutine_for_closure` for foreign crates) - rust-lang#120937 ([docs] Update armv6k-nintendo-3ds platform docs for outdated info) r? `@ghost` `@rustbot` modify labels: rollup
Fixes #99388
Fixes #117047