From 27477755edcf76c7bd579661fc83d6ae2a4970eb Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Thu, 30 Aug 2018 02:05:40 +0900 Subject: [PATCH 01/48] [ci] add qemu-system-arm in docker image --- src/ci/docker/dist-various-1/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ci/docker/dist-various-1/Dockerfile b/src/ci/docker/dist-various-1/Dockerfile index e2484b7224b26..c7e6af28f9d4f 100644 --- a/src/ci/docker/dist-various-1/Dockerfile +++ b/src/ci/docker/dist-various-1/Dockerfile @@ -22,7 +22,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libssl-dev \ pkg-config \ gcc-arm-none-eabi \ - libnewlib-arm-none-eabi + libnewlib-arm-none-eabi \ + qemu-system-arm WORKDIR /build From 502023a9baeb9c0f8cc50874e74b22c526fce923 Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Mon, 3 Sep 2018 05:42:40 +0900 Subject: [PATCH 02/48] [ci] thumbv7m-none-eabi: build lm3s6965evb and runon QEMU --- src/test/run-make/thumb-none-qemu/Makefile | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/test/run-make/thumb-none-qemu/Makefile diff --git a/src/test/run-make/thumb-none-qemu/Makefile b/src/test/run-make/thumb-none-qemu/Makefile new file mode 100644 index 0000000000000..8194b949dfcdc --- /dev/null +++ b/src/test/run-make/thumb-none-qemu/Makefile @@ -0,0 +1,40 @@ +-include ../../run-make-fulldeps/tools.mk + +# How to run this +# $ ./x.py clean +# $ ./x.py test --target thumbv7m-none-eabi src/test/run-make + +ifeq ($(TARGET),thumbv7m-none-eabi)) + +# For cargo setting +RUSTC := $(RUSTC_ORIGINAL) +LD_LIBRARY_PATH := $(HOST_RPATH_DIR) +# We need to be outside of 'src' dir in order to run cargo +WORK_DIR := $(TMPDIR) + +HERE := $(shell pwd) + +CRATE := lm3s6965evb +CRATE_URL := https://github.com/japaric/lm3s6965evb +CRATE_SHA1 := 9eeea58826438e84d89e9691a1bb0f85b03d377c +QEMU_CPU := cortex-m3 +QEMU_MACHINE := lm3s6965evb + +all: + env + mkdir -p $(WORK_DIR) + -cd $(WORK_DIR) && rm -rf $(CRATE) + cd $(WORK_DIR) && bash -x $(HERE)/../git_clone_sha1.sh $(CRATE) $(CRATE_URL) $(CRATE_SHA1) + cd $(WORK_DIR)/$(CRATE) && $(CARGO) build --target $(TARGET) -v + cd $(WORK_DIR)/$(CRATE) && qemu-system-arm \ + -cpu $(QEMU_CPU) \ + -machine $(QEMU_MACHINE) \ + -semihosting-config enable=on,target=native \ + -nographic \ + -kernel target/$(TARGET)/debug/$(CRATE) > out.txt + cd $(WORK_DIR)/$(CRATE) && grep "x = 42" out.txt +else + +all: + +endif From 719a592cb08ab32d8e348796afd278a36c396c37 Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Mon, 3 Sep 2018 09:51:01 +0900 Subject: [PATCH 03/48] [ci] thumbv7m-none-eabi: add more variable. --- src/test/run-make/thumb-none-qemu/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/run-make/thumb-none-qemu/Makefile b/src/test/run-make/thumb-none-qemu/Makefile index 8194b949dfcdc..514c8348f82f1 100644 --- a/src/test/run-make/thumb-none-qemu/Makefile +++ b/src/test/run-make/thumb-none-qemu/Makefile @@ -11,14 +11,16 @@ RUSTC := $(RUSTC_ORIGINAL) LD_LIBRARY_PATH := $(HOST_RPATH_DIR) # We need to be outside of 'src' dir in order to run cargo WORK_DIR := $(TMPDIR) - HERE := $(shell pwd) + +# hint: we could set variables per $(TARGET) basis in order to support other targets. CRATE := lm3s6965evb CRATE_URL := https://github.com/japaric/lm3s6965evb CRATE_SHA1 := 9eeea58826438e84d89e9691a1bb0f85b03d377c QEMU_CPU := cortex-m3 QEMU_MACHINE := lm3s6965evb +QEMU_OUTPUT_TEXT := "x = 42" all: env @@ -32,7 +34,7 @@ all: -semihosting-config enable=on,target=native \ -nographic \ -kernel target/$(TARGET)/debug/$(CRATE) > out.txt - cd $(WORK_DIR)/$(CRATE) && grep "x = 42" out.txt + cd $(WORK_DIR)/$(CRATE) && grep $(QEMU_OUTPUT_TEXT) out.txt else all: From a04754fd365398e5445d2c4b985023350fb2c4aa Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Sun, 30 Sep 2018 09:34:51 +0900 Subject: [PATCH 04/48] [ci] run-make/thumb-none-qemu: uses cortex-m-rt crate. --- src/test/run-make/thumb-none-qemu/Makefile | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/test/run-make/thumb-none-qemu/Makefile b/src/test/run-make/thumb-none-qemu/Makefile index 514c8348f82f1..d1482a1dda49f 100644 --- a/src/test/run-make/thumb-none-qemu/Makefile +++ b/src/test/run-make/thumb-none-qemu/Makefile @@ -15,26 +15,17 @@ HERE := $(shell pwd) # hint: we could set variables per $(TARGET) basis in order to support other targets. -CRATE := lm3s6965evb -CRATE_URL := https://github.com/japaric/lm3s6965evb -CRATE_SHA1 := 9eeea58826438e84d89e9691a1bb0f85b03d377c -QEMU_CPU := cortex-m3 -QEMU_MACHINE := lm3s6965evb -QEMU_OUTPUT_TEXT := "x = 42" +CRATE := cortex-m-rt +CRATE_URL := https://github.com/rust-embedded/cortex-m-rt +CRATE_SHA1 := 62972c8a89ff54b76f9ef0d600c1fcf7a233aabd all: env mkdir -p $(WORK_DIR) -cd $(WORK_DIR) && rm -rf $(CRATE) cd $(WORK_DIR) && bash -x $(HERE)/../git_clone_sha1.sh $(CRATE) $(CRATE_URL) $(CRATE_SHA1) - cd $(WORK_DIR)/$(CRATE) && $(CARGO) build --target $(TARGET) -v - cd $(WORK_DIR)/$(CRATE) && qemu-system-arm \ - -cpu $(QEMU_CPU) \ - -machine $(QEMU_MACHINE) \ - -semihosting-config enable=on,target=native \ - -nographic \ - -kernel target/$(TARGET)/debug/$(CRATE) > out.txt - cd $(WORK_DIR)/$(CRATE) && grep $(QEMU_OUTPUT_TEXT) out.txt + cd $(WORK_DIR)/$(CRATE) && $(CARGO) run --target $(TARGET) --example qemu | grep "x = 42" + cd $(WORK_DIR)/$(CRATE) && $(CARGO) run --target $(TARGET) --example qemu --release | grep "x = 42" else all: From fdf4d6efac79de2df444ee4975b381b43d76dee1 Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Sun, 30 Sep 2018 10:55:49 +0900 Subject: [PATCH 05/48] [ci] run-make/thumb-none-qemu: add thumbv6m-none-qemu --- src/test/run-make/thumb-none-qemu/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make/thumb-none-qemu/Makefile b/src/test/run-make/thumb-none-qemu/Makefile index d1482a1dda49f..518b2ec643175 100644 --- a/src/test/run-make/thumb-none-qemu/Makefile +++ b/src/test/run-make/thumb-none-qemu/Makefile @@ -4,7 +4,7 @@ # $ ./x.py clean # $ ./x.py test --target thumbv7m-none-eabi src/test/run-make -ifeq ($(TARGET),thumbv7m-none-eabi)) +ifneq (,$(filter $(TARGET),thumbv6m-none-eabi thumbv7m-none-eabi)) # For cargo setting RUSTC := $(RUSTC_ORIGINAL) From 8b097c4ce92869b012c36ba0c7c0a2a096a17849 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 4 Oct 2018 16:23:22 +0200 Subject: [PATCH 06/48] Don't try to promote already promoted out temporaries --- src/librustc_mir/transform/promote_consts.rs | 2 ++ src/librustc_mir/transform/qualify_consts.rs | 18 ++++++++++++++---- .../ui/consts/const-eval/double_promotion.rs | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/consts/const-eval/double_promotion.rs diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 34339b0634194..bba9260f2b829 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -332,6 +332,8 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let operand = Operand::Copy(promoted_place(ty, span)); mem::replace(&mut args[index], operand) } + // already promoted out + TerminatorKind::Goto { .. } => return, _ => bug!() } } diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 17fe78d325cf1..4808f02c1dff4 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -812,7 +812,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { let fn_ty = func.ty(self.mir, self.tcx); let mut callee_def_id = None; - let (mut is_shuffle, mut is_const_fn) = (false, false); + let mut is_shuffle = false; + let mut is_const_fn = false; + let mut is_promotable_const_fn = false; if let ty::FnDef(def_id, _) = fn_ty.sty { callee_def_id = Some(def_id); match self.tcx.fn_sig(def_id).abi() { @@ -873,6 +875,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { // functions without #[rustc_promotable] if self.tcx.is_promotable_const_fn(def_id) { is_const_fn = true; + is_promotable_const_fn = true; + } else if self.tcx.is_const_fn(def_id) { + is_const_fn = true; } } else { // stable const fn or unstable const fns with their feature gate @@ -974,7 +979,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { if !constant_arguments.contains(&i) { return } - if this.qualif.is_empty() { + // if the argument requires a constant, we care about constness, not + // promotability + if (this.qualif - Qualif::NOT_PROMOTABLE).is_empty() { this.promotion_candidates.push(candidate); } else { this.tcx.sess.span_err(this.span, @@ -985,7 +992,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { } // non-const fn calls. - if !is_const_fn { + if is_const_fn { + if !is_promotable_const_fn && self.mode == Mode::Fn { + self.qualif = Qualif::NOT_PROMOTABLE; + } + } else { self.qualif = Qualif::NOT_CONST; if self.mode != Mode::Fn { self.tcx.sess.delay_span_bug( @@ -1003,7 +1014,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { // Be conservative about the returned value of a const fn. let tcx = self.tcx; let ty = dest.ty(self.mir, tcx).to_ty(tcx); - self.qualif = Qualif::empty(); self.add_type(ty); } self.assign(dest, location); diff --git a/src/test/ui/consts/const-eval/double_promotion.rs b/src/test/ui/consts/const-eval/double_promotion.rs new file mode 100644 index 0000000000000..0e75ea8e66b3c --- /dev/null +++ b/src/test/ui/consts/const-eval/double_promotion.rs @@ -0,0 +1,17 @@ +// compile-pass + +#![feature(const_fn, rustc_attrs)] + +#[rustc_args_required_const(0)] +pub const fn a(value: u8) -> u8 { + value +} + +#[rustc_args_required_const(0)] +pub fn b(_: u8) { + unimplemented!() +} + +fn main() { + let _ = b(a(0)); +} From 7d3d835c58e789127744076c97110664ea9c6087 Mon Sep 17 00:00:00 2001 From: Philip Munksgaard Date: Thu, 4 Oct 2018 22:17:01 +0200 Subject: [PATCH 07/48] replace escape-rust-expr test with dont-show-const-contents The old test was supposed to check for proper html escaping when showing the contents of constants. This was changed as part of #53409. The revised test asserts that the contents of the constant is not shown as part of the generated documentation. --- .../{escape-rust-expr.rs => dont-show-const-contents.rs} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename src/test/rustdoc/{escape-rust-expr.rs => dont-show-const-contents.rs} (64%) diff --git a/src/test/rustdoc/escape-rust-expr.rs b/src/test/rustdoc/dont-show-const-contents.rs similarity index 64% rename from src/test/rustdoc/escape-rust-expr.rs rename to src/test/rustdoc/dont-show-const-contents.rs index 4594eb95ea18e..1392c62b4abb1 100644 --- a/src/test/rustdoc/escape-rust-expr.rs +++ b/src/test/rustdoc/dont-show-const-contents.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Test that we HTML-escape Rust expressions, where HTML special chars -// can occur, and we know it's definitely not markup. +// Test that the contents of constants are not displayed as part of the +// documentation. -// @!has escape_rust_expr/constant.CONST_S.html '//pre[@class="rust const"]' '"