From 870b8311c17fb51139d5cc95fc592bcea85ee6ac Mon Sep 17 00:00:00 2001 From: rdambrosio Date: Tue, 23 Nov 2021 22:30:20 -0500 Subject: [PATCH 1/6] Feat: make cg_ssa get_param borrow the builder mutable --- compiler/rustc_codegen_gcc/src/abi.rs | 2 +- compiler/rustc_codegen_llvm/src/abi.rs | 2 +- compiler/rustc_codegen_ssa/src/traits/abi.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_codegen_gcc/src/abi.rs b/compiler/rustc_codegen_gcc/src/abi.rs index ce428c589a478..2bbb199c89982 100644 --- a/compiler/rustc_codegen_gcc/src/abi.rs +++ b/compiler/rustc_codegen_gcc/src/abi.rs @@ -14,7 +14,7 @@ impl<'a, 'gcc, 'tcx> AbiBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { // TODO(antoyo) } - fn get_param(&self, index: usize) -> Self::Value { + fn get_param(&mut self, index: usize) -> Self::Value { self.cx.current_func.borrow().expect("current func") .get_param(index as i32) .to_rvalue() diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index bedd3523d899e..07adfff0901a1 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -607,7 +607,7 @@ impl AbiBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { fn_abi.apply_attrs_callsite(self, callsite) } - fn get_param(&self, index: usize) -> Self::Value { + fn get_param(&mut self, index: usize) -> Self::Value { llvm::get_param(self.llfn(), index as c_uint) } } diff --git a/compiler/rustc_codegen_ssa/src/traits/abi.rs b/compiler/rustc_codegen_ssa/src/traits/abi.rs index dd8495850bd54..a00d78daf4dcb 100644 --- a/compiler/rustc_codegen_ssa/src/traits/abi.rs +++ b/compiler/rustc_codegen_ssa/src/traits/abi.rs @@ -4,5 +4,5 @@ use rustc_target::abi::call::FnAbi; pub trait AbiBuilderMethods<'tcx>: BackendTypes { fn apply_attrs_callsite(&mut self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, callsite: Self::Value); - fn get_param(&self, index: usize) -> Self::Value; + fn get_param(&mut self, index: usize) -> Self::Value; } From 644b445428845a4e662c15059193dfa492bc0c44 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Wed, 24 Nov 2021 15:59:28 +0100 Subject: [PATCH 2/6] If the thread does not get the lock in the short term, yield the CPU Reduces the amount of wasted processor cycles --- library/std/src/sys/hermit/mutex.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/hermit/mutex.rs b/library/std/src/sys/hermit/mutex.rs index 691e7e07902d8..79692ef2442ca 100644 --- a/library/std/src/sys/hermit/mutex.rs +++ b/library/std/src/sys/hermit/mutex.rs @@ -46,8 +46,17 @@ impl Spinlock { #[inline] fn obtain_lock(&self) { let ticket = self.queue.fetch_add(1, Ordering::SeqCst) + 1; + let mut counter: u16 = 0; while self.dequeue.load(Ordering::SeqCst) != ticket { - hint::spin_loop(); + counter = counter + 1; + if counter < 100 { + hint::spin_loop(); + } else { + counter = 0; + unsafe { + abi::yield_now(); + } + } } } From 6911af9d06ef4f92659326ce426c6aefc7b47282 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Wed, 24 Nov 2021 21:12:56 +0100 Subject: [PATCH 3/6] Improving the readability Co-authored-by: kennytm --- library/std/src/sys/hermit/mutex.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/hermit/mutex.rs b/library/std/src/sys/hermit/mutex.rs index 79692ef2442ca..415cbba101c67 100644 --- a/library/std/src/sys/hermit/mutex.rs +++ b/library/std/src/sys/hermit/mutex.rs @@ -48,7 +48,7 @@ impl Spinlock { let ticket = self.queue.fetch_add(1, Ordering::SeqCst) + 1; let mut counter: u16 = 0; while self.dequeue.load(Ordering::SeqCst) != ticket { - counter = counter + 1; + counter += 1; if counter < 100 { hint::spin_loop(); } else { From c981d40d43c76267e7b4002e381851f0e92875bf Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 25 Nov 2021 17:08:23 +0100 Subject: [PATCH 4/6] Fix invalid scrollbar display on source code page --- src/librustdoc/html/static/css/rustdoc.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 0f3eb2ca07d23..bfad510695131 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -305,6 +305,10 @@ nav.sub { overflow-y: scroll; } +.rustdoc.source .sidebar { + overflow-y: auto; +} + /* Improve the scrollbar display on firefox */ * { scrollbar-width: initial; From 718a3b1f2d59943c90cd02b9d0b90b315e003ec0 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 25 Nov 2021 06:48:09 +0000 Subject: [PATCH 5/6] Fix issue 91206 --- .../src/diagnostics/mutability_errors.rs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 46e2a99a0d094..a0f8aabbe0e72 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -447,16 +447,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { // check if the RHS is from desugaring let opt_assignment_rhs_span = self.body.find_assignments(local).first().map(|&location| { - let stmt = &self.body[location.block].statements - [location.statement_index]; - match stmt.kind { - mir::StatementKind::Assign(box ( - _, - mir::Rvalue::Use(mir::Operand::Copy(place)), - )) => { - self.body.local_decls[place.local].source_info.span - } - _ => self.body.source_info(location).span, + if let Some(mir::Statement { + source_info: _, + kind: + mir::StatementKind::Assign(box ( + _, + mir::Rvalue::Use(mir::Operand::Copy(place)), + )), + }) = self.body[location.block] + .statements + .get(location.statement_index) + { + self.body.local_decls[place.local].source_info.span + } else { + self.body.source_info(location).span } }); match opt_assignment_rhs_span.and_then(|s| s.desugaring_kind()) { From 69d1917672d302e2da14ad6673e6a0478c62d1ad Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 25 Nov 2021 16:33:01 +0000 Subject: [PATCH 6/6] Add test demonstrating no more ICE --- src/test/ui/borrowck/issue-91206.rs | 15 +++++++++++++++ src/test/ui/borrowck/issue-91206.stderr | 12 ++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/test/ui/borrowck/issue-91206.rs create mode 100644 src/test/ui/borrowck/issue-91206.stderr diff --git a/src/test/ui/borrowck/issue-91206.rs b/src/test/ui/borrowck/issue-91206.rs new file mode 100644 index 0000000000000..3b1fbf4b69902 --- /dev/null +++ b/src/test/ui/borrowck/issue-91206.rs @@ -0,0 +1,15 @@ +struct TestClient; + +impl TestClient { + fn get_inner_ref(&self) -> &Vec { + todo!() + } +} + +fn main() { + let client = TestClient; + let inner = client.get_inner_ref(); + //~^ HELP consider changing this to be a mutable reference + inner.clear(); + //~^ ERROR cannot borrow `*inner` as mutable, as it is behind a `&` reference [E0596] +} diff --git a/src/test/ui/borrowck/issue-91206.stderr b/src/test/ui/borrowck/issue-91206.stderr new file mode 100644 index 0000000000000..535d247452a59 --- /dev/null +++ b/src/test/ui/borrowck/issue-91206.stderr @@ -0,0 +1,12 @@ +error[E0596]: cannot borrow `*inner` as mutable, as it is behind a `&` reference + --> $DIR/issue-91206.rs:13:5 + | +LL | let inner = client.get_inner_ref(); + | ----- help: consider changing this to be a mutable reference: `&mut Vec` +LL | +LL | inner.clear(); + | ^^^^^^^^^^^^^ `inner` is a `&` reference, so the data it refers to cannot be borrowed as mutable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0596`.