From 1a6730e31ced3a7264c80c0bbdd9f42c54f1534b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 31 Jul 2020 13:15:47 +0200 Subject: [PATCH 1/6] Clean up E0741 error explanation --- src/librustc_error_codes/error_codes/E0741.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0741.md b/src/librustc_error_codes/error_codes/E0741.md index 0a8650282a374..91379bfe05c65 100644 --- a/src/librustc_error_codes/error_codes/E0741.md +++ b/src/librustc_error_codes/error_codes/E0741.md @@ -1,5 +1,6 @@ -Only structural-match types (that is, types that derive `PartialEq` and `Eq`) -may be used as the types of const generic parameters. +A non-structural-match type was used as the type of a const generic parameter. + +Erroneous code example: ```compile_fail,E0741 #![feature(const_generics)] @@ -9,12 +10,15 @@ struct A; struct B; // error! ``` -To fix this example, we derive `PartialEq` and `Eq`. +Only structural-match types (that is, types that derive `PartialEq` and `Eq`) +may be used as the types of const generic parameters. + +To fix the previous code example, we derive `PartialEq` and `Eq`: ``` #![feature(const_generics)] -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq)] // We derive both traits here. struct A; struct B; // ok! From 3e48848538a49c66e3447a46346b96e8dc972531 Mon Sep 17 00:00:00 2001 From: Takayuki Nakata Date: Fri, 31 Jul 2020 23:53:05 +0900 Subject: [PATCH 2/6] Some fixes for `plugin.md` in unstable-book - sample codes not working - broken link --- .../src/language-features/plugin.md | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/doc/unstable-book/src/language-features/plugin.md b/src/doc/unstable-book/src/language-features/plugin.md index 1f010656bb854..3835113152762 100644 --- a/src/doc/unstable-book/src/language-features/plugin.md +++ b/src/doc/unstable-book/src/language-features/plugin.md @@ -45,42 +45,40 @@ that warns about any item named `lintme`. extern crate rustc_ast; // Load rustc as a plugin to get macros -#[macro_use] -extern crate rustc; extern crate rustc_driver; +#[macro_use] +extern crate rustc_lint; +#[macro_use] +extern crate rustc_session; -use rustc::lint::{EarlyContext, LintContext, LintPass, EarlyLintPass, - EarlyLintPassObject, LintArray}; use rustc_driver::plugin::Registry; +use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass}; use rustc_ast::ast; - declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'"); -struct Pass; - -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(TEST_LINT) - } -} +declare_lint_pass!(Pass => [TEST_LINT]); impl EarlyLintPass for Pass { fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { - if it.ident.as_str() == "lintme" { - cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"); + if it.ident.name.as_str() == "lintme" { + cx.lint(TEST_LINT, |lint| { + lint.build("item is named 'lintme'").set_span(it.span).emit() + }); } } } #[plugin_registrar] pub fn plugin_registrar(reg: &mut Registry) { - reg.register_early_lint_pass(box Pass as EarlyLintPassObject); + reg.lint_store.register_lints(&[&TEST_LINT]); + reg.lint_store.register_early_pass(|| box Pass); } ``` Then code like ```rust,ignore +#![feature(plugin)] #![plugin(lint_plugin_test)] fn lintme() { } @@ -107,7 +105,7 @@ The components of a lint plugin are: Lint passes are syntax traversals, but they run at a late stage of compilation where type information is available. `rustc`'s [built-in -lints](https://github.com/rust-lang/rust/blob/master/src/librustc/lint/builtin.rs) +lints](https://github.com/rust-lang/rust/blob/master/src/librustc_session/lint/builtin.rs) mostly use the same infrastructure as lint plugins, and provide examples of how to access type information. From 9ade8366c076f1b40d846b5ed76c141d48beb70d Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 31 Jul 2020 16:07:08 -0700 Subject: [PATCH 3/6] Update the WASI libc build to LLVM 10. Among other things, this brings in [the `__main_argc_argv`] patch, which simplifies the interaction between the compiler and WASI libc's startup code, which will help work on reactor support. [the `__main_argc_argv` patch]: https://github.com/llvm/llvm-project/commit/00072c08c75050ae2c835b7bb0e505475dbcd7b9 --- .../host-x86_64/dist-various-2/build-wasi-toolchain.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh b/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh index c82031690ab6a..496639e83db2a 100755 --- a/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh +++ b/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh @@ -4,10 +4,10 @@ set -ex -# Originally from https://releases.llvm.org/9.0.0/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz -curl https://ci-mirrors.rust-lang.org/rustc/clang%2Bllvm-9.0.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz | \ +# Originally from https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz +curl https://ci-mirrors.rust-lang.org/rustc/clang%2Bllvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz | \ tar xJf - -export PATH=`pwd`/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-14.04/bin:$PATH +export PATH=`pwd`/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin:$PATH git clone https://github.com/CraneStation/wasi-libc From 21cab87f08604021bd031b4133287a18b18e359f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 1 Aug 2020 01:41:36 +0200 Subject: [PATCH 4/6] submodules: update cargo from 974eb438d to 2d5c2381e Changes: ```` Use the same index location on nightly as beta relax deprecated diagnostic message check Don't print to raw stderr in test Emit the `test` field in cargo metadata ```` --- src/tools/cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cargo b/src/tools/cargo index 974eb438da8ce..2d5c2381e4e50 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 974eb438da8ced6e3becda2bbf63d9b643eacdeb +Subproject commit 2d5c2381e4e50484bf281fc1bfe19743aa9eb37a From aba0251c78f88b12c499ba956beb8a9734ffdc1a Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 31 Jul 2020 18:40:25 +0200 Subject: [PATCH 5/6] Replace a recursive algorithm with an iterative one and a stack. --- src/librustc_mir/transform/simplify.rs | 69 ++++++++++++++++---------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/src/librustc_mir/transform/simplify.rs b/src/librustc_mir/transform/simplify.rs index 491c37cbe06e8..9288d6e16f5e0 100644 --- a/src/librustc_mir/transform/simplify.rs +++ b/src/librustc_mir/transform/simplify.rs @@ -33,6 +33,7 @@ use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; +use smallvec::SmallVec; use std::borrow::Cow; pub struct SimplifyCfg { @@ -172,9 +173,12 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> { } } - // Collapse a goto chain starting from `start` - fn collapse_goto_chain(&mut self, start: &mut BasicBlock, changed: &mut bool) { - let mut terminator = match self.basic_blocks[*start] { + /// This function will return `None` if + /// * the block has statements + /// * the block has a terminator other than `goto` + /// * the block has no terminator (meaning some other part of the current optimization stole it) + fn take_terminator_if_simple_goto(&mut self, bb: BasicBlock) -> Option> { + match self.basic_blocks[bb] { BasicBlockData { ref statements, terminator: @@ -183,32 +187,45 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> { } if statements.is_empty() => terminator.take(), // if `terminator` is None, this means we are in a loop. In that // case, let all the loop collapse to its entry. - _ => return, - }; - - let target = match terminator { - Some(Terminator { kind: TerminatorKind::Goto { ref mut target }, .. }) => { - self.collapse_goto_chain(target, changed); - *target - } - _ => unreachable!(), - }; - self.basic_blocks[*start].terminator = terminator; - - debug!("collapsing goto chain from {:?} to {:?}", *start, target); - - *changed |= *start != target; + _ => None, + } + } - if self.pred_count[*start] == 1 { - // This is the last reference to *start, so the pred-count to - // to target is moved into the current block. - self.pred_count[*start] = 0; - } else { - self.pred_count[target] += 1; - self.pred_count[*start] -= 1; + /// Collapse a goto chain starting from `start` + fn collapse_goto_chain(&mut self, start: &mut BasicBlock, changed: &mut bool) { + // Using `SmallVec` here, because in some logs on libcore oli-obk saw many single-element + // goto chains. We should probably benchmark different sizes. + let mut terminators: SmallVec<[_; 1]> = Default::default(); + let mut current = *start; + while let Some(terminator) = self.take_terminator_if_simple_goto(current) { + let target = match terminator { + Terminator { kind: TerminatorKind::Goto { target }, .. } => target, + _ => unreachable!(), + }; + terminators.push((current, terminator)); + current = target; } + let last = current; + *start = last; + while let Some((current, mut terminator)) = terminators.pop() { + let target = match terminator { + Terminator { kind: TerminatorKind::Goto { ref mut target }, .. } => target, + _ => unreachable!(), + }; + *target = last; + debug!("collapsing goto chain from {:?} to {:?}", current, target); - *start = target; + if self.pred_count[current] == 1 { + // This is the last reference to current, so the pred-count to + // to target is moved into the current block. + self.pred_count[current] = 0; + } else { + self.pred_count[*target] += 1; + self.pred_count[current] -= 1; + } + *changed = true; + self.basic_blocks[current].terminator = Some(terminator); + } } // merge a block with 1 `goto` predecessor to its parent From 4bd313fb0fd3436058c10c95958f3eb80125a2a3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 1 Aug 2020 15:19:00 +0200 Subject: [PATCH 6/6] Clean up E0743 explanation --- src/librustc_error_codes/error_codes/E0743.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0743.md b/src/librustc_error_codes/error_codes/E0743.md index 1780fe59cbd69..ddd3136df0c39 100644 --- a/src/librustc_error_codes/error_codes/E0743.md +++ b/src/librustc_error_codes/error_codes/E0743.md @@ -8,10 +8,9 @@ Erroneous code example: fn foo2(x: u8, y: &...) {} // error! ``` -Only foreign functions can use the C-variadic type (`...`). -In such functions, `...` may only occur non-nested. -That is, `y: &'a ...` is not allowed. +Only foreign functions can use the C-variadic type (`...`). In such functions, +`...` may only occur non-nested. That is, `y: &'a ...` is not allowed. -A C-variadic type is used to give an undefined number -of parameters to a given function (like `printf` in C). -The equivalent in Rust would be to use macros directly. +A C-variadic type is used to give an undefined number of parameters to a given +function (like `printf` in C). The equivalent in Rust would be to use macros +directly (like `println!` for example).