Skip to content

Commit a9eba8d

Browse files
committed
Auto merge of rust-lang#113508 - matthiaskrgr:rollup-xzrp4nt, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#111618 (Always name the return place.) - rust-lang#113247 (Add Tests for native wasm exceptions) - rust-lang#113273 (Use String or Int to set the opt level) - rust-lang#113469 (Remove `default_free_fn` feature) - rust-lang#113493 (additional io::copy specializations) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b12ff66 + 205ae16 commit a9eba8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+758
-323
lines changed

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
328328

329329
let local_ref = &self.locals[local];
330330

331-
// FIXME Should the return place be named?
332-
let name = if bx.sess().fewer_names() || local == mir::RETURN_PLACE {
331+
let name = if bx.sess().fewer_names() {
333332
None
334333
} else {
335334
Some(match whole_local_var.or(fallback_var.clone()) {

config.example.toml

+12-2
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,20 @@ changelog-seen = 2
400400
# =============================================================================
401401
[rust]
402402

403-
# Whether or not to optimize the compiler and standard library.
403+
# Whether or not to optimize when compiling the compiler and standard library,
404+
# and what level of optimization to use.
404405
# WARNING: Building with optimize = false is NOT SUPPORTED. Due to bootstrapping,
405406
# building without optimizations takes much longer than optimizing. Further, some platforms
406407
# fail to build without this optimization (c.f. #65352).
408+
# The valid options are:
409+
# true - Enable optimizations.
410+
# false - Disable optimizations.
411+
# 0 - Disable optimizations.
412+
# 1 - Basic optimizations.
413+
# 2 - Some optimizations.
414+
# 3 - All optimizations.
415+
# "s" - Optimize for binary size.
416+
# "z" - Optimize for binary size, but also turn off loop vectorization.
407417
#optimize = true
408418

409419
# Indicates that the build should be configured for debugging Rust. A
@@ -757,7 +767,7 @@ changelog-seen = 2
757767
# This option will override the same option under [build] section.
758768
#profiler = build.profiler (bool)
759769

760-
# This option supports enable `rpath` in each target independently,
770+
# This option supports enable `rpath` in each target independently,
761771
# and will override the same option under [rust] section. It only works on Unix platforms
762772
#rpath = rust.rpath (bool)
763773

library/core/src/default.rs

-45
Original file line numberDiff line numberDiff line change
@@ -133,51 +133,6 @@ pub trait Default: Sized {
133133
fn default() -> Self;
134134
}
135135

136-
/// Return the default value of a type according to the `Default` trait.
137-
///
138-
/// The type to return is inferred from context; this is equivalent to
139-
/// `Default::default()` but shorter to type.
140-
///
141-
/// For example:
142-
/// ```
143-
/// #![feature(default_free_fn)]
144-
///
145-
/// use std::default::default;
146-
///
147-
/// #[derive(Default)]
148-
/// struct AppConfig {
149-
/// foo: FooConfig,
150-
/// bar: BarConfig,
151-
/// }
152-
///
153-
/// #[derive(Default)]
154-
/// struct FooConfig {
155-
/// foo: i32,
156-
/// }
157-
///
158-
/// #[derive(Default)]
159-
/// struct BarConfig {
160-
/// bar: f32,
161-
/// baz: u8,
162-
/// }
163-
///
164-
/// fn main() {
165-
/// let options = AppConfig {
166-
/// foo: default(),
167-
/// bar: BarConfig {
168-
/// bar: 10.1,
169-
/// ..default()
170-
/// },
171-
/// };
172-
/// }
173-
/// ```
174-
#[unstable(feature = "default_free_fn", issue = "73014")]
175-
#[must_use]
176-
#[inline]
177-
pub fn default<T: Default>() -> T {
178-
Default::default()
179-
}
180-
181136
/// Derive macro generating an impl of the trait `Default`.
182137
#[rustc_builtin_macro(Default, attributes(default))]
183138
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]

library/std/src/io/copy.rs

+79-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
use super::{BorrowedBuf, BufReader, BufWriter, ErrorKind, Read, Result, Write, DEFAULT_BUF_SIZE};
2+
use crate::alloc::Allocator;
3+
use crate::cmp;
4+
use crate::collections::VecDeque;
5+
use crate::io::IoSlice;
26
use crate::mem::MaybeUninit;
37

48
#[cfg(test)]
@@ -86,7 +90,7 @@ where
8690

8791
/// Specialization of the read-write loop that reuses the internal
8892
/// buffer of a BufReader. If there's no buffer then the writer side
89-
/// should be used intead.
93+
/// should be used instead.
9094
trait BufferedReaderSpec {
9195
fn buffer_size(&self) -> usize;
9296

@@ -104,7 +108,39 @@ where
104108
}
105109

106110
default fn copy_to(&mut self, _to: &mut (impl Write + ?Sized)) -> Result<u64> {
107-
unimplemented!("only called from specializations");
111+
unreachable!("only called from specializations")
112+
}
113+
}
114+
115+
impl BufferedReaderSpec for &[u8] {
116+
fn buffer_size(&self) -> usize {
117+
// prefer this specialization since the source "buffer" is all we'll ever need,
118+
// even if it's small
119+
usize::MAX
120+
}
121+
122+
fn copy_to(&mut self, to: &mut (impl Write + ?Sized)) -> Result<u64> {
123+
let len = self.len();
124+
to.write_all(self)?;
125+
*self = &self[len..];
126+
Ok(len as u64)
127+
}
128+
}
129+
130+
impl<A: Allocator> BufferedReaderSpec for VecDeque<u8, A> {
131+
fn buffer_size(&self) -> usize {
132+
// prefer this specialization since the source "buffer" is all we'll ever need,
133+
// even if it's small
134+
usize::MAX
135+
}
136+
137+
fn copy_to(&mut self, to: &mut (impl Write + ?Sized)) -> Result<u64> {
138+
let len = self.len();
139+
let (front, back) = self.as_slices();
140+
let bufs = &mut [IoSlice::new(front), IoSlice::new(back)];
141+
to.write_all_vectored(bufs)?;
142+
self.clear();
143+
Ok(len as u64)
108144
}
109145
}
110146

@@ -218,6 +254,47 @@ impl<I: Write + ?Sized> BufferedWriterSpec for BufWriter<I> {
218254
}
219255
}
220256

257+
impl<A: Allocator> BufferedWriterSpec for Vec<u8, A> {
258+
fn buffer_size(&self) -> usize {
259+
cmp::max(DEFAULT_BUF_SIZE, self.capacity() - self.len())
260+
}
261+
262+
fn copy_from<R: Read + ?Sized>(&mut self, reader: &mut R) -> Result<u64> {
263+
let mut bytes = 0;
264+
265+
// avoid allocating before we have determined that there's anything to read
266+
if self.capacity() == 0 {
267+
bytes = stack_buffer_copy(&mut reader.take(DEFAULT_BUF_SIZE as u64), self)?;
268+
if bytes == 0 {
269+
return Ok(0);
270+
}
271+
}
272+
273+
loop {
274+
self.reserve(DEFAULT_BUF_SIZE);
275+
let mut buf: BorrowedBuf<'_> = self.spare_capacity_mut().into();
276+
match reader.read_buf(buf.unfilled()) {
277+
Ok(()) => {}
278+
Err(e) if e.kind() == ErrorKind::Interrupted => continue,
279+
Err(e) => return Err(e),
280+
};
281+
282+
let read = buf.filled().len();
283+
if read == 0 {
284+
break;
285+
}
286+
287+
// SAFETY: BorrowedBuf guarantees all of its filled bytes are init
288+
// and the number of read bytes can't exceed the spare capacity since
289+
// that's what the buffer is borrowing from.
290+
unsafe { self.set_len(self.len() + read) };
291+
bytes += read as u64;
292+
}
293+
294+
Ok(bytes)
295+
}
296+
}
297+
221298
fn stack_buffer_copy<R: Read + ?Sized, W: Write + ?Sized>(
222299
reader: &mut R,
223300
writer: &mut W,

library/std/src/io/copy/tests.rs

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use crate::cmp::{max, min};
2+
use crate::collections::VecDeque;
3+
use crate::io;
24
use crate::io::*;
35

46
#[test]
@@ -19,7 +21,7 @@ struct ShortReader {
1921

2022
impl Read for ShortReader {
2123
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
22-
let bytes = min(self.cap, self.read_size);
24+
let bytes = min(self.cap, self.read_size).min(buf.len());
2325
self.cap -= bytes;
2426
self.observed_buffer = max(self.observed_buffer, buf.len());
2527
Ok(bytes)
@@ -78,6 +80,40 @@ fn copy_specializes_bufreader() {
7880
);
7981
}
8082

83+
#[test]
84+
fn copy_specializes_to_vec() {
85+
let cap = 123456;
86+
let mut source = ShortReader { cap, observed_buffer: 0, read_size: 1337 };
87+
let mut sink = Vec::new();
88+
assert_eq!(cap as u64, io::copy(&mut source, &mut sink).unwrap());
89+
assert!(
90+
source.observed_buffer > DEFAULT_BUF_SIZE,
91+
"expected a large buffer to be provided to the reader"
92+
);
93+
}
94+
95+
#[test]
96+
fn copy_specializes_from_vecdeque() {
97+
let mut source = VecDeque::with_capacity(100 * 1024);
98+
for _ in 0..20 * 1024 {
99+
source.push_front(0);
100+
}
101+
for _ in 0..20 * 1024 {
102+
source.push_back(0);
103+
}
104+
let mut sink = WriteObserver { observed_buffer: 0 };
105+
assert_eq!(40 * 1024u64, io::copy(&mut source, &mut sink).unwrap());
106+
assert_eq!(20 * 1024, sink.observed_buffer);
107+
}
108+
109+
#[test]
110+
fn copy_specializes_from_slice() {
111+
let mut source = [1; 60 * 1024].as_slice();
112+
let mut sink = WriteObserver { observed_buffer: 0 };
113+
assert_eq!(60 * 1024u64, io::copy(&mut source, &mut sink).unwrap());
114+
assert_eq!(60 * 1024, sink.observed_buffer);
115+
}
116+
81117
#[cfg(unix)]
82118
mod io_benches {
83119
use crate::fs::File;

src/bootstrap/config.rs

+60-13
Original file line numberDiff line numberDiff line change
@@ -875,11 +875,10 @@ impl Default for StringOrBool {
875875
}
876876
}
877877

878-
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
879-
#[serde(untagged)]
878+
#[derive(Clone, Debug, PartialEq, Eq)]
880879
pub enum RustOptimize {
881-
#[serde(deserialize_with = "deserialize_and_validate_opt_level")]
882880
String(String),
881+
Int(u8),
883882
Bool(bool),
884883
}
885884

@@ -889,26 +888,74 @@ impl Default for RustOptimize {
889888
}
890889
}
891890

892-
fn deserialize_and_validate_opt_level<'de, D>(d: D) -> Result<String, D::Error>
893-
where
894-
D: serde::de::Deserializer<'de>,
895-
{
896-
let v = String::deserialize(d)?;
897-
if ["0", "1", "2", "3", "s", "z"].iter().find(|x| **x == v).is_some() {
898-
Ok(v)
899-
} else {
900-
Err(format!(r#"unrecognized option for rust optimize: "{}", expected one of "0", "1", "2", "3", "s", "z""#, v)).map_err(serde::de::Error::custom)
891+
impl<'de> Deserialize<'de> for RustOptimize {
892+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
893+
where
894+
D: Deserializer<'de>,
895+
{
896+
deserializer.deserialize_any(OptimizeVisitor)
897+
}
898+
}
899+
900+
struct OptimizeVisitor;
901+
902+
impl<'de> serde::de::Visitor<'de> for OptimizeVisitor {
903+
type Value = RustOptimize;
904+
905+
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
906+
formatter.write_str(r#"one of: 0, 1, 2, 3, "s", "z", true, false"#)
907+
}
908+
909+
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
910+
where
911+
E: serde::de::Error,
912+
{
913+
if ["s", "z"].iter().find(|x| **x == value).is_some() {
914+
Ok(RustOptimize::String(value.to_string()))
915+
} else {
916+
Err(format_optimize_error_msg(value)).map_err(serde::de::Error::custom)
917+
}
918+
}
919+
920+
fn visit_i64<E>(self, value: i64) -> Result<Self::Value, E>
921+
where
922+
E: serde::de::Error,
923+
{
924+
if matches!(value, 0..=3) {
925+
Ok(RustOptimize::Int(value as u8))
926+
} else {
927+
Err(format_optimize_error_msg(value)).map_err(serde::de::Error::custom)
928+
}
929+
}
930+
931+
fn visit_bool<E>(self, value: bool) -> Result<Self::Value, E>
932+
where
933+
E: serde::de::Error,
934+
{
935+
Ok(RustOptimize::Bool(value))
901936
}
902937
}
903938

939+
fn format_optimize_error_msg(v: impl std::fmt::Display) -> String {
940+
format!(
941+
r#"unrecognized option for rust optimize: "{}", expected one of 0, 1, 2, 3, "s", "z", true, false"#,
942+
v
943+
)
944+
}
945+
904946
impl RustOptimize {
905947
pub(crate) fn is_release(&self) -> bool {
906-
if let RustOptimize::Bool(true) | RustOptimize::String(_) = &self { true } else { false }
948+
match &self {
949+
RustOptimize::Bool(true) | RustOptimize::String(_) => true,
950+
RustOptimize::Int(i) => *i > 0,
951+
RustOptimize::Bool(false) => false,
952+
}
907953
}
908954

909955
pub(crate) fn get_opt_level(&self) -> Option<String> {
910956
match &self {
911957
RustOptimize::String(s) => Some(s.clone()),
958+
RustOptimize::Int(i) => Some(i.to_string()),
912959
RustOptimize::Bool(_) => None,
913960
}
914961
}

src/bootstrap/config/tests.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ fn rust_optimize() {
184184
assert_eq!(parse("").rust_optimize.is_release(), true);
185185
assert_eq!(parse("rust.optimize = false").rust_optimize.is_release(), false);
186186
assert_eq!(parse("rust.optimize = true").rust_optimize.is_release(), true);
187-
assert_eq!(parse("rust.optimize = \"1\"").rust_optimize.get_opt_level(), Some("1".to_string()));
187+
assert_eq!(parse("rust.optimize = 0").rust_optimize.is_release(), false);
188+
assert_eq!(parse("rust.optimize = 1").rust_optimize.is_release(), true);
189+
assert_eq!(parse("rust.optimize = 1").rust_optimize.get_opt_level(), Some("1".to_string()));
190+
assert_eq!(parse("rust.optimize = \"s\"").rust_optimize.is_release(), true);
188191
assert_eq!(parse("rust.optimize = \"s\"").rust_optimize.get_opt_level(), Some("s".to_string()));
189192
}
190193

src/ci/docker/host-x86_64/test-various/Dockerfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins
2424
qemu-system-x86 \
2525
&& rm -rf /var/lib/apt/lists/*
2626

27-
RUN curl -sL https://nodejs.org/dist/v15.14.0/node-v15.14.0-linux-x64.tar.xz | \
27+
RUN curl -sL https://nodejs.org/dist/v18.12.0/node-v18.12.0-linux-x64.tar.xz | \
2828
tar -xJ
2929

3030
# Install 32-bit OVMF files for the i686-unknown-uefi test. This package
@@ -42,7 +42,7 @@ RUN sh /scripts/sccache.sh
4242

4343
ENV RUST_CONFIGURE_ARGS \
4444
--musl-root-x86_64=/usr/local/x86_64-linux-musl \
45-
--set build.nodejs=/node-v15.14.0-linux-x64/bin/node \
45+
--set build.nodejs=/node-v18.12.0-linux-x64/bin/node \
4646
--set rust.lld
4747

4848
# Some run-make tests have assertions about code size, and enabling debug
@@ -58,6 +58,8 @@ ENV WASM_SCRIPT python3 /checkout/x.py --stage 2 test --host='' --target $WASM_T
5858
tests/ui \
5959
tests/mir-opt \
6060
tests/codegen-units \
61+
tests/codegen \
62+
tests/assembly \
6163
library/core
6264

6365
ENV NVPTX_TARGETS=nvptx64-nvidia-cuda

0 commit comments

Comments
 (0)