Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustup #3453

Merged
merged 38 commits into from
Apr 6, 2024
Merged

Rustup #3453

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b29145e
add 'x.py miri', and make it work for 'library/{core,alloc,std}'
RalfJung Apr 1, 2024
2c12f42
Auto merge of #119820 - lcnr:leak-check-2, r=jackh726
bors Apr 4, 2024
2f96976
Auto merge of #123052 - maurer:addr-taken, r=compiler-errors
bors Apr 4, 2024
f4b44ca
adjust frame_in_std to recognize std tests
RalfJung Apr 2, 2024
a61edcc
Auto merge of #121026 - Zalathar:version, r=oli-obk
bors Apr 4, 2024
3504606
Auto merge of #123377 - oli-obk:private_projection, r=compiler-errors
bors Apr 4, 2024
b0216c7
remove miri jobserver workaround
belovdv Apr 4, 2024
bdbd3d2
Auto merge of #123097 - oli-obk:perf_experiment, r=petrochenkov
bors Apr 4, 2024
4b35147
Actually use the inferred ClosureKind from signature inference in cor…
compiler-errors Apr 1, 2024
35f0eca
Force `move` async-closures that are `FnOnce` to make their inner cor…
compiler-errors Apr 3, 2024
81633ad
Auto merge of #123469 - belovdv:remove-miri-jobserver-fixme, r=petroc…
bors Apr 5, 2024
f5eae9c
miri: go look for the item in all crates of the right name
RalfJung Apr 5, 2024
3e496a0
Auto merge of #122070 - Zoxc:dep-edges-from-previous, r=cjgillot
bors Apr 5, 2024
6f65d83
Auto merge of #123317 - RalfJung:test-in-miri, r=m-ou-se,saethlin,onu…
bors Apr 5, 2024
d4ef5a3
Rollup merge of #122334 - GuillaumeGomez:vendor-cg_gcc, r=Mark-Simula…
GuillaumeGomez Apr 5, 2024
c9f7911
Rollup merge of #122894 - compiler-errors:downgrade, r=lcnr
GuillaumeGomez Apr 5, 2024
94a1b1a
Rollup merge of #123149 - jieyouxu:rmake-arguments-non-c-like-enum, r…
GuillaumeGomez Apr 5, 2024
35b90a6
Rollup merge of #123311 - Jules-Bertholet:andpat-everywhere, r=Nadrieril
GuillaumeGomez Apr 5, 2024
5d6f914
Rollup merge of #123350 - compiler-errors:async-closure-by-move, r=ol…
GuillaumeGomez Apr 5, 2024
b8c0ae1
Rollup merge of #123474 - jieyouxu:issue-7349-port, r=Mark-Simulacrum
GuillaumeGomez Apr 5, 2024
cfa2c93
Rollup merge of #123489 - onur-ozkan:handle-rustc-args-properly, r=cl…
GuillaumeGomez Apr 5, 2024
bc17ba9
Rollup merge of #123496 - lcnr:wf-ping, r=compiler-errors
GuillaumeGomez Apr 5, 2024
8c79546
Auto merge of #123497 - GuillaumeGomez:rollup-usqb4q9, r=GuillaumeGomez
bors Apr 5, 2024
184384f
Revert "remove miri jobserver workaround"
belovdv Apr 5, 2024
4513f0f
Auto merge of #123502 - bjorn3:sync_cg_clif-2024-04-05, r=bjorn3
bors Apr 5, 2024
171f99f
Auto merge of #122747 - Urgau:non-local-defs_perfect_impl, r=lcnr
bors Apr 5, 2024
f4dcc88
Rollup merge of #121419 - agg23:xrOS-pr, r=davidtwco
GuillaumeGomez Apr 5, 2024
f9f6ae8
Rollup merge of #123159 - chrisnc:fix-arm-rm-none-eabihf-features, r=…
GuillaumeGomez Apr 5, 2024
3ba15aa
Rollup merge of #123487 - rcvalle:rust-cfi-restore-typeid-for-instanc…
GuillaumeGomez Apr 5, 2024
1b725c9
Rollup merge of #123500 - belovdv:remove-miri-jobserver-fixme, r=Ralf…
GuillaumeGomez Apr 5, 2024
0d27480
Rollup merge of #123505 - ChrisDenton:revert-121666, r=workingjubilee
GuillaumeGomez Apr 5, 2024
79141d4
Rollup merge of #123509 - jieyouxu:add-jieyouxu-review-rotation, r=Ma…
GuillaumeGomez Apr 5, 2024
e7a7fd6
Rollup merge of #123514 - WaffleLapkin:stpe, r=compiler-errors
GuillaumeGomez Apr 5, 2024
8c5486c
Rollup merge of #123515 - GuillaumeGomez:use-include, r=notriddle
GuillaumeGomez Apr 5, 2024
7e8b1b6
Auto merge of #123517 - GuillaumeGomez:rollup-eys3jfp, r=GuillaumeGomez
bors Apr 5, 2024
b4f84c8
Auto merge of #123433 - GnomedDev:remove-threadname-alloc, r=joboet
bors Apr 6, 2024
5265781
Preparing for merge from rustc
RalfJung Apr 6, 2024
aba29d8
Merge from rustc
RalfJung Apr 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ binaries, and as such worth documenting:
crate currently being compiled.
* `MIRI_ORIG_RUSTDOC` is set and read by different phases of `cargo-miri` to remember the
value of `RUSTDOC` from before it was overwritten.
* `MIRI_REPLACE_LIBRS_IF_NOT_TEST` when set to any value enables a hack that helps bootstrap
run the standard library tests in Miri.
* `MIRI_VERBOSE` when set to any value tells the various `cargo-miri` phases to
perform verbose logging.
* `MIRI_HOST_SYSROOT` is set by bootstrap to tell `cargo-miri` which sysroot to use for *host*
Expand Down
53 changes: 46 additions & 7 deletions cargo-miri/src/phases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::env;
use std::fs::{self, File};
use std::io::BufReader;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::Command;

