]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #2323 - RalfJung:box-is-special, r=RalfJung
authorbors <bors@rust-lang.org>
Tue, 5 Jul 2022 12:35:03 +0000 (12:35 +0000)
committerbors <bors@rust-lang.org>
Tue, 5 Jul 2022 12:35:03 +0000 (12:35 +0000)
handle Box with allocators

This is the Miri side of https://github.com/rust-lang/rust/pull/98847.

Thanks `@DrMeepster` for doing most of the work of getting this test case to pass in Miri. :)

21 files changed:
CONTRIBUTING.md
bench-cargo-miri/serde1/Cargo.toml
bench-cargo-miri/serde2/Cargo.lock [new file with mode: 0644]
bench-cargo-miri/serde2/Cargo.toml [new file with mode: 0644]
bench-cargo-miri/serde2/src/main.rs [new file with mode: 0644]
bench-cargo-miri/unicode/src/main.rs
benches/fibonacci.rs [deleted file]
benches/helpers/fibonacci_helper.rs [deleted file]
benches/helpers/fibonacci_helper_iterative.rs [deleted file]
benches/helpers/miri_helper.rs [deleted file]
benches/helpers/mod.rs [deleted file]
benches/helpers/repeat.rs [deleted file]
benches/helpers/repeat_manual.rs [deleted file]
benches/helpers/smoke_helper.rs [deleted file]
benches/repeat.rs [deleted file]
benches/smoke.rs [deleted file]
ci.sh
miri
src/diagnostics.rs
src/helpers.rs
src/stacked_borrows/diagnostics.rs

index a3bad3d154075023c0b27687b66053a6978cb848..bde1921eb8ce467fbb85e5b86443ea7ebf2ce0ee 100644 (file)
@@ -147,6 +147,12 @@ does not automatically trigger a re-build of the standard library; you have to
 clear the Miri build cache manually (on Linux, `rm -rf ~/.cache/miri`;
 and on Windows, `rmdir /S "%LOCALAPPDATA%\rust-lang\miri\cache"`).
 
+### Benchmarking
+
+Miri comes with a few benchmarks; you can run `./miri bench` to run them with the locally built
+Miri. Note: this will run `./miri install` as a side-effect. Also requires `hyperfine` to be
+installed (`cargo install hyperfine`).
+
 ## Configuring `rust-analyzer`
 
 To configure `rust-analyzer` and VS Code for working on Miri, save the following
index 29f0abff5d73de9dd9d456c7c09727249fc12bcc..7cb863a7abf33ee070f229e6ccb1ee9b5ea6ee77 100644 (file)
@@ -5,5 +5,5 @@ authors = ["Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>"]
 edition = "2018"
 
 [dependencies]
