diff options
| author | The Miri Cronjob Bot <miri@cron.bot> | 2025-05-12 05:01:00 +0000 |
|---|---|---|
| committer | The Miri Cronjob Bot <miri@cron.bot> | 2025-05-12 05:01:00 +0000 |
| commit | 7479482e2166e82b46d621b2759c6af0dda820e8 (patch) | |
| tree | 646043ebdc679f5d8da3ae7c5858a0ad2a8a38e5 /src | |
| parent | 30eca8ba9160bf18c4f0a3c9bb760d270f012240 (diff) | |
| parent | 718ddf660e6a1802c39b4962cf7eaa4db57025ef (diff) | |
| download | rust-7479482e2166e82b46d621b2759c6af0dda820e8.tar.gz rust-7479482e2166e82b46d621b2759c6af0dda820e8.zip | |
Merge from rustc
Diffstat (limited to 'src')
27 files changed, 169 insertions, 143 deletions
diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock index cdad3bd46fa..05ab1b6edde 100644 --- a/src/bootstrap/Cargo.lock +++ b/src/bootstrap/Cargo.lock @@ -220,9 +220,9 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" dependencies = [ "libc", "windows-sys 0.59.0", @@ -236,13 +236,13 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "fd-lock" -version = "4.0.2" +version = "4.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e5768da2206272c81ef0b5e951a41862938a6070da63bcea197899942d3b947" +checksum = "0ce92ff622d6dadf7349484f42c93271a0d49b7cc4d466a936405bacbe10aa78" dependencies = [ "cfg-if", - "rustix 0.38.40", - "windows-sys 0.52.0", + "rustix", + "windows-sys 0.59.0", ] [[package]] @@ -347,9 +347,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.171" +version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] name = "libredox" @@ -364,12 +364,6 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - -[[package]] -name = "linux-raw-sys" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413" @@ -585,19 +579,6 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rustix" -version = "0.38.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys 0.4.14", - "windows-sys 0.52.0", -] - -[[package]] -name = "rustix" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7178faa4b75a30e269c71e61c353ce2748cf3d76f0c44c393f4e60abf49b825" @@ -605,7 +586,7 @@ dependencies = [ "bitflags", "errno", "libc", - "linux-raw-sys 0.9.3", + "linux-raw-sys", "windows-sys 0.59.0", ] @@ -745,7 +726,7 @@ dependencies = [ "fastrand", "getrandom", "once_cell", - "rustix 1.0.2", + "rustix", "windows-sys 0.59.0", ] @@ -1182,13 +1163,12 @@ dependencies = [ [[package]] name = "xattr" -version = "1.3.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da84f1a25939b27f6820d92aed108f83ff920fdf11a7b19366c27c4cda81d4f" +checksum = "0d65cbf2f12c15564212d48f4e3dfb87923d25d611f2aed18f4cb23f0413d89e" dependencies = [ "libc", - "linux-raw-sys 0.4.14", - "rustix 0.38.40", + "rustix", ] [[package]] diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs index b95d07356c1..da305fb18fa 100644 --- a/src/bootstrap/src/core/download.rs +++ b/src/bootstrap/src/core/download.rs @@ -852,7 +852,8 @@ download-rustc = false t!(fs::create_dir_all(&gcc_cache)); } let base = &self.stage0_metadata.config.artifacts_server; - let filename = format!("gcc-nightly-{}.tar.xz", self.build.triple); + let version = self.artifact_version_part(gcc_sha); + let filename = format!("gcc-{version}-{}.tar.xz", self.build.triple); let tarball = gcc_cache.join(&filename); if !tarball.exists() { let help_on_error = "ERROR: failed to download gcc from ci diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh b/src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh index 28c035daa5d..9ed5b519b6e 100755 --- a/src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh +++ b/src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh @@ -40,6 +40,14 @@ if [ -z "${PR_CI_JOB:-}" ]; then else python3 "$X_PY" test --stage 2 src/tools/miri src/tools/miri/cargo-miri fi +# We re-run the test suite for a chance to find bugs in the intrinsic fallback bodies and in MIR +# optimizations. This can miss UB, so we only run the "pass" tests. We need to enable debug +# assertions as `-O` disables them but some tests rely on them. We also set a cfg flag so tests can +# adjust their expectations if needed. This can change the output of the tests so we ignore that, +# we only ensure that all assertions still pass. +MIRIFLAGS="-Zmiri-force-intrinsic-fallback --cfg force_intrinsic_fallback -O -Zmir-opt-level=4 -Cdebug-assertions=yes" \ + MIRI_SKIP_UI_CHECKS=1 \ + python3 "$X_PY" test --stage 2 src/tools/miri -- tests/{pass,panic} # We natively run this script on x86_64-unknown-linux-gnu and x86_64-pc-windows-msvc. # Also cover some other targets via cross-testing, in particular all tier 1 targets. case $HOST_TARGET in diff --git a/src/doc/edition-guide b/src/doc/edition-guide -Subproject 467f45637b73ec6aa70fb36bc3054bb50b8967e +Subproject 1b1bb49babd65c732468cfa515b0c009bd1d26b diff --git a/src/doc/rustc-dev-guide/src/tests/compiletest.md b/src/doc/rustc-dev-guide/src/tests/compiletest.md index 2c35381eadf..0ba078f0b49 100644 --- a/src/doc/rustc-dev-guide/src/tests/compiletest.md +++ b/src/doc/rustc-dev-guide/src/tests/compiletest.md @@ -325,12 +325,8 @@ The tests in [`tests/codegen-units`] test the [monomorphization](../backend/monomorph.md) collector and CGU partitioning. These tests work by running `rustc` with a flag to print the result of the -monomorphization collection pass, and then special annotations in the file are -used to compare against that. - -Each test should be annotated with the `//@ -compile-flags:-Zprint-mono-items=VAL` directive with the appropriate `VAL` to -instruct `rustc` to print the monomorphization information. +monomorphization collection pass, i.e., `-Zprint-mono-items`, and then special +annotations in the file are used to compare against that. Then, the test should be annotated with comments of the form `//~ MONO_ITEM name` where `name` is the monomorphized string printed by rustc like `fn <u32 as diff --git a/src/doc/unstable-book/src/library-features/duration-constructors-lite.md b/src/doc/unstable-book/src/library-features/duration-constructors-lite.md new file mode 100644 index 00000000000..5238b84f776 --- /dev/null +++ b/src/doc/unstable-book/src/library-features/duration-constructors-lite.md @@ -0,0 +1,11 @@ +# `duration_constructors_lite` + +The tracking issue for this feature is: [#140881] + +[#140881]: https://github.com/rust-lang/rust/issues/140881 + +------------------------ + +Add the methods `from_mins`, `from_hours` to `Duration`. + +For `from_days` and `from_weeks` see [`duration_constructors`](https://github.com/rust-lang/rust/issues/120301). diff --git a/src/doc/unstable-book/src/library-features/duration-constructors.md b/src/doc/unstable-book/src/library-features/duration-constructors.md index 098519c7c90..49ad78d1961 100644 --- a/src/doc/unstable-book/src/library-features/duration-constructors.md +++ b/src/doc/unstable-book/src/library-features/duration-constructors.md @@ -6,4 +6,5 @@ The tracking issue for this feature is: [#120301] ------------------------ -Add the methods `from_mins`, `from_hours` and `from_days` to `Duration`. +Add the methods `from_days` and `from_weeks` to `Duration`. +For `from_mins` and `from_hours` see [duration-constructors-lite.md](./duration-constructors-lite.md) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 4ef73ff48ed..f93aa8ffd0d 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -174,7 +174,7 @@ pub(crate) struct Options { pub(crate) expanded_args: Vec<String>, /// Arguments to be used when compiling doctests. - pub(crate) doctest_compilation_args: Vec<String>, + pub(crate) doctest_build_args: Vec<String>, } impl fmt::Debug for Options { @@ -802,7 +802,7 @@ impl Options { let scrape_examples_options = ScrapeExamplesOptions::new(matches, dcx); let with_examples = matches.opt_strs("with-examples"); let call_locations = crate::scrape_examples::load_call_locations(with_examples, dcx); - let doctest_compilation_args = matches.opt_strs("doctest-compilation-args"); + let doctest_build_args = matches.opt_strs("doctest-build-arg"); let unstable_features = rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref()); @@ -851,7 +851,7 @@ impl Options { scrape_examples_options, unstable_features, expanded_args: args, - doctest_compilation_args, + doctest_build_args, }; let render_options = RenderOptions { output, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 0cdf2f92a89..ef70b862185 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -51,46 +51,6 @@ pub(crate) struct GlobalTestOptions { pub(crate) args_file: PathBuf, } -/// Function used to split command line arguments just like a shell would. -fn split_args(args: &str) -> Vec<String> { - let mut out = Vec::new(); - let mut iter = args.chars(); - let mut current = String::new(); - - while let Some(c) = iter.next() { - if c == '\\' { - if let Some(c) = iter.next() { - // If it's escaped, even a quote or a whitespace will be ignored. - current.push(c); - } - } else if c == '"' || c == '\'' { - while let Some(new_c) = iter.next() { - if new_c == c { - break; - } else if new_c == '\\' { - if let Some(c) = iter.next() { - // If it's escaped, even a quote will be ignored. - current.push(c); - } - } else { - current.push(new_c); - } - } - } else if " \n\t\r".contains(c) { - if !current.is_empty() { - out.push(current.clone()); - current.clear(); - } - } else { - current.push(c); - } - } - if !current.is_empty() { - out.push(current); - } - out -} - pub(crate) fn generate_args_file(file_path: &Path, options: &RustdocOptions) -> Result<(), String> { let mut file = File::create(file_path) .map_err(|error| format!("failed to create args file: {error:?}"))?; @@ -119,9 +79,7 @@ pub(crate) fn generate_args_file(file_path: &Path, options: &RustdocOptions) -> content.push(format!("-Z{unstable_option_str}")); } - for compilation_args in &options.doctest_compilation_args { - content.extend(split_args(compilation_args)); - } + content.extend(options.doctest_build_args.clone()); let content = content.join("\n"); diff --git a/src/librustdoc/doctest/tests.rs b/src/librustdoc/doctest/tests.rs index 49add73e9d6..618c2041b43 100644 --- a/src/librustdoc/doctest/tests.rs +++ b/src/librustdoc/doctest/tests.rs @@ -382,28 +382,6 @@ fn main() { } #[test] -fn check_split_args() { - fn compare(input: &str, expected: &[&str]) { - let output = super::split_args(input); - let expected = expected.iter().map(|s| s.to_string()).collect::<Vec<_>>(); - assert_eq!(expected, output, "test failed for {input:?}"); - } - - compare("'a' \"b\"c", &["a", "bc"]); - compare("'a' \"b \"c d", &["a", "b c", "d"]); - compare("'a' \"b\\\"c\"", &["a", "b\"c"]); - compare("'a\"'", &["a\""]); - compare("\"a'\"", &["a'"]); - compare("\\ a", &[" a"]); - compare("\\\\", &["\\"]); - compare("a'", &["a"]); - compare("a ", &["a"]); - compare("a b", &["a", "b"]); - compare("a\n\t \rb", &["a", "b"]); - compare("a\n\t1 \rb", &["a", "1", "b"]); -} - -#[test] fn comment_in_attrs() { // If there is an inline code comment after attributes, we need to ensure that // a backline will be added to prevent generating code "inside" it (and thus generating) diff --git a/src/librustdoc/html/static/css/noscript.css b/src/librustdoc/html/static/css/noscript.css index 477a79d63e9..a3c6bf98161 100644 --- a/src/librustdoc/html/static/css/noscript.css +++ b/src/librustdoc/html/static/css/noscript.css @@ -43,6 +43,7 @@ nav.sub { --settings-button-border-focus: #717171; --sidebar-background-color: #f5f5f5; --sidebar-background-color-hover: #e0e0e0; + --sidebar-border-color: #ddd; --code-block-background-color: #f5f5f5; --scrollbar-track-background-color: #dcdcdc; --scrollbar-thumb-background-color: rgba(36, 37, 39, 0.6); @@ -149,6 +150,7 @@ nav.sub { --settings-button-border-focus: #ffb900; --sidebar-background-color: #505050; --sidebar-background-color-hover: #676767; + --sidebar-border-color: #2A2A2A; --code-block-background-color: #2A2A2A; --scrollbar-track-background-color: #717171; --scrollbar-thumb-background-color: rgba(32, 34, 37, .6); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index f838f3f1106..a81d5c9c49b 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1,4 +1,6 @@ -/* When static files are updated, their suffixes need to be updated. +/* ignore-tidy-filelength */ +/* + When static files are updated, their suffixes need to be updated. 1. In the top directory run: ./x.py doc --stage 1 library/core 2. Find the directory containing files named with updated suffixes: @@ -496,12 +498,13 @@ img { top: 0; left: 0; z-index: var(--desktop-sidebar-z-index); + /* resize indicator: hide this when on touch or mobile */ + border-right: solid 1px var(--sidebar-border-color); } .rustdoc.src .sidebar { flex-basis: 50px; width: 50px; - border-right: 1px solid; overflow-x: hidden; /* The sidebar is by default hidden */ overflow-y: hidden; @@ -515,12 +518,27 @@ img { .sidebar-resizer { touch-action: none; width: 9px; - cursor: col-resize; + cursor: ew-resize; z-index: calc(var(--desktop-sidebar-z-index) + 1); position: fixed; height: 100%; - /* make sure there's a 1px gap between the scrollbar and resize handle */ - left: calc(var(--desktop-sidebar-width) + 1px); + left: var(--desktop-sidebar-width); + display: flex; + align-items: center; + justify-content: flex-start; + color: var(--right-side-color); +} +.sidebar-resizer::before { + content: ""; + border-right: dotted 2px currentColor; + width: 2px; + height: 12px; +} +.sidebar-resizer::after { + content: ""; + border-right: dotted 2px currentColor; + width: 2px; + height: 16px; } .rustdoc.src .sidebar-resizer { @@ -543,11 +561,12 @@ img { } .sidebar-resizing * { - cursor: col-resize !important; + cursor: ew-resize !important; } .sidebar-resizing .sidebar { position: fixed; + border-right: solid 2px var(--sidebar-resizer-active); } .sidebar-resizing > body { padding-left: var(--resizing-sidebar-width); @@ -561,8 +580,9 @@ img { margin: 0; /* when active or hovered, place resizer glow on top of the sidebar (right next to, or even on top of, the scrollbar) */ - left: var(--desktop-sidebar-width); + left: calc(var(--desktop-sidebar-width) - 1px); border-left: solid 1px var(--sidebar-resizer-hover); + color: var(--sidebar-resizer-hover); } .src-sidebar-expanded .rustdoc.src .sidebar-resizer:hover, @@ -578,21 +598,20 @@ img { /* too easy to hit the resizer while trying to hit the [-] toggle */ display: none !important; } + .sidebar { + /* resize indicator: hide this when on touch or mobile */ + border-right: none; + } } .sidebar-resizer.active { /* make the resize tool bigger when actually resizing, to avoid :hover styles on other stuff while resizing */ padding: 0 140px; - width: 2px; + width: calc(140px + 140px + 9px + 2px); margin-left: -140px; border-left: none; -} -.sidebar-resizer.active::before { - border-left: solid 2px var(--sidebar-resizer-active); - display: block; - height: 100%; - content: ""; + color: var(--sidebar-resizer-active); } .sidebar, .mobile-topbar, .sidebar-menu-toggle, @@ -2509,6 +2528,8 @@ in src-script.js and main.js /* Reduce height slightly to account for mobile topbar. */ height: calc(100vh - 45px); width: 200px; + /* resize indicator: hide this when on touch or mobile */ + border-right: none; } /* The source view uses a different design for the sidebar toggle, and doesn't have a topbar, @@ -2897,6 +2918,7 @@ by default. --settings-button-border-focus: #717171; --sidebar-background-color: #f5f5f5; --sidebar-background-color-hover: #e0e0e0; + --sidebar-border-color: #ddd; --code-block-background-color: #f5f5f5; --scrollbar-track-background-color: #dcdcdc; --scrollbar-thumb-background-color: rgba(36, 37, 39, 0.6); @@ -3002,6 +3024,7 @@ by default. --settings-button-border-focus: #ffb900; --sidebar-background-color: #505050; --sidebar-background-color-hover: #676767; + --sidebar-border-color: #999; --code-block-background-color: #2A2A2A; --scrollbar-track-background-color: #717171; --scrollbar-thumb-background-color: rgba(32, 34, 37, .6); @@ -3114,6 +3137,7 @@ Original by Dempfi (https://github.com/dempfi/ayu) --settings-button-border-focus: #e0e0e0; --sidebar-background-color: #14191f; --sidebar-background-color-hover: rgba(70, 70, 70, 0.33); + --sidebar-border-color: #5c6773; --code-block-background-color: #191f26; --scrollbar-track-background-color: transparent; --scrollbar-thumb-background-color: #5c6773; diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index 5ef376f4acb..7af99e7097c 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -114,7 +114,7 @@ {% endif %} {{ sidebar|safe }} </nav> {# #} - <div class="sidebar-resizer"></div> {# #} + <div class="sidebar-resizer" title="Drag to resize sidebar"></div> {# #} <main> {% if page.css_class != "src" %}<div class="width-limiter">{% endif %} {# defined in storage.js to avoid duplicating complex UI across every page #} diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index bca40b8117b..b4210e7b518 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -73,9 +73,11 @@ extern crate tikv_jemalloc_sys as jemalloc_sys; use std::env::{self, VarError}; use std::io::{self, IsTerminal}; +use std::path::Path; use std::process; use rustc_errors::DiagCtxtHandle; +use rustc_hir::def_id::LOCAL_CRATE; use rustc_interface::interface; use rustc_middle::ty::TyCtxt; use rustc_session::config::{ErrorOutputType, RustcOptGroup, make_crate_type_option}; @@ -654,9 +656,9 @@ fn opts() -> Vec<RustcOptGroup> { Unstable, Multi, "", - "doctest-compilation-args", - "", - "add arguments to be used when compiling doctests", + "doctest-build-arg", + "One argument (of possibly many) to be used when compiling doctests", + "ARG", ), opt( Unstable, @@ -904,6 +906,10 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { rustc_interface::passes::write_dep_info(tcx); } + if let Some(metrics_dir) = &sess.opts.unstable_opts.metrics_dir { + dump_feature_usage_metrics(tcx, metrics_dir); + } + if run_check { // Since we're in "check" mode, no need to generate anything beyond this point. return; @@ -923,3 +929,16 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { }) }) } + +fn dump_feature_usage_metrics(tcxt: TyCtxt<'_>, metrics_dir: &Path) { + let hash = tcxt.crate_hash(LOCAL_CRATE); + let crate_name = tcxt.crate_name(LOCAL_CRATE); + let metrics_file_name = format!("unstable_feature_usage_metrics-{crate_name}-{hash}.json"); + let metrics_path = metrics_dir.join(metrics_file_name); + if let Err(error) = tcxt.features().dump_feature_usage_metrics(metrics_path) { + // FIXME(yaahc): once metrics can be enabled by default we will want "failure to emit + // default metrics" to only produce a warning when metrics are enabled by default and emit + // an error only when the user manually enables metrics + tcxt.dcx().err(format!("cannot emit feature usage metrics: {error}")); + } +} diff --git a/src/tools/cargo b/src/tools/cargo -Subproject 7918c7eb59614c39f1c4e27e99d557720976bdd +Subproject 056f5f4f3c100cb36b5e9aed2d20b9ea70aae29 diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 40c9f29375b..3c87bcb205f 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1583,7 +1583,10 @@ impl<'test> TestCx<'test> { Crashes => { set_mir_dump_dir(&mut rustc); } - Pretty | DebugInfo | Rustdoc | RustdocJson | RunMake | CodegenUnits | RustdocJs => { + CodegenUnits => { + rustc.arg("-Zprint-mono-items"); + } + Pretty | DebugInfo | Rustdoc | RustdocJson | RunMake | RustdocJs => { // do not use JSON output } } diff --git a/src/tools/coverage-dump/Cargo.toml b/src/tools/coverage-dump/Cargo.toml index 6f92ac50d96..36a66f16030 100644 --- a/src/tools/coverage-dump/Cargo.toml +++ b/src/tools/coverage-dump/Cargo.toml @@ -10,6 +10,6 @@ anyhow = "1.0.71" itertools = "0.12" leb128 = "0.2.5" md5 = { package = "md-5" , version = "0.10.5" } -miniz_oxide = "0.7.1" +miniz_oxide = "0.8.8" regex = "1.8.4" rustc-demangle = "0.1.23" diff --git a/src/tools/miri/README.md b/src/tools/miri/README.md index a78cc9d9319..b692ddab4ff 100644 --- a/src/tools/miri/README.md +++ b/src/tools/miri/README.md @@ -393,6 +393,9 @@ to Miri failing to detect cases of undefined behavior in a program. disables the randomization of the next thread to be picked, instead fixing a round-robin schedule. Note however that other aspects of Miri's concurrency behavior are still randomize; use `-Zmiri-deterministic-concurrency` to disable them all. +* `-Zmiri-force-intrinsic-fallback` forces the use of the "fallback" body for all intrinsics that + have one. This is useful to test the fallback bodies, but should not be used otherwise. It is + **unsound** since the fallback body might not be checking for all UB. * `-Zmiri-native-lib=<path to a shared object file>` is an experimental flag for providing support for calling native functions from inside the interpreter via FFI. The flag is supported only on Unix systems. Functions not provided by that file are still executed via the usual Miri shims. diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index eb5111774a0..469fc264970 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -584,6 +584,8 @@ fn main() { } else if arg == "-Zmiri-ignore-leaks" { miri_config.ignore_leaks = true; miri_config.collect_leak_backtraces = false; + } else if arg == "-Zmiri-force-intrinsic-fallback" { + miri_config.force_intrinsic_fallback = true; } else if arg == "-Zmiri-strict-provenance" { miri_config.provenance_mode = ProvenanceMode::Strict; } else if arg == "-Zmiri-permissive-provenance" { diff --git a/src/tools/miri/src/eval.rs b/src/tools/miri/src/eval.rs index bb5e5d7ee81..a90c6ab9d40 100644 --- a/src/tools/miri/src/eval.rs +++ b/src/tools/miri/src/eval.rs @@ -165,6 +165,8 @@ pub struct MiriConfig { pub address_reuse_cross_thread_rate: f64, /// Round Robin scheduling with no preemption. pub fixed_scheduling: bool, + /// Always prefer the intrinsic fallback body over the native Miri implementation. + pub force_intrinsic_fallback: bool, } impl Default for MiriConfig { @@ -203,6 +205,7 @@ impl Default for MiriConfig { address_reuse_rate: 0.5, address_reuse_cross_thread_rate: 0.1, fixed_scheduling: false, + force_intrinsic_fallback: false, } } } diff --git a/src/tools/miri/src/intrinsics/mod.rs b/src/tools/miri/src/intrinsics/mod.rs index 3334c0b5edf..982fbc31811 100644 --- a/src/tools/miri/src/intrinsics/mod.rs +++ b/src/tools/miri/src/intrinsics/mod.rs @@ -28,6 +28,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Option<ty::Instance<'tcx>>> { let this = self.eval_context_mut(); + // Force use of fallback body, if available. + if this.machine.force_intrinsic_fallback + && !this.tcx.intrinsic(instance.def_id()).unwrap().must_be_overridden + { + return interp_ok(Some(ty::Instance { + def: ty::InstanceKind::Item(instance.def_id()), + args: instance.args, + })); + } + // See if the core engine can handle this intrinsic. if this.eval_intrinsic(instance, args, dest, ret)? { return interp_ok(None); diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 6060d41dac5..dbde415170c 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -614,6 +614,9 @@ pub struct MiriMachine<'tcx> { /// Cache for `mangle_internal_symbol`. pub(crate) mangle_internal_symbol_cache: FxHashMap<&'static str, String>, + + /// Always prefer the intrinsic fallback body over the native Miri implementation. + pub force_intrinsic_fallback: bool, } impl<'tcx> MiriMachine<'tcx> { @@ -770,6 +773,7 @@ impl<'tcx> MiriMachine<'tcx> { reject_in_isolation_warned: Default::default(), int2ptr_warned: Default::default(), mangle_internal_symbol_cache: Default::default(), + force_intrinsic_fallback: config.force_intrinsic_fallback, } } @@ -946,6 +950,7 @@ impl VisitProvenance for MiriMachine<'_> { reject_in_isolation_warned: _, int2ptr_warned: _, mangle_internal_symbol_cache: _, + force_intrinsic_fallback: _, } = self; threads.visit_provenance(visit); diff --git a/src/tools/miri/tests/pass/intrinsics/intrinsics.rs b/src/tools/miri/tests/pass/intrinsics/intrinsics.rs index 89289a25d50..913c3cde272 100644 --- a/src/tools/miri/tests/pass/intrinsics/intrinsics.rs +++ b/src/tools/miri/tests/pass/intrinsics/intrinsics.rs @@ -33,20 +33,24 @@ fn main() { assert_eq!(intrinsics::likely(false), false); assert_eq!(intrinsics::unlikely(true), true); - let mut saw_true = false; - let mut saw_false = false; + // Skip this test when we use the fallback bodies, as that one is deterministic. + // (CI sets `--cfg force_intrinsic_fallback` together with `-Zmiri-force-intrinsic-fallback`.) + if !cfg!(force_intrinsic_fallback) { + let mut saw_true = false; + let mut saw_false = false; - for _ in 0..50 { - if intrinsics::is_val_statically_known(0) { - saw_true = true; - } else { - saw_false = true; + for _ in 0..50 { + if intrinsics::is_val_statically_known(0) { + saw_true = true; + } else { + saw_false = true; + } } + assert!( + saw_true && saw_false, + "`is_val_statically_known` failed to return both true and false. Congrats, you won the lottery!" + ); } - assert!( - saw_true && saw_false, - "`is_val_statically_known` failed to return both true and false. Congrats, you won the lottery!" - ); intrinsics::forget(Bomb); diff --git a/src/tools/run-make-support/src/command.rs b/src/tools/run-make-support/src/command.rs index 70a72bd1abe..b46ddd1d315 100644 --- a/src/tools/run-make-support/src/command.rs +++ b/src/tools/run-make-support/src/command.rs @@ -63,6 +63,12 @@ impl Command { } } + // Internal-only. + pub(crate) fn into_raw_command(mut self) -> std::process::Command { + self.drop_bomb.defuse(); + self.cmd + } + /// Specify a stdin input buffer. This is a convenience helper, pub fn stdin_buf<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self { self.stdin_buf = Some(input.as_ref().to_vec().into_boxed_slice()); diff --git a/src/tools/run-make-support/src/external_deps/rustdoc.rs b/src/tools/run-make-support/src/external_deps/rustdoc.rs index 433a57cd9fa..7040fb667cf 100644 --- a/src/tools/run-make-support/src/external_deps/rustdoc.rs +++ b/src/tools/run-make-support/src/external_deps/rustdoc.rs @@ -5,7 +5,7 @@ use crate::command::Command; use crate::env::env_var; use crate::util::set_host_compiler_dylib_path; -/// Construct a new `rustdoc` invocation. +/// Construct a new `rustdoc` invocation. This will configure the host compiler runtime libs. #[track_caller] pub fn rustdoc() -> Rustdoc { Rustdoc::new() @@ -28,7 +28,7 @@ fn setup_common() -> Command { } impl Rustdoc { - /// Construct a bare `rustdoc` invocation. + /// Construct a bare `rustdoc` invocation. This will configure the host compiler runtime libs. #[track_caller] pub fn new() -> Self { let cmd = setup_common(); diff --git a/src/tools/run-make-support/src/macros.rs b/src/tools/run-make-support/src/macros.rs index 94955aefe57..9d5cc4e5876 100644 --- a/src/tools/run-make-support/src/macros.rs +++ b/src/tools/run-make-support/src/macros.rs @@ -28,6 +28,18 @@ macro_rules! impl_common_helpers { ($wrapper: ident) => { impl $wrapper { + /// In very rare circumstances, you may need a e.g. `bare_rustc()` or `bare_rustdoc()` + /// with host runtime libs configured, but want the underlying raw + /// [`std::process::Command`] (e.g. for manipulating pipes or whatever). This function + /// will consume the command wrapper and extract the underlying + /// [`std::process::Command`]. + /// + /// Caution: this will mean that you can no longer use the convenience methods on the + /// command wrapper. Use as a last resort. + pub fn into_raw_command(self) -> ::std::process::Command { + self.cmd.into_raw_command() + } + /// Specify an environment variable. pub fn env<K, V>(&mut self, key: K, value: V) -> &mut Self where diff --git a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs index 706d04484f6..f9ff3921266 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs @@ -5789,7 +5789,7 @@ The tracking issue for this feature is: [#120301] ------------------------ -Add the methods `from_mins`, `from_hours` and `from_days` to `Duration`. +Add the methods `from_days` and `from_weeks` to `Duration`. "##, default_severity: Severity::Allow, warn_since: None, |