use rustc_version::VersionMeta;
Expand Down Expand Up @@ -412,9 +412,25 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
// Arguments are treated very differently depending on whether this crate is
// for interpretation by Miri, or for use by a build script / proc macro.
if target_crate {
// Forward arguments, but remove "link" from "--emit" to make this a check-only build.
// Forward arguments, but patched.
let emit_flag = "--emit";
// This hack helps bootstrap run standard library tests in Miri. The issue is as follows:
// when running `cargo miri test` on libcore, cargo builds a local copy of core and makes it
// a dependency of the integration test crate. This copy duplicates all the lang items, so
// the build fails. (Regular testing avoids this because the sysroot is a literal copy of
// what `cargo build` produces, but since Miri builds its own sysroot this does not work for
// us.) So we need to make it so that the locally built libcore contains all the items from
// `core`, but does not re-define them -- we want to replace the entire crate but a
// re-export of the sysroot crate. We do this by swapping out the source file: if
// `MIRI_REPLACE_LIBRS_IF_NOT_TEST` is set and we are building a `lib.rs` file, and a
// `lib.miri.rs` file exists in the same folder, we build that instead. But crucially we
// only do that for the library, not the unit test crate (which would be runnable) or
// rustdoc (which would have a different `phase`).
let replace_librs = env::var_os("MIRI_REPLACE_LIBRS_IF_NOT_TEST").is_some()
&& !runnable_crate
&& phase == RustcPhase::Build;
while let Some(arg) = args.next() {
// Patch `--emit`: remove "link" from "--emit" to make this a check-only build.
if let Some(val) = arg.strip_prefix(emit_flag) {
// Patch this argument. First, extract its value.
let val =
Expand All @@ -429,13 +445,36 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
}
}
cmd.arg(format!("{emit_flag}={}", val.join(",")));
} else if arg == "--extern" {
// Patch `--extern` filenames, since Cargo sometimes passes stub `.rlib` files:
// https://github.com/rust-lang/miri/issues/1705
continue;
}
// Patch `--extern` filenames, since Cargo sometimes passes stub `.rlib` files:
// https://github.com/rust-lang/miri/issues/1705
if arg == "--extern" {
forward_patched_extern_arg(&mut args, &mut cmd);
} else {
cmd.arg(arg);
continue;
}
// If the REPLACE_LIBRS hack is enabled and we are building a `lib.rs` file, and a
// `lib.miri.rs` file exists, then build that instead. We only consider relative paths
// as cargo uses those for files in the workspace; dependencies from crates.io get
// absolute paths.
if replace_librs {
let path = Path::new(&arg);
if path.is_relative()
&& path.file_name().is_some_and(|f| f == "lib.rs")
&& path.is_file()
{
let miri_rs = Path::new(&arg).with_extension("miri.rs");
if miri_rs.is_file() {
if verbose > 0 {
eprintln!("Performing REPLACE_LIBRS hack: {arg:?} -> {miri_rs:?}");
}
cmd.arg(miri_rs);
continue;
}
}
}
// Fallback: just propagate the argument.
cmd.arg(arg);
}

// During setup, patch the panic runtime for `libpanic_abort` (mirroring what bootstrap usually does).
Expand Down
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0accf4ec4c07d23aa86f6a97aeb8797941abc30e
23d47dba319331d4418827cfbb8c1af283497d3c
69 changes: 42 additions & 27 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,41 @@ fn try_resolve_did(tcx: TyCtxt<'_>, path: &[&str], namespace: Option<Namespace>)
(path, None)
};