-serde = { version = "*", features = ["derive"] }
-serde_json = "*"
+serde = { version = "1.0", features = ["derive"] }
+serde_json = "1.0"
diff --git a/bench-cargo-miri/serde2/Cargo.lock b/bench-cargo-miri/serde2/Cargo.lock
new file mode 100644 (file)
index 0000000..4875057
--- /dev/null
@@ -0,0 +1,89 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "cargo-miri-test"
+version = "0.1.0"
+dependencies = [
+ "serde",
+ "serde_json",
+]
+
+[[package]]
+name = "itoa"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.39"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "ryu"
+version = "1.0.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695"
+
+[[package]]
+name = "serde"
+version = "1.0.137"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.137"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "serde_json"
+version = "1.0.81"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c"
+dependencies = [
+ "itoa",
+ "ryu",
+ "serde",
+]
+
+[[package]]
+name = "syn"
+version = "1.0.96"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
diff --git a/bench-cargo-miri/serde2/Cargo.toml b/bench-cargo-miri/serde2/Cargo.toml
new file mode 100644 (file)
index 0000000..7cb863a
--- /dev/null
@@ -0,0 +1,9 @@
+[package]
+name = "cargo-miri-test"
+version = "0.1.0"
+authors = ["Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>"]
+edition = "2018"
+
+[dependencies]
+serde = { version = "1.0", features = ["derive"] }
+serde_json = "1.0"
diff --git a/bench-cargo-miri/serde2/src/main.rs b/bench-cargo-miri/serde2/src/main.rs
new file mode 100644 (file)
index 0000000..c81b32c
--- /dev/null
@@ -0,0 +1,18 @@
+// Like serde1, but in two threads concurrently. And we don't print.
+static JSON: &str = r#"{"buffer":[-29,-42,-40,-37,-28,-5,-21,1,-24,-8,-20,4,-18,26,-24,44,-26,66,-30,86,-37,88,-41,72,-46,50,-31,28,23,14,64,16,51,26,32,34,39,42,48,35,58,0,72,-36,69,-59,58,-98,54,-124,36,-103,12,-110,5,-173,-19,-146,-59,-4,-42,51,1,-23,-6,-30,-6,45,46,47,70,6,55,19,60,38,62,42,47,61,46,40,42,-19,22,-34,6,-35,-50,-61,-141,-37,-171,17,-163,26,-180,46,-154,80,-63,48,-4,18,20,50,47,58,53,44,61,57,85,37,80,0,86,-8,106,-95,49,-213,-8,-131,47,49,63,40,-39,-69,-74,-37,-20,63,-12,58,-14,-12,25,-31,41,11,45,76,47,167,5,261,-37,277,-83,183,-172,35,-122,-79,138,-70,266,69,124,228,0,391,-29,594,-84,702,-78,627,-8,551,-13,509,13,372,120,352,125,622,127,691,223,362,126,386,-33,915,198,958,457,456,298,500,233,1027,469,1096,426,918,160,1067,141,1220,189,1245,164,1375,297,1378,503,1299,702,1550,929,1799,855,1752,547,1830,602,1928,832,1736,796,1735,933,1961,1385,1935,1562,2105,1485,2716,1449,2948,1305,2768,1205,2716,1346,2531,1450,2470,1653,3117,2111,3370,2176,2696,1947,2925,2305,3846,2658,2425,2184,-877,1981,-2261,2623,-1645,2908,-1876,2732,-2704,2953,-2484,3116,-2120,2954,-2442,3216,-2466,3499,-2192,3234,-2392,3361,-2497,3869,-2078,3772,-1858,3915,-2066,4438,-2285,2934,-2294,-280,-2066,-1762,-1992,-1412,-2298,-1535,-2399,-1789,-2223,-1419,-2244,-1334,-2092,-1476,-1777,-1396,-2014,-1571,-2199,-1574,-1843,-1167,-1910,-1446,-2007,-1818,-1506,-1331,-2526,-2048,-5535,-4573,-7148,-5828,-6422,-5327,-5840,-5488,-5992,-6144,-6014,-6164,-6109,-6234,-6271,-6388,-6288,-6156,-6517,-6249,-6794,-6602,-6822,-6418,-6788,-6245,-6490,-6560,-6394,-6794,-7920,-6937,-10397,-7140,-11428,-6972,-11019,-6610,-11141,-6665,-11913,-7046,-11979,-7235,-11599,-7015,-11854,-6912,-12161,-7441,-12136,-7761,-12861,-7292,-13390,-7254,-12345,-7809,-12490,-7463,-13983,-6969,-10489,-8465,-2382,-11054,1272,-12247,-270,-12060,-323,-12113,502,-12486,-697,-12251,-1086,-12141,-181,-13116,-670,-13509,-1173,-12592,-443,-12811,-449,-13698,-934,-12850,-747,-13083,-873,-15036,-1161,-11478,-1047,-2669,-1407,1006,-1658,-1146,-1195,-1297,-1421,-73,-1946,-977,-1590,-1499,-1577,-1010,-1862,-1256,-1389,-962,-1692,-509,-2613,-1317,-2087,-1359,-1997,-1034,-2891,-2024,-119,-84,5651,5723,8074,8306,7156,6870,6985,7106,7312,8403,7114,8096,7173,7848,7082,7827,6761,7189,6985,7368,7076,7835,6992,7297,7453,7260,7016,7755,6025,7429,8533,7352,14150,7628,17142,7077,16399,6947,15939,7475,16564,7069,16463,6882,16400,7602,17031,7233,16543,6517,15395,7018,15985,7104,16689,6869,15655,7622,16155,7198,17884,6022,14056,8856,5665,14484,1815,16782,3034,15786,3107,15664,2312,16517,2965,16443,3036,16120,2287,16584,2479,16720,2693,16073,2535,16159,2958,16609,3067,16086,2716,16579,3035,17752,3092,13704,2499,5265,2620,1452,2808,3024,2444,3275,2839,2267,3340,2857,2968,3232,3066,2867,3152,3072,2248,2961,2413,2807,3238,3237,2368,2699,2262,2392,3537,3339,827,823,-5020,-5359,-7095,-7857,-5973,-6274,-6208,-6279,-6934,-7181,-6893,-6647,-7146,-6687,-7026,-7328,-6451,-6924,-6763,-6535,-7109,-6639,-6926,-6559,-7188,-6799,-6727,-6955,-5786,-6554,-8543,-6796,-14465,-7190,-17356,-6641,-16372,-6529,-15941,-6898,-16526,-6434,-16219,-6520,-16222,-7449,-17077,-7097,-16665,-6476,-15675,-7026,-16498,-6848,-17147,-6271,-15894,-7069,-16266,-7032,-17817,-5991,-13796,-8594,-5421,-14349,-1649,-17288,-2847,-16525,-2974,-15945,-2324,-16482,-3022,-16593,-3097,-16451,-2420,-16780,-2649,-16641,-2836,-15900,-2660,-16214,-3050,-16827,-3111,-15993,-2741,-16151,-2994,-17537,-2933,-13812,-2314,-5216,-2475,-1125,-2648,-2801,-2290,-3285,-2796,-2243,-3415,-2642,-3109,-3000,-3271,-2839,-3408,-3161,-2497,-2876,-2603,-2570,-3351,-3173,-2416,-2832,-2235,-2408,-3405,-3186,-613,-768,5271,5201,7376,7644,6241,6176,6366,6275,6964,7124,6831,6508,6998,6566,6836,7230,6277,6777,6589,6376,6934,6536,6819,6494,7160,6749,6736,6900,5822,6476,8593,6747,14520,7204,17448,6637,16490,6483,16033,6906,16600,6511,16304,6568,16279,7438,17079,7072,16624,6463,15577,7028,16343,6877,16990,6331,15760,7121,16140,7023,17719,5944,13748,8575,5401,14336,1645,17210,2880,16419,3036,15896,2382,16483,3074,16584,3143,16425,2443,16782,2650,16695,2825,15978,2632,16272,3015,16880,3084,16096,2709,16289,2965,17641,2932,13887,2323,5330,2474,1286,2656,2954,2309,3410,2803,2373,3414,2795,3106,3151,3263,2952,3403,3241,2483,2969,2568,2681,3316,3245,2383,2837,2199,2390,3396,3165,641,706,-5230,-5323,-7307,-7790,-6136,-6317,-6268,-6419,-6884,-7278,-6766,-6666,-6976,-6731,-6853,-7406,-6308,-6958,-6636,-6553,-6978,-6703,-6829,-6647,-7156,-6883,-6737,-7017,-5814,-6581,-8575,-6833,-14490,-7270,-17411,-6699,-16466,-6539,-16016,-6931,-16571,-6504,-16257,-6551,-16202,-7408,-16983,-7021,-16545,-6410,-15512,-6976,-16305,-6803,-17017,-6243,-15820,-7037,-16197,-6923,-17802,-5820,-13840,-8455,-5475,-14227,-1724,-17099,-2923,-16314,-3008,-15801,-2362,-16392,-3088,-16506,-3163,-16356,-2503,-16700,-2717,-16605,-2855,-15904,-2710,-16226,-3108,-16870,-3089,-16101,-2747,-16257,-3087,-17584,-2975,-13868,-2324,-5343,-2548,-1275,-2673,-2917,-2213,-3363,-2694,-2311,-3251,-2744,-2867,-3129,-3034,-2939,-3190,-3234,-2346,-2964,-2639,-2658,-3558,-3241,-2670,-2892,-2453,-2437,-3564,-3175,-771,-779,5105,5171,7308,7655,6265,6204,6397,6288,7024,7172,6903,6586,7002,6627,6777,7308,6190,6889,6537,6465,7011,6613,6985,6631,7393,6934,7073,7072,6112,6615,8751,6859,14672,7282,17448,6652,16146,6448,15565,6899,16151,6547,15860,6591,16048,7446,17065,7064,16661,6368,15774,6857,16524,6677,16825,6071,15577,6900,16119,7040,17490,6118,13495,8696,5432,14446,1678,17366,3036,16488,3624,15834,3012,16382,3575,16465,3685,16301,2815,16708,2982,16679,3356,15952,2934,16049,3290,16352,3964,15605,3612,16222,3647,17764,4272,13865,3977,5384,3592,1580,3794,3243,3627,3670,3622,2758,4007,3130,3835,3294,3964,3065,4468,3408,3933,3234,3789,3118,4634,3643,4211,3174,4155,3176,5512,4400,2792,1730,-3702,-4499,-5940,-6691,-4265,-5094,-4381,-5215,-4918,-5746,-4217,-4871,-4402,-4981,-4479,-5525,-3732,-4968,-4118,-4924,-4300,-5349,-3422,-5021,-3876,-4886,-4087,-4860,-2790,-4254,-5025,-4196,-10898,-4415,-13419,-4007,-12198,-4121,-11995,-4413,-12471,-3808,-11937,-3920,-11792,-4583,-12284,-3776,-12085,-3107,-11421,-3583,-11226,-3081,-11157,-2768,-10580,-3914,-10424,-3197,-11040,-1715,-9822,-5144,-6189,-11154,-4236,-13029,-5134,-11598,-5507,-10949,-4921,-11142,-4999,-11180,-4883,-11184,-4366,-11090,-4548,-10887,-4818,-10708,-4866,-10534,-5253,-10272,-5179,-9894,-4633,-10029,-4773,-10382,-4977,-8674,-4668,-5292,-4651,-3928,-4629,-4465,-4312,-3994,-4459,-3528,-4570,-4400,-4272,-4601,-4482,-4035,-4627,-4334,-4080,-4498,-4045,-3835,-4204,-3526,-3695,-3646,-4045,-4101,-4856,-4628,-3338,-3235,-673,-508,28,147,-453,-639,11,0,8,-2,7,0,7,-3,11,-8,15,-9,17,-6,17,-5,13,-3,7,0,3,0,-2,0,-4,0,-4,-2,-6,0,-14,-2,-17,-4,-8,0,-7,5,-17,7,-18,10,-7,18,-2,25,-3,27,0,31,4,34,4,34,8,36,8,37,2,36,4,34,8,28,3,15,0,11,0,12,-5,8,-4,10,0,23,-4,31,-8,30,-2,30,0,26,-6,22,-6,20,-12,15,-19,10,-10,13,-14,6,-43,-13,-43,-16,-9,-12,-10,-29,-42,-40,-37,-28,-5,-21,1,-24,-8,-20,4,-18,26,-24,44,-26,66,-30,86,-37,88,-41,72,-46,50,-31,28,23,14,64,16,51,26,32,34,39,42,48,35,58,0,72,-36,69,-59,58,-98,54,-124,36,-103,12,-110,5,-173,-19,-146,-59,-4,-42,51,1,-23,-6,-30,-6,45,46,47,70,6,55,19,60,38,62,42,47,61,46,40,42,-19,22,-34,6,-35,-50,-61,-141,-37,-171,17,-163,26,-180,46,-154,80,-63,48,-4,18,20,50,47,58,53,44,61,57,85,37,80,0,86,-8,106,-95,49,-213,-8,-131,47,49,63,40,-39,-69,-74,-37,-20,63,-12,58,-14,-12,25,-31,41,11,45,76,47,167,5,261,-37,277,-83,183,-172,35,-122,-79,138,-70,266,69,124,228,0,391,-29,594,-84,702,-78,627,-8,551,-13,509,13,372,120,352,125,622,127,691,223,362,126,386,-33,915,198,958,457,456,298,500,233,1027,469,1096,426,918,160,1067,141,1220,189,1245,164,1375,297,1378,503,1299,702,1550,929,1799,855,1752,547,1830,602,1928,832,1736,796,1735,933,1961,1385,1935,1562,2105,1485,2716,1449,2948,1305,2768,1205,2716,1346,2531,1450,2470,1653,3117,2111,3370,2176,2696,1947,2925,2305,3846,2658,2425,2184,-877,1981,-2261,2623,-1645,2908,-1876,2732,-2704,2953,-2484,3116,-2120,2954,-2442,3216,-2466,3499,-2192,3234,-2392,3361,-2497,3869,-2078,3772,-1858,3915,-2066,4438,-2285,2934,-2294,-280,-2066,-1762,-1992,-1412,-2298,-1535,-2399,-1789,-2223,-1419,-2244,-1334,-2092,-1476,-1777,-1396,-2014,-1571,-2199,-1574,-1843,-1167,-1910,-1446,-2007,-1818,-1506,-1331,-2526,-2048,-5535,-4573,-7148,-5828,-6422,-5327,-5840,-5488,-5992,-6144,-6014,-6164,-6109,-6234,-6271,-6388,-6288,-6156,-6517,-6249,-6794,-6602,-6822,-6418,-6788,-6245,-6490,-6560,-6394,-6794,-7920,-6937,-10397,-7140,-11428,-6972,-11019,-6610,-11141,-6665,-11913,-7046,-11979,-7235,-11599,-7015,-11854,-6912,-12161,-7441,-12136,-7761,-12861,-7292,-13390,-7254,-12345,-7809,-12490,-7463,-13983,-6969,-10489,-8465,-2382,-11054,1272,-12247,-270,-12060,-323,-12113,502,-12486,-697,-12251,-1086,-12141,-181,-13116,-670,-13509,-1173,-12592,-443,-12811,-449,-13698,-934,-12850,-747,-13083,-873,-15036,-1161,-11478,-1047,-2669,-1407,1006,-1658,-1146,-1195,-1297,-1421,-73,-1946,-977,-1590,-1499,-1577,-1010,-1862,-1256,-1389,-962,-1692,-509,-2613,-1317,-2087,-1359,-1997,-1034,-2891,-2024,-119,-84,5651,5723,8074,8306,7156,6870,6985,7106,7312,8403,7114,8096,7173,7848,7082,7827,6761,7189,6985,7368]}"#;
+
+use serde::Deserialize;
+use std::thread;
+
+#[derive(Deserialize)]
+struct DeriveStruct {
+    buffer: Vec<i16>,
+}
+
+fn main() {
+    let t = thread::spawn(|| {
+        let _info: DeriveStruct = serde_json::from_str(JSON).unwrap();
+    });
+    let _info: DeriveStruct = serde_json::from_str(JSON).unwrap();
+    t.join().unwrap();
+}
index 3f0ee5ecf6af61bcbe17a017c7b6e3fe86769e91..3cf25ba9cf6c287a9d75cc9c993541d38b4dbf60 100644 (file)
@@ -14,7 +14,7 @@ fn all_valid_chars() -> impl Iterator<Item = char> {
 
 fn main() {
     // Take only the first few chars because we don't want to wait all day
-    for c in all_valid_chars().take(2_000) {
+    for c in all_valid_chars().take(1_500) {
         let _ = UnicodeXID::is_xid_continue(c);
     }
 }
diff --git a/benches/fibonacci.rs b/benches/fibonacci.rs
deleted file mode 100644 (file)
index 9a68a69..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#![feature(test, rustc_private)]
-
-extern crate test;
-use crate::test::Bencher;
-mod helpers;
-use crate::helpers::*;
-
-#[bench]
-fn fib(bencher: &mut Bencher) {
-    bencher.iter(fibonacci_helper::main)
-}
-
-#[bench]
-fn fib_miri(bencher: &mut Bencher) {
-    miri_helper::run("fibonacci_helper", bencher);
-}
-
-#[bench]
-fn fib_iter(bencher: &mut Bencher) {
-    bencher.iter(fibonacci_helper_iterative::main)
-}
-
-#[bench]
-fn fib_iter_miri(bencher: &mut Bencher) {
-    miri_helper::run("fibonacci_helper_iterative", bencher);
-}
diff --git a/benches/helpers/fibonacci_helper.rs b/benches/helpers/fibonacci_helper.rs
deleted file mode 100644 (file)
index 586f1ce..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#[inline(never)]
-pub fn main() {
-    assert_eq!(fib(10), 55);
-}
-
-fn fib(n: usize) -> usize {
-    if n <= 2 { 1 } else { fib(n - 1) + fib(n - 2) }
-}
diff --git a/benches/helpers/fibonacci_helper_iterative.rs b/benches/helpers/fibonacci_helper_iterative.rs
deleted file mode 100644 (file)
index 0c27328..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#[inline(never)]
-pub fn main() {
-    assert_eq!(fib(10), 55);
-}
-
-fn fib(n: usize) -> usize {
-    let mut a = 0;
-    let mut b = 1;
-    for _ in 0..n {
-        let c = a;
-        a = b;
-        b += c;
-    }
-    a
-}
diff --git a/benches/helpers/miri_helper.rs b/benches/helpers/miri_helper.rs
deleted file mode 100644 (file)
index be542c2..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-extern crate rustc_driver;
-extern crate rustc_hir;
-extern crate rustc_interface;
-
-use rustc_driver::Compilation;
-use rustc_interface::{interface, Queries};
-
-use crate::test::Bencher;
-
-struct MiriCompilerCalls<'a> {
-    bencher: &'a mut Bencher,
-}
-
-impl rustc_driver::Callbacks for MiriCompilerCalls<'_> {
-    fn after_analysis<'tcx>(
-        &mut self,
-        compiler: &interface::Compiler,
-        queries: &'tcx Queries<'tcx>,
-    ) -> Compilation {
-        compiler.session().abort_if_errors();
-
-        queries.global_ctxt().unwrap().peek_mut().enter(|tcx| {
-            let (entry_def_id, entry_type) =
-                tcx.entry_fn(()).expect("no main or start function found");
-
-            self.bencher.iter(|| {
-                let config = miri::MiriConfig::default();
-                miri::eval_entry(tcx, entry_def_id, entry_type, config);
-            });
-        });
-
-        compiler.session().abort_if_errors();
-
-        Compilation::Stop
-    }
-}
-
-fn find_sysroot() -> String {
-    // Taken from https://github.com/Manishearth/rust-clippy/pull/911.
-    let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
-    let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
-    match (home, toolchain) {
-        (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
-        _ =>
-            option_env!("RUST_SYSROOT")
-                .expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
-                .to_owned(),
-    }
-}
-
-pub fn run(filename: &str, bencher: &mut Bencher) {
-    let args = &[
-        "miri".to_string(),
-        format!("benches/helpers/{}.rs", filename),
-        "--sysroot".to_string(),
-        find_sysroot(),
-    ];
-    rustc_driver::RunCompiler::new(args, &mut MiriCompilerCalls { bencher }).run().unwrap()
-}
diff --git a/benches/helpers/mod.rs b/benches/helpers/mod.rs
deleted file mode 100644 (file)
index 27504a2..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// This module gets included in multiple crates, and they each only use part of it.
-#![allow(dead_code)]
-
-pub mod fibonacci_helper;
-pub mod fibonacci_helper_iterative;
-pub mod miri_helper;
-pub mod smoke_helper;
diff --git a/benches/helpers/repeat.rs b/benches/helpers/repeat.rs
deleted file mode 100644 (file)
index 0e8c598..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-fn main() {
-    let data: [u8; 1024] = [42; 1024];
-    assert_eq!(data.len(), 1024);
-}
diff --git a/benches/helpers/repeat_manual.rs b/benches/helpers/repeat_manual.rs
deleted file mode 100644 (file)
index bd5d6b1..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-fn main() {
-    let mut data: [u8; 1024] = unsafe { std::mem::uninitialized() };
-    for i in 0..data.len() {
-        unsafe {
-            std::ptr::write(&mut data[i], 0);
-        }
-    }
-    assert_eq!(data.len(), 1024);
-}
diff --git a/benches/helpers/smoke_helper.rs b/benches/helpers/smoke_helper.rs
deleted file mode 100644 (file)
index e81db81..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#[inline(never)]
-pub fn main() {}
diff --git a/benches/repeat.rs b/benches/repeat.rs
deleted file mode 100644 (file)
index 0369b1f..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#![feature(test, rustc_private)]
-
-extern crate test;
-use crate::test::Bencher;
-mod helpers;
-use crate::helpers::*;
-
-#[bench]
-fn repeat(bencher: &mut Bencher) {
-    miri_helper::run("repeat", bencher);
-}
-
-#[bench]
-fn repeat_manual(bencher: &mut Bencher) {
-    miri_helper::run("repeat_manual", bencher);
-}
diff --git a/benches/smoke.rs b/benches/smoke.rs
deleted file mode 100644 (file)
index 372cd0b..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#![feature(test, rustc_private)]
-
-extern crate test;
-use crate::test::Bencher;
-mod helpers;
-use crate::helpers::*;
-
-#[bench]
-fn noop(bencher: &mut Bencher) {
-    bencher.iter(smoke_helper::main)
-}
-
-/*
-// really slow
-#[bench]
-fn noop_miri_full(bencher: &mut Bencher) {
-    let path = std::env::var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set");
-    bencher.iter(|| {
-        let mut process = std::process::Command::new("target/release/miri");
-        process.arg("benches/smoke_helper.rs")
-               .arg("--sysroot").arg(&path);
-        let output = process.output().unwrap();
-        if !output.status.success() {
-            println!("{}", String::from_utf8(output.stdout).unwrap());
-            println!("{}", String::from_utf8(output.stderr).unwrap());
-            panic!("failed to run miri");
-        }
-    })
-}
-*/
-
-#[bench]
-fn noop_miri_interpreter(bencher: &mut Bencher) {
-    miri_helper::run("smoke_helper", bencher);
-}
diff --git a/ci.sh b/ci.sh
index b914477d44a81ca5817d9818d54b83f807d7868f..e7c6ed833c60c4b60bed064f5128570375a5f70b 100755 (executable)
--- a/ci.sh
+++ b/ci.sh
@@ -1,15 +1,16 @@
 #!/bin/bash
 set -euo pipefail
+set -x
 
 # Determine configuration
 export RUSTFLAGS="-D warnings"
 export CARGO_INCREMENTAL=0
-export CARGO_EXTRA_FLAGS="--all-features"
+export CARGO_EXTRA_FLAGS="--all-features" # in particular, expensive-debug-assertions
 
 # Prepare
 echo "Build and install miri"
-./miri build --all-targets --locked
-./miri install # implicitly locked
+CARGO_EXTRA_FLAGS="" ./miri install # implicitly locked -- and the *installed* Miri does *not* get the expensive-debug-assertions feature
+./miri build --all-targets --locked # the build that all the `./miri test` below will use
 echo
 
 # Test
@@ -40,6 +41,13 @@ function run_tests {
   # any interactive questions.
   ${PYTHON} test-cargo-miri/run-test.py
   echo
+
+  # Ensure that our benchmarks all work, on the host at least.
+  if [ -z "${MIRI_TEST_TARGET+exists}" ]; then
+    for BENCH in $(ls "bench-cargo-miri"); do
+      cargo miri run --manifest-path bench-cargo-miri/$BENCH/Cargo.toml
+    done
+  fi
 }
 
 function run_tests_minimal {
diff --git a/miri b/miri
index da5634d6a95c1b6e1a607c64276e17d07b8bfe56..2debf70c1664449b071421cd8208e04fd090a0f0 100755 (executable)
--- a/miri
+++ b/miri
@@ -37,6 +37,10 @@ Runs <command> over and over again with different seeds for Miri. The MIRIFLAGS
 variable is set to its original value appended with ` -Zmiri-seed=$SEED` for
 many different seeds.
 
+./miri bench <benches>:
+Runs the benchmarks from bench-cargo-miri in hyperfine. hyperfine needs to be installed.
+<benches> can explicitly list the benchmarks to run; by default, all of them are run.
+
   ENVIRONMENT VARIABLES
 
 MIRI_SYSROOT:
@@ -47,6 +51,11 @@ Pass extra flags to all cargo invocations.
 EOF
 )
 
+## Preparation
+# macOS does not have a useful readlink/realpath so we have to use Python instead...
+MIRIDIR=$(python3 -c 'import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' "$0")
+TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1)
+
 # Determine command.
 COMMAND="$1"
 [ $# -gt 0 ] && shift
@@ -60,14 +69,23 @@ many-seeds)
     done
     exit 0
     ;;
