Skip to content

Commit 86911fd

Browse files
committed
Auto merge of rust-lang#2368 - RalfJung:debug, r=oli-obk
Make "./miri {build,run,test}" use debug assertions but "./miri install" not This makes `./miri run`/`./miri test` use the full set of debug assertions (including the rather expensive ones that check consistency of the Stacked Borrows cache), but `./miri install` installs a Miri *without* those debug assertions. That's the same behavior as cargo, and helps catch Miri bugs with the test suite while making installed Miri usable for larger runs.
2 parents 7b79801 + d6cbe5d commit 86911fd

File tree

6 files changed

+56
-61
lines changed

6 files changed

+56
-61
lines changed

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ harness = false
5454

5555
[features]
5656
default = ["stack-cache"]
57-
# Will be enabled on CI via `--all-features`.
58-
expensive-debug-assertions = []
5957
stack-cache = []
58+
59+
[profile.dev]
60+
opt-level = 2 # because it's too slow otherwise

ci.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ set -x
55
# Determine configuration
66
export RUSTFLAGS="-D warnings"
77
export CARGO_INCREMENTAL=0
8-
export CARGO_EXTRA_FLAGS="--all-features" # in particular, expensive-debug-assertions
8+
export CARGO_EXTRA_FLAGS="--all-features"
99

1010
# Prepare
1111
echo "Build and install miri"
12-
CARGO_EXTRA_FLAGS="" ./miri install # implicitly locked -- and the *installed* Miri does *not* get the expensive-debug-assertions feature
12+
./miri install # implicitly locked
1313
./miri build --all-targets --locked # the build that all the `./miri test` below will use
1414
echo
1515

miri

+26-50
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ USAGE=$(cat <<"EOF"
66
./miri install <flags>:
77
Installs the miri driver and cargo-miri. <flags> are passed to `cargo
88
install`. Sets up the rpath such that the installed binary should work in any
9-
working directory.
9+
working directory. However, the rustup toolchain when invoking `cargo miri`
10+
needs to be the same one used for `./miri install`.
1011
1112
./miri build <flags>:
1213
Just build miri. <flags> are passed to `cargo build`.
@@ -22,10 +23,6 @@ to the final `cargo test` invocation.
2223
Build miri, set up a sysroot and then run the driver with the given <flags>.
2324
(Also respects MIRIFLAGS environment variable.)
2425
25-
The commands above also exist in a "-debug" variant (e.g. "./miri run-debug
26-
<flags>") which uses debug builds instead of release builds, for faster build
27-
times and slower execution times.
28-
2926
./miri fmt <flags>:
3027
Format all sources and tests. <flags> are passed to `rustfmt`.
3128
@@ -99,40 +96,21 @@ fi
9996

10097
# Prepare flags for cargo and rustc.
10198
CARGO="cargo +$TOOLCHAIN"
102-
if [ -z "$CARGO_INCREMENTAL" ]; then
103-
# Default CARGO_INCREMENTAL to 1.
104-
export CARGO_INCREMENTAL=1
105-
fi
10699
if [ -z "$CARGO_TARGET_DIR" ]; then
107100
# Share target dir between `miri` and `cargo-miri`.
108101
export CARGO_TARGET_DIR="$MIRIDIR/target"
109102
fi
110103
# We set the rpath so that Miri finds the private rustc libraries it needs.
111-
# We enable debug-assertions to get tracing.
112-
# We enable line-only debuginfo for backtraces.
113-
export RUSTFLAGS="-C link-args=-Wl,-rpath,$LIBDIR -C debug-assertions -C debuginfo=1 $RUSTFLAGS"
114-
# Determine flags passed to all cargo invocations.
115-
# This is a bit more annoying that one would hope due to
116-
# <https://github.com/rust-lang/cargo/issues/6992>.
117-
case "$COMMAND" in
118-
*-debug)
119-
CARGO_INSTALL_FLAGS="--target $TARGET --debug $CARGO_EXTRA_FLAGS"
120-
CARGO_BUILD_FLAGS="--target $TARGET $CARGO_EXTRA_FLAGS"
121-
;;
122-
*)
123-
CARGO_INSTALL_FLAGS="--target $TARGET $CARGO_EXTRA_FLAGS"
124-
CARGO_BUILD_FLAGS="--target $TARGET --release $CARGO_EXTRA_FLAGS"
125-
;;
126-
esac
104+
export RUSTFLAGS="-C link-args=-Wl,-rpath,$LIBDIR $RUSTFLAGS"
127105

