Skip to content

Commit 4e1c5f0

Browse files
committed
Auto merge of #69535 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] backports This backports the following PRs: * ci: switch macOS builders to 10.15 #68863 * Backport release notes of 1.41.1 #69468 * Cherry-pick the LLVM fix for #69225 #69450 * `lit_to_const`: gracefully bubble up type errors. #69330 * [beta] bootstrap from 1.41.1 stable #69518 * bootstrap: Configure cmake when building sanitizer runtimes #69104 r? @ghost
2 parents 13e0fbc + d620bec commit 4e1c5f0

File tree

18 files changed

+126
-73
lines changed

18 files changed

+126
-73
lines changed

RELEASES.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Version 1.41.1 (2020-02-27)
2+
===========================
3+
4+
* [Always check types of static items][69145]
5+
* [Always check lifetime bounds of `Copy` impls][69145]
6+
* [Fix miscompilation in callers of `Layout::repeat`][69225]
7+
8+
[69225]: https://github.com/rust-lang/rust/issues/69225
9+
[69145]: https://github.com/rust-lang/rust/pull/69145
10+
111
Version 1.41.0 (2020-01-30)
212
===========================
313

src/bootstrap/native.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl Step for Llvm {
264264
cfg.define("PYTHON_EXECUTABLE", python);
265265
}
266266

267-
configure_cmake(builder, target, &mut cfg);
267+
configure_cmake(builder, target, &mut cfg, true);
268268

269269
// FIXME: we don't actually need to build all LLVM tools and all LLVM
270270
// libraries here, e.g., we just want a few components and a few
@@ -303,7 +303,12 @@ fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) {
303303
panic!("\n\nbad LLVM version: {}, need >=7.0\n\n", version)
304304
}
305305

