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

Rollup of 4 pull requests #116924

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
316c9a9
Add stack-protector test for Windows
wesleywiser Sep 19, 2023
dfadd17
Make TCP connect() handle EINTR correctly
darthunix Oct 5, 2023
786834d
Allow to run filecheck in mir-opt tests.
cjgillot Oct 16, 2023
5175e1c
Run filecheck on reference_prop.rs
cjgillot Oct 16, 2023
64103d7
FileCheck array_index_is_temporary.rs
cjgillot Oct 16, 2023
4c3dfb8
FileCheck asm_unwind_panic_abort.rs
cjgillot Oct 16, 2023
3e9fa2d
FileCheck basic_assignment.rs.
cjgillot Oct 16, 2023
cc03573
FileCheck box_expr.rs
cjgillot Oct 16, 2023
9db3aeb
Add README.
cjgillot Oct 16, 2023
8b500db
FileCheck combine_array_len.
cjgillot Oct 16, 2023
c65e373
FileCheck bool_compare.
cjgillot Oct 16, 2023
2f599af
FileCheck combine_clone_of_primitives.
cjgillot Oct 16, 2023
a293463
FileCheck intrinsic_asserts.
cjgillot Oct 16, 2023
75081b7
FileCheck duplicate_switch_targets.
cjgillot Oct 16, 2023
3417fe2
FileCheck combine_transmutes.
cjgillot Oct 16, 2023
98312ea
FileCheck casts.
cjgillot Oct 16, 2023
f77a3ef
FileCheck lower_intrinsics.
cjgillot Oct 16, 2023
d556de3
FileCheck lower_array_len.
cjgillot Oct 16, 2023
aad5093
FileCheck lower_slice_len.
cjgillot Oct 16, 2023
809c3cf
Mention skip in README.
cjgillot Oct 16, 2023
8fa8777
FileCheck issue_106141.
cjgillot Oct 16, 2023
eaabda7
FileCheck inline_shims.
cjgillot Oct 16, 2023
804aa6a
FileCheck transmute.
cjgillot Oct 16, 2023
c1c5a1d
Only check in a single place if a pass is enabled.
cjgillot Oct 18, 2023
0e17e5b
Rollup merge of #116037 - wesleywiser:stack_protector_test_windows, r…
fmease Oct 19, 2023
14da43e
Rollup merge of #116132 - darthunix:connect_poll, r=cuviper
fmease Oct 19, 2023
c3d0f11
Rollup merge of #116810 - cjgillot:mir-opt-check, r=oli-obk
fmease Oct 19, 2023
b6f4522
Rollup merge of #116896 - cjgillot:single-inline, r=oli-obk
fmease Oct 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
let is_fn_like = tcx.def_kind(def).is_fn_like();
if is_fn_like {
// Do not compute the mir call graph without said call graph actually being used.
if inline::Inline.is_enabled(&tcx.sess) {
if pm::should_run_pass(tcx, &inline::Inline) {
tcx.ensure_with_value().mir_inliner_callees(ty::InstanceDef::Item(def.to_def_id()));
}
}
Expand Down
33 changes: 21 additions & 12 deletions compiler/rustc_mir_transform/src/pass_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ pub fn run_passes<'tcx>(
run_passes_inner(tcx, body, passes, phase_change, true);
}

pub fn should_run_pass<'tcx, P>(tcx: TyCtxt<'tcx>, pass: &P) -> bool
where
P: MirPass<'tcx> + ?Sized,
{
let name = pass.name();

let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
let overridden =
overridden_passes.iter().rev().find(|(s, _)| s == &*name).map(|(_name, polarity)| {
trace!(
pass = %name,
"{} as requested by flag",
if *polarity { "Running" } else { "Not running" },
);
*polarity
});
overridden.unwrap_or_else(|| pass.is_enabled(&tcx.sess))
}