128106
## Helper functions
129107

130108
# Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
131109
build_sysroot() {
132110
# Build once, for the user to see.
133-
$CARGO run $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml -- miri setup "$@"
111+
$CARGO run $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml -- miri setup "$@"
134112
# Call again, to just set env var.
135-
export MIRI_SYSROOT="$($CARGO run $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml -q -- miri setup --print-sysroot "$@")"
113+
export MIRI_SYSROOT="$($CARGO run $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml -q -- miri setup --print-sysroot "$@")"
136114
}
137115

138116
# Prepare and set MIRI_SYSROOT. Respects `MIRI_TEST_TARGET` and takes into account
@@ -154,37 +132,35 @@ find_sysroot() {
154132

155133
# Run command.
156134
case "$COMMAND" in
157-
install|install-debug)
135+
install)
158136
# "--locked" to respect the Cargo.lock file if it exists,
159137
# "--offline" to avoid querying the registry (for yanked packages).
160-
$CARGO install $CARGO_INSTALL_FLAGS --path "$MIRIDIR" --force --locked --offline "$@"
161-
$CARGO install $CARGO_INSTALL_FLAGS --path "$MIRIDIR"/cargo-miri --force --locked --offline "$@"
138+
$CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR" --force --locked --offline "$@"
139+
$CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR"/cargo-miri --force --locked --offline "$@"
162140
;;
163-
check|check-debug)
141+
check)
164142
# Check, and let caller control flags.
165-
$CARGO check $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml --all-targets "$@"
166-
$CARGO check $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml "$@"
143+
$CARGO check $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml --all-targets "$@"
144+
$CARGO check $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml "$@"
167145
;;
168-
build|build-debug)
146+
build)
169147
# Build, and let caller control flags.
170-
$CARGO build $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml "$@"
171-
$CARGO build $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml "$@"
148+
$CARGO build $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml "$@"
149+
$CARGO build $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml "$@"
172150
;;
173-
test|test-debug|bless|bless-debug)
151+
test|bless)
174152
# First build and get a sysroot.
175-
$CARGO build $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml
153+
$CARGO build $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml
176154
find_sysroot
177-
case "$COMMAND" in
178-
bless|bless-debug)
155+
if [ "$COMMAND" = "bless" ]; then
179156
export MIRI_BLESS="Gesundheit"
180-
;;
181-
esac
157+
fi
182158
# Then test, and let caller control flags.
183159
# Only in root project and ui_test as `cargo-miri` has no tests.
184-
$CARGO test $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml "$@"
185-
$CARGO test $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/ui_test/Cargo.toml "$@"
160+
$CARGO test $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml "$@"
161+
$CARGO test $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/ui_test/Cargo.toml "$@"
186162
;;
187-
run|run-debug)
163+
run)
188164
# Scan for "--target" to overwrite the "MIRI_TEST_TARGET" env var so
189165
# that we set the MIRI_SYSROOT up the right way.
190166
FOUND_TARGET_OPT=0
@@ -202,19 +178,19 @@ run|run-debug)
202178
MIRIFLAGS="$MIRIFLAGS --target $MIRI_TEST_TARGET"
203179
fi
204180
# First build and get a sysroot.
205-
$CARGO build $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml
181+
$CARGO build $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml
206182
find_sysroot
207183
# Then run the actual command.
208-
exec $CARGO run $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml -- --sysroot "$MIRI_SYSROOT" $MIRIFLAGS "$@"
184+
exec $CARGO run $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml -- --sysroot "$MIRI_SYSROOT" $MIRIFLAGS "$@"
209185
;;
210186
fmt)
211187
find "$MIRIDIR" -not \( -name target -prune \) -name '*.rs' \
212188
| xargs rustfmt +$TOOLCHAIN --edition=2021 --config-path "$MIRIDIR/rustfmt.toml" "$@"
213189
;;
214190
clippy)
215-
$CARGO clippy $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml --all-targets "$@"
216-
$CARGO clippy $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/ui_test/Cargo.toml --all-targets "$@"
217-
$CARGO clippy $CARGO_BUILD_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml "$@"
191+
$CARGO clippy $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml --all-targets "$@"
192+
$CARGO clippy $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/ui_test/Cargo.toml --all-targets "$@"
193+
$CARGO clippy $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml "$@"
218194
;;
219195
*)
220196
if [ -n "$COMMAND" ]; then

