From 6c7c5120200b711262f1c67f1924ae0835080286 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 13 Dec 2019 14:00:47 -0800 Subject: [PATCH 01/10] Fix the configure.py TOML field for a couple LLVM options The actual fields in `config.toml.example` have dashes, not underscores. --- src/bootstrap/configure.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index bb6041d7f3196..7cfc5385e2104 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -59,13 +59,13 @@ def v(*args): o("lld", "rust.lld", "build lld") o("lldb", "rust.lldb", "build lldb") o("missing-tools", "dist.missing-tools", "allow failures when building tools") -o("use-libcxx", "llvm.use_libcxx", "build LLVM with libc++") +o("use-libcxx", "llvm.use-libcxx", "build LLVM with libc++") o("cflags", "llvm.cflags", "build LLVM with these extra compiler flags") o("cxxflags", "llvm.cxxflags", "build LLVM with these extra compiler flags") o("ldflags", "llvm.ldflags", "build LLVM with these extra linker flags") -o("llvm-libunwind", "rust.llvm_libunwind", "use LLVM libunwind") +o("llvm-libunwind", "rust.llvm-libunwind", "use LLVM libunwind") # Optimization and debugging options. These may be overridden by the release # channel, etc. From 3594d8b8a14d48c8aec90a2e702cf312ea2d7f02 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 15 Dec 2019 12:47:40 +0000 Subject: [PATCH 02/10] make htons const fn --- src/libstd/net/addr.rs | 14 +++++++------- src/libstd/net/mod.rs | 19 ++++--------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index d5f4ece726bea..a9d88370c612f 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -4,7 +4,7 @@ use crate::hash; use crate::io; use crate::iter; use crate::mem; -use crate::net::{hton, ntoh, IpAddr, Ipv4Addr, Ipv6Addr}; +use crate::net::{htons, ntohs, IpAddr, Ipv4Addr, Ipv6Addr}; use crate::option; use crate::slice; use crate::sys::net::netc as c; @@ -276,7 +276,7 @@ impl SocketAddrV4 { SocketAddrV4 { inner: c::sockaddr_in { sin_family: c::AF_INET as c::sa_family_t, - sin_port: hton(port), + sin_port: htons(port), sin_addr: *ip.as_inner(), ..unsafe { mem::zeroed() } }, @@ -326,7 +326,7 @@ impl SocketAddrV4 { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn port(&self) -> u16 { - ntoh(self.inner.sin_port) + ntohs(self.inner.sin_port) } /// Changes the port number associated with this socket address. @@ -342,7 +342,7 @@ impl SocketAddrV4 { /// ``` #[stable(feature = "sockaddr_setters", since = "1.9.0")] pub fn set_port(&mut self, new_port: u16) { - self.inner.sin_port = hton(new_port); + self.inner.sin_port = htons(new_port); } } @@ -368,7 +368,7 @@ impl SocketAddrV6 { SocketAddrV6 { inner: c::sockaddr_in6 { sin6_family: c::AF_INET6 as c::sa_family_t, - sin6_port: hton(port), + sin6_port: htons(port), sin6_addr: *ip.as_inner(), sin6_flowinfo: flowinfo, sin6_scope_id: scope_id, @@ -420,7 +420,7 @@ impl SocketAddrV6 { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn port(&self) -> u16 { - ntoh(self.inner.sin6_port) + ntohs(self.inner.sin6_port) } /// Changes the port number associated with this socket address. @@ -436,7 +436,7 @@ impl SocketAddrV6 { /// ``` #[stable(feature = "sockaddr_setters", since = "1.9.0")] pub fn set_port(&mut self, new_port: u16) { - self.inner.sin6_port = hton(new_port); + self.inner.sin6_port = htons(new_port); } /// Returns the flow information associated with this address. diff --git a/src/libstd/net/mod.rs b/src/libstd/net/mod.rs index b68146939fdcc..8652ed8b046bb 100644 --- a/src/libstd/net/mod.rs +++ b/src/libstd/net/mod.rs @@ -85,21 +85,10 @@ pub enum Shutdown { Both, } -#[doc(hidden)] -trait NetInt { - fn from_be(i: Self) -> Self; - fn to_be(&self) -> Self; -} -macro_rules! doit { - ($($t:ident)*) => ($(impl NetInt for $t { - fn from_be(i: Self) -> Self { <$t>::from_be(i) } - fn to_be(&self) -> Self { <$t>::to_be(*self) } - })*) -} -doit! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize } - -fn hton(i: I) -> I { i.to_be() } -fn ntoh(i: I) -> I { I::from_be(i) } +#[inline] +const fn htons(i: u16) -> u16 { i.to_be() } +#[inline] +const fn ntohs(i: u16) -> u16 { u16::from_be(i) } fn each_addr(addr: A, mut f: F) -> io::Result where F: FnMut(io::Result<&SocketAddr>) -> io::Result From 6ad0b55597d58f65b775cc32588d5cb396993c0c Mon Sep 17 00:00:00 2001 From: Robin Kruppe Date: Sun, 15 Dec 2019 18:17:00 +0100 Subject: [PATCH 03/10] Remove now-redundant range check on u128 -> f32 casts This code was added to avoid UB in LLVM 6 and earlier, but we no longer support those LLVM versions. Since https://reviews.llvm.org/D47807 (released in LLVM 7), uitofp does exactly what we need. Closes #51872 --- src/librustc_codegen_ssa/mir/rvalue.rs | 43 +++++--------------------- 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index 488ae8dbf9036..55d63f18cd906 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -341,6 +341,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { llval } } + (CastTy::Int(_), CastTy::Float) => { + if signed { + bx.sitofp(llval, ll_t_out) + } else { + bx.uitofp(llval, ll_t_out) + } + } (CastTy::Ptr(_), CastTy::Ptr(_)) | (CastTy::FnPtr, CastTy::Ptr(_)) | (CastTy::RPtr(_), CastTy::Ptr(_)) => @@ -352,8 +359,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let usize_llval = bx.intcast(llval, bx.cx().type_isize(), signed); bx.inttoptr(usize_llval, ll_t_out) } - (CastTy::Int(_), CastTy::Float) => - cast_int_to_float(&mut bx, signed, llval, ll_t_in, ll_t_out), (CastTy::Float, CastTy::Int(IntTy::I)) => cast_float_to_int(&mut bx, true, llval, ll_t_in, ll_t_out), (CastTy::Float, CastTy::Int(_)) => @@ -720,40 +725,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } -fn cast_int_to_float<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( - bx: &mut Bx, - signed: bool, - x: Bx::Value, - int_ty: Bx::Type, - float_ty: Bx::Type -) -> Bx::Value { - // Most integer types, even i128, fit into [-f32::MAX, f32::MAX] after rounding. - // It's only u128 -> f32 that can cause overflows (i.e., should yield infinity). - // LLVM's uitofp produces undef in those cases, so we manually check for that case. - let is_u128_to_f32 = !signed && - bx.cx().int_width(int_ty) == 128 && - bx.cx().float_width(float_ty) == 32; - if is_u128_to_f32 { - // All inputs greater or equal to (f32::MAX + 0.5 ULP) are rounded to infinity, - // and for everything else LLVM's uitofp works just fine. - use rustc_apfloat::ieee::Single; - const MAX_F32_PLUS_HALF_ULP: u128 = ((1 << (Single::PRECISION + 1)) - 1) - << (Single::MAX_EXP - Single::PRECISION as i16); - let max = bx.cx().const_uint_big(int_ty, MAX_F32_PLUS_HALF_ULP); - let overflow = bx.icmp(IntPredicate::IntUGE, x, max); - let infinity_bits = bx.cx().const_u32(ieee::Single::INFINITY.to_bits() as u32); - let infinity = bx.bitcast(infinity_bits, float_ty); - let fp = bx.uitofp(x, float_ty); - bx.select(overflow, infinity, fp) - } else { - if signed { - bx.sitofp(x, float_ty) - } else { - bx.uitofp(x, float_ty) - } - } -} - fn cast_float_to_int<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, signed: bool, From f365dbc869be1e9990aaa1611daea0a4336fef49 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 16 Dec 2019 08:52:50 -0500 Subject: [PATCH 04/10] Set release channel on non-dist builders Toolstate publication only runs if the channel is "nightly" and previously the toolstate builders did not know that the channel was nightly (since they are not dist builders). A look through bootstrap seems to indicate that nothing should directly depend on the channel being set to `-dev` on the test builders, though this may cause some problems with UI tests (if for some reason they're dumping the channel into stderr), but we cannot find evidence of such so hopefully this is fine. --- src/ci/run.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ci/run.sh b/src/ci/run.sh index 38d1d2baf2507..73c3a964f5396 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -44,8 +44,13 @@ fi # FIXME: need a scheme for changing this `nightly` value to `beta` and `stable` # either automatically or manually. export RUST_RELEASE_CHANNEL=nightly + +# Always set the release channel for bootstrap; this is normally not important (i.e., only dist +# builds would seem to matter) but in practice bootstrap wants to know whether we're targeting +# master, beta, or stable with a build to determine whether to run some checks (notably toolstate). +RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL" + if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then - RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.remap-debuginfo" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --debuginfo-level-std=1" From dd7593b8ce4eaf386c1aefdd01cebc32441e9019 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Tue, 29 Oct 2019 08:33:11 -0700 Subject: [PATCH 05/10] Add individual crates to rustfmt ignore list. Co-Authored-By: Mark Rousskov --- rustfmt.toml | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/rustfmt.toml b/rustfmt.toml index df230cde9b713..a25324273f274 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -4,3 +4,86 @@ # be picked up automatically). version = "Two" use_small_heuristics = "Max" + +# by default we ignore everything in the repository +# tidy only checks files which are not ignored, each entry follows gitignore style +ignore = [ + # remove directories below, or opt out their subdirectories, as they are formatted + "src/bootstrap/", + "src/build_helper/", + "src/liballoc/", + "src/libarena/", + "src/libcore/", + "src/libfmt_macros/", + "src/libgraphviz/", + "src/libpanic_abort/", + "src/libpanic_unwind/", + "src/libproc_macro/", + "src/libprofiler_builtins/", + "src/librustc/", + "src/librustc_apfloat/", + "src/librustc_asan/", + "src/librustc_codegen_llvm/", + "src/librustc_codegen_ssa/", + "src/librustc_codegen_utils/", + "src/librustc_data_structures/", + "src/librustc_driver/", + "src/librustc_errors/", + "src/librustc_fs_util/", + "src/librustc_feature/", + "src/librustc_incremental/", + "src/librustc_index/", + "src/librustc_interface/", + "src/librustc_lexer/", + "src/librustc_lint/", + "src/librustc_llvm/", + "src/librustc_lsan/", + "src/librustc_macros/", + "src/librustc_metadata/", + "src/librustc_mir/", + "src/librustc_msan/", + "src/librustc_parse/", + "src/librustc_passes/", + "src/librustc_plugin/", + "src/librustc_plugin_impl/", + "src/librustc_privacy/", + "src/librustc_resolve/", + "src/librustc_save_analysis/", + "src/librustc_session/", + "src/librustc_target/", + "src/librustc_traits/", + "src/librustc_tsan/", + "src/librustc_typeck/", + "src/librustdoc/", + "src/libserialize/", + "src/libstd/", + "src/libsyntax/", + "src/libsyntax_expand/", + "src/libsyntax_ext/", + "src/libsyntax_pos/", + "src/libterm/", + "src/libtest/", + "src/libunwind/", + "src/rtstartup/", + "src/rustc/", + "src/rustllvm/", + "src/test/", + "src/tools/", + + # do not format submodules + "src/doc/book", + "src/doc/edition-guide", + "src/doc/embedded-book", + "src/doc/nomicon", + "src/doc/reference", + "src/doc/rust-by-example", + "src/doc/rustc-guide", + "src/llvm-project", + "src/stdarch", + "src/tools/cargo", + "src/tools/clippy", + "src/tools/miri", + "src/tools/rls", + "src/tools/rust-installer", + "src/tools/rustfmt", +] From cf0e6aa8f607aca43b832b4940281b945fdbaa03 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Tue, 29 Oct 2019 19:43:37 -0700 Subject: [PATCH 06/10] bootstrap.py fetches rustfmt. Co-Authored-By: Mark Rousskov --- src/bootstrap/bootstrap.py | 45 ++++++++++++++++++++++++++++++--- src/bootstrap/bootstrap_test.py | 4 +-- src/stage0.txt | 5 ++++ 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index bb169414886de..6737086f6e5b0 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -322,6 +322,7 @@ def __init__(self): self.date = '' self._download_url = '' self.rustc_channel = '' + self.rustfmt_channel = '' self.build = '' self.build_dir = os.path.join(os.getcwd(), "build") self.clean = False @@ -344,6 +345,7 @@ def download_stage0(self): """ rustc_channel = self.rustc_channel cargo_channel = self.cargo_channel + rustfmt_channel = self.rustfmt_channel def support_xz(): try: @@ -393,13 +395,29 @@ def support_xz(): with output(self.cargo_stamp()) as cargo_stamp: cargo_stamp.write(self.date) - def _download_stage0_helper(self, filename, pattern, tarball_suffix): + if self.rustfmt() and self.rustfmt().startswith(self.bin_root()) and ( + not os.path.exists(self.rustfmt()) + or self.program_out_of_date(self.rustfmt_stamp()) + ): + if rustfmt_channel: + tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz' + [channel, date] = rustfmt_channel.split('-', 1) + filename = "rustfmt-{}-{}{}".format(channel, self.build, tarball_suffix) + self._download_stage0_helper(filename, "rustfmt-preview", tarball_suffix, date) + self.fix_executable("{}/bin/rustfmt".format(self.bin_root())) + self.fix_executable("{}/bin/cargo-fmt".format(self.bin_root())) + with output(self.rustfmt_stamp()) as rustfmt_stamp: + rustfmt_stamp.write(self.date) + + def _download_stage0_helper(self, filename, pattern, tarball_suffix, date=None): + if date is None: + date = self.date cache_dst = os.path.join(self.build_dir, "cache") - rustc_cache = os.path.join(cache_dst, self.date) + rustc_cache = os.path.join(cache_dst, date) if not os.path.exists(rustc_cache): os.makedirs(rustc_cache) - url = "{}/dist/{}".format(self._download_url, self.date) + url = "{}/dist/{}".format(self._download_url, date) tarball = os.path.join(rustc_cache, filename) if not os.path.exists(tarball): get("{}/{}".format(url, filename), tarball, verbose=self.verbose) @@ -493,6 +511,16 @@ def cargo_stamp(self): """ return os.path.join(self.bin_root(), '.cargo-stamp') + def rustfmt_stamp(self): + """Return the path for .rustfmt-stamp + + >>> rb = RustBuild() + >>> rb.build_dir = "build" + >>> rb.rustfmt_stamp() == os.path.join("build", "stage0", ".rustfmt-stamp") + True + """ + return os.path.join(self.bin_root(), '.rustfmt-stamp') + def program_out_of_date(self, stamp_path): """Check if the given program stamp is out of date""" if not os.path.exists(stamp_path) or self.clean: @@ -565,6 +593,12 @@ def rustc(self): """Return config path for rustc""" return self.program_config('rustc') + def rustfmt(self): + """Return config path for rustfmt""" + if not self.rustfmt_channel: + return None + return self.program_config('rustfmt') + def program_config(self, program): """Return config path for the given program @@ -868,6 +902,9 @@ def bootstrap(help_triggered): build.rustc_channel = data['rustc'] build.cargo_channel = data['cargo'] + if "rustfmt" in data: + build.rustfmt_channel = data['rustfmt'] + if 'dev' in data: build.set_dev_environment() else: @@ -895,6 +932,8 @@ def bootstrap(help_triggered): env["RUSTC_BOOTSTRAP"] = '1' env["CARGO"] = build.cargo() env["RUSTC"] = build.rustc() + if build.rustfmt(): + env["RUSTFMT"] = build.rustfmt() run(args, env=env, verbose=build.verbose) diff --git a/src/bootstrap/bootstrap_test.py b/src/bootstrap/bootstrap_test.py index 689298f32d03c..0e941e1367668 100644 --- a/src/bootstrap/bootstrap_test.py +++ b/src/bootstrap/bootstrap_test.py @@ -20,14 +20,14 @@ def setUp(self): os.mkdir(os.path.join(self.rust_root, "src")) with open(os.path.join(self.rust_root, "src", "stage0.txt"), "w") as stage0: - stage0.write("#ignore\n\ndate: 2017-06-15\nrustc: beta\ncargo: beta") + stage0.write("#ignore\n\ndate: 2017-06-15\nrustc: beta\ncargo: beta\nrustfmt: beta") def tearDown(self): rmtree(self.rust_root) def test_stage0_data(self): """Extract data from stage0.txt""" - expected = {"date": "2017-06-15", "rustc": "beta", "cargo": "beta"} + expected = {"date": "2017-06-15", "rustc": "beta", "cargo": "beta", "rustfmt": "beta"} data = bootstrap.stage0_data(self.rust_root) self.assertDictEqual(data, expected) diff --git a/src/stage0.txt b/src/stage0.txt index 3c84890158381..ce132d619718b 100644 --- a/src/stage0.txt +++ b/src/stage0.txt @@ -16,6 +16,11 @@ date: 2019-11-06 rustc: beta cargo: beta +# We use a nightly rustfmt to format the source because it solves some bootstrapping +# issues with use of new syntax in this repo. If you're looking at the beta/stable branch, this key should be omitted, +# as we don't want to depend on rustfmt from nightly there. +rustfmt: nightly-2019-11-05 + # When making a stable release the process currently looks like: # # 1. Produce stable build, upload it to dev-static From dd65f8c32c23b9aa70c73b425835372037ec4633 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Wed, 30 Oct 2019 16:56:27 -0700 Subject: [PATCH 07/10] Implement `./x.py fmt [--check]`. --- src/bootstrap/builder.rs | 5 +++-- src/bootstrap/config.rs | 11 +++++++++-- src/bootstrap/flags.rs | 26 +++++++++++++++++++++++++- src/bootstrap/format.rs | 28 ++++++++++++++++++++++++++++ src/bootstrap/lib.rs | 5 +++++ 5 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 src/bootstrap/format.rs diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 8b0ad169cfc25..598b8001372ff 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -321,6 +321,7 @@ pub enum Kind { Check, Clippy, Fix, + Format, Test, Bench, Dist, @@ -360,7 +361,7 @@ impl<'a> Builder<'a> { tool::Miri, native::Lld ), - Kind::Check | Kind::Clippy | Kind::Fix => describe!( + Kind::Check | Kind::Clippy | Kind::Fix | Kind::Format => describe!( check::Std, check::Rustc, check::Rustdoc @@ -524,7 +525,7 @@ impl<'a> Builder<'a> { Subcommand::Bench { ref paths, .. } => (Kind::Bench, &paths[..]), Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]), Subcommand::Install { ref paths } => (Kind::Install, &paths[..]), - Subcommand::Clean { .. } => panic!(), + Subcommand::Format { .. } | Subcommand::Clean { .. } => panic!(), }; let builder = Builder { diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 5f2ef01bd5c45..3e67734e69078 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -5,6 +5,7 @@ use std::collections::{HashMap, HashSet}; use std::env; +use std::ffi::OsString; use std::fs; use std::path::{Path, PathBuf}; use std::process; @@ -149,6 +150,7 @@ pub struct Config { // These are either the stage0 downloaded binaries or the locally installed ones. pub initial_cargo: PathBuf, pub initial_rustc: PathBuf, + pub initial_rustfmt: Option, pub out: PathBuf, } @@ -348,12 +350,16 @@ struct TomlTarget { impl Config { fn path_from_python(var_key: &str) -> PathBuf { match env::var_os(var_key) { - // Do not trust paths from Python and normalize them slightly (#49785). - Some(var_val) => Path::new(&var_val).components().collect(), + Some(var_val) => Self::normalize_python_path(var_val), _ => panic!("expected '{}' to be set", var_key), } } + /// Normalizes paths from Python slightly. We don't trust paths from Python (#49785). + fn normalize_python_path(path: OsString) -> PathBuf { + Path::new(&path).components().collect() + } + pub fn default_opts() -> Config { let mut config = Config::default(); config.llvm_optimize = true; @@ -380,6 +386,7 @@ impl Config { config.initial_rustc = Config::path_from_python("RUSTC"); config.initial_cargo = Config::path_from_python("CARGO"); + config.initial_rustfmt = env::var_os("RUSTFMT").map(Config::normalize_python_path); config } diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index 7b49cc0a9298c..b98e2c1bf2466 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -53,6 +53,9 @@ pub enum Subcommand { Fix { paths: Vec, }, + Format { + check: bool, + }, Doc { paths: Vec, }, @@ -102,6 +105,7 @@ Subcommands: check Compile either the compiler or libraries, using cargo check clippy Run clippy fix Run cargo fix + fmt Run rustfmt test Build and run some test suites bench Build and run some benchmarks doc Build documentation @@ -160,6 +164,7 @@ To learn more about a subcommand, run `./x.py -h`" || (s == "check") || (s == "clippy") || (s == "fix") + || (s == "fmt") || (s == "test") || (s == "bench") || (s == "doc") @@ -222,6 +227,9 @@ To learn more about a subcommand, run `./x.py -h`" "clean" => { opts.optflag("", "all", "clean all build artifacts"); } + "fmt" => { + opts.optflag("", "check", "check formatting instead of applying."); + } _ => {} }; @@ -323,6 +331,17 @@ Arguments: ./x.py fix src/libcore src/libproc_macro", ); } + "fmt" => { + subcommand_help.push_str( + "\n +Arguments: + This subcommand optionally accepts a `--check` flag which succeeds if formatting is correct and + fails if it is not. For example: + + ./x.py fmt + ./x.py fmt --check", + ); + } "test" => { subcommand_help.push_str( "\n @@ -388,7 +407,7 @@ Arguments: let maybe_rules_help = Builder::get_help(&build, subcommand.as_str()); extra_help.push_str(maybe_rules_help.unwrap_or_default().as_str()); - } else if subcommand.as_str() != "clean" { + } else if !(subcommand.as_str() == "clean" || subcommand.as_str() == "fmt") { extra_help.push_str( format!( "Run `./x.py {} -h -v` to see a list of available paths.", @@ -439,6 +458,11 @@ Arguments: all: matches.opt_present("all"), } } + "fmt" => { + Subcommand::Format { + check: matches.opt_present("check"), + } + } "dist" => Subcommand::Dist { paths }, "install" => Subcommand::Install { paths }, _ => { diff --git a/src/bootstrap/format.rs b/src/bootstrap/format.rs new file mode 100644 index 0000000000000..0c542594effeb --- /dev/null +++ b/src/bootstrap/format.rs @@ -0,0 +1,28 @@ +//! Runs rustfmt on the repository. + +use crate::{util, Build}; +use std::process::Command; + +pub fn format(build: &Build, check: bool) { + let target = &build.build; + let rustfmt_path = build.config.initial_rustfmt.as_ref().unwrap_or_else(|| { + eprintln!("./x.py fmt is not supported on this channel"); + std::process::exit(1); + }).clone(); + let cargo_fmt_path = rustfmt_path.with_file_name(util::exe("cargo-fmt", &target)); + assert!(cargo_fmt_path.is_file(), "{} not a file", cargo_fmt_path.display()); + + let mut cmd = Command::new(&cargo_fmt_path); + // cargo-fmt calls rustfmt as a bare command, so we need it to only find the correct one + cmd.env("PATH", cargo_fmt_path.parent().unwrap()); + cmd.current_dir(&build.src); + cmd.arg("fmt"); + + if check { + cmd.arg("--"); + cmd.arg("--check"); + } + + let status = cmd.status().expect("executing cargo-fmt"); + assert!(status.success(), "cargo-fmt errored with status {:?}", status); +} diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 080bef6853a20..ff9a55afa2957 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -147,6 +147,7 @@ mod builder; mod cache; mod tool; mod toolstate; +mod format; #[cfg(windows)] mod job; @@ -421,6 +422,10 @@ impl Build { job::setup(self); } + if let Subcommand::Format { check } = self.config.cmd { + return format::format(self, check); + } + if let Subcommand::Clean { all } = self.config.cmd { return clean::clean(self, all); } From 72a90b1a33d0d177a89f4c1f5661b9f34dbc2b6e Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Mon, 4 Nov 2019 08:28:40 -0800 Subject: [PATCH 08/10] Format src/librustc_fs_util. In total it's about 100 lines of code and has received less than 5 commits in 2019 -- a good starting point. --- rustfmt.toml | 1 - src/librustc_fs_util/lib.rs | 37 +++++++++++++++++-------------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index a25324273f274..bb656891446a2 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -29,7 +29,6 @@ ignore = [ "src/librustc_data_structures/", "src/librustc_driver/", "src/librustc_errors/", - "src/librustc_fs_util/", "src/librustc_feature/", "src/librustc_incremental/", "src/librustc_index/", diff --git a/src/librustc_fs_util/lib.rs b/src/librustc_fs_util/lib.rs index eaf08d76b9905..289b9f30c3bbb 100644 --- a/src/librustc_fs_util/lib.rs +++ b/src/librustc_fs_util/lib.rs @@ -1,7 +1,7 @@ -use std::path::{Path, PathBuf}; use std::ffi::CString; use std::fs; use std::io; +use std::path::{Path, PathBuf}; // Unfortunately, on windows, it looks like msvcrt.dll is silently translating // verbatim paths under the hood to non-verbatim paths! This manifests itself as @@ -21,8 +21,8 @@ use std::io; // https://github.com/rust-lang/rust/issues/25505#issuecomment-102876737 #[cfg(windows)] pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf { - use std::path; use std::ffi::OsString; + use std::path; let mut components = p.components(); let prefix = match components.next() { Some(path::Component::Prefix(p)) => p, @@ -68,12 +68,10 @@ pub fn link_or_copy, Q: AsRef>(p: P, q: Q) -> io::Result
  • Ok(LinkOrCopy::Link), - Err(_) => { - match fs::copy(p, q) { - Ok(_) => Ok(LinkOrCopy::Copy), - Err(e) => Err(e), - } - } + Err(_) => match fs::copy(p, q) { + Ok(_) => Ok(LinkOrCopy::Copy), + Err(e) => Err(e), + }, } } @@ -86,29 +84,28 @@ pub enum RenameOrCopyRemove { /// Rename `p` into `q`, preferring to use `rename` if possible. /// If `rename` fails (rename may fail for reasons such as crossing /// filesystem), fallback to copy & remove -pub fn rename_or_copy_remove, Q: AsRef>(p: P, - q: Q) - -> io::Result { +pub fn rename_or_copy_remove, Q: AsRef>( + p: P, + q: Q, +) -> io::Result { let p = p.as_ref(); let q = q.as_ref(); match fs::rename(p, q) { Ok(()) => Ok(RenameOrCopyRemove::Rename), - Err(_) => { - match fs::copy(p, q) { - Ok(_) => { - fs::remove_file(p)?; - Ok(RenameOrCopyRemove::CopyRemove) - } - Err(e) => Err(e), + Err(_) => match fs::copy(p, q) { + Ok(_) => { + fs::remove_file(p)?; + Ok(RenameOrCopyRemove::CopyRemove) } - } + Err(e) => Err(e), + }, } } #[cfg(unix)] pub fn path_to_c_string(p: &Path) -> CString { - use std::os::unix::ffi::OsStrExt; use std::ffi::OsStr; + use std::os::unix::ffi::OsStrExt; let p: &OsStr = p.as_ref(); CString::new(p.as_bytes()).unwrap() } From f93af13b44cbadadf1411f3a6c1e9b0ca7c35a19 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Wed, 30 Oct 2019 19:23:50 -0700 Subject: [PATCH 09/10] Include formatting check in the test step for tidy. --- src/bootstrap/test.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index f3b2a73d3c5dc..17aea17e69e0b 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -779,6 +779,9 @@ impl Step for Tidy { /// This tool in `src/tools` checks up on various bits and pieces of style and /// otherwise just implements a few lint-like checks that are specific to the /// compiler itself. + /// + /// Once tidy passes, this step also runs `fmt --check` if tests are being run + /// for the `dev` or `nightly` channels. fn run(self, builder: &Builder<'_>) { let mut cmd = builder.tool_cmd(Tool::Tidy); cmd.arg(builder.src.join("src")); @@ -792,6 +795,11 @@ impl Step for Tidy { builder.info("tidy check"); try_run(builder, &mut cmd); + + if builder.config.channel == "dev" || builder.config.channel == "nightly" { + builder.info("fmt check"); + crate::format::format(&builder.build, true); + } } fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { From 7f00a5f26a4687c0c667d2ca02cb73eef677ae2e Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 17 Dec 2019 16:28:33 -0500 Subject: [PATCH 10/10] Revert "Auto merge of #67362 - Mark-Simulacrum:par-4-default, r=alexcrichton" This reverts commit 3ed3b8bb7b100afecf7d5f52eafbb70fec27f537, reversing changes made to 99b89533d4cdf7682ea4054ad0ee36c351d05df1. We will reland a similar patch at a future date but for now we should get a nightly released in a few hours with the parallel patch, so this should be reverted to make sure that the next nightly is not parallel-enabled. --- src/bootstrap/test.rs | 26 +++++++++---------- src/ci/run.sh | 5 ++-- src/librustc/dep_graph/graph.rs | 14 +++++----- src/librustc_data_structures/lib.rs | 1 - src/librustc_data_structures/sync.rs | 4 +-- src/librustc_session/config.rs | 10 +++---- src/librustc_session/session.rs | 6 ++--- src/test/ui/traits/cycle-cache-err-60010.rs | 2 +- .../ui/traits/cycle-cache-err-60010.stderr | 18 ++++++++++++- 9 files changed, 50 insertions(+), 36 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index c086bf2cf402a..f3b2a73d3c5dc 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -4,10 +4,10 @@ //! our CI. use std::env; -//use std::ffi::OsString; +use std::ffi::OsString; use std::fmt; use std::fs; -//use std::iter; +use std::iter; use std::path::{Path, PathBuf}; use std::process::Command; @@ -204,8 +204,8 @@ impl Step for Cargo { } /// Runs `cargo test` for `cargo` packaged with Rust. - fn run(self, _builder: &Builder<'_>) { - /*let compiler = builder.compiler(self.stage, self.host); + fn run(self, builder: &Builder<'_>) { + let compiler = builder.compiler(self.stage, self.host); builder.ensure(tool::Cargo { compiler, @@ -235,7 +235,7 @@ impl Step for Cargo { cargo.env("PATH", &path_for_cargo(builder, compiler)); - try_run(builder, &mut cargo.into());*/ + try_run(builder, &mut cargo.into()); } } @@ -590,14 +590,14 @@ impl Step for Clippy { } } -//fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString { -// // Configure PATH to find the right rustc. NB. we have to use PATH -// // and not RUSTC because the Cargo test suite has tests that will -// // fail if rustc is not spelled `rustc`. -// let path = builder.sysroot(compiler).join("bin"); -// let old_path = env::var_os("PATH").unwrap_or_default(); -// env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("") -//} +fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString { + // Configure PATH to find the right rustc. NB. we have to use PATH + // and not RUSTC because the Cargo test suite has tests that will + // fail if rustc is not spelled `rustc`. + let path = builder.sysroot(compiler).join("bin"); + let old_path = env::var_os("PATH").unwrap_or_default(); + env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("") +} #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct RustdocTheme { diff --git a/src/ci/run.sh b/src/ci/run.sh index 4afd61bf8a7ba..38d1d2baf2507 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -37,8 +37,6 @@ if [ "$DIST_SRC" = "" ]; then RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-dist-src" fi -RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.parallel-compiler" - # If we're deploying artifacts then we set the release channel, otherwise if # we're not deploying then we want to be sure to enable all assertions because # we'll be running tests @@ -55,6 +53,9 @@ if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions" elif [ "$DEPLOY_ALT" != "" ]; then + if [ "$NO_PARALLEL_COMPILER" = "" ]; then + RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.parallel-compiler" + fi RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-assertions" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.verify-llvm-ir" fi diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs index aa7f4f2155dd1..d952bf7ab9e25 100644 --- a/src/librustc/dep_graph/graph.rs +++ b/src/librustc/dep_graph/graph.rs @@ -3,7 +3,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_index::vec::{Idx, IndexVec}; use smallvec::SmallVec; -use rustc_data_structures::sync::{Lrc, Lock, AtomicU32, AtomicUsize, Ordering}; +use rustc_data_structures::sync::{Lrc, Lock, AtomicU32, AtomicU64, Ordering}; use rustc_data_structures::sharded::{self, Sharded}; use std::sync::atomic::Ordering::SeqCst; use std::env; @@ -485,8 +485,8 @@ impl DepGraph { if cfg!(debug_assertions) { let current_dep_graph = &self.data.as_ref().unwrap().current; - Some((current_dep_graph.total_read_count.load(SeqCst) as u64, - current_dep_graph.total_duplicate_read_count.load(SeqCst) as u64)) + Some((current_dep_graph.total_read_count.load(SeqCst), + current_dep_graph.total_duplicate_read_count.load(SeqCst))) } else { None } @@ -970,8 +970,8 @@ pub(super) struct CurrentDepGraph { /// These are simple counters that are for profiling and /// debugging and only active with `debug_assertions`. - total_read_count: AtomicUsize, - total_duplicate_read_count: AtomicUsize, + total_read_count: AtomicU64, + total_duplicate_read_count: AtomicU64, } impl CurrentDepGraph { @@ -1012,8 +1012,8 @@ impl CurrentDepGraph { )), anon_id_seed: stable_hasher.finish(), forbidden_edge, - total_read_count: AtomicUsize::new(0), - total_duplicate_read_count: AtomicUsize::new(0), + total_read_count: AtomicU64::new(0), + total_duplicate_read_count: AtomicU64::new(0), } } diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 02611a36aaebc..fb541637e5f79 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -24,7 +24,6 @@ #![feature(integer_atomics)] #![feature(test)] #![feature(associated_type_bounds)] -#![feature(cfg_target_has_atomic)] #![cfg_attr(unix, feature(libc))] diff --git a/src/librustc_data_structures/sync.rs b/src/librustc_data_structures/sync.rs index c4aed0628ba42..6a19f52897e5d 100644 --- a/src/librustc_data_structures/sync.rs +++ b/src/librustc_data_structures/sync.rs @@ -317,9 +317,7 @@ cfg_if! { pub use parking_lot::MutexGuard as LockGuard; pub use parking_lot::MappedMutexGuard as MappedLockGuard; - pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32}; - #[cfg(target_has_atomic = "64")] - pub use std::sync::atomic::{AtomicU64}; + pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32, AtomicU64}; pub use crossbeam_utils::atomic::AtomicCell; diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs index 359c8b3e73a90..7f3bab8f23299 100644 --- a/src/librustc_session/config.rs +++ b/src/librustc_session/config.rs @@ -1358,11 +1358,11 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "prints the LLVM optimization passes being run"), ast_json: bool = (false, parse_bool, [UNTRACKED], "print the AST as JSON and halt"), - // We default to min(4, vCPUs) here since we want to avoid spawning *too* - // many threads -- that causes scalability issues due to contention on - // the jobserver pipe (at least) -- but 4 is a reasonable amount on systems - // with lots of cores. - threads: usize = (std::cmp::min(::num_cpus::get(), 4), parse_threads, [UNTRACKED], + // We default to 1 here since we want to behave like + // a sequential compiler for now. This'll likely be adjusted + // in the future. Note that -Zthreads=0 is the way to get + // the num_cpus behavior. + threads: usize = (1, parse_threads, [UNTRACKED], "use a thread pool with N threads"), ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED], "print the pre-expansion AST as JSON and halt"), diff --git a/src/librustc_session/session.rs b/src/librustc_session/session.rs index 4e72249aed129..150d207e5bfe9 100644 --- a/src/librustc_session/session.rs +++ b/src/librustc_session/session.rs @@ -14,7 +14,7 @@ use rustc_errors::ErrorReported; use rustc_data_structures::base_n; use rustc_data_structures::sync::{ - self, Lrc, Lock, OneThread, Once, AtomicUsize, Ordering, + self, Lrc, Lock, OneThread, Once, AtomicU64, AtomicUsize, Ordering, Ordering::SeqCst, }; use rustc_data_structures::impl_stable_hash_via_hash; @@ -119,7 +119,7 @@ pub struct Session { /// If `-zprint-fuel=crate`, `Some(crate)`. pub print_fuel_crate: Option, /// Always set to zero and incremented so that we can print fuel expended by a crate. - pub print_fuel: AtomicUsize, + pub print_fuel: AtomicU64, /// Loaded up early on in the initialization of this `Session` to avoid /// false positives about a job server in our environment. @@ -1116,7 +1116,7 @@ fn build_session_( out_of_fuel: false, }); let print_fuel_crate = sopts.debugging_opts.print_fuel.clone(); - let print_fuel = AtomicUsize::new(0); + let print_fuel = AtomicU64::new(0); let working_dir = env::current_dir().unwrap_or_else(|e| parse_sess.span_diagnostic diff --git a/src/test/ui/traits/cycle-cache-err-60010.rs b/src/test/ui/traits/cycle-cache-err-60010.rs index ebed4a02d0f33..cbddef082be67 100644 --- a/src/test/ui/traits/cycle-cache-err-60010.rs +++ b/src/test/ui/traits/cycle-cache-err-60010.rs @@ -28,7 +28,7 @@ struct SalsaStorage { } impl Database for RootDatabase { - type Storage = SalsaStorage; + type Storage = SalsaStorage; //~ ERROR overflow } impl HasQueryGroup for RootDatabase {} impl Query for ParseQuery diff --git a/src/test/ui/traits/cycle-cache-err-60010.stderr b/src/test/ui/traits/cycle-cache-err-60010.stderr index 2fc26bb11e3e3..295845b1146ef 100644 --- a/src/test/ui/traits/cycle-cache-err-60010.stderr +++ b/src/test/ui/traits/cycle-cache-err-60010.stderr @@ -6,6 +6,22 @@ LL | _parse: >::Data, | = note: required because of the requirements on the impl of `Query` for `ParseQuery` -error: aborting due to previous error +error[E0275]: overflow evaluating the requirement `Runtime: std::panic::RefUnwindSafe` + --> $DIR/cycle-cache-err-60010.rs:31:5 + | +LL | type Storage; + | ------- associated type defined here +... +LL | impl Database for RootDatabase { + | ------------------------------ in this `impl` item +LL | type Storage = SalsaStorage; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: required because it appears within the type `RootDatabase` + = note: required because of the requirements on the impl of `SourceDatabase` for `RootDatabase` + = note: required because of the requirements on the impl of `Query` for `ParseQuery` + = note: required because it appears within the type `SalsaStorage` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0275`.