306-
fn configure_cmake(builder: &Builder<'_>, target: Interned<String>, cfg: &mut cmake::Config) {
306+
fn configure_cmake(
307+
builder: &Builder<'_>,
308+
target: Interned<String>,
309+
cfg: &mut cmake::Config,
310+
use_compiler_launcher: bool,
311+
) {
307312
// Do not print installation messages for up-to-date files.
308313
// LLVM and LLD builds can produce a lot of those and hit CI limits on log size.
309314
cfg.define("CMAKE_INSTALL_MESSAGE", "LAZY");
@@ -374,9 +379,11 @@ fn configure_cmake(builder: &Builder<'_>, target: Interned<String>, cfg: &mut cm
374379
} else {
375380
// If ccache is configured we inform the build a little differently how
376381
// to invoke ccache while also invoking our compilers.
377-
if let Some(ref ccache) = builder.config.ccache {
378-
cfg.define("CMAKE_C_COMPILER_LAUNCHER", ccache)
379-
.define("CMAKE_CXX_COMPILER_LAUNCHER", ccache);
382+
if use_compiler_launcher {
383+
if let Some(ref ccache) = builder.config.ccache {
384+
cfg.define("CMAKE_C_COMPILER_LAUNCHER", ccache)
385+
.define("CMAKE_CXX_COMPILER_LAUNCHER", ccache);
386+
}
380387
}
381388
cfg.define("CMAKE_C_COMPILER", sanitize_cc(cc))
382389
.define("CMAKE_CXX_COMPILER", sanitize_cc(cxx));
@@ -460,7 +467,7 @@ impl Step for Lld {
460467
t!(fs::create_dir_all(&out_dir));
461468

462469
let mut cfg = cmake::Config::new(builder.src.join("src/llvm-project/lld"));
463-
configure_cmake(builder, target, &mut cfg);
470+
configure_cmake(builder, target, &mut cfg, true);
464471

465472
// This is an awful, awful hack. Discovered when we migrated to using
466473
// clang-cl to compile LLVM/LLD it turns out that LLD, when built out of
@@ -597,10 +604,7 @@ impl Step for Sanitizers {
597604
let _time = util::timeit(&builder);
598605

599606
let mut cfg = cmake::Config::new(&compiler_rt_dir);
600-
cfg.target(&self.target);
601-
cfg.host(&builder.config.build);
602607
cfg.profile("Release");
603-
604608
cfg.define("CMAKE_C_COMPILER_TARGET", self.target);
605609
cfg.define("COMPILER_RT_BUILD_BUILTINS", "OFF");
606610
cfg.define("COMPILER_RT_BUILD_CRT", "OFF");
@@ -612,6 +616,12 @@ impl Step for Sanitizers {
612616
cfg.define("COMPILER_RT_USE_LIBCXX", "OFF");
613617
cfg.define("LLVM_CONFIG_PATH", &llvm_config);
614618

619+
// On Darwin targets the sanitizer runtimes are build as universal binaries.
620+
// Unfortunately sccache currently lacks support to build them successfully.
621+
// Disable compiler launcher on Darwin targets to avoid potential issues.
622+
let use_compiler_launcher = !self.target.contains("apple-darwin");
623+
configure_cmake(builder, self.target, &mut cfg, use_compiler_launcher);
624+
615625
t!(fs::create_dir_all(&out_dir));
616626
cfg.out_dir(out_dir);
617627

src/bootstrap/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1050,10 +1050,10 @@ impl Step for Compiletest {
10501050
cmd.arg("--docck-python").arg(builder.python());
10511051

10521052
if builder.config.build.ends_with("apple-darwin") {
1053-
// Force /usr/bin/python on macOS for LLDB tests because we're loading the
1053+
// Force /usr/bin/python3 on macOS for LLDB tests because we're loading the
10541054
// LLDB plugin's compiled module which only works with the system python
10551055
// (namely not Homebrew-installed python)
1056-
cmd.arg("--lldb-python").arg("/usr/bin/python");
1056+
cmd.arg("--lldb-python").arg("/usr/bin/python3");
10571057
} else {
10581058
cmd.arg("--lldb-python").arg(builder.python());
10591059
}

src/ci/azure-pipelines/auto.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
- job: macOS
6464
timeoutInMinutes: 600
6565
pool:
66-
vmImage: macos-10.13
66+
vmImage: macos-10.15
6767
steps:
6868
- template: steps/run.yml
6969
strategy:

src/ci/azure-pipelines/steps/run.yml

-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ steps:
5151
displayName: Install clang
5252
condition: and(succeeded(), not(variables.SKIP_JOB))
5353

54-
- bash: src/ci/scripts/switch-xcode.sh
55-
displayName: Switch to Xcode 9.3
56-
condition: and(succeeded(), not(variables.SKIP_JOB))
57-
5854
- bash: src/ci/scripts/install-wix.sh
5955
displayName: Install wix
6056
condition: and(succeeded(), not(variables.SKIP_JOB))

src/ci/azure-pipelines/try.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
# - job: macOS
2626
# timeoutInMinutes: 600
2727
# pool:
28-
# vmImage: macos-10.13
28+
# vmImage: macos-10.15
2929
# steps:
3030
# - template: steps/run.yml
3131
# strategy:

src/ci/scripts/install-clang.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ if isMacOS; then
1919
# native clang is configured to use the correct path, but our custom one
2020
# doesn't. This sets the SDKROOT environment variable to the SDK so that
2121
# our own clang can figure out the correct include path on its own.
22-
if ! [[ -d "/usr/include" ]]; then
23-
ciCommandSetEnv SDKROOT "$(xcrun --sdk macosx --show-sdk-path)"
24-
fi
22+
ciCommandSetEnv SDKROOT "$(xcrun --sdk macosx --show-sdk-path)"
2523

2624
# Configure `AR` specifically so rustbuild doesn't try to infer it as
2725
# `clang-ar` by accident.

src/ci/scripts/switch-xcode.sh

-13
This file was deleted.

src/librustc/mir/interpret/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ pub struct LitToConstInput<'tcx> {
162162
/// Error type for `tcx.lit_to_const`.
163163
#[derive(Copy, Clone, Debug, Eq, PartialEq, HashStable)]
164164
pub enum LitToConstError {
165+
/// The literal's inferred type did not match the expected `ty` in the input.
166+
/// This is used for graceful error handling (`delay_span_bug`) in
167+
/// type checking (`AstConv::ast_const_to_const`).
168+
TypeError,
165169
UnparseableFloat,
166170
Reported,
167171
}

src/librustc_mir_build/hair/constant.rs

+22-37
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc::mir::interpret::{
22
truncate, Allocation, ConstValue, LitToConstError, LitToConstInput, Scalar,
33
};
4-
use rustc::ty::{self, layout::Size, ParamEnv, TyCtxt};
4+
use rustc::ty::{self, layout::Size, ParamEnv, TyCtxt, TyS};
55
use rustc_span::symbol::Symbol;
66
use syntax::ast;
77

@@ -20,50 +20,35 @@ crate fn lit_to_const<'tcx>(
2020
Ok(ConstValue::Scalar(Scalar::from_uint(result, width)))
2121
};
2222

23-
let lit = match *lit {
24-
ast::LitKind::Str(ref s, _) => {
23+
let lit = match (lit, &ty.kind) {
24+
(ast::LitKind::Str(s, _), ty::Ref(_, TyS { kind: ty::Str, .. }, _)) => {
2525
let s = s.as_str();
2626
let allocation = Allocation::from_byte_aligned_bytes(s.as_bytes());
2727
let allocation = tcx.intern_const_alloc(allocation);
2828
ConstValue::Slice { data: allocation, start: 0, end: s.len() }
2929
}
30-
ast::LitKind::ByteStr(ref data) => {
31-
if let ty::Ref(_, ref_ty, _) = ty.kind {
32-
match ref_ty.kind {
33-
ty::Slice(_) => {
34-
let allocation = Allocation::from_byte_aligned_bytes(data as &Vec<u8>);
35-
let allocation = tcx.intern_const_alloc(allocation);
36-
ConstValue::Slice { data: allocation, start: 0, end: data.len() }
37-
}
38-
ty::Array(_, _) => {
39-
let id = tcx.allocate_bytes(data);
40-
ConstValue::Scalar(Scalar::Ptr(id.into()))
41-
}
42-
_ => {
43-
bug!("bytestring should have type of either &[u8] or &[u8; _], not {}", ty)
44-
}
45-
}
46-
} else {
47-
bug!("bytestring should have type of either &[u8] or &[u8; _], not {}", ty)
48-
}
30+
(ast::LitKind::ByteStr(data), ty::Ref(_, TyS { kind: ty::Slice(_), .. }, _)) => {
31+
let allocation = Allocation::from_byte_aligned_bytes(data as &Vec<u8>);
32+
let allocation = tcx.intern_const_alloc(allocation);
33+
ConstValue::Slice { data: allocation, start: 0, end: data.len() }
34+
}
35+
(ast::LitKind::ByteStr(data), ty::Ref(_, TyS { kind: ty::Array(_, _), .. }, _)) => {
36+
let id = tcx.allocate_bytes(data);
37+
ConstValue::Scalar(Scalar::Ptr(id.into()))
38+
}
39+
(ast::LitKind::Byte(n), ty::Uint(ast::UintTy::U8)) => {
40+
ConstValue::Scalar(Scalar::from_uint(*n, Size::from_bytes(1)))
4941
}
50-
ast::LitKind::Byte(n) => ConstValue::Scalar(Scalar::from_uint(n, Size::from_bytes(1))),
51-
ast::LitKind::Int(n, _) if neg => {
52-
let n = n as i128;
53-
let n = n.overflowing_neg().0;
54-
trunc(n as u128)?
42+
(ast::LitKind::Int(n, _), ty::Uint(_)) | (ast::LitKind::Int(n, _), ty::Int(_)) => {
43+
trunc(if neg { (*n as i128).overflowing_neg().0 as u128 } else { *n })?
5544
}
56-
ast::LitKind::Int(n, _) => trunc(n)?,
57-
ast::LitKind::Float(n, _) => {
58-
let fty = match ty.kind {
59-
ty::Float(fty) => fty,
60-
_ => bug!(),
61-
};
62-
parse_float(n, fty, neg).map_err(|_| LitToConstError::UnparseableFloat)?
45+
(ast::LitKind::Float(n, _), ty::Float(fty)) => {
46+
parse_float(*n, *fty, neg).map_err(|_| LitToConstError::UnparseableFloat)?
6347
}
64-
ast::LitKind::Bool(b) => ConstValue::Scalar(Scalar::from_bool(b)),
65-
ast::LitKind::Char(c) => ConstValue::Scalar(Scalar::from_char(c)),
66-
ast::LitKind::Err(_) => return Err(LitToConstError::Reported),
48+
(ast::LitKind::Bool(b), ty::Bool) => ConstValue::Scalar(Scalar::from_bool(*b)),
49+
(ast::LitKind::Char(c), ty::Char) => ConstValue::Scalar(Scalar::from_char(*c)),
50+
(ast::LitKind::Err(_), _) => return Err(LitToConstError::Reported),
51+
_ => return Err(LitToConstError::TypeError),
6752
};
6853
Ok(tcx.mk_const(ty::Const { val: ty::ConstKind::Value(lit), ty }))
6954
}

src/librustc_mir_build/hair/cx/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> {
148148
// create a dummy value and continue compiling
149149
Const::from_bits(self.tcx, 0, self.param_env.and(ty))
150150
}
151+
Err(LitToConstError::TypeError) => bug!("const_eval_literal: had type error"),
151152
}
152153
}
153154

src/librustc_mir_build/hair/pattern/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
843843
PatKind::Wild
844844
}
845845
Err(LitToConstError::Reported) => PatKind::Wild,
846+
Err(LitToConstError::TypeError) => bug!("lower_lit: had type error"),
846847
}
847848
}
848849
}

src/librustc_typeck/astconv.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2738,6 +2738,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27382738
// mir.
27392739
if let Ok(c) = tcx.at(expr.span).lit_to_const(lit_input) {
27402740
return c;
2741+
} else {
2742+
tcx.sess.delay_span_bug(expr.span, "ast_const_to_const: couldn't lit_to_const");
27412743
}
27422744
}
27432745

src/stage0.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
# source tarball for a stable release you'll likely see `1.x.0` for rustc and
1313
# `0.x.0` for Cargo where they were released on `date`.
1414

15-
date: 2020-01-30
16-
rustc: 1.41.0
15+
date: 2020-02-27
16+
rustc: 1.41.1
1717
cargo: 0.42.0
1818

1919
# We use a nightly rustfmt to format the source because it solves some bootstrapping
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This is a regression test for #69310, which was injected by #68118.
2+
// The issue here was that as a performance optimization,
3+
// we call the query `lit_to_const(input);`.
4+
// However, the literal `input.lit` would not be of the type expected by `input.ty`.
5+
// As a result, we immediately called `bug!(...)` instead of bubbling up the problem
6+
// so that it could be handled by the caller of `lit_to_const` (`ast_const_to_const`).
7+
8+
fn main() {}
9+
10+
const A: [(); 0.1] = [()]; //~ ERROR mismatched types
11+
const B: [(); b"a"] = [()]; //~ ERROR mismatched types
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-69310-array-size-lit-wrong-ty.rs:10:15
3+
|
4+
LL | const A: [(); 0.1] = [()];
5+
| ^^^ expected `usize`, found floating-point number
6+
7+
error[E0308]: mismatched types
8+
--> $DIR/issue-69310-array-size-lit-wrong-ty.rs:11:15
9+
|
10+
LL | const B: [(); b"a"] = [()];
11+
| ^^^^ expected `usize`, found `&[u8; 1]`
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// run-fail
2+
// compile-flags: -C opt-level=3
3+
// error-pattern: index out of bounds: the len is 0 but the index is 16777216
4+
// ignore-wasm no panic or subprocess support
5+
// ignore-emscripten no panic or subprocess support
6+
7+
fn do_test(x: usize) {
8+
let mut arr = vec![vec![0u8; 3]];
9+
10+
let mut z = vec![0];
11+
for arr_ref in arr.iter_mut() {
12+
for y in 0..x {
13+
for _ in 0..1 {
14+
z.reserve_exact(x);
15+
let iterator = std::iter::repeat(0).take(x);
16+
let mut cnt = 0;
17+
iterator.for_each(|_| {
18+
z[0] = 0;
19+
cnt += 1;
20+
});
21+
let a = y * x;
22+
let b = (y + 1) * x - 1;
23+
let slice = &mut arr_ref[a..b];
24+
slice[1 << 24] += 1;
25+
}
26+
}
27+
}
28+
}
29+
30+
fn main() {
31+
do_test(1);
32+
do_test(2);
33+
}

0 commit comments

Comments
 (0)