src/concurrency/range_object_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ impl<T> RangeObjectMap<T> {
117117
self.v.insert(pos, Elem { range, data });
118118
// If we aren't the first element, then our start must be greater than the preivous element's end
119119
if pos > 0 {
120-
debug_assert!(self.v[pos - 1].range.end() <= range.start);
120+
assert!(self.v[pos - 1].range.end() <= range.start);
121121
}
122122
// If we aren't the last element, then our end must be smaller than next element's start
123123
if pos < self.v.len() - 1 {
124-
debug_assert!(range.end() <= self.v[pos + 1].range.start);
124+
assert!(range.end() <= self.v[pos + 1].range.start);
125125
}
126126
}
127127

src/range_map.rs

+18
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ impl<T> RangeMap<T> {
7777
};
7878
// The first offset that is not included any more.
7979
let end = offset + len;
80+
assert!(
81+
end <= self.v.last().unwrap().range.end,
82+
"iterating beyond the bounds of this RangeMap"
83+
);
8084
slice
8185
.iter()
8286
.take_while(move |elem| elem.range.start < end)
@@ -279,4 +283,18 @@ mod tests {
279283
assert_eq!(map.v.len(), 5);
280284
assert_eq!(to_vec(&map, 10, 10), vec![23, 42, 23, 23, 23, 19, 19, 19, 19, 19]);
281285
}
286+
287+
#[test]
288+
#[should_panic]
289+
fn out_of_range_iter_mut() {
290+
let mut map = RangeMap::<i32>::new(Size::from_bytes(20), -1);
291+
let _ = map.iter_mut(Size::from_bytes(11), Size::from_bytes(11));
292+
}
293+
294+
#[test]
295+
#[should_panic]
296+
fn out_of_range_iter() {
297+
let map = RangeMap::<i32>::new(Size::from_bytes(20), -1);
298+
let _ = map.iter(Size::from_bytes(11), Size::from_bytes(11));
299+
}
282300
}

src/stacked_borrows/stack.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'tcx> Stack {
8282
/// Panics if any of the caching mechanisms have broken,
8383
/// - The StackCache indices don't refer to the parallel items,
8484
/// - There are no Unique items outside of first_unique..last_unique
85-
#[cfg(feature = "expensive-debug-assertions")]
85+
#[cfg(debug_assertions)]
8686
fn verify_cache_consistency(&self) {
8787
// Only a full cache needs to be valid. Also see the comments in find_granting_cache
8888
// and set_unknown_bottom.
@@ -115,7 +115,7 @@ impl<'tcx> Stack {
115115
tag: SbTagExtra,
116116
exposed_tags: &FxHashSet<SbTag>,
117117
) -> Result<Option<usize>, ()> {
118-
#[cfg(feature = "expensive-debug-assertions")]
118+
#[cfg(debug_assertions)]
119119
self.verify_cache_consistency();
120120

121121
let SbTagExtra::Concrete(tag) = tag else {
@@ -247,7 +247,7 @@ impl<'tcx> Stack {
247247
// This primes the cache for the next access, which is almost always the just-added tag.
248248
self.cache.add(new_idx, new);
249249

250-
#[cfg(feature = "expensive-debug-assertions")]
250+
#[cfg(debug_assertions)]
251251
self.verify_cache_consistency();
252252
}
253253

@@ -325,7 +325,7 @@ impl<'tcx> Stack {
325325
self.unique_range.end = self.unique_range.end.min(disable_start + 1);
326326
}
327327

328-
#[cfg(feature = "expensive-debug-assertions")]
328+
#[cfg(debug_assertions)]
329329
self.verify_cache_consistency();
330330

331331
Ok(())
@@ -380,7 +380,7 @@ impl<'tcx> Stack {
380380
self.unique_range = 0..0;
381381
}
382382

383-
#[cfg(feature = "expensive-debug-assertions")]
383+
#[cfg(debug_assertions)]
384384
self.verify_cache_consistency();
385385
Ok(())
386386
}

0 commit comments

Comments
 (0)