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 7 pull requests #127701

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6bd68fc
Run filecheck on dest-prop/branch.rs
CastilloDel Apr 14, 2024
f238eba
Run filecheck on dest-prop/copy_propagation.rs
CastilloDel Apr 14, 2024
853311c
Run filecheck on dest-prop/cycle.rs
CastilloDel Apr 14, 2024
0692090
Run filecheck on dest-prop/dead_stores_79191.rs and dead_stores_bette…
CastilloDel Apr 14, 2024
f0f867e
Run filecheck on dest-prop/simple.rs
CastilloDel Apr 14, 2024
2d5a483
Acknowledge comments
CastilloDel Jun 26, 2024
04eed9b
Initial implementation of annoymous_pipe
NobodyXu Jun 30, 2024
72bda33
Fix compilation errors
NobodyXu Jun 30, 2024
42e8beb
Implement validation in `TryFrom<OwnedFd> for PIpe*` on unix
NobodyXu Jun 30, 2024
e170c78
Move the mod `pipe` to `std::net`
NobodyXu Jun 30, 2024
473fbce
Fix typo
NobodyXu Jun 30, 2024
97626b6
Fix tidy errors
NobodyXu Jun 30, 2024
d60438f
Validate pipe in `TryFrom<OwnedHandle> for Pipe*`
NobodyXu Jun 30, 2024
b7af685
Refactor: Extract new method `FileDesc::get_access_mode`
NobodyXu Jun 30, 2024
4c6b6bb
Add testing for anonymous pipe
NobodyXu Jul 1, 2024
594abec
Refactor: Put mod `unix` & `windows` into separate files
NobodyXu Jul 2, 2024
d9f0980
Fix `anonymous_pipe` impl for not supported targets
NobodyXu Jul 2, 2024
6c755a3
Optimize: Add `#[inline]` to very simple function
NobodyXu Jul 2, 2024
4819270
use "bootstrap" instead of "rustbuild" in comments and docs
onur-ozkan Jul 6, 2024
99721c8
Clear `inner_attr_ranges` regularly.
nnethercote Jul 8, 2024
d15cee5
Refactor: Make `AcessMode` an enum`
NobodyXu Jul 9, 2024
e22dd1a
Update mod.rs
NobodyXu Jul 10, 2024
100fe5c
Move `std::net::pip*` to a new mod `std::pipe`
NobodyXu Jul 10, 2024
62b846e
Remove use of `macro_rules!`
NobodyXu Jul 10, 2024
4547b30
Replace `TryFrom<Owned*>` with `From`
NobodyXu Jul 10, 2024
72f5999
Fix compilation on non-unix, non-windows targets
NobodyXu Jul 11, 2024
45886cc
Fix compilation error on unsupported target
NobodyXu Jul 12, 2024
7fc6943
Use ManuallyDrop in BufWriter::into_parts
saethlin Jul 12, 2024
4d35754
Add URL and crate_name to test cases
notriddle Jul 13, 2024
17419f6
rustdoc: rename `issue-\d+.rs` tests to have meaningful names
notriddle Jul 13, 2024
42ee400
Move assertion-free rustdoc ice tests to rustdoc-ui
notriddle Jul 13, 2024
fc0d1dc
use `ModeToolBootstrap` for run-make-support's crate tests
onur-ozkan Jul 13, 2024
41070bd
explain why we use in-tree std for compiletest
onur-ozkan Jul 13, 2024
cf0c9eb
Rollup merge of #122300 - CastilloDel:master, r=cjgillot
jhpratt Jul 13, 2024
9df00a2
Rollup merge of #127153 - NobodyXu:pipe, r=jhpratt
jhpratt Jul 13, 2024
40e6379
Rollup merge of #127434 - onur-ozkan:use-bootstrap-instead-of-rustbui…
jhpratt Jul 13, 2024
6982f91
Rollup merge of #127477 - nnethercote:tweak-inner_attr_ranges, r=petr…
jhpratt Jul 13, 2024
e6af63a
Rollup merge of #127659 - saethlin:manually-drop-bufwriter, r=joboet
jhpratt Jul 13, 2024
6e18eaf
Rollup merge of #127671 - notriddle:notriddle/issue-d, r=Mark-Simulacrum
jhpratt Jul 13, 2024
7a165e5
Rollup merge of #127677 - onur-ozkan:use-correct-modes, r=Kobzol
jhpratt Jul 13, 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: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ python x.py build

Right now, building Rust only works with some known versions of Visual Studio.
If you have a more recent version installed and the build system doesn't
understand, you may need to force rustbuild to use an older version.
understand, you may need to force bootstrap to use an older version.
This can be done by manually calling the appropriate vcvars file before running
the bootstrap.

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ impl<'a> GccLinker<'a> {
self.link_arg("-dylib");

// Note that the `osx_rpath_install_name` option here is a hack
// purely to support rustbuild right now, we should get a more
// purely to support bootstrap right now, we should get a more
// principled solution at some point to force the compiler to pass
// the right `-Wl,-install_name` with an `@rpath` in it.
if self.sess.opts.cg.rpath || self.sess.opts.unstable_opts.osx_rpath_install_name {
Expand Down
11 changes: 3 additions & 8 deletions compiler/rustc_parse/src/parser/attr_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,10 @@ impl<'a> Parser<'a> {
let target = AttrsTarget { attrs: final_attrs.iter().cloned().collect(), tokens };
self.capture_state.replace_ranges.push((start_pos..end_pos, Some(target)));
self.capture_state.replace_ranges.extend(inner_attr_replace_ranges);
}

// Only clear our `replace_ranges` when we're finished capturing entirely.
if matches!(self.capture_state.capturing, Capturing::No) {
} else if matches!(self.capture_state.capturing, Capturing::No) {
// Only clear the ranges once we've finished capturing entirely.
self.capture_state.replace_ranges.clear();
// We don't clear `inner_attr_ranges`, as doing so repeatedly
// had a measurable performance impact. Most inner attributes that
// we insert will get removed - when we drop the parser, we'll free
// up the memory used by any attributes that we didn't remove from the map.
self.capture_state.inner_attr_ranges.clear();
}
Ok(ret)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2620,7 +2620,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
// This is the location used by the `rust-src` `rustup` component.
let mut candidate = sysroot.join("lib/rustlib/src/rust");
if let Ok(metadata) = candidate.symlink_metadata() {
// Replace the symlink rustbuild creates, with its destination.
// Replace the symlink bootstrap creates, with its destination.
// We could try to use `fs::canonicalize` instead, but that might
// produce unnecessarily verbose path.
if metadata.file_type().is_symlink() {
Expand Down
8 changes: 4 additions & 4 deletions config.example.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sample TOML configuration file for building Rust.
#
# To configure rustbuild, run `./configure` or `./x.py setup`.
# To configure bootstrap, run `./configure` or `./x.py setup`.
# See https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html#create-a-configtoml for more information.
#
# All options are commented out by default in this file, and they're commented
Expand Down Expand Up @@ -109,7 +109,7 @@
# increases the size of binaries and consequently the memory required by
# each linker process.
# If set to 0, linker invocations are treated like any other job and
# controlled by rustbuild's -j parameter.
# controlled by bootstrap's -j parameter.
#link-jobs = 0

# Whether to build LLVM as a dynamically linked library (as opposed to statically linked).
Expand Down Expand Up @@ -371,11 +371,11 @@
# Useful for modifying only the stage2 compiler without having to pass `--keep-stage 0` each time.
#local-rebuild = false

# Print out how long each rustbuild step took (mostly intended for CI and
# Print out how long each bootstrap step took (mostly intended for CI and
# tracking over time)
#print-step-timings = false

# Print out resource usage data for each rustbuild step, as defined by the Unix
# Print out resource usage data for each bootstrap step, as defined by the Unix
# struct rusage. (Note that this setting is completely unstable: the data it
# captures, what platforms it supports, the format of its associated output, and
# this setting's very existence, are all subject to change.)
Expand Down
14 changes: 7 additions & 7 deletions library/std/src/io/buffered/bufwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::fmt;
use crate::io::{
self, ErrorKind, IntoInnerError, IoSlice, Seek, SeekFrom, Write, DEFAULT_BUF_SIZE,
};
use crate::mem;
use crate::mem::{self, ManuallyDrop};
use crate::ptr;

/// Wraps a writer and buffers its output.
Expand Down Expand Up @@ -164,13 +164,13 @@ impl<W: Write> BufWriter<W> {
/// assert_eq!(&buffered_data.unwrap(), b"ata");
/// ```
#[stable(feature = "bufwriter_into_parts", since = "1.56.0")]
pub fn into_parts(mut self) -> (W, Result<Vec<u8>, WriterPanicked>) {
let buf = mem::take(&mut self.buf);
let buf = if !self.panicked { Ok(buf) } else { Err(WriterPanicked { buf }) };
pub fn into_parts(self) -> (W, Result<Vec<u8>, WriterPanicked>) {
let mut this = ManuallyDrop::new(self);
let buf = mem::take(&mut this.buf);
let buf = if !this.panicked { Ok(buf) } else { Err(WriterPanicked { buf }) };

// SAFETY: forget(self) prevents double dropping inner
let inner = unsafe { ptr::read(&self.inner) };
mem::forget(self);
// SAFETY: double-drops are prevented by putting `this` in a ManuallyDrop that is never dropped
let inner = unsafe { ptr::read(&this.inner) };

(inner, buf)
}
Expand Down
10 changes: 10 additions & 0 deletions library/std/src/io/buffered/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,3 +1067,13 @@ fn bufreader_full_initialize() {
// But we initialized the whole buffer!
assert_eq!(reader.initialized(), reader.capacity());
}

/// This is a regression test for https://github.com/rust-lang/rust/issues/127584.
#[test]
fn bufwriter_aliasing() {
use crate::io::{BufWriter, Cursor};
let mut v = vec![0; 1024];
let c = Cursor::new(&mut v);
let w = BufWriter::new(Box::new(c));
let _ = w.into_parts();
}
3 changes: 3 additions & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ pub use core::{
module_path, option_env, stringify, trace_macros,
};

#[unstable(feature = "anonymous_pipe", issue = "127154")]
pub use crate::sys::anonymous_pipe as pipe;

#[unstable(
feature = "concat_bytes",
issue = "87555",
Expand Down
141 changes: 141 additions & 0 deletions library/std/src/sys/anonymous_pipe/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
//! Module for annoymous pipe
//!
//! ```
//! #![feature(anonymous_pipe)]
//! # fn main() -> std::io::Result<()> {
//! let (reader, writer) = std::pipe::pipe()?;
//! # Ok(())
//! # }
//! ```

use crate::{io, sys::pipe::AnonPipe};

/// Create annoymous pipe that is close-on-exec and blocking.
#[unstable(feature = "anonymous_pipe", issue = "127154")]
#[inline]
pub fn pipe() -> io::Result<(PipeReader, PipeWriter)> {
cfg_if::cfg_if! {
if #[cfg(unix)] {
unix::pipe()
} else if #[cfg(windows)] {
windows::pipe()
} else {
Err(io::Error::UNSUPPORTED_PLATFORM)
}
}
}

