So it looks like thanks to @christianpoveda we will soon have a first version of intrptrcast. That's great! For now it will be off-by-default and only enabled when a seed is given, as allocation comes with some non-determinism that the seed will be used to resolve (this part is not yet implemented).
However, I think it might make sense to have intptrcast on by default. The libstd code that runs before main() does a bunch of things that we currently carry hacks for in Miri (such as testing whether a pointer is > 0), and similar for the slice comparison code (we assume allocations all have a base address of at least 32 or so). Also the integer-binop and integer-cast code is extra messy because it has to support pointer values. We have to duplicate parts of our test suite to make sure the right thing happens both with and without intrptrcast. And every now and then people run into the problem that alignment checking code does not work in Miri without intptrcast, and they don't know that they have to do cargo miri run -- -Zmiri-seed=42. So, in terms of user experience, it strikes me as a bad default.
The current "no base address" mode is nice to help detect code that assumes that no allocation will ever be "low" (which e.g. Rc did for some time) -- but OTOH code that assumes an OS, like Tokio, legitimately makes that assumption. And the cost for carrying that mode is non-trivial.
Considering in particular the UX aspect, it seems to me that rather than having Miri support a minimal set of features per default and letting the user opt-in to more, it might be better to support all (implemented) features per default and allow disabling them. So per default we would actually pick a "truly random" seed on startup, but -Zmiri-seed=xx could make that choice deterministic (but Miri would always have an RNG it could use for stuff). Per default we would allow communicating with the host system (file system and network access, system time, environment variables, ...), but -Zmiri-isolate would disable that. And so on.
CTFE might at some point become powerful enough that we'll want some of these hacks in rustc proper, but certainly not all of them, and I think we can implement them in a better way there if no machine hook is in the way.
@oli-obk (and anyone else reading) what do you think?
The concrete plan for now:
So it looks like thanks to @christianpoveda we will soon have a first version of intrptrcast. That's great! For now it will be off-by-default and only enabled when a seed is given, as allocation comes with some non-determinism that the seed will be used to resolve (this part is not yet implemented).
However, I think it might make sense to have intptrcast on by default. The libstd code that runs before
main()does a bunch of things that we currently carry hacks for in Miri (such as testing whether a pointer is> 0), and similar for the slice comparison code (we assume allocations all have a base address of at least 32 or so). Also the integer-binop and integer-cast code is extra messy because it has to support pointer values. We have to duplicate parts of our test suite to make sure the right thing happens both with and without intrptrcast. And every now and then people run into the problem that alignment checking code does not work in Miri without intptrcast, and they don't know that they have to docargo miri run -- -Zmiri-seed=42. So, in terms of user experience, it strikes me as a bad default.The current "no base address" mode is nice to help detect code that assumes that no allocation will ever be "low" (which e.g.
Rcdid for some time) -- but OTOH code that assumes an OS, like Tokio, legitimately makes that assumption. And the cost for carrying that mode is non-trivial.Considering in particular the UX aspect, it seems to me that rather than having Miri support a minimal set of features per default and letting the user opt-in to more, it might be better to support all (implemented) features per default and allow disabling them. So per default we would actually pick a "truly random" seed on startup, but
-Zmiri-seed=xxcould make that choice deterministic (but Miri would always have an RNG it could use for stuff). Per default we would allow communicating with the host system (file system and network access, system time, environment variables, ...), but-Zmiri-isolatewould disable that. And so on.CTFE might at some point become powerful enough that we'll want some of these hacks in rustc proper, but certainly not all of them, and I think we can implement them in a better way there if no machine hook is in the way.
@oli-obk (and anyone else reading) what do you think?
The concrete plan for now:
Option.tests/compile-fail/intptrcast_*).-Zmiri-seedfrom playground invocation. (Of course the attribute remains documented. We should probably move that section up above "Development" as it is more relevant.)-Zmiri-seedfrom miri-test-libstdcopy_nonoverlapping(see update Miri rust#62823).