// First find the crate.
let krate =
tcx.crates(()).iter().find(|&&krate| tcx.crate_name(krate).as_str() == crate_name)?;
let mut cur_item = DefId { krate: *krate, index: CRATE_DEF_INDEX };
// Then go over the modules.
for &segment in modules {
cur_item = find_children(tcx, cur_item, segment)
.find(|item| tcx.def_kind(item) == DefKind::Mod)?;
}
// Finally, look up the desired item in this module, if any.
match item {
Some((item_name, namespace)) =>
Some(
find_children(tcx, cur_item, item_name)
.find(|item| tcx.def_kind(item).ns() == Some(namespace))?,
),
None => Some(cur_item),
// There may be more than one crate with this name. We try them all.
// (This is particularly relevant when running `std` tests as then there are two `std` crates:
// the one in the sysroot and the one locally built by `cargo test`.)
// FIXME: can we prefer the one from the sysroot?
'crates: for krate in
tcx.crates(()).iter().filter(|&&krate| tcx.crate_name(krate).as_str() == crate_name)
{
let mut cur_item = DefId { krate: *krate, index: CRATE_DEF_INDEX };
// Go over the modules.
for &segment in modules {
let Some(next_item) = find_children(tcx, cur_item, segment)
.find(|item| tcx.def_kind(item) == DefKind::Mod)
else {
continue 'crates;
};
cur_item = next_item;
}
// Finally, look up the desired item in this module, if any.
match item {
Some((item_name, namespace)) => {
let Some(item) = find_children(tcx, cur_item, item_name)
.find(|item| tcx.def_kind(item).ns() == Some(namespace))
else {
continue 'crates;
};
return Some(item);
}
None => {
// Just return the module.
return Some(cur_item);
}
}
}
// Item not found in any of the crates with the right name.
None
}

/// Convert a softfloat type to its corresponding hostfloat type.
Expand Down Expand Up @@ -968,10 +985,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {

fn frame_in_std(&self) -> bool {
let this = self.eval_context_ref();
let Some(start_fn) = this.tcx.lang_items().start_fn() else {
// no_std situations
return false;
};
let frame = this.frame();
// Make an attempt to get at the instance of the function this is inlined from.
let instance: Option<_> = try {
Expand All @@ -982,13 +995,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
};
// Fall back to the instance of the function itself.
let instance = instance.unwrap_or(frame.instance);
// Now check if this is in the same crate as start_fn.
// As a special exception we also allow unit tests from
// <https://github.com/rust-lang/miri-test-libstd/tree/master/std_miri_test> to call these
// shims.
// Now check the crate it is in. We could try to be clever here and e.g. check if this is
// the same crate as `start_fn`, but that would not work for running std tests in Miri, so
// we'd need some more hacks anyway. So we just check the name of the crate. If someone
// calls their crate `std` then we'll just let them keep the pieces.
let frame_crate = this.tcx.def_path(instance.def_id()).krate;
frame_crate == this.tcx.def_path(start_fn).krate
|| this.tcx.crate_name(frame_crate).as_str() == "std_miri_test"
let crate_name = this.tcx.crate_name(frame_crate);
let crate_name = crate_name.as_str();
// On miri-test-libstd, the name of the crate is different.
crate_name == "std" || crate_name == "std_miri_test"
}

/// Handler that should be called when unsupported functionality is encountered.
Expand Down
34 changes: 34 additions & 0 deletions tests/pass/async-closure-captures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,38 @@ async fn async_main() {
};
call_once(c).await;
}

fn force_fnonce<T>(f: impl async FnOnce() -> T) -> impl async FnOnce() -> T {
f
}

// Capture something with `move`, but infer to `AsyncFnOnce`
{
let x = Hello(6);
let c = force_fnonce(async move || {
println!("{x:?}");
});
call_once(c).await;

let x = &Hello(7);
let c = force_fnonce(async move || {
println!("{x:?}");
});
call_once(c).await;
}

// Capture something by-ref, but infer to `AsyncFnOnce`
{
let x = Hello(8);
let c = force_fnonce(async || {
println!("{x:?}");
});
call_once(c).await;

let x = &Hello(9);
let c = force_fnonce(async || {
println!("{x:?}");
});
call_once(c).await;
}
}
4 changes: 4 additions & 0 deletions tests/pass/async-closure-captures.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ Hello(3)
Hello(4)
Hello(4)
Hello(5)
Hello(6)
Hello(7)
Hello(8)
Hello(9)
Loading