/// Read end of the annoymous pipe.
#[unstable(feature = "anonymous_pipe", issue = "127154")]
#[derive(Debug)]
pub struct PipeReader(AnonPipe);

/// Write end of the annoymous pipe.
#[unstable(feature = "anonymous_pipe", issue = "127154")]
#[derive(Debug)]
pub struct PipeWriter(AnonPipe);

impl PipeReader {
/// Create a new [`PipeReader`] instance that shares the same underlying file description.
#[unstable(feature = "anonymous_pipe", issue = "127154")]
pub fn try_clone(&self) -> io::Result<Self> {
self.0.try_clone().map(Self)
}
}

impl PipeWriter {
/// Create a new [`PipeWriter`] instance that shares the same underlying file description.
#[unstable(feature = "anonymous_pipe", issue = "127154")]
pub fn try_clone(&self) -> io::Result<Self> {
self.0.try_clone().map(Self)
}
}

#[unstable(feature = "anonymous_pipe", issue = "127154")]
impl io::Read for &PipeReader {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.0.read(buf)
}
fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
self.0.read_vectored(bufs)
}
#[inline]
fn is_read_vectored(&self) -> bool {
self.0.is_read_vectored()
}
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
self.0.read_to_end(buf)
}
fn read_buf(&mut self, buf: io::BorrowedCursor<'_>) -> io::Result<()> {
self.0.read_buf(buf)
}
}

