rust-lang / miri

An interpreter for Rust's mid-level intermediate representation
Apache License 2.0
4.13k stars 318 forks source link

Support setting Miri flags in the rustc file via attributes #3670

Open RalfJung opened 2 weeks ago

RalfJung commented 2 weeks ago

It could be quite useful to support a crate-level attribute on binary crates like #[miri::flag("-Zmiri-disable-leak-check")]. That would help both on the playground and for doctests, to control the flags the file is run with.

Not sure how to best implement that though, and it may be considered an abomination by the compiler team. ;)

RalfJung commented 1 week ago

@oli-obk any idea what the best way might be to implement such an attribute? I am imagining something like

#![miri::flag("-Zmiri-tree-borrows")]

Usually this would be gated by cfg_attr(miri, ...).

In a lib crate this has no effect (we should likely lint against that), but in a binary crate this makes Miri act as-if those flags were passes on the command line.

Or should this maybe even be a more general rustc feature?

oli-obk commented 1 week ago

yea I've wanted this as a general rustc feature before, but it can't really work because some flags are processed before the source file is even opened.

I think I would prefer just allowing miri flags to also be used via native attributes like #[miri::tree_borrows]. We can set up the infrastructure to not duplicate the logic between attributes and command line flags