Skip to content

(When) Should we do intptrcast (and other opt-in features) per default? #785

Closed
@RalfJung

Description

@RalfJung

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:

  • When no seed is given, use some default. So we always have an RNG, we can remove the Option.
  • Get rid of intptrcast special handling in run-pass test-suite, and delete redundant compile-fail tests (some of tests/compile-fail/intptrcast_*).
  • Fix panic when an odd number of digits is given for the seed, better error.
  • Get rid of the error catching introduced in Enable intptrcast for explicit casts rust#62229 (just always force_bits).
  • Move cast.rs and operator.rs to type-based dispatching for all types.
  • Remove -Zmiri-seed from playground invocation. (Of course the attribute remains documented. We should probably move that section up above "Development" as it is more relevant.)
  • Remove -Zmiri-seed from miri-test-libstd
  • Re-enable "overlaps" check for copy_nonoverlapping (see update Miri rust#62823).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-intptrcastArea: affects int2ptr and ptr2int castsC-projectCategory: a larger project is being tracked here, usually with checkmarks for individual steps

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions