Comments (7)
pointers to different zst values will compare equal, but comparing pointers to different types is probably forbidden anyway
I'm worried about allowing this from a correctness standpoint. They could be the same type:
let x = ();
let y = 1;
let z = ();
assert_eq!(&x as *const (), &z as *const ());
This (probably) fails in rustc and currently does in miri but wouldn't with the suggested change. I'm not sure what is or should be guaranteed here.
@ubsan Any thoughts?
On the other hand, this is probably a major low-hanging fruit optimization, and it would be nice to make these faster one way or another. I have some vague thoughts about passing around PrimVal
instead of Pointer
for some of miri's operations to reduce the number of allocations created which might help here, too. I need some more time to investigate that.
By the way, ZST Allocation
s themselves don't require any heap allocation in the interpreter, aside from the space used in the HashMap
in Memory
. Another idea is to have fake Pointer
s for ZSTs which somehow preserve distinctness but don't actually key into the HashMap
.
from miri.
Another idea is to have fake Pointers for ZSTs which somehow preserve distinctness but don't actually key into the HashMap.
Easy, just increase the alloc_id counter without allocating and make sure that miri doesn't actually deref ZST pointers. There'd be no way to detect dangling zst pointers, but I don't think that's an issue.
from miri.
@solson I don't believe we make any guarantees about the uniqueness of ZST pointers (or, to be honest, any of the other pointer types), and we do not guarantee the ordering of stack variables.
from miri.
@ubsan we do make guarantees for &mut T
when T
is not ZST
from miri.
@oli-obk I don't think so... I can't imagine an implementation which would break that though (i.e., I can't imagine an implementation that requires what Rust does, and still would be able to do that). I believe we do specifically want to be able to do this:
{
let x = 0;
let y = 0;
&x as *const _ == &y as *const _ // true
}
We guarantee noalias semantics, but nothing about pointer comparisons, actually. So... if someone wanted to make an entirely completely ridiculous implementation, they could do something like optimizing
fn doop (ptr1: *const u32, ptr2: *const u32) -> bool {
ptr1 == ptr2
}
// to
fn doop (ptr1: *const u32, ptr2: *const u32) -> bool {
true
}
from miri.
Easy, just increase the alloc_id counter without allocating and make sure that miri doesn't actually deref ZST pointers. There'd be no way to detect dangling zst pointers, but I don't think that's an issue.
@oli-obk I'd like to at least be able to tell a dangling pointer deref apart from a ZST deref (after being casted to a different pointer type, say).
from miri.
@oli-obk Based on @ubsan's comments, I think it would be fine to implement your original suggestion of a single ZST allocation. This would remove the problem of my previous comment.
from miri.
Related Issues (20)
- Make it possible to hide certain functions in MIRI_LOG output
- Disable diagnostic duplication
- Start/stop verbose tracing dynamically
- Possible false positive in data race detection HOT 8
- Set MIRI_TEMP to a fresh temporary directory
- Explore using cargo-hakari to avoid duplicate builds between `miri test` and `miri run` HOT 3
- Miri does not support `Command` HOT 1
- time-with-isolation test is drifting and often confuses people
- [guide] How to disable miri in doctests HOT 6
- ICE: hir: index out of bounds HOT 1
- teach miri to use intrinsics' fallback bodies HOT 2
- ICE: Layout != Layout HOT 7
- `cargo miri test` is broken for doctests (Option 'sysroot' given more than once) HOT 13
- Are our many-seeds tests failing on Windows?
- `munmap` need not point to the start of an object HOT 6
- Support argfiles in all our argument munching HOT 1
- cargo-miri: ensure all rustc invocations go via our wrapper HOT 3
- Improve deadlock diagnostics
- Detect partial deadlocks HOT 1
- Re-introduce the "expensive debug assertions" feature
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from miri.