fn run_passes_inner<'tcx>(
tcx: TyCtxt<'tcx>,
body: &mut Body<'tcx>,
Expand All @@ -100,19 +119,9 @@ fn run_passes_inner<'tcx>(
for pass in passes {
let name = pass.name();

let overridden = overridden_passes.iter().rev().find(|(s, _)| s == &*name).map(
|(_name, polarity)| {
trace!(
pass = %name,
"{} as requested by flag",
if *polarity { "Running" } else { "Not running" },
);
*polarity
},
);
if !overridden.unwrap_or_else(|| pass.is_enabled(&tcx.sess)) {
if !should_run_pass(tcx, *pass) {
continue;
}
};

let dump_enabled = pass.is_mir_dump_enabled();

Expand Down
6 changes: 6 additions & 0 deletions library/std/src/sys/hermit/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ impl Socket {
unimplemented!()
}

pub fn connect(&self, addr: &SocketAddr) -> io::Result<()> {
let (addr, len) = addr.into_inner();
cvt_r(|| unsafe { netc::connect(self.as_raw_fd(), addr.as_ptr(), len) })?;
Ok(())
}

pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> {
self.set_nonblocking(true)?;
let r = unsafe {
Expand Down
11 changes: 7 additions & 4 deletions library/std/src/sys/solid/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,15 @@ impl Socket {
}
}

pub fn connect(&self, addr: &SocketAddr) -> io::Result<()> {
let (addr, len) = addr.into_inner();
cvt(unsafe { netc::connect(self.0.raw(), addr.as_ptr(), len) })?;
Ok(())
}

pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> {
self.set_nonblocking(true)?;
let r = unsafe {
let (addr, len) = addr.into_inner();
cvt(netc::connect(self.0.raw(), addr.as_ptr(), len))
};
let r = self.connect(addr);
self.set_nonblocking(false)?;

match r {
Expand Down
17 changes: 17 additions & 0 deletions library/std/src/sys/unix/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::net::{Shutdown, SocketAddr};
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
use crate::str;
use crate::sys::fd::FileDesc;
use crate::sys::unix::IsMinusOne;
use crate::sys_common::net::{getsockopt, setsockopt, sockaddr_to_addr};
use crate::sys_common::{AsInner, FromInner, IntoInner};
use crate::time::{Duration, Instant};
Expand Down Expand Up @@ -140,6 +141,22 @@ impl Socket {
unimplemented!()
}

pub fn connect(&self, addr: &SocketAddr) -> io::Result<()> {
let (addr, len) = addr.into_inner();
loop {
let result = unsafe { libc::connect(self.as_raw_fd(), addr.as_ptr(), len) };
if result.is_minus_one() {
let err = crate::sys::os::errno();
match err {
libc::EINTR => continue,
libc::EISCONN => return Ok(()),
_ => return Err(io::Error::from_raw_os_error(err)),
}
}
return Ok(());
}
}

pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> {
self.set_nonblocking(true)?;
let r = unsafe {
Expand Down
12 changes: 7 additions & 5 deletions library/std/src/sys/windows/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ impl Socket {
}
}

pub fn connect(&self, addr: &SocketAddr) -> io::Result<()> {
let (addr, len) = addr.into_inner();
let result = unsafe { c::connect(self.as_raw(), addr.as_ptr(), len) };
cvt(result).map(drop)
}

pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> {
self.set_nonblocking(true)?;
let result = {
let (addr, len) = addr.into_inner();
let result = unsafe { c::connect(self.as_raw(), addr.as_ptr(), len) };
cvt(result).map(drop)
};
let result = self.connect(addr);
self.set_nonblocking(false)?;

match result {
Expand Down
4 changes: 1 addition & 3 deletions library/std/src/sys_common/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ impl TcpStream {
init();

let sock = Socket::new(addr, c::SOCK_STREAM)?;

let (addr, len) = addr.into_inner();
cvt_r(|| unsafe { c::connect(sock.as_raw(), addr.as_ptr(), len) })?;
sock.connect(addr)?;
Ok(TcpStream { inner: sock })
}

Expand Down
65 changes: 26 additions & 39 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::json;
use crate::read2::{read2_abbreviated, Truncated};
use crate::util::{add_dylib_path, dylib_env_var, logv, PathBufExt};
use crate::ColorConfig;
use miropt_test_tools::{files_for_miropt_test, MiroptTest, MiroptTestFile};
use regex::{Captures, Regex};
use rustfix::{apply_suggestions, get_suggestions_from_json, Filter};

Expand Down Expand Up @@ -229,6 +230,7 @@ enum Emit {
None,
Metadata,
LlvmIr,
Mir,
Asm,
LinkArgsAsm,
}
Expand Down Expand Up @@ -2506,6 +2508,9 @@ impl<'test> TestCx<'test> {
Emit::LlvmIr => {
rustc.args(&["--emit", "llvm-ir"]);
}
Emit::Mir => {
rustc.args(&["--emit", "mir"]);
}
Emit::Asm => {
rustc.args(&["--emit", "asm"]);
}
Expand Down Expand Up @@ -3984,11 +3989,17 @@ impl<'test> TestCx<'test> {
fn run_mir_opt_test(&self) {
let pm = self.pass_mode();
let should_run = self.should_run(pm);
let emit_metadata = self.should_emit_metadata(pm);
let passes = self.get_passes();

let proc_res = self.compile_test_with_passes(should_run, emit_metadata, passes);
self.check_mir_dump();
let mut test_info = files_for_miropt_test(
&self.testpaths.file,
self.config.get_pointer_width(),
self.config.target_cfg().panic.for_miropt_test_tools(),
);

let passes = std::mem::take(&mut test_info.passes);

let proc_res = self.compile_test_with_passes(should_run, Emit::Mir, passes);
self.check_mir_dump(test_info);
if !proc_res.status.success() {
self.fatal_proc_rec("compilation failed!", &proc_res);
}
Expand All @@ -4002,37 +4013,12 @@ impl<'test> TestCx<'test> {
}
}

fn get_passes(&self) -> Vec<String> {
let files = miropt_test_tools::files_for_miropt_test(
&self.testpaths.file,
self.config.get_pointer_width(),
self.config.target_cfg().panic.for_miropt_test_tools(),
);

let mut out = Vec::new();

for miropt_test_tools::MiroptTestFiles {
from_file: _,
to_file: _,
expected_file: _,
passes,
} in files
{
out.extend(passes);
}
out
}

fn check_mir_dump(&self) {
fn check_mir_dump(&self, test_info: MiroptTest) {
let test_dir = self.testpaths.file.parent().unwrap();
let test_crate =
self.testpaths.file.file_stem().unwrap().to_str().unwrap().replace("-", "_");

let suffix = miropt_test_tools::output_file_suffix(
&self.testpaths.file,
self.config.get_pointer_width(),
self.config.target_cfg().panic.for_miropt_test_tools(),
);
let MiroptTest { run_filecheck, suffix, files, passes: _ } = test_info;

if self.config.bless {
for e in
Expand All @@ -4047,14 +4033,7 @@ impl<'test> TestCx<'test> {
}
}

let files = miropt_test_tools::files_for_miropt_test(
&self.testpaths.file,
self.config.get_pointer_width(),
self.config.target_cfg().panic.for_miropt_test_tools(),
);
for miropt_test_tools::MiroptTestFiles { from_file, to_file, expected_file, passes: _ } in
files
{
for MiroptTestFile { from_file, to_file, expected_file } in files {
let dumped_string = if let Some(after) = to_file {
self.diff_mir_files(from_file.into(), after.into())
} else {
Expand Down Expand Up @@ -4095,6 +4074,14 @@ impl<'test> TestCx<'test> {
}
}
}

if run_filecheck {
let output_path = self.output_base_name().with_extension("mir");
let proc_res = self.verify_with_filecheck(&output_path);
if !proc_res.status.success() {
self.fatal_proc_rec("verification with 'FileCheck' failed", &proc_res);
}
}
}

fn diff_mir_files(&self, before: PathBuf, after: PathBuf) -> String {
Expand Down
27 changes: 17 additions & 10 deletions src/tools/miropt-test-tools/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use std::fs;
use std::path::Path;

pub struct MiroptTestFiles {
pub struct MiroptTestFile {
pub expected_file: std::path::PathBuf,
pub from_file: String,
pub to_file: Option<String>,
}

pub struct MiroptTest {
pub run_filecheck: bool,
pub suffix: String,
pub files: Vec<MiroptTestFile>,
/// Vec of passes under test to be dumped
pub passes: Vec<String>,
}
Expand All @@ -14,11 +20,7 @@ pub enum PanicStrategy {
Abort,
}

pub fn output_file_suffix(
testfile: &Path,
bit_width: u32,
panic_strategy: PanicStrategy,
) -> String {
fn output_file_suffix(testfile: &Path, bit_width: u32, panic_strategy: PanicStrategy) -> String {
let mut each_bit_width = false;
let mut each_panic_strategy = false;
for line in fs::read_to_string(testfile).unwrap().lines() {
Expand Down Expand Up @@ -47,16 +49,22 @@ pub fn files_for_miropt_test(
testfile: &std::path::Path,
bit_width: u32,
panic_strategy: PanicStrategy,
) -> Vec<MiroptTestFiles> {
) -> MiroptTest {
let mut out = Vec::new();
let test_file_contents = fs::read_to_string(&testfile).unwrap();

let test_dir = testfile.parent().unwrap();
let test_crate = testfile.file_stem().unwrap().to_str().unwrap().replace('-', "_");

let suffix = output_file_suffix(testfile, bit_width, panic_strategy);
let mut run_filecheck = true;
let mut passes = Vec::new();

for l in test_file_contents.lines() {
if l.starts_with("// skip-filecheck") {
run_filecheck = false;
continue;
}
if l.starts_with("// EMIT_MIR ") {
let test_name = l.trim_start_matches("// EMIT_MIR ").trim();
let mut test_names = test_name.split(' ');
Expand All @@ -65,7 +73,6 @@ pub fn files_for_miropt_test(
let mut expected_file;
let from_file;
let to_file;
let mut passes = Vec::new();

if test_name.ends_with(".diff") {
let trimmed = test_name.trim_end_matches(".diff");
Expand Down Expand Up @@ -114,9 +121,9 @@ pub fn files_for_miropt_test(
}
let expected_file = test_dir.join(expected_file);

out.push(MiroptTestFiles { expected_file, from_file, to_file, passes });
out.push(MiroptTestFile { expected_file, from_file, to_file });
}
}

out
MiroptTest { run_filecheck, suffix, files: out, passes }
}
3 changes: 2 additions & 1 deletion src/tools/tidy/src/mir_opt_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ fn check_unused_files(path: &Path, bless: bool, bad: &mut bool) {
for file in rs_files {
for bw in [32, 64] {
for ps in [PanicStrategy::Unwind, PanicStrategy::Abort] {
for output_file in miropt_test_tools::files_for_miropt_test(&file, bw, ps) {
let mir_opt_test = miropt_test_tools::files_for_miropt_test(&file, bw, ps);
for output_file in mir_opt_test.files {
output_files.remove(&output_file.expected_file);
}
}
Expand Down
Loading