#[unstable(feature = "anonymous_pipe", issue = "127154")]
impl io::Read for PipeReader {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.0.read(buf)
}
fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
self.0.read_vectored(bufs)
}
#[inline]
fn is_read_vectored(&self) -> bool {
self.0.is_read_vectored()
}
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
self.0.read_to_end(buf)
}
fn read_buf(&mut self, buf: io::BorrowedCursor<'_>) -> io::Result<()> {
self.0.read_buf(buf)
}
}

#[unstable(feature = "anonymous_pipe", issue = "127154")]
impl io::Write for &PipeWriter {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.write(buf)
}
#[inline]
fn flush(&mut self) -> io::Result<()> {
Ok(())
}

fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
self.0.write_vectored(bufs)
}

#[inline]
fn is_write_vectored(&self) -> bool {
self.0.is_write_vectored()
}
}

#[unstable(feature = "anonymous_pipe", issue = "127154")]
impl io::Write for PipeWriter {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.write(buf)
}
#[inline]
fn flush(&mut self) -> io::Result<()> {
Ok(())
}

fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
self.0.write_vectored(bufs)
}

#[inline]
fn is_write_vectored(&self) -> bool {
self.0.is_write_vectored()
}
}

#[cfg(unix)]
mod unix;

#[cfg(windows)]
mod windows;

#[cfg(test)]
mod tests;
29 changes: 29 additions & 0 deletions library/std/src/sys/anonymous_pipe/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use super::*;
use crate::io::{Read, Write};

#[test]
fn pipe_creation_and_rw() {
let (mut rx, mut tx) = pipe().unwrap();
tx.write_all(b"12345").unwrap();
drop(tx);

let mut s = String::new();
rx.read_to_string(&mut s).unwrap();
assert_eq!(s, "12345");
}

#[test]
fn pipe_try_clone_and_rw() {
let (mut rx, mut tx) = pipe().unwrap();
tx.try_clone().unwrap().write_all(b"12").unwrap();
tx.write_all(b"345").unwrap();
drop(tx);

let mut s = String::new();
rx.try_clone().unwrap().take(3).read_to_string(&mut s).unwrap();
assert_eq!(s, "123");

s.clear();
rx.read_to_string(&mut s).unwrap();
assert_eq!(s, "45");
}
Loading
Loading