Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upComparing trait object references for equality gives different results based on the number of codegen units #46139
Comments
This comment has been minimized.
This comment has been minimized.
|
The vtable pointers are different (try transmuting |
This comment has been minimized.
This comment has been minimized.
|
I ran into this a while ago, and @eddyb said that we never make any guarantees around uniqueness of vtables: #30485 (comment). |
This comment has been minimized.
This comment has been minimized.
|
@durka is there anything I can clarify? |
This comment has been minimized.
This comment has been minimized.
|
Something I'd like clarified - this is considered a bug right? It seems to me that If we never make any guarantees around uniqueness of vtables, then |
This comment has been minimized.
This comment has been minimized.
|
Not necessarily - imagine you had a
The data pointers of |
This comment has been minimized.
This comment has been minimized.
|
It seems pretty weird that the same trait gets different vtables. |
This comment has been minimized.
This comment has been minimized.
|
Okay, but to clarify again - this is a discussion of how to fix the issue? Not whether there is an issue? Because I'm appreciating the discussion of what caused it, and potential issues with simple ways to fix it, but I'm still not completely sure if people agree that it is an issue that needs fixing? To discuss the potential fix more - shouldn't they compare equal? From the documentation of Regardless, it seems important that, if there's going to be no guarantees about vtables, that doesn't also mean that there is no guarantee the comparing pointers to trait objects will ever return true. As far as I can tell, it's just not useful at that point? |
This comment has been minimized.
This comment has been minimized.
|
@durka Not all that weird - we could defer vtable instantiation until the final link, but then you'd have to do a bunch of rewriting of all of the rlibs you're linking to rather than just having each compilation unit create the vtables it needs. @PeterHatch The documentation should definitely note the behavior around trait objects, yeah. |
This comment has been minimized.
This comment has been minimized.
|
Yeah, if the behavior of comparing pointers to trait objects depends on random details of the compilation environment like CGUs, LTO, etc, it seems like a footgun for the operator to have |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@arielb1 states:
|
shepmaster
changed the title
ptr::eq giving wrong result sometimes in beta/nightly debug
Comparing trait object references for equality gives different results based on the number of codegen units
Nov 25, 2017
shepmaster
added
T-compiler
C-bug
labels
Nov 25, 2017
This comment has been minimized.
This comment has been minimized.
|
Also note that you can throw away part of the fat pointer if all you care about is the data portion: let a = container.item as *const _ as *const ();
let b = &item as *const _ as *const ();
assert!(ptr::eq(a, b)); |
This comment has been minimized.
This comment has been minimized.
|
Why would it be a bug? Maybe it's suboptimal? But we make no guarantees. |
This comment has been minimized.
This comment has been minimized.
burdges
commented
Aug 27, 2018
|
It's worth giving a warning in I suppose In other words, I can cast an Should maybe
|
PeterHatch commentedNov 20, 2017
I'm seeing the ptr::eq function from the standard library sometimes return false when it should return true. This is happening in debug mode in nightly and beta, but not stable, and not in any version in release mode.
Here's the simplest I could get a reproduction of the issue:
Expected the assertion to pass, and it fails on beta and nightly, in debug mode only.
Meta
rustc +beta --version --verbose:rustc 1.22.0-beta.3 (cc6ed06 2017-11-13)
binary: rustc
commit-hash: cc6ed06
commit-date: 2017-11-13
host: x86_64-pc-windows-msvc
release: 1.22.0-beta.3
LLVM version: 4.0
rustc +nightly --version --verbose:rustc 1.23.0-nightly (5041b3b 2017-11-19)
binary: rustc
commit-hash: 5041b3b
commit-date: 2017-11-19
host: x86_64-pc-windows-msvc
release: 1.23.0-nightly
LLVM version: 4.0