From f313646a3b5732be29226326889f85b4f4d4b599 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 15 Feb 2017 08:53:18 -0800 Subject: [PATCH 01/10] test: Verify all sysroot crates are unstable As we continue to add more crates to the compiler and use them to implement various features we want to be sure we're not accidentally expanding the API surface area of the compiler! To that end this commit adds a new `run-make` test which will attempt to `extern crate foo` all crates in the sysroot, verifying that they're all unstable. This commit discovered that the `std_shim` and `test_shim` crates were accidentally stable and fixes the situation by deleting those shims. The shims are no longer necessary due to changes in Cargo that have happened since they were originally incepted. --- src/Cargo.lock | 15 ------ src/Cargo.toml | 4 +- src/bootstrap/README.md | 4 +- src/bootstrap/check.rs | 4 +- src/bootstrap/compile.rs | 4 +- src/bootstrap/doc.rs | 4 +- src/bootstrap/metadata.rs | 4 +- src/bootstrap/step.rs | 50 +++++++++---------- src/liballoc_jemalloc/lib.rs | 12 ----- src/rustc/std_shim/Cargo.toml | 46 ----------------- src/rustc/std_shim/lib.rs | 17 ------- src/rustc/test_shim/Cargo.toml | 16 ------ src/rustc/test_shim/lib.rs | 15 ------ .../sysroot-crates-are-unstable/Makefile | 28 +++++++++++ 14 files changed, 65 insertions(+), 158 deletions(-) delete mode 100644 src/rustc/std_shim/Cargo.toml delete mode 100644 src/rustc/std_shim/lib.rs delete mode 100644 src/rustc/test_shim/Cargo.toml delete mode 100644 src/rustc/test_shim/lib.rs create mode 100644 src/test/run-make/sysroot-crates-are-unstable/Makefile diff --git a/src/Cargo.lock b/src/Cargo.lock index 51d45c06fcb49..1d1d63c9ee463 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -762,14 +762,6 @@ dependencies = [ "unwind 0.0.0", ] -[[package]] -name = "std_shim" -version = "0.0.0" -dependencies = [ - "core 0.0.0", - "std 0.0.0", -] - [[package]] name = "std_unicode" version = "0.0.0" @@ -835,13 +827,6 @@ dependencies = [ "term 0.0.0", ] -[[package]] -name = "test_shim" -version = "0.0.0" -dependencies = [ - "test 0.0.0", -] - [[package]] name = "thread-id" version = "2.0.0" diff --git a/src/Cargo.toml b/src/Cargo.toml index d8dedd11f357d..0dafbb8428e3e 100644 --- a/src/Cargo.toml +++ b/src/Cargo.toml @@ -2,8 +2,8 @@ members = [ "bootstrap", "rustc", - "rustc/std_shim", - "rustc/test_shim", + "libstd", + "libtest", "tools/cargotest", "tools/compiletest", "tools/error_index_generator", diff --git a/src/bootstrap/README.md b/src/bootstrap/README.md index ac84edb403847..2f7757fb1d5ba 100644 --- a/src/bootstrap/README.md +++ b/src/bootstrap/README.md @@ -267,8 +267,8 @@ build/ The current build is unfortunately not quite as simple as `cargo build` in a directory, but rather the compiler is split into three different Cargo projects: -* `src/rustc/std_shim` - a project which builds and compiles libstd -* `src/rustc/test_shim` - a project which builds and compiles libtest +* `src/libstd` - the standard library +* `src/libtest` - testing support, depends on libstd * `src/rustc` - the actual compiler itself Each "project" has a corresponding Cargo.lock file with all dependencies, and diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index 00758460becc5..dfe96b51799c0 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -346,10 +346,10 @@ pub fn krate(build: &Build, krate: Option<&str>) { let (name, path, features, root) = match mode { Mode::Libstd => { - ("libstd", "src/rustc/std_shim", build.std_features(), "std_shim") + ("libstd", "src/libstd", build.std_features(), "std") } Mode::Libtest => { - ("libtest", "src/rustc/test_shim", String::new(), "test_shim") + ("libtest", "src/libtest", String::new(), "test") } Mode::Librustc => { ("librustc", "src/rustc", build.rustc_features(), "rustc-main") diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 0b1a1f39d8d42..00904bc776aa9 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -64,7 +64,7 @@ pub fn std(build: &Build, target: &str, compiler: &Compiler) { } cargo.arg("--features").arg(features) .arg("--manifest-path") - .arg(build.src.join("src/rustc/std_shim/Cargo.toml")); + .arg(build.src.join("src/libstd/Cargo.toml")); if let Some(target) = build.config.target_config.get(target) { if let Some(ref jemalloc) = target.jemalloc { @@ -162,7 +162,7 @@ pub fn test(build: &Build, target: &str, compiler: &Compiler) { build.clear_if_dirty(&out_dir, &libstd_stamp(build, compiler, target)); let mut cargo = build.cargo(compiler, Mode::Libtest, target, "build"); cargo.arg("--manifest-path") - .arg(build.src.join("src/rustc/test_shim/Cargo.toml")); + .arg(build.src.join("src/libtest/Cargo.toml")); build.run(&mut cargo); update_mtime(build, &libtest_stamp(build, compiler, target)); } diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 74b13144f2ff0..3fcc15b35b541 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -152,7 +152,7 @@ pub fn std(build: &Build, stage: u32, target: &str) { let mut cargo = build.cargo(&compiler, Mode::Libstd, target, "doc"); cargo.arg("--manifest-path") - .arg(build.src.join("src/rustc/std_shim/Cargo.toml")) + .arg(build.src.join("src/libstd/Cargo.toml")) .arg("--features").arg(build.std_features()); // We don't want to build docs for internal std dependencies unless @@ -198,7 +198,7 @@ pub fn test(build: &Build, stage: u32, target: &str) { let mut cargo = build.cargo(&compiler, Mode::Libtest, target, "doc"); cargo.arg("--manifest-path") - .arg(build.src.join("src/rustc/test_shim/Cargo.toml")); + .arg(build.src.join("src/libtest/Cargo.toml")); build.run(&mut cargo); cp_r(&out_dir, &out) } diff --git a/src/bootstrap/metadata.rs b/src/bootstrap/metadata.rs index 8befb105ff618..5ab542b6a2489 100644 --- a/src/bootstrap/metadata.rs +++ b/src/bootstrap/metadata.rs @@ -43,8 +43,8 @@ struct ResolveNode { } pub fn build(build: &mut Build) { - build_krate(build, "src/rustc/std_shim"); - build_krate(build, "src/rustc/test_shim"); + build_krate(build, "src/libstd"); + build_krate(build, "src/libtest"); build_krate(build, "src/rustc"); } diff --git a/src/bootstrap/step.rs b/src/bootstrap/step.rs index ee5b61062fed8..ef84693b5b319 100644 --- a/src/bootstrap/step.rs +++ b/src/bootstrap/step.rs @@ -246,14 +246,14 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules { crate_rule(build, &mut rules, "libstd-link", - "build-crate-std_shim", + "build-crate-std", compile::std_link) .dep(|s| s.name("startup-objects")) .dep(|s| s.name("create-sysroot").target(s.host)); crate_rule(build, &mut rules, "libtest-link", - "build-crate-test_shim", + "build-crate-test", compile::test_link) .dep(|s| s.name("libstd-link")); crate_rule(build, @@ -263,13 +263,13 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules { compile::rustc_link) .dep(|s| s.name("libtest-link")); - for (krate, path, _default) in krates("std_shim") { + for (krate, path, _default) in krates("std") { rules.build(&krate.build_step, path) .dep(|s| s.name("startup-objects")) .dep(move |s| s.name("rustc").host(&build.config.build).target(s.host)) .run(move |s| compile::std(build, s.target, &s.compiler())); } - for (krate, path, _default) in krates("test_shim") { + for (krate, path, _default) in krates("test") { rules.build(&krate.build_step, path) .dep(|s| s.name("libstd-link")) .run(move |s| compile::test(build, s.target, &s.compiler())); @@ -384,7 +384,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules { "pretty", "run-fail-fulldeps"); } - for (krate, path, _default) in krates("std_shim") { + for (krate, path, _default) in krates("std") { rules.test(&krate.test_step, path) .dep(|s| s.name("libtest")) .dep(|s| s.name("emulator-copy-libs")) @@ -400,7 +400,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules { Mode::Libstd, TestKind::Test, None)); // std benchmarks - for (krate, path, _default) in krates("std_shim") { + for (krate, path, _default) in krates("std") { rules.bench(&krate.bench_step, path) .dep(|s| s.name("libtest")) .dep(|s| s.name("emulator-copy-libs")) @@ -415,7 +415,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules { .run(move |s| check::krate(build, &s.compiler(), s.target, Mode::Libstd, TestKind::Bench, None)); - for (krate, path, _default) in krates("test_shim") { + for (krate, path, _default) in krates("test") { rules.test(&krate.test_step, path) .dep(|s| s.name("libtest")) .dep(|s| s.name("emulator-copy-libs")) @@ -583,13 +583,13 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules { .default(build.config.docs) .host(true) .run(move |s| doc::error_index(build, s.target)); - for (krate, path, default) in krates("std_shim") { + for (krate, path, default) in krates("std") { rules.doc(&krate.doc_step, path) .dep(|s| s.name("libstd-link")) .default(default && build.config.docs) .run(move |s| doc::std(build, s.stage, s.target)); } - for (krate, path, default) in krates("test_shim") { + for (krate, path, default) in krates("test") { rules.doc(&krate.doc_step, path) .dep(|s| s.name("libtest-link")) .default(default && build.config.compiler_docs) @@ -1154,23 +1154,23 @@ mod tests { let mut build = Build::new(flags, config); let cwd = env::current_dir().unwrap(); - build.crates.insert("std_shim".to_string(), ::Crate { - name: "std_shim".to_string(), + build.crates.insert("std".to_string(), ::Crate { + name: "std".to_string(), deps: Vec::new(), - path: cwd.join("src/std_shim"), - doc_step: "doc-std_shim".to_string(), - build_step: "build-crate-std_shim".to_string(), - test_step: "test-std_shim".to_string(), - bench_step: "bench-std_shim".to_string(), + path: cwd.join("src/std"), + doc_step: "doc-std".to_string(), + build_step: "build-crate-std".to_string(), + test_step: "test-std".to_string(), + bench_step: "bench-std".to_string(), }); - build.crates.insert("test_shim".to_string(), ::Crate { - name: "test_shim".to_string(), + build.crates.insert("test".to_string(), ::Crate { + name: "test".to_string(), deps: Vec::new(), - path: cwd.join("src/test_shim"), - doc_step: "doc-test_shim".to_string(), - build_step: "build-crate-test_shim".to_string(), - test_step: "test-test_shim".to_string(), - bench_step: "bench-test_shim".to_string(), + path: cwd.join("src/test"), + doc_step: "doc-test".to_string(), + build_step: "build-crate-test".to_string(), + test_step: "test-test".to_string(), + bench_step: "bench-test".to_string(), }); build.crates.insert("rustc-main".to_string(), ::Crate { name: "rustc-main".to_string(), @@ -1360,7 +1360,7 @@ mod tests { let all = rules.expand(&plan); println!("all rules: {:#?}", all); assert!(!all.contains(&step.name("rustc"))); - assert!(!all.contains(&step.name("build-crate-std_shim").stage(1))); + assert!(!all.contains(&step.name("build-crate-std").stage(1))); // all stage0 compiles should be for the build target, A for step in all.iter().filter(|s| s.stage == 0) { @@ -1425,7 +1425,7 @@ mod tests { assert!(!plan.iter().any(|s| s.name.contains("rustc"))); assert!(plan.iter().all(|s| { - !s.name.contains("test_shim") || s.target == "C" + !s.name.contains("test") || s.target == "C" })); } diff --git a/src/liballoc_jemalloc/lib.rs b/src/liballoc_jemalloc/lib.rs index 8d81a09f5af0f..a496ab870c63b 100644 --- a/src/liballoc_jemalloc/lib.rs +++ b/src/liballoc_jemalloc/lib.rs @@ -122,18 +122,6 @@ mod imp { let flags = align_to_flags(align); unsafe { nallocx(size as size_t, flags) as usize } } - - // These symbols are used by jemalloc on android but the really old android - // we're building on doesn't have them defined, so just make sure the symbols - // are available. - #[no_mangle] - #[cfg(all(target_os = "android", not(cargobuild)))] - pub extern "C" fn pthread_atfork(_prefork: *mut u8, - _postfork_parent: *mut u8, - _postfork_child: *mut u8) - -> i32 { - 0 - } } #[cfg(dummy_jemalloc)] diff --git a/src/rustc/std_shim/Cargo.toml b/src/rustc/std_shim/Cargo.toml deleted file mode 100644 index db96079d3e916..0000000000000 --- a/src/rustc/std_shim/Cargo.toml +++ /dev/null @@ -1,46 +0,0 @@ -# This is a shim Cargo.toml which serves as a proxy for building the standard -# library. The reason for this is a little subtle, as one might reasonably -# expect that we just `cargo build` the standard library itself. -# -# One of the output artifacts for the standard library is a dynamic library, and -# on platforms like OSX the name of the output artifact is actually encoded into -# the library itself (similar to a soname on Linux). When the library is linked -# against, this encoded name is what's literally looked for at runtime when the -# dynamic loader is probing for libraries. -# -# Cargo, however, by default will not mangle the output filename of the -# top-level target. If we were to run `cargo build` on libstd itself, we would -# generate a file `libstd.so`. When installing, however, this file is called -# something like `libstd-abcdef0123.so`. On OSX at least this causes a failure -# at runtime because the encoded "soname" is `libstd.so`, not what the file is -# actually called. -# -# By using this shim library to build the standard library by proxy we sidestep -# this problem. The standard library is built with mangled hex already in its -# name so there's nothing extra we need to do. - -[package] -name = "std_shim" -version = "0.0.0" -authors = ["The Rust Project Developers"] - -[lib] -name = "std_shim" -path = "lib.rs" -doc = false - -[dependencies] -std = { path = "../../libstd" } -core = { path = "../../libcore" } - -# Reexport features from std -[features] -asan = ["std/asan"] -backtrace = ["std/backtrace"] -debug-jemalloc = ["std/debug-jemalloc"] -jemalloc = ["std/jemalloc"] -force_alloc_system = ["std/force_alloc_system"] -lsan = ["std/lsan"] -msan = ["std/msan"] -panic-unwind = ["std/panic-unwind"] -tsan = ["std/tsan"] diff --git a/src/rustc/std_shim/lib.rs b/src/rustc/std_shim/lib.rs deleted file mode 100644 index 2fc5d8d6e5321..0000000000000 --- a/src/rustc/std_shim/lib.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// See comments in Cargo.toml for why this exists - -// There's a bug right now where if we pass --extern std=... and we're cross -// compiling then this doesn't work with `#[macro_use] extern crate std;`. Work -// around this by not having `#[macro_use] extern crate std;` -#![no_std] -extern crate std; diff --git a/src/rustc/test_shim/Cargo.toml b/src/rustc/test_shim/Cargo.toml deleted file mode 100644 index 6ef613eee0628..0000000000000 --- a/src/rustc/test_shim/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -# This is a shim Cargo.toml which serves as a proxy for building libtest. -# -# The reason this shim exists is basically the same reason that `std_shim` -# exists, and more documentation can be found in that `Cargo.toml` as to why. - -[package] -name = "test_shim" -version = "0.0.0" -authors = ["The Rust Project Developers"] - -[lib] -name = "test_shim" -path = "lib.rs" - -[dependencies] -test = { path = "../../libtest" } diff --git a/src/rustc/test_shim/lib.rs b/src/rustc/test_shim/lib.rs deleted file mode 100644 index d614d967e3b07..0000000000000 --- a/src/rustc/test_shim/lib.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// See comments in Cargo.toml for why this exists - -#![feature(test)] - -extern crate test; diff --git a/src/test/run-make/sysroot-crates-are-unstable/Makefile b/src/test/run-make/sysroot-crates-are-unstable/Makefile new file mode 100644 index 0000000000000..f08b62ad3aafe --- /dev/null +++ b/src/test/run-make/sysroot-crates-are-unstable/Makefile @@ -0,0 +1,28 @@ +# This is a whitelist of crates which are stable, we don't check for the +# instability of these crates as they're all stable! +STABLE_CRATES := \ + std \ + core \ + proc_macro + +# Generate a list of all crates in the sysroot. To do this we list all files in +# rustc's sysroot, look at the filename, strip everything after the `-`, and +# strip the leading `lib` (if present) +SYSROOT := $(shell $(RUSTC) --print sysroot) +LIBS := $(wildcard $(SYSROOT)/lib/rustlib/$(TARGET)/lib/*) +LIBS := $(foreach lib,$(LIBS),$(notdir $(lib))) +LIBS := $(foreach lib,$(LIBS),$(word 1,$(subst -, ,$(lib)))) +LIBS := $(foreach lib,$(LIBS),$(patsubst lib%,%,$(lib))) +LIBS := $(filter-out $(STABLE_CRATES),$(LIBS)) + +all: $(foreach lib,$(LIBS),check-crate-$(lib)-is-unstable) + +check-crate-%-is-unstable: + @echo verifying $* is an unstable crate + @echo 'extern crate $*;' | \ + $(RUSTC) - --crate-type rlib 2>&1 | cat > $(TMPDIR)/$*; \ + true + @grep -q 'use of unstable library feature' $(TMPDIR)/$* || \ + (echo crate $* is not unstable && \ + cat $(TMPDIR)/$* && \ + false) From fdf4a98760bd555b3bebec27d19d88f56429606d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 15 Feb 2017 09:36:52 -0800 Subject: [PATCH 02/10] appveyor: Move MSVC dist builds to their own builder In the long run we want to separate out the dist builders from the test builders. This provides us leeway to expand the dist builders with more tools (e.g. Cargo and the RLS) without impacting cycle times. Currently the Travis dist builders double-up the platforms they provide builds for, so I figured we could try that out for MSVC as well. This commit adds a new AppVeyor builder which runs a dist for all the MSVC targets: * x86_64-pc-windows-msvc * i686-pc-windows-msvc * i586-pc-windows-msvc If this takes too long and/or times out we'll need to split this up. In any case we're going to need more capacity from AppVeyor no matter what becaue the two pc-windows-gnu targets can't cross compile so we need at least 2 more builders no matter what. --- appveyor.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 6b906fd9ab618..35f0101c2c3ca 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,15 +7,13 @@ environment: matrix: # 32/64 bit MSVC - MSYS_BITS: 64 - RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-extended - SCRIPT: python x.py test && python x.py dist - DEPLOY: 1 + RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc + SCRIPT: python x.py test - MSYS_BITS: 32 - RUST_CONFIGURE_ARGS: --build=i686-pc-windows-msvc --target=i586-pc-windows-msvc --enable-extended - SCRIPT: python x.py test --host i686-pc-windows-msvc --target i686-pc-windows-msvc && python x.py dist - DEPLOY: 1 + RUST_CONFIGURE_ARGS: --build=i686-pc-windows-msvc --target=i586-pc-windows-msvc + SCRIPT: python x.py test --host i686-pc-windows-msvc --target i686-pc-windows-msvc - # MSVC cargotest + # MSVC aux tests - MSYS_BITS: 64 RUST_CHECK_TARGET: check-aux RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc @@ -60,6 +58,15 @@ environment: MINGW_DIR: mingw64 DEPLOY: 1 + # 32/64 bit MSVC deployment + - RUST_CONFIGURE_ARGS: > + --build=x86_64-pc-windows-msvc + --host=i686-pc-windows-msvc + --target=i586-pc-windows-msvc + --enable-extended + SCRIPT: python x.py dist + DEPLOY: 1 + # "alternate" deployment, see .travis.yml for more info - MSYS_BITS: 64 RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-extended From 4a3c66ad2f4211137fcb98a31d1e1033d5765e22 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Wed, 15 Feb 2017 21:21:36 +0200 Subject: [PATCH 03/10] [MIR] Make InlineAsm a Statement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously InlineAsm was an Rvalue, but its semantics doesn’t really match the semantics of an Rvalue – rather it behaves more like a Statement. --- src/librustc/mir/mod.rs | 21 +++++++++---------- src/librustc/mir/tcx.rs | 1 - src/librustc/mir/visit.rs | 21 +++++++++---------- .../borrowck/mir/dataflow/impls.rs | 1 + .../borrowck/mir/dataflow/sanity_check.rs | 1 + .../borrowck/mir/gather_moves.rs | 4 ++-- src/librustc_borrowck/borrowck/mir/mod.rs | 1 + src/librustc_mir/build/expr/as_rvalue.rs | 16 +------------- src/librustc_mir/build/expr/into.rs | 2 +- src/librustc_mir/build/expr/stmt.rs | 17 +++++++++++++++ src/librustc_mir/transform/qualify_consts.rs | 5 +---- src/librustc_mir/transform/type_check.rs | 5 +++-- src/librustc_passes/mir_stats.rs | 2 +- src/librustc_trans/mir/constant.rs | 3 ++- src/librustc_trans/mir/rvalue.rs | 21 ++----------------- src/librustc_trans/mir/statement.rs | 14 +++++++++++++ 16 files changed, 67 insertions(+), 68 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index d8212807eb277..3403cf0477450 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -777,6 +777,12 @@ pub enum StatementKind<'tcx> { /// End the current live range for the storage of the local. StorageDead(Lvalue<'tcx>), + InlineAsm { + asm: InlineAsm, + outputs: Vec>, + inputs: Vec> + }, + /// No-op. Useful for deleting instructions without affecting statement indices. Nop, } @@ -790,7 +796,10 @@ impl<'tcx> Debug for Statement<'tcx> { StorageDead(ref lv) => write!(fmt, "StorageDead({:?})", lv), SetDiscriminant{lvalue: ref lv, variant_index: index} => { write!(fmt, "discriminant({:?}) = {:?}", lv, index) - } + }, + InlineAsm { ref asm, ref outputs, ref inputs } => { + write!(fmt, "asm!({:?} : {:?} : {:?})", asm, outputs, inputs) + }, Nop => write!(fmt, "nop"), } } @@ -1004,12 +1013,6 @@ pub enum Rvalue<'tcx> { /// that `Foo` has a destructor. These rvalues can be optimized /// away after type-checking and before lowering. Aggregate(AggregateKind<'tcx>, Vec>), - - InlineAsm { - asm: InlineAsm, - outputs: Vec>, - inputs: Vec> - } } #[derive(Clone, Copy, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)] @@ -1111,10 +1114,6 @@ impl<'tcx> Debug for Rvalue<'tcx> { UnaryOp(ref op, ref a) => write!(fmt, "{:?}({:?})", op, a), Discriminant(ref lval) => write!(fmt, "discriminant({:?})", lval), Box(ref t) => write!(fmt, "Box({:?})", t), - InlineAsm { ref asm, ref outputs, ref inputs } => { - write!(fmt, "asm!({:?} : {:?} : {:?})", asm, outputs, inputs) - } - Ref(_, borrow_kind, ref lv) => { let kind_str = match borrow_kind { BorrowKind::Shared => "", diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index 7b0863b4c42bc..5c8d031caf60d 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -207,7 +207,6 @@ impl<'tcx> Rvalue<'tcx> { } } } - Rvalue::InlineAsm { .. } => None } } } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index be3c43db7badd..7cdbd5cae061f 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -333,6 +333,16 @@ macro_rules! make_mir_visitor { StatementKind::StorageDead(ref $($mutability)* lvalue) => { self.visit_lvalue(lvalue, LvalueContext::StorageDead, location); } + StatementKind::InlineAsm { ref $($mutability)* outputs, + ref $($mutability)* inputs, + asm: _ } => { + for output in & $($mutability)* outputs[..] { + self.visit_lvalue(output, LvalueContext::Store, location); + } + for input in & $($mutability)* inputs[..] { + self.visit_operand(input, location); + } + } StatementKind::Nop => {} } } @@ -526,17 +536,6 @@ macro_rules! make_mir_visitor { self.visit_operand(operand, location); } } - - Rvalue::InlineAsm { ref $($mutability)* outputs, - ref $($mutability)* inputs, - asm: _ } => { - for output in & $($mutability)* outputs[..] { - self.visit_lvalue(output, LvalueContext::Store, location); - } - for input in & $($mutability)* inputs[..] { - self.visit_operand(input, location); - } - } } } diff --git a/src/librustc_borrowck/borrowck/mir/dataflow/impls.rs b/src/librustc_borrowck/borrowck/mir/dataflow/impls.rs index 1fa4da94dd6bf..7888a56d39dfb 100644 --- a/src/librustc_borrowck/borrowck/mir/dataflow/impls.rs +++ b/src/librustc_borrowck/borrowck/mir/dataflow/impls.rs @@ -473,6 +473,7 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> { } mir::StatementKind::StorageLive(_) | mir::StatementKind::StorageDead(_) | + mir::StatementKind::InlineAsm { .. } | mir::StatementKind::Nop => {} } } diff --git a/src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs b/src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs index ea6ef423c92ce..940dd5433a0d9 100644 --- a/src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs +++ b/src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs @@ -104,6 +104,7 @@ fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } mir::StatementKind::StorageLive(_) | mir::StatementKind::StorageDead(_) | + mir::StatementKind::InlineAsm { .. } | mir::StatementKind::Nop => continue, mir::StatementKind::SetDiscriminant{ .. } => span_bug!(stmt.source_info.span, diff --git a/src/librustc_borrowck/borrowck/mir/gather_moves.rs b/src/librustc_borrowck/borrowck/mir/gather_moves.rs index 0c7e922c48ab4..35ace6628cfed 100644 --- a/src/librustc_borrowck/borrowck/mir/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/mir/gather_moves.rs @@ -412,6 +412,7 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> { span_bug!(stmt.source_info.span, "SetDiscriminant should not exist during borrowck"); } + StatementKind::InlineAsm { .. } | StatementKind::Nop => {} } } @@ -436,8 +437,7 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> { } Rvalue::Ref(..) | Rvalue::Discriminant(..) | - Rvalue::Len(..) | - Rvalue::InlineAsm { .. } => {} + Rvalue::Len(..) => {} Rvalue::Box(..) => { // This returns an rvalue with uninitialized contents. We can't // move out of it here because it is an rvalue - assignments always diff --git a/src/librustc_borrowck/borrowck/mir/mod.rs b/src/librustc_borrowck/borrowck/mir/mod.rs index a0c36139ddcd2..d9283e7037f50 100644 --- a/src/librustc_borrowck/borrowck/mir/mod.rs +++ b/src/librustc_borrowck/borrowck/mir/mod.rs @@ -378,6 +378,7 @@ fn drop_flag_effects_for_location<'a, 'tcx, F>( } mir::StatementKind::StorageLive(_) | mir::StatementKind::StorageDead(_) | + mir::StatementKind::InlineAsm { .. } | mir::StatementKind::Nop => {} }, None => { diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index dad1d713168cd..7adcc0e730b15 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -49,21 +49,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ExprKind::Scope { extent, value } => { this.in_scope(extent, block, |this| this.as_rvalue(block, value)) } - ExprKind::InlineAsm { asm, outputs, inputs } => { - let outputs = outputs.into_iter().map(|output| { - unpack!(block = this.as_lvalue(block, output)) - }).collect(); - - let inputs = inputs.into_iter().map(|input| { - unpack!(block = this.as_operand(block, input)) - }).collect(); - - block.and(Rvalue::InlineAsm { - asm: asm.clone(), - outputs: outputs, - inputs: inputs - }) - } ExprKind::Repeat { value, count } => { let value_operand = unpack!(block = this.as_operand(block, value)); block.and(Rvalue::Repeat(value_operand, count)) @@ -238,6 +223,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ExprKind::Break { .. } | ExprKind::Continue { .. } | ExprKind::Return { .. } | + ExprKind::InlineAsm { .. } | ExprKind::StaticRef { .. } => { // these do not have corresponding `Rvalue` variants, // so make an operand and then return that diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index 35841c2cbdf01..e66f2b4e2bfc0 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -232,6 +232,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ExprKind::AssignOp { .. } | ExprKind::Continue { .. } | ExprKind::Break { .. } | + ExprKind::InlineAsm { .. } | ExprKind::Return {.. } => { this.stmt_expr(block, expr) } @@ -257,7 +258,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { ExprKind::Index { .. } | ExprKind::Deref { .. } | ExprKind::Literal { .. } | - ExprKind::InlineAsm { .. } | ExprKind::Field { .. } => { debug_assert!(match Category::of(&expr.kind).unwrap() { Category::Rvalue(RvalueFunc::Into) => false, diff --git a/src/librustc_mir/build/expr/stmt.rs b/src/librustc_mir/build/expr/stmt.rs index f04d630379a35..c577aab40dbeb 100644 --- a/src/librustc_mir/build/expr/stmt.rs +++ b/src/librustc_mir/build/expr/stmt.rs @@ -117,6 +117,23 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { this.exit_scope(expr_span, extent, block, return_block); this.cfg.start_new_block().unit() } + ExprKind::InlineAsm { asm, outputs, inputs } => { + let outputs = outputs.into_iter().map(|output| { + unpack!(block = this.as_lvalue(block, output)) + }).collect(); + let inputs = inputs.into_iter().map(|input| { + unpack!(block = this.as_operand(block, input)) + }).collect(); + this.cfg.push(block, Statement { + source_info: source_info, + kind: StatementKind::InlineAsm { + asm: asm.clone(), + outputs: outputs, + inputs: inputs + }, + }); + block.unit() + } _ => { let expr_ty = expr.ty; let temp = this.temp(expr.ty.clone()); diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 922521726c626..4459142cfb274 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -774,10 +774,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { } } } - - Rvalue::InlineAsm {..} => { - self.not_const(); - } } } @@ -933,6 +929,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { StatementKind::SetDiscriminant { .. } | StatementKind::StorageLive(_) | StatementKind::StorageDead(_) | + StatementKind::InlineAsm {..} | StatementKind::Nop => {} } }); diff --git a/src/librustc_mir/transform/type_check.rs b/src/librustc_mir/transform/type_check.rs index 8ede7aaab5f68..8d108815e0f3c 100644 --- a/src/librustc_mir/transform/type_check.rs +++ b/src/librustc_mir/transform/type_check.rs @@ -361,9 +361,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { span_mirbug!(self, stmt, "bad assignment ({:?} = {:?}): {:?}", lv_ty, rv_ty, terr); } - // FIXME: rvalue with undeterminable type - e.g. inline - // asm. } + // FIXME: rvalue with undeterminable type - e.g. AggregateKind::Array branch that + // returns `None`. } StatementKind::SetDiscriminant{ ref lvalue, variant_index } => { let lvalue_type = lvalue.ty(mir, tcx).to_ty(tcx); @@ -392,6 +392,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { } } } + StatementKind::InlineAsm { .. } | StatementKind::Nop => {} } } diff --git a/src/librustc_passes/mir_stats.rs b/src/librustc_passes/mir_stats.rs index 517a472056334..33b7089c38214 100644 --- a/src/librustc_passes/mir_stats.rs +++ b/src/librustc_passes/mir_stats.rs @@ -128,6 +128,7 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> { StatementKind::SetDiscriminant { .. } => "StatementKind::SetDiscriminant", StatementKind::StorageLive(..) => "StatementKind::StorageLive", StatementKind::StorageDead(..) => "StatementKind::StorageDead", + StatementKind::InlineAsm { .. } => "StatementKind::InlineAsm", StatementKind::Nop => "StatementKind::Nop", }, &statement.kind); self.super_statement(block, statement, location); @@ -198,7 +199,6 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> { "Rvalue::Aggregate" } - Rvalue::InlineAsm { .. } => "Rvalue::InlineAsm", }; self.record(rvalue_kind, rvalue); self.super_rvalue(rvalue, location); diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs index 19139301bb0c4..7e17ae5f1d389 100644 --- a/src/librustc_trans/mir/constant.rs +++ b/src/librustc_trans/mir/constant.rs @@ -287,8 +287,9 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> { mir::StatementKind::StorageLive(_) | mir::StatementKind::StorageDead(_) | mir::StatementKind::Nop => {} + mir::StatementKind::InlineAsm { .. } | mir::StatementKind::SetDiscriminant{ .. } => { - span_bug!(span, "SetDiscriminant should not appear in constants?"); + span_bug!(span, "{:?} should not appear in constants?", statement.kind); } } } diff --git a/src/librustc_trans/mir/rvalue.rs b/src/librustc_trans/mir/rvalue.rs index 38ee67796c6de..7d4f542addbb1 100644 --- a/src/librustc_trans/mir/rvalue.rs +++ b/src/librustc_trans/mir/rvalue.rs @@ -16,7 +16,6 @@ use rustc::mir::tcx::LvalueTy; use rustc::mir; use middle::lang_items::ExchangeMallocFnLangItem; -use asm; use base; use builder::Builder; use callee::Callee; @@ -156,20 +155,6 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { bcx } - mir::Rvalue::InlineAsm { ref asm, ref outputs, ref inputs } => { - let outputs = outputs.iter().map(|output| { - let lvalue = self.trans_lvalue(&bcx, output); - (lvalue.llval, lvalue.ty.to_ty(bcx.tcx())) - }).collect(); - - let input_vals = inputs.iter().map(|input| { - self.trans_operand(&bcx, input).immediate() - }).collect(); - - asm::trans_inline_asm(&bcx, asm, outputs, input_vals); - bcx - } - _ => { assert!(rvalue_creates_operand(rvalue)); let (bcx, temp) = self.trans_rvalue_operand(bcx, rvalue); @@ -468,8 +453,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { (bcx, operand) } mir::Rvalue::Repeat(..) | - mir::Rvalue::Aggregate(..) | - mir::Rvalue::InlineAsm { .. } => { + mir::Rvalue::Aggregate(..) => { bug!("cannot generate operand from rvalue {:?}", rvalue); } @@ -669,8 +653,7 @@ pub fn rvalue_creates_operand(rvalue: &mir::Rvalue) -> bool { mir::Rvalue::Use(..) => true, mir::Rvalue::Repeat(..) | - mir::Rvalue::Aggregate(..) | - mir::Rvalue::InlineAsm { .. } => + mir::Rvalue::Aggregate(..) => false, } diff --git a/src/librustc_trans/mir/statement.rs b/src/librustc_trans/mir/statement.rs index 48fc9720e4b83..29a0648c8f8f8 100644 --- a/src/librustc_trans/mir/statement.rs +++ b/src/librustc_trans/mir/statement.rs @@ -11,6 +11,7 @@ use rustc::mir; use base; +use asm; use common; use builder::Builder; @@ -73,6 +74,19 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { mir::StatementKind::StorageDead(ref lvalue) => { self.trans_storage_liveness(bcx, lvalue, base::Lifetime::End) } + mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => { + let outputs = outputs.iter().map(|output| { + let lvalue = self.trans_lvalue(&bcx, output); + (lvalue.llval, lvalue.ty.to_ty(bcx.tcx())) + }).collect(); + + let input_vals = inputs.iter().map(|input| { + self.trans_operand(&bcx, input).immediate() + }).collect(); + + asm::trans_inline_asm(&bcx, asm, outputs, input_vals); + bcx + } mir::StatementKind::Nop => bcx, } } From e77f8568f67b6dc265a620f7506a6f931c3a002e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 14 Feb 2017 04:10:52 +0000 Subject: [PATCH 04/10] Add a test that -fPIC is applied --- src/test/run-make/fpic/Makefile | 9 +++++++++ src/test/run-make/fpic/hello.rs | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/test/run-make/fpic/Makefile create mode 100644 src/test/run-make/fpic/hello.rs diff --git a/src/test/run-make/fpic/Makefile b/src/test/run-make/fpic/Makefile new file mode 100644 index 0000000000000..da69c83eb3713 --- /dev/null +++ b/src/test/run-make/fpic/Makefile @@ -0,0 +1,9 @@ +-include ../tools.mk + +# Test for #39529. +# `-z text` causes ld to error if there are any non-PIC sections + +all: +ifndef IS_WINDOWS + $(RUSTC) hello.rs -C link-args=-Wl,-z,text +endif diff --git a/src/test/run-make/fpic/hello.rs b/src/test/run-make/fpic/hello.rs new file mode 100644 index 0000000000000..a9e231b0ea839 --- /dev/null +++ b/src/test/run-make/fpic/hello.rs @@ -0,0 +1,11 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { } From ab57e7b86817b8ca9b7e6afb2f689ae67274ec7c Mon Sep 17 00:00:00 2001 From: Amos Onn Date: Thu, 16 Feb 2017 02:16:41 +0100 Subject: [PATCH 05/10] std::io::cursor Added test for seeking beyond i64. --- src/libstd/io/cursor.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 0cff8661d8871..9427e4afa2142 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -526,6 +526,43 @@ mod tests { assert_eq!(r.write(&[3]).unwrap(), 0); } + #[test] + fn seek_past_i64() { + let buf = [0xff]; + let mut r = Cursor::new(&buf[..]); + assert_eq!(r.seek(SeekFrom::Start(6)).unwrap(), 6); + assert_eq!(r.seek(SeekFrom::Current(0x7ffffffffffffff0)).unwrap(), 0x7ffffffffffffff6); + assert_eq!(r.seek(SeekFrom::Current(0x10)).unwrap(), 0x8000000000000006); + assert_eq!(r.seek(SeekFrom::Current(0)).unwrap(), 0x8000000000000006); + assert!(r.seek(SeekFrom::Current(0x7ffffffffffffffd)).is_err()); + assert_eq!(r.seek(SeekFrom::Current(-0x8000000000000000)).unwrap(), 6); + + let mut r = Cursor::new(vec![10]); + assert_eq!(r.seek(SeekFrom::Start(6)).unwrap(), 6); + assert_eq!(r.seek(SeekFrom::Current(0x7ffffffffffffff0)).unwrap(), 0x7ffffffffffffff6); + assert_eq!(r.seek(SeekFrom::Current(0x10)).unwrap(), 0x8000000000000006); + assert_eq!(r.seek(SeekFrom::Current(0)).unwrap(), 0x8000000000000006); + assert!(r.seek(SeekFrom::Current(0x7ffffffffffffffd)).is_err()); + assert_eq!(r.seek(SeekFrom::Current(-0x8000000000000000)).unwrap(), 6); + + let mut buf = [0]; + let mut r = Cursor::new(&mut buf[..]); + assert_eq!(r.seek(SeekFrom::Start(6)).unwrap(), 6); + assert_eq!(r.seek(SeekFrom::Current(0x7ffffffffffffff0)).unwrap(), 0x7ffffffffffffff6); + assert_eq!(r.seek(SeekFrom::Current(0x10)).unwrap(), 0x8000000000000006); + assert_eq!(r.seek(SeekFrom::Current(0)).unwrap(), 0x8000000000000006); + assert!(r.seek(SeekFrom::Current(0x7ffffffffffffffd)).is_err()); + assert_eq!(r.seek(SeekFrom::Current(-0x8000000000000000)).unwrap(), 6); + + let mut r = Cursor::new(vec![10].into_boxed_slice()); + assert_eq!(r.seek(SeekFrom::Start(6)).unwrap(), 6); + assert_eq!(r.seek(SeekFrom::Current(0x7ffffffffffffff0)).unwrap(), 0x7ffffffffffffff6); + assert_eq!(r.seek(SeekFrom::Current(0x10)).unwrap(), 0x8000000000000006); + assert_eq!(r.seek(SeekFrom::Current(0)).unwrap(), 0x8000000000000006); + assert!(r.seek(SeekFrom::Current(0x7ffffffffffffffd)).is_err()); + assert_eq!(r.seek(SeekFrom::Current(-0x8000000000000000)).unwrap(), 6); + } + #[test] fn seek_before_0() { let buf = [0xff]; From ebf70a9a206e3ecff7d442a7edf297731e9fe042 Mon Sep 17 00:00:00 2001 From: Shawn Walker-Salas Date: Wed, 15 Feb 2017 17:48:20 -0800 Subject: [PATCH 06/10] libstd needs update for pending libc change Fixes #39868 --- src/libstd/sys/unix/os.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 6992a17832e41..1dbfa640d5251 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -483,7 +483,6 @@ pub fn home_dir() -> Option { target_os = "nacl", target_os = "emscripten")))] unsafe fn fallback() -> Option { - #[cfg(not(target_os = "solaris"))] unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd, buf: &mut Vec) -> Option<()> { let mut result = ptr::null_mut(); @@ -495,16 +494,6 @@ pub fn home_dir() -> Option { } } - #[cfg(target_os = "solaris")] - unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd, - buf: &mut Vec) -> Option<()> { - // getpwuid_r semantics is different on Illumos/Solaris: - // http://illumos.org/man/3c/getpwuid_r - let result = libc::getpwuid_r(me, passwd, buf.as_mut_ptr(), - buf.capacity()); - if result.is_null() { None } else { Some(()) } - } - let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { n if n < 0 => 512 as usize, n => n as usize, From a2d176e8f4774b84db22540a45eed7b29482f154 Mon Sep 17 00:00:00 2001 From: Amos Onn Date: Thu, 16 Feb 2017 02:21:08 +0100 Subject: [PATCH 07/10] std::io::cursor: Fixed Seek so test passes. --- src/libstd/io/cursor.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 9427e4afa2142..60767ea478661 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -200,18 +200,20 @@ impl Cursor { #[stable(feature = "rust1", since = "1.0.0")] impl io::Seek for Cursor where T: AsRef<[u8]> { fn seek(&mut self, style: SeekFrom) -> io::Result { - let pos = match style { - SeekFrom::Start(n) => { self.pos = n; return Ok(n) } - SeekFrom::End(n) => self.inner.as_ref().len() as i64 + n, - SeekFrom::Current(n) => self.pos as i64 + n, + let (base_pos, offset) = match style { + SeekFrom::Start(n) => { self.pos = n; return Ok(n); } + SeekFrom::End(n) => (self.inner.as_ref().len() as u64, n), + SeekFrom::Current(n) => (self.pos, n), }; - - if pos < 0 { - Err(Error::new(ErrorKind::InvalidInput, - "invalid seek to a negative position")) + let new_pos = if offset >= 0 { + base_pos.checked_add(offset as u64) } else { - self.pos = pos as u64; - Ok(self.pos) + base_pos.checked_sub((offset.wrapping_neg()) as u64) + }; + match new_pos { + Some(n) => {self.pos = n; Ok(self.pos)} + None => Err(Error::new(ErrorKind::InvalidInput, + "invalid seek to a negative or overflowing position")) } } } From c02c44db724ddf63e6d5a3725dd5cd7f8c344052 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 14 Feb 2017 14:30:39 -0800 Subject: [PATCH 08/10] rustc: Link statically to the MSVCRT This commit changes all MSVC rustc binaries to be compiled with `-C target-feature=+crt-static` to link statically against the MSVCRT instead of dynamically (as it does today). This also necessitates compiling LLVM in a different fashion, ensuring it's compiled with `/MT` instead of `/MD`. cc #37406 --- src/bootstrap/bin/rustc.rs | 5 +++++ src/bootstrap/native.rs | 6 ++++++ src/rustllvm/llvm-auto-clean-trigger | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 90fd31ecbdd73..62e476bd737d3 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -205,6 +205,11 @@ fn main() { } } } + + if target.contains("pc-windows-msvc") { + cmd.arg("-Z").arg("unstable-options"); + cmd.arg("-C").arg("target-feature=+crt-static"); + } } if verbose > 1 { diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 21fc61cc81484..f16fc2092f616 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -99,6 +99,12 @@ pub fn llvm(build: &Build, target: &str) { .define("LLVM_TARGET_ARCH", target.split('-').next().unwrap()) .define("LLVM_DEFAULT_TARGET_TRIPLE", target); + if target.contains("msvc") { + cfg.define("LLVM_USE_CRT_DEBUG", "MT"); + cfg.define("LLVM_USE_CRT_RELEASE", "MT"); + cfg.define("LLVM_USE_CRT_RELWITHDEBINFO", "MT"); + } + if target.starts_with("i686") { cfg.define("LLVM_BUILD_32_BITS", "ON"); } diff --git a/src/rustllvm/llvm-auto-clean-trigger b/src/rustllvm/llvm-auto-clean-trigger index b74f491385820..ab36e9a2c2b20 100644 --- a/src/rustllvm/llvm-auto-clean-trigger +++ b/src/rustllvm/llvm-auto-clean-trigger @@ -1,4 +1,4 @@ # If this file is modified, then llvm will be forcibly cleaned and then rebuilt. # The actual contents of this file do not matter, but to trigger a change on the # build bots then the contents should be changed so git updates the mtime. -2016-12-19 +2017-02-15 From a7f63d12a701f8d2c7b975ef605a50bb83318b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 15 Feb 2017 21:46:23 -0800 Subject: [PATCH 09/10] Remove noop method `Substs::params()` Re: 48b3dd11f59f48819031206ee2b3ab98ceae1550 --- src/librustc/traits/select.rs | 4 ++-- src/librustc/ty/relate.rs | 2 +- src/librustc/ty/subst.rs | 6 ------ src/librustc_typeck/check/method/confirm.rs | 6 +++--- src/librustc_typeck/check/method/probe.rs | 4 ++-- src/librustc_typeck/check/writeback.rs | 2 +- 6 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 41f3f825c3d19..40c62762c3cf3 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -2547,7 +2547,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { // TyError and ensure they do not affect any other fields. // This could be checked after type collection for any struct // with a potentially unsized trailing field. - let params = substs_a.params().iter().enumerate().map(|(i, &k)| { + let params = substs_a.iter().enumerate().map(|(i, &k)| { if ty_params.contains(i) { Kind::from(tcx.types.err) } else { @@ -2567,7 +2567,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { // Check that the source structure with the target's // type parameters is a subtype of the target. - let params = substs_a.params().iter().enumerate().map(|(i, &k)| { + let params = substs_a.iter().enumerate().map(|(i, &k)| { if ty_params.contains(i) { Kind::from(substs_b.type_at(i)) } else { diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index adedf78bba7c0..2e3009b4ed6db 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -143,7 +143,7 @@ pub fn relate_substs<'a, 'gcx, 'tcx, R>(relation: &mut R, { let tcx = relation.tcx(); - let params = a_subst.params().iter().zip(b_subst.params()).enumerate().map(|(i, (a, b))| { + let params = a_subst.iter().zip(b_subst).enumerate().map(|(i, (a, b))| { let variance = variances.map_or(ty::Invariant, |v| v[i]); if let (Some(a_ty), Some(b_ty)) = (a.as_type(), b.as_type()) { Ok(Kind::from(relation.relate_with_variance(variance, &a_ty, &b_ty)?)) diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index d6f61a12a3c6e..c0a529b936b0f 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -254,12 +254,6 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> { self.is_empty() } - #[inline] - pub fn params(&self) -> &[Kind<'tcx>] { - // FIXME (dikaiosune) this should be removed, and corresponding compilation errors fixed - self - } - #[inline] pub fn types(&'a self) -> impl DoubleEndedIterator> + 'a { self.iter().filter_map(|k| k.as_type()) diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index ff9eaa012ba41..2d90394025d21 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -309,17 +309,17 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { // parameters from the type and those from the method. // // FIXME -- permit users to manually specify lifetimes - let supplied_start = substs.params().len() + method_generics.regions.len(); + let supplied_start = substs.len() + method_generics.regions.len(); Substs::for_item(self.tcx, pick.item.def_id, |def, _| { let i = def.index as usize; - if i < substs.params().len() { + if i < substs.len() { substs.region_at(i) } else { self.region_var_for_def(self.span, def) } }, |def, cur_substs| { let i = def.index as usize; - if i < substs.params().len() { + if i < substs.len() { substs.type_at(i) } else if supplied_method_types.is_empty() { self.type_var_for_def(self.span, def, cur_substs) diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 201a223c15f15..fd29ff0be43b4 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1326,7 +1326,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { } else { let substs = Substs::for_item(self.tcx, method, |def, _| { let i = def.index as usize; - if i < substs.params().len() { + if i < substs.len() { substs.region_at(i) } else { // In general, during probe we erase regions. See @@ -1335,7 +1335,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { } }, |def, cur_substs| { let i = def.index as usize; - if i < substs.params().len() { + if i < substs.len() { substs.type_at(i) } else { self.type_var_for_def(self.span, def, cur_substs) diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 28156dd616b3a..a292227058379 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -100,7 +100,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { let gcx = fcx.tcx.global_tcx(); let free_substs = fcx.parameter_environment.free_substs; - for (i, k) in free_substs.params().iter().enumerate() { + for (i, k) in free_substs.iter().enumerate() { let r = if let Some(r) = k.as_region() { r } else { From 57895393115c61ec01fcbc9815f9821b2bfe5886 Mon Sep 17 00:00:00 2001 From: Shawn Walker-Salas Date: Wed, 15 Feb 2017 22:52:47 -0800 Subject: [PATCH 10/10] simplify home_dir by removing unnecessary getpwuid_r wrapper --- src/libstd/sys/unix/os.rs | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 1dbfa640d5251..e78928c266792 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -483,30 +483,21 @@ pub fn home_dir() -> Option { target_os = "nacl", target_os = "emscripten")))] unsafe fn fallback() -> Option { - unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd, - buf: &mut Vec) -> Option<()> { - let mut result = ptr::null_mut(); - match libc::getpwuid_r(me, passwd, buf.as_mut_ptr(), - buf.capacity(), - &mut result) { - 0 if !result.is_null() => Some(()), - _ => None - } - } - let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { n if n < 0 => 512 as usize, n => n as usize, }; let mut buf = Vec::with_capacity(amt); let mut passwd: libc::passwd = mem::zeroed(); - - if getpwduid_r(libc::getuid(), &mut passwd, &mut buf).is_some() { - let ptr = passwd.pw_dir as *const _; - let bytes = CStr::from_ptr(ptr).to_bytes().to_vec(); - Some(OsStringExt::from_vec(bytes)) - } else { - None + let mut result = ptr::null_mut(); + match libc::getpwuid_r(libc::getuid(), &mut passwd, buf.as_mut_ptr(), + buf.capacity(), &mut result) { + 0 if !result.is_null() => { + let ptr = passwd.pw_dir as *const _; + let bytes = CStr::from_ptr(ptr).to_bytes().to_vec(); + Some(OsStringExt::from_vec(bytes)) + }, + _ => None, } } }