From 8b7a3f4d53f9e96a49d77ed42d22baf4d7743b94 Mon Sep 17 00:00:00 2001 From: Evan Richter Date: Tue, 17 May 2022 00:53:06 -0500 Subject: [PATCH 1/9] impl Read and Write for VecDeque * For read and read_buf, only the front slice of a discontiguous VecDeque is copied. The VecDeque is advanced after reading, making any back slice available for reading with a second call to Read::read(_buf). * For write, the VecDeque always appends the entire slice to the end, growing its allocation when necessary. --- library/std/src/io/impls.rs | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index 64d2457bce159..0ca58efe1fe2f 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -3,6 +3,7 @@ mod tests; use crate::alloc::Allocator; use crate::cmp; +use crate::collections::VecDeque; use crate::fmt; use crate::io::{ self, BufRead, ErrorKind, IoSlice, IoSliceMut, Read, ReadBuf, Seek, SeekFrom, Write, @@ -410,3 +411,50 @@ impl Write for Vec { Ok(()) } } + +/// Read is implemented for `VecDeque` by consuming bytes from the front of the `VecDeque`. +#[stable(feature = "vecdeque_read_write", since = "1.63.0")] +impl Read for VecDeque { + /// Fill `buf` with the contents of the "front" slice as returned by + /// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are + /// discontiguous, multiple calls to `read` will be needed to read the entire content. + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + let (ref mut front, _) = self.as_slices(); + let n = Read::read(front, buf)?; + self.drain(..n); + Ok(n) + } + + #[inline] + fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> io::Result<()> { + let (ref mut front, _) = self.as_slices(); + let n = cmp::min(buf.remaining(), front.len()); + Read::read_buf(front, buf)?; + self.drain(..n); + Ok(()) + } +} + +/// Write is implemented for `VecDeque` by appending to the `VecDeque`, growing it as needed. +#[stable(feature = "vecdeque_read_write", since = "1.63.0")] +impl Write for VecDeque { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + self.reserve(buf.len()); + self.extend(buf); + Ok(buf.len()) + } + + #[inline] + fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { + self.reserve(buf.len()); + self.extend(buf); + Ok(()) + } + + #[inline] + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} From 94134695b5c08af393da1c321913e10dd4b7c6e0 Mon Sep 17 00:00:00 2001 From: Marko Mijalkovic Date: Sun, 16 Jan 2022 16:55:07 -0500 Subject: [PATCH 2/9] Relax mipsel-sony-psp's linker script Previously, the linker script forcefully kept all `.lib.stub` sections, unnecessarily bloating the binary. Now, the script is LTO and `--gc-sections` friendly. `--nmagic` was also added to the linker, because page alignment is not required on the PSP. This further reduces binary size. Accompanying changes for the PSP crate are found in: https://github.com/overdrivenpotato/rust-psp/pull/118 --- .../rustc_target/src/spec/mipsel_sony_psp.rs | 5 ++++- .../src/spec/mipsel_sony_psp_linker_script.ld | 21 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_target/src/spec/mipsel_sony_psp.rs b/compiler/rustc_target/src/spec/mipsel_sony_psp.rs index 45966b97d6abc..c7ee52c2454be 100644 --- a/compiler/rustc_target/src/spec/mipsel_sony_psp.rs +++ b/compiler/rustc_target/src/spec/mipsel_sony_psp.rs @@ -6,7 +6,10 @@ const LINKER_SCRIPT: &str = include_str!("./mipsel_sony_psp_linker_script.ld"); pub fn target() -> Target { let mut pre_link_args = LinkArgs::new(); - pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["--emit-relocs".into()]); + pre_link_args.insert( + LinkerFlavor::Lld(LldFlavor::Ld), + vec!["--emit-relocs".into(), "--nmagic".into()], + ); Target { llvm_target: "mipsel-sony-psp".into(), diff --git a/compiler/rustc_target/src/spec/mipsel_sony_psp_linker_script.ld b/compiler/rustc_target/src/spec/mipsel_sony_psp_linker_script.ld index 1bd436d6f94cc..9eb35ad9f5d2e 100644 --- a/compiler/rustc_target/src/spec/mipsel_sony_psp_linker_script.ld +++ b/compiler/rustc_target/src/spec/mipsel_sony_psp_linker_script.ld @@ -7,14 +7,18 @@ SECTIONS /* Sort stubs for convenient ordering */ .sceStub.text : { *(.sceStub.text) *(SORT(.sceStub.text.*)) } + /* PSP import library stub sections. Bundles together `.lib.stub.entry.*` + * sections for better `--gc-sections` support. */ + .lib.stub.top : { *(.lib.stub.top) } + .lib.stub : { *(.lib.stub) *(.lib.stub.entry.*) } + .lib.stub.btm : { *(.lib.stub.btm) } + /* Keep these sections around, even though they may appear unused to the linker */ .lib.ent.top : { KEEP(*(.lib.ent.top)) } .lib.ent : { KEEP(*(.lib.ent)) } .lib.ent.btm : { KEEP(*(.lib.ent.btm)) } - .lib.stub.top : { KEEP(*(.lib.stub.top)) } - .lib.stub : { KEEP(*(.lib.stub)) } - .lib.stub.btm : { KEEP(*(.lib.stub.btm)) } - .eh_frame_hdr : { KEEP(*(.eh_frame_hdr)) } + + .eh_frame_hdr : { *(.eh_frame_hdr) } /* Add symbols for LLVM's libunwind */ __eh_frame_hdr_start = SIZEOF(.eh_frame_hdr) > 0 ? ADDR(.eh_frame_hdr) : 0; @@ -27,8 +31,15 @@ SECTIONS } /* These are explicitly listed to avoid being merged into .rodata */ - .rodata.sceResident : { *(.rodata.sceResident) } + .rodata.sceResident : { *(.rodata.sceResident) *(.rodata.sceResident.*) } .rodata.sceModuleInfo : { *(.rodata.sceModuleInfo) } /* Sort NIDs for convenient ordering */ .rodata.sceNid : { *(.rodata.sceNid) *(SORT(.rodata.sceNid.*)) } + + .rodata : { *(.rodata .rodata.*) } + .data : { *(.data .data.*) } + .gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) } + .bss : { *(.bss .bss.*) } + + /DISCARD/ : { *(.rel.sceStub.text .MIPS.abiflags .reginfo) } } From d92e213e3d2470e16c5e0107a9d6e41f54a40342 Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Tue, 7 Jun 2022 13:21:34 -0400 Subject: [PATCH 3/9] hexagon: adapt test for upstream output changes The output of IR formatting changed slightly in upstream rev a0bc67e555f404d0e7ddb2e78cb891d96eaf913d (https://reviews.llvm.org/D123096). I'm not actually sure what any of that means, as I don't even know what hexagon is in this context, but this change allows the test to pass on both old and new LLVMs. r? @nikic --- src/test/assembly/asm/hexagon-types.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/assembly/asm/hexagon-types.rs b/src/test/assembly/asm/hexagon-types.rs index de310c78488d9..eff9a0bb431d4 100644 --- a/src/test/assembly/asm/hexagon-types.rs +++ b/src/test/assembly/asm/hexagon-types.rs @@ -73,7 +73,7 @@ macro_rules! check_reg { // CHECK-LABEL: sym_static: // CHECK: InlineAsm Start -// CHECK: r0 = #extern_static +// CHECK: r0 = {{#+}}extern_static // CHECK: InlineAsm End #[no_mangle] pub unsafe fn sym_static() { @@ -88,7 +88,7 @@ pub unsafe fn sym_static() { // CHECK-LABEL: sym_fn: // CHECK: InlineAsm Start -// CHECK: r0 = #extern_func +// CHECK: r0 = {{#+}}extern_func // CHECK: InlineAsm End #[no_mangle] pub unsafe fn sym_fn() { @@ -108,7 +108,7 @@ pub unsafe fn sym_fn() { // CHECK: InlineAsm Start // CHECK: { // CHECK: r{{[0-9]+}} = r0 -// CHECK: memw(r1) = r{{[0-9]+}} +// CHECK: memw(r1{{(\+#0)?}}) = r{{[0-9]+}} // CHECK: } // CHECK: InlineAsm End #[no_mangle] From 611107af5f870f8f5f1d77b19e8f735be2a1da36 Mon Sep 17 00:00:00 2001 From: Marko Mijalkovic Date: Tue, 7 Jun 2022 16:02:11 -0400 Subject: [PATCH 4/9] Formatting fix --- compiler/rustc_target/src/spec/mipsel_sony_psp.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_target/src/spec/mipsel_sony_psp.rs b/compiler/rustc_target/src/spec/mipsel_sony_psp.rs index c7ee52c2454be..03e0934ea5ecc 100644 --- a/compiler/rustc_target/src/spec/mipsel_sony_psp.rs +++ b/compiler/rustc_target/src/spec/mipsel_sony_psp.rs @@ -6,10 +6,8 @@ const LINKER_SCRIPT: &str = include_str!("./mipsel_sony_psp_linker_script.ld"); pub fn target() -> Target { let mut pre_link_args = LinkArgs::new(); - pre_link_args.insert( - LinkerFlavor::Lld(LldFlavor::Ld), - vec!["--emit-relocs".into(), "--nmagic".into()], - ); + pre_link_args + .insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["--emit-relocs".into(), "--nmagic".into()]); Target { llvm_target: "mipsel-sony-psp".into(), From 9edaa76adce4de737db54194eb13d6c298827b37 Mon Sep 17 00:00:00 2001 From: Caio Date: Tue, 7 Jun 2022 21:50:45 -0300 Subject: [PATCH 5/9] Stabilize $$ in Rust 1.63.0 --- compiler/rustc_expand/src/mbe/quoted.rs | 2 - .../rfc-3086-metavar-expr/allowed-features.rs | 12 +++++ ...quired-feature.rs => required-features.rs} | 12 ----- ...eature.stderr => required-features.stderr} | 50 +++---------------- 4 files changed, 19 insertions(+), 57 deletions(-) create mode 100644 src/test/ui/macros/rfc-3086-metavar-expr/allowed-features.rs rename src/test/ui/macros/rfc-3086-metavar-expr/{required-feature.rs => required-features.rs} (65%) rename src/test/ui/macros/rfc-3086-metavar-expr/{required-feature.stderr => required-features.stderr} (52%) diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index 707cb73f097f8..d4b8563a03666 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -234,8 +234,6 @@ fn parse_tree( sess, &Token { kind: token::Dollar, span }, ); - } else { - maybe_emit_macro_metavar_expr_feature(features, sess, span); } TokenTree::token(token::Dollar, span) } diff --git a/src/test/ui/macros/rfc-3086-metavar-expr/allowed-features.rs b/src/test/ui/macros/rfc-3086-metavar-expr/allowed-features.rs new file mode 100644 index 0000000000000..c248c46f52cd3 --- /dev/null +++ b/src/test/ui/macros/rfc-3086-metavar-expr/allowed-features.rs @@ -0,0 +1,12 @@ +// check-pass + +macro_rules! dollar_dollar { + () => { + macro_rules! bar { + ( $$( $$any:tt )* ) => { $$( $$any )* }; + } + }; +} + +fn main() { +} diff --git a/src/test/ui/macros/rfc-3086-metavar-expr/required-feature.rs b/src/test/ui/macros/rfc-3086-metavar-expr/required-features.rs similarity index 65% rename from src/test/ui/macros/rfc-3086-metavar-expr/required-feature.rs rename to src/test/ui/macros/rfc-3086-metavar-expr/required-features.rs index b4fef11f1e29a..cce3e578aeafe 100644 --- a/src/test/ui/macros/rfc-3086-metavar-expr/required-feature.rs +++ b/src/test/ui/macros/rfc-3086-metavar-expr/required-features.rs @@ -5,18 +5,6 @@ macro_rules! count { }; } -macro_rules! dollar_dollar { - () => { - macro_rules! bar { - ( $$( $$any:tt )* ) => { $$( $$any )* }; - //~^ ERROR meta-variable expressions are unstable - //~| ERROR meta-variable expressions are unstable - //~| ERROR meta-variable expressions are unstable - //~| ERROR meta-variable expressions are unstable - } - }; -} - macro_rules! index { ( $( $e:stmt ),* ) => { $( ${ignore(e)} ${index()} )* diff --git a/src/test/ui/macros/rfc-3086-metavar-expr/required-feature.stderr b/src/test/ui/macros/rfc-3086-metavar-expr/required-features.stderr similarity index 52% rename from src/test/ui/macros/rfc-3086-metavar-expr/required-feature.stderr rename to src/test/ui/macros/rfc-3086-metavar-expr/required-features.stderr index ecf598b104d05..5efd3b10442d1 100644 --- a/src/test/ui/macros/rfc-3086-metavar-expr/required-feature.stderr +++ b/src/test/ui/macros/rfc-3086-metavar-expr/required-features.stderr @@ -1,5 +1,5 @@ error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:3:10 + --> $DIR/required-features.rs:3:10 | LL | ${ count(e) } | ^^^^^^^^^^^^ @@ -8,43 +8,7 @@ LL | ${ count(e) } = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:11:16 - | -LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; - | ^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:11:20 - | -LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; - | ^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:11:39 - | -LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; - | ^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:11:43 - | -LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; - | ^ - | - = note: see issue #83527 for more information - = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable - -error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:22:13 + --> $DIR/required-features.rs:10:13 | LL | $( ${ignore(e)} ${index()} )* | ^^^^^^^^^^^ @@ -53,7 +17,7 @@ LL | $( ${ignore(e)} ${index()} )* = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:22:26 + --> $DIR/required-features.rs:10:26 | LL | $( ${ignore(e)} ${index()} )* | ^^^^^^^^^ @@ -62,7 +26,7 @@ LL | $( ${ignore(e)} ${index()} )* = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:30:19 + --> $DIR/required-features.rs:18:19 | LL | 0 $( + 1 ${ignore(i)} )* | ^^^^^^^^^^^ @@ -71,7 +35,7 @@ LL | 0 $( + 1 ${ignore(i)} )* = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:37:13 + --> $DIR/required-features.rs:25:13 | LL | $( ${ignore(e)} ${length()} )* | ^^^^^^^^^^^ @@ -80,7 +44,7 @@ LL | $( ${ignore(e)} ${length()} )* = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable error[E0658]: meta-variable expressions are unstable - --> $DIR/required-feature.rs:37:26 + --> $DIR/required-features.rs:25:26 | LL | $( ${ignore(e)} ${length()} )* | ^^^^^^^^^^ @@ -88,6 +52,6 @@ LL | $( ${ignore(e)} ${length()} )* = note: see issue #83527 for more information = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable -error: aborting due to 10 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0658`. From 2ecbdc1b3223eb9acda60014946738cd8e87f7e5 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 8 Jun 2022 10:04:02 -0700 Subject: [PATCH 6/9] Don't use __gxx_personality_v0 in panic_unwind on emscripten target This resolves #85821. See also the discussion here: https://github.com/emscripten-core/emscripten/issues/17128 The consensus seems to be that rust_eh_personality is never invoked. I patched __gxx_personality_v0 to log invocations and then ran various panic tests and it was never called, so this analysis matches what seems to happen in practice. This replaces the definition with an abort, modeled on the structured exception handling implementation. --- library/panic_unwind/src/emcc.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/panic_unwind/src/emcc.rs b/library/panic_unwind/src/emcc.rs index 12f0fe9c3c3a9..e3a32a5581eaf 100644 --- a/library/panic_unwind/src/emcc.rs +++ b/library/panic_unwind/src/emcc.rs @@ -105,6 +105,11 @@ extern "C" fn exception_cleanup(ptr: *mut libc::c_void) -> *mut libc::c_void { } } + +// This is required by the compiler to exist (e.g., it's a lang item), but it's +// never actually called by the compiler. Emscripten EH doesn't use a +// personality function at all, it instead uses __cxa_find_matching_catch. +// Wasm error handling would use __gxx_personality_wasm0. #[lang = "eh_personality"] unsafe extern "C" fn rust_eh_personality( version: c_int, @@ -113,7 +118,7 @@ unsafe extern "C" fn rust_eh_personality( exception_object: *mut uw::_Unwind_Exception, context: *mut uw::_Unwind_Context, ) -> uw::_Unwind_Reason_Code { - __gxx_personality_v0(version, actions, exception_class, exception_object, context) + core::intrinsics::abort() } extern "C" { From 0ec3174e3ea682aac2633b38e75db0e94eabe5c9 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 8 Jun 2022 10:25:18 -0700 Subject: [PATCH 7/9] Fix formatter --- library/panic_unwind/src/emcc.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/panic_unwind/src/emcc.rs b/library/panic_unwind/src/emcc.rs index e3a32a5581eaf..790aacdbe455d 100644 --- a/library/panic_unwind/src/emcc.rs +++ b/library/panic_unwind/src/emcc.rs @@ -105,7 +105,6 @@ extern "C" fn exception_cleanup(ptr: *mut libc::c_void) -> *mut libc::c_void { } } - // This is required by the compiler to exist (e.g., it's a lang item), but it's // never actually called by the compiler. Emscripten EH doesn't use a // personality function at all, it instead uses __cxa_find_matching_catch. From 46a3f0feb6bee316a682bd8b62d3a0a0f2647619 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 8 Jun 2022 16:31:21 -0700 Subject: [PATCH 8/9] Remove __gxx_personality_v0 declaration --- library/panic_unwind/src/emcc.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/library/panic_unwind/src/emcc.rs b/library/panic_unwind/src/emcc.rs index 790aacdbe455d..c458af10aad19 100644 --- a/library/panic_unwind/src/emcc.rs +++ b/library/panic_unwind/src/emcc.rs @@ -129,11 +129,4 @@ extern "C" { tinfo: *const TypeInfo, dest: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void, ) -> !; - fn __gxx_personality_v0( - version: c_int, - actions: uw::_Unwind_Action, - exception_class: uw::_Unwind_Exception_Class, - exception_object: *mut uw::_Unwind_Exception, - context: *mut uw::_Unwind_Context, - ) -> uw::_Unwind_Reason_Code; } From 36a4490271f5e32c54f2a9d8e49267c2783e0586 Mon Sep 17 00:00:00 2001 From: lcnr Date: Wed, 8 Jun 2022 13:58:28 +0200 Subject: [PATCH 9/9] rewrite combine doc comment --- compiler/rustc_infer/src/infer/combine.rs | 46 +++++++++++------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 534106ac446cf..120e57ecebd75 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -1,26 +1,26 @@ -/////////////////////////////////////////////////////////////////////////// -// # Type combining -// -// There are four type combiners: equate, sub, lub, and glb. Each -// implements the trait `Combine` and contains methods for combining -// two instances of various things and yielding a new instance. These -// combiner methods always yield a `Result`. There is a lot of -// common code for these operations, implemented as default methods on -// the `Combine` trait. -// -// Each operation may have side-effects on the inference context, -// though these can be unrolled using snapshots. On success, the -// LUB/GLB operations return the appropriate bound. The Eq and Sub -// operations generally return the first operand. -// -// ## Contravariance -// -// When you are relating two things which have a contravariant -// relationship, you should use `contratys()` or `contraregions()`, -// rather than inversing the order of arguments! This is necessary -// because the order of arguments is not relevant for LUB and GLB. It -// is also useful to track which value is the "expected" value in -// terms of error reporting. +//! There are four type combiners: [Equate], [Sub], [Lub], and [Glb]. +//! Each implements the trait [TypeRelation] and contains methods for +//! combining two instances of various things and yielding a new instance. +//! These combiner methods always yield a `Result`. To relate two +//! types, you can use `infcx.at(cause, param_env)` which then allows +//! you to use the relevant methods of [At](super::at::At). +//! +//! Combiners mostly do their specific behavior and then hand off the +//! bulk of the work to [InferCtxt::super_combine_tys] and +//! [InferCtxt::super_combine_consts]. +//! +//! Combining two types may have side-effects on the inference contexts +//! which can be undone by using snapshots. You probably want to use +//! either [InferCtxt::commit_if_ok] or [InferCtxt::probe]. +//! +//! On success, the LUB/GLB operations return the appropriate bound. The +//! return value of `Equate` or `Sub` shouldn't really be used. +//! +//! ## Contravariance +//! +//! We explicitly track which argument is expected using +//! [TypeRelation::a_is_expected], so when dealing with contravariance +//! this should be correctly updated. use super::equate::Equate; use super::glb::Glb;