+bench)
+    # Make sure we have an up-to-date Miri installed
+    "$0" install
+    # Run the requested benchmarks
+    if [ -z "$@" ]; then
+        BENCHES=( $(ls "$MIRIDIR/bench-cargo-miri" ) )
+    else
+        BENCHES=("$@")
+    fi
+    for BENCH in "${BENCHES[@]}"; do
+        hyperfine -w 1 -m 5 --shell=none "cargo +$TOOLCHAIN miri run --manifest-path bench-cargo-miri/$BENCH/Cargo.toml"
+    done
+    exit 0
+    ;;
 esac
 
-## Preparation
-# macOS does not have a useful readlink/realpath so we have to use Python instead...
-MIRIDIR=$(python3 -c 'import os, sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' "$0")
-# Determine toolchain *in the Miri dir* and use that.
-TOOLCHAIN=$(cd "$MIRIDIR"; rustup show active-toolchain | head -n 1 | cut -d ' ' -f 1)
-
+## Prepare the environment
 # Determine some toolchain properties
 TARGET=$(rustc +$TOOLCHAIN --version --verbose | grep "^host:" | cut -d ' ' -f 2)
 SYSROOT=$(rustc +$TOOLCHAIN --print sysroot)
index a942390e549f5ea41099b4fe1a338ffa92ba3f47..11b5a21b2af898fcb4be0199b1210c826488e568 100644 (file)
@@ -8,7 +8,6 @@
 use rustc_span::{source_map::DUMMY_SP, Span, SpanData, Symbol};
 use rustc_target::abi::{Align, Size};
 
-use crate::helpers::HexRange;
 use crate::stacked_borrows::{diagnostics::TagHistory, AccessKind};
 use crate::*;
 
@@ -184,14 +183,14 @@ pub fn report_error<'tcx, 'mir>(
                     ];
                     match history {
                         Some(TagHistory::Tagged {tag, created: (created_range, created_span), invalidated, protected }) => {
-                            let msg = format!("{:?} was created by a retag at offsets {}", tag, HexRange(*created_range));
+                            let msg = format!("{tag:?} was created by a retag at offsets {created_range:?}");
                             helps.push((Some(*created_span), msg));
                             if let Some((invalidated_range, invalidated_span)) = invalidated {
-                                let msg = format!("{:?} was later invalidated at offsets {}", tag, HexRange(*invalidated_range));
+                                let msg = format!("{tag:?} was later invalidated at offsets {invalidated_range:?}");
                                 helps.push((Some(*invalidated_span), msg));
                             }
                             if let Some((protecting_tag, protecting_tag_span, protection_span)) = protected {
-                                helps.push((Some(*protecting_tag_span), format!("{:?} was protected due to {:?} which was created here", tag, protecting_tag)));
+                                helps.push((Some(*protecting_tag_span), format!("{tag:?} was protected due to {protecting_tag:?} which was created here")));
                                 helps.push((Some(*protection_span), format!("this protector is live for this call")));
                             }
                         }
@@ -448,32 +447,38 @@ fn process_diagnostics(&self, info: TopFrameInfo<'tcx>) {
             for e in diagnostics.drain(..) {
                 use NonHaltingDiagnostic::*;
                 let msg = match e {
-                    CreatedPointerTag(tag, None) => format!("created tag {tag:?}"),
+                    CreatedPointerTag(tag, None) =>
+                        format!("created tag {tag:?}"),
                     CreatedPointerTag(tag, Some((alloc_id, range))) =>
-                        format!("created tag {tag:?} at {alloc_id:?}{}", HexRange(range)),
+                        format!("created tag {tag:?} at {alloc_id:?}{range:?}"),
                     PoppedPointerTag(item, tag) =>
                         match tag {
                             None =>
                                 format!(
-                                    "popped tracked tag for item {:?} due to deallocation",
-                                    item
+                                    "popped tracked tag for item {item:?} due to deallocation",
                                 ),
                             Some((tag, access)) => {
                                 format!(
-                                    "popped tracked tag for item {:?} due to {:?} access for {:?}",
-                                    item, access, tag
+                                    "popped tracked tag for item {item:?} due to {access:?} access for {tag:?}",
                                 )
                             }
                         },
-                    CreatedCallId(id) => format!("function call with id {id}"),
+                    CreatedCallId(id) =>
+                        format!("function call with id {id}"),
                     CreatedAlloc(AllocId(id), size, align, kind) =>
-                        format!("created {kind} allocation of {} bytes (alignment {} bytes) with id {id}", size.bytes(), align.bytes()),
-                    FreedAlloc(AllocId(id)) => format!("freed allocation with id {id}"),
+                        format!(
+                            "created {kind} allocation of {size} bytes (alignment {align} bytes) with id {id}",
+                            size = size.bytes(),
+                            align = align.bytes(),
+                        ),
+                    FreedAlloc(AllocId(id)) =>
+                        format!("freed allocation with id {id}"),
                     RejectedIsolatedOp(ref op) =>
                         format!("{op} was made to return an error due to isolation"),
                     ProgressReport =>
                         format!("progress report: current operation being executed is here"),
-                    Int2Ptr { .. } => format!("integer-to-pointer cast"),
+                    Int2Ptr { .. } =>
+                        format!("integer-to-pointer cast"),
                 };
 
                 let (title, diag_level) = match e {
index 7e702e065619d7597b645e61497605388436e046..4b2604afa2c1532ea3f3cc177bf1e19ac3db0d0f 100644 (file)
@@ -905,15 +905,6 @@ pub fn get_local_crates(tcx: TyCtxt<'_>) -> Vec<CrateNum> {
     local_crates
 }
 
-/// Formats an AllocRange like [0x1..0x3], for use in diagnostics.
-pub struct HexRange(pub AllocRange);
-
-impl std::fmt::Display for HexRange {
-    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        write!(f, "[{:#x}..{:#x}]", self.0.start.bytes(), self.0.end().bytes())
-    }
-}
-
 /// Helper function used inside the shims of foreign functions to check that
 /// `target_os` is a supported UNIX OS.
 pub fn target_os_is_unix(target_os: &str) -> bool {
index fe3716a911162a15d378dc91e97695cb49692eff..cee643fdf82122807dbb005173dfb28d59322f6f 100644 (file)
@@ -4,7 +4,7 @@
 use rustc_span::{Span, SpanData};
 use rustc_target::abi::Size;
 
-use crate::helpers::{CurrentSpan, HexRange};
+use crate::helpers::CurrentSpan;
 use crate::stacked_borrows::{err_sb_ub, AccessKind, Permission};
 use crate::Item;
 use crate::SbTag;
@@ -178,7 +178,7 @@ fn operation_summary(
     alloc_id: AllocId,
     alloc_range: AllocRange,
 ) -> String {
-    format!("this error occurs as part of {} at {:?}{}", operation, alloc_id, HexRange(alloc_range))
+    format!("this error occurs as part of {operation} at {alloc_id:?}{alloc_range:?}")
 }
 
 fn error_cause(stack: &Stack, tag: SbTagExtra) -> &'static str {