Skip to content

Commit 548afdb

Browse files
committed
Auto merge of #70726 - Centril:rollup-zrdkkpt, r=Centril
Rollup of 5 pull requests Successful merges: - #68334 (AArch64 bare-metal targets: Build rust-std) - #70224 (Clean up rustdoc js testers) - #70532 (Miri engine: stronger type-based sanity check for assignments) - #70698 (bootstrap: add `--json-output` for rust-analyzer) - #70715 (Fix typo in operands section) Failed merges: r? @ghost
2 parents c53e4b3 + c2372f1 commit 548afdb

File tree

14 files changed

+448
-643
lines changed

14 files changed

+448
-643
lines changed

src/bootstrap/compile.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,11 @@ pub fn stream_cargo(
935935
}
936936
// Instruct Cargo to give us json messages on stdout, critically leaving
937937
// stderr as piped so we can get those pretty colors.
938-
let mut message_format = String::from("json-render-diagnostics");
938+
let mut message_format = if builder.config.json_output {
939+
String::from("json")
940+
} else {
941+
String::from("json-render-diagnostics")
942+
};
939943
if let Some(s) = &builder.config.rustc_error_format {
940944
message_format.push_str(",json-diagnostic-");
941945
message_format.push_str(s);

src/bootstrap/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub struct Config {
4848
pub ignore_git: bool,
4949
pub exclude: Vec<PathBuf>,
5050
pub rustc_error_format: Option<String>,
51+
pub json_output: bool,
5152
pub test_compare_mode: bool,
5253
pub llvm_libunwind: bool,
5354

@@ -415,6 +416,7 @@ impl Config {
415416
let mut config = Config::default_opts();
416417
config.exclude = flags.exclude;
417418
config.rustc_error_format = flags.rustc_error_format;
419+
config.json_output = flags.json_output;
418420
config.on_fail = flags.on_fail;
419421
config.stage = flags.stage;
420422
config.jobs = flags.jobs.map(threads_from_config);

src/bootstrap/flags.rs

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub struct Flags {
3131
pub incremental: bool,
3232
pub exclude: Vec<PathBuf>,
3333
pub rustc_error_format: Option<String>,
34+
pub json_output: bool,
3435
pub dry_run: bool,
3536

3637
// This overrides the deny-warnings configuration option,
@@ -156,6 +157,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
156157
"VALUE",
157158
);
158159
opts.optopt("", "error-format", "rustc error format", "FORMAT");
160+
opts.optflag("", "json-output", "use message-format=json");
159161
opts.optopt(
160162
"",
161163
"llvm-skip-rebuild",
@@ -503,6 +505,7 @@ Arguments:
503505
dry_run: matches.opt_present("dry-run"),
504506
on_fail: matches.opt_str("on-fail"),
505507
rustc_error_format: matches.opt_str("error-format"),
508+
json_output: matches.opt_present("json-output"),
506509
keep_stage: matches
507510
.opt_strs("keep-stage")
508511
.into_iter()

src/ci/docker/dist-various-1/Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ RUN ./install-mips-musl.sh
7272
COPY dist-various-1/install-mipsel-musl.sh /build
7373
RUN ./install-mipsel-musl.sh
7474

75+
COPY dist-various-1/install-aarch64-none-elf.sh /build
76+
RUN ./install-aarch64-none-elf.sh
77+
7578
# Suppress some warnings in the openwrt toolchains we downloaded
7679
ENV STAGING_DIR=/tmp
7780

@@ -140,6 +143,8 @@ ENV TARGETS=$TARGETS,armv5te-unknown-linux-gnueabi
140143
ENV TARGETS=$TARGETS,armv5te-unknown-linux-musleabi
141144
ENV TARGETS=$TARGETS,armv7-unknown-linux-musleabihf
142145
ENV TARGETS=$TARGETS,aarch64-unknown-linux-musl
146+
ENV TARGETS=$TARGETS,aarch64-unknown-none
147+
ENV TARGETS=$TARGETS,aarch64-unknown-none-softfloat
143148
ENV TARGETS=$TARGETS,sparc64-unknown-linux-gnu
144149
ENV TARGETS=$TARGETS,x86_64-unknown-redox
145150
ENV TARGETS=$TARGETS,thumbv6m-none-eabi
@@ -178,6 +183,10 @@ ENV CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \
178183
CC_armv7a_none_eabihf=arm-none-eabi-gcc \
179184
CFLAGS_armv7a_none_eabi=-march=armv7-a \
180185
CFLAGS_armv7a_none_eabihf=-march=armv7-a+vfpv3 \
186+
CC_aarch64_unknown_none_softfloat=aarch64-none-elf-gcc \
187+
CFLAGS_aarch64_unknown_none_softfloat=-mstrict-align -march=armv8-a+nofp+nosimd \
188+
CC_aarch64_unknown_none=aarch64-none-elf-gcc \
189+
CFLAGS_aarch64_unknown_none=-mstrict-align -march=armv8-a+fp+simd \
181190
CC_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-gcc \
182191
AR_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-ar \
183192
CXX_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-g++ \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
curl -L https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf.tar.xz \
6+
| tar --extract --xz --strip 1 --directory /usr/local

src/doc/unstable-book/src/library-features/llvm-asm.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ llvm_asm!("xor %eax, %eax" ::: "eax");
8686

8787
Input and output operands follow the same format: `:
8888
"constraints1"(expr1), "constraints2"(expr2), ..."`. Output operand
89-
expressions must be mutable lvalues, or not yet assigned:
89+
expressions must be mutable place, or not yet assigned:
9090

9191
```rust
9292
# #![feature(llvm_asm)]

src/librustc_mir/interpret/eval_context.rs

+49-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::ty::query::TyCtxtAt;
1818
use rustc_middle::ty::subst::SubstsRef;
1919
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
2020
use rustc_span::source_map::DUMMY_SP;
21-
use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Size, TargetDataLayout};
21+
use rustc_target::abi::{Abi, Align, HasDataLayout, LayoutOf, Size, TargetDataLayout};
2222

2323
use super::{
2424
Immediate, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory, OpTy, Operand, Place, PlaceTy,
@@ -210,6 +210,53 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> {
210210
}
211211
}
212212

213+
/// Test if it is valid for a MIR assignment to assign `src`-typed place to `dest`-typed value.
214+
/// This test should be symmetric, as it is primarily about layout compatibility.
215+
pub(super) fn mir_assign_valid_types<'tcx>(
216+
src: TyAndLayout<'tcx>,
217+
dest: TyAndLayout<'tcx>,
218+
) -> bool {
219+
if src.ty == dest.ty {
220+
// Equal types, all is good.
221+
return true;
222+
}
223+
// Type-changing assignments can happen for (at least) two reasons:
224+
// - `&mut T` -> `&T` gets optimized from a reborrow to a mere assignment.
225+
// - Subtyping is used. While all normal lifetimes are erased, higher-ranked lifetime
226+
// bounds are still around and can lead to type differences.
227+
// There is no good way to check the latter, so we compare layouts instead -- but only
228+
// for values with `Scalar`/`ScalarPair` abi.
229+
// FIXME: Do something more accurate, type-based.
230+
match &src.abi {
231+
Abi::Scalar(..) | Abi::ScalarPair(..) => src.layout == dest.layout,
232+
_ => false,
233+
}
234+
}
235+
236+
/// Use the already known layout if given (but sanity check in debug mode),
237+
/// or compute the layout.
238+
#[cfg_attr(not(debug_assertions), inline(always))]
239+
pub(super) fn from_known_layout<'tcx>(
240+
known_layout: Option<TyAndLayout<'tcx>>,
241+
compute: impl FnOnce() -> InterpResult<'tcx, TyAndLayout<'tcx>>,
242+
) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
243+
match known_layout {
244+
None => compute(),
245+
Some(known_layout) => {
246+
if cfg!(debug_assertions) {
247+
let check_layout = compute()?;
248+
assert!(
249+
mir_assign_valid_types(check_layout, known_layout),
250+
"expected type differs from actual type.\nexpected: {:?}\nactual: {:?}",
251+
known_layout.ty,
252+
check_layout.ty,
253+
);
254+
}
255+
Ok(known_layout)
256+
}
257+
}
258+
}
259+
213260
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
214261
pub fn new(
215262
tcx: TyCtxtAt<'tcx>,
@@ -377,7 +424,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
377424
// have to support that case (mostly by skipping all caching).
378425
match frame.locals.get(local).and_then(|state| state.layout.get()) {
379426
None => {
380-
let layout = crate::interpret::operand::from_known_layout(layout, || {
427+
let layout = from_known_layout(layout, || {
381428
let local_ty = frame.body.local_decls[local].ty;
382429
let local_ty =
383430
self.subst_from_frame_and_normalize_erasing_regions(frame, local_ty);

src/librustc_mir/interpret/mod.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@ mod visitor;
1818
pub use rustc_middle::mir::interpret::*; // have all the `interpret` symbols in one place: here
1919

2020
pub use self::eval_context::{Frame, InterpCx, LocalState, LocalValue, StackPopCleanup};
21-
22-
pub use self::place::{MPlaceTy, MemPlace, MemPlaceMeta, Place, PlaceTy};
23-
24-
pub use self::memory::{AllocCheck, FnVal, Memory, MemoryKind};
25-
21+
pub use self::intern::{intern_const_alloc_recursive, InternKind};
2622
pub use self::machine::{AllocMap, Machine, MayLeak, StackPopJump};
27-
28-
pub use self::operand::{ImmTy, Immediate, OpTy, Operand, ScalarMaybeUndef};
29-
30-
pub use self::visitor::{MutValueVisitor, ValueVisitor};
31-
23+
pub use self::memory::{AllocCheck, FnVal, Memory, MemoryKind};
24+
pub use self::operand::{ImmTy, Immediate, OpTy, Operand};
25+
pub use self::place::{MPlaceTy, MemPlace, MemPlaceMeta, Place, PlaceTy};
3226
pub use self::validity::RefTracking;
33-
34-
pub use self::intern::{intern_const_alloc_recursive, InternKind};
27+
pub use self::visitor::{MutValueVisitor, ValueVisitor};
3528

3629
crate use self::intrinsics::eval_nullary_intrinsic;
30+
use eval_context::{from_known_layout, mir_assign_valid_types};

src/librustc_mir/interpret/operand.rs

+6-29
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
//! All high-level functions to read from memory work on operands as sources.
33
44
use std::convert::TryFrom;
5+
use std::fmt::Write;
56

6-
use super::{InterpCx, MPlaceTy, Machine, MemPlace, Place, PlaceTy};
77
use rustc_hir::def::Namespace;
88
use rustc_macros::HashStable;
9-
pub use rustc_middle::mir::interpret::ScalarMaybeUndef;
10-
use rustc_middle::mir::interpret::{
11-
sign_extend, truncate, AllocId, ConstValue, GlobalId, InterpResult, Pointer, Scalar,
12-
};
139
use rustc_middle::ty::layout::{IntegerExt, PrimitiveExt, TyAndLayout};
1410
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Printer};
1511
use rustc_middle::ty::Ty;
1612
use rustc_middle::{mir, ty};
1713
use rustc_target::abi::{Abi, DiscriminantKind, HasDataLayout, Integer, LayoutOf, Size};
1814
use rustc_target::abi::{VariantIdx, Variants};
19-
use std::fmt::Write;
15+
16+
use super::{
17+
from_known_layout, sign_extend, truncate, AllocId, ConstValue, GlobalId, InterpCx,
18+
InterpResult, MPlaceTy, Machine, MemPlace, Place, PlaceTy, Pointer, Scalar, ScalarMaybeUndef,
19+
};
2020

2121
/// An `Immediate` represents a single immediate self-contained Rust value.
2222
///
@@ -203,29 +203,6 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
203203
}
204204
}
205205

206-
// Use the existing layout if given (but sanity check in debug mode),
207-
// or compute the layout.
208-
#[inline(always)]
209-
pub(super) fn from_known_layout<'tcx>(
210-
layout: Option<TyAndLayout<'tcx>>,
211-
compute: impl FnOnce() -> InterpResult<'tcx, TyAndLayout<'tcx>>,
212-
) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
213-
match layout {
214-
None => compute(),
215-
Some(layout) => {
216-
if cfg!(debug_assertions) {
217-
let layout2 = compute()?;
218-
assert_eq!(
219-
layout.layout, layout2.layout,
220-
"mismatch in layout of supposedly equal-layout types {:?} and {:?}",
221-
layout.ty, layout2.ty
222-
);
223-
}
224-
Ok(layout)
225-
}
226-
}
227-
}
228-
229206
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
230207
/// Normalice `place.ptr` to a `Pointer` if this is a place and not a ZST.
231208
/// Can be helpful to avoid lots of `force_ptr` calls later, if this place is used a lot.

src/librustc_mir/interpret/place.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ use std::hash::Hash;
77

88
use rustc_macros::HashStable;
99
use rustc_middle::mir;
10-
use rustc_middle::mir::interpret::truncate;
1110
use rustc_middle::ty::layout::{PrimitiveExt, TyAndLayout};
1211
use rustc_middle::ty::{self, Ty};
1312
use rustc_target::abi::{Abi, Align, DiscriminantKind, FieldsShape};
1413
use rustc_target::abi::{HasDataLayout, LayoutOf, Size, VariantIdx, Variants};
1514

1615
use super::{
17-
AllocId, AllocMap, Allocation, AllocationExtra, ImmTy, Immediate, InterpCx, InterpResult,
18-
LocalValue, Machine, MemoryKind, OpTy, Operand, Pointer, PointerArithmetic, RawConst, Scalar,
19-
ScalarMaybeUndef,
16+
mir_assign_valid_types, truncate, AllocId, AllocMap, Allocation, AllocationExtra, ImmTy,
17+
Immediate, InterpCx, InterpResult, LocalValue, Machine, MemoryKind, OpTy, Operand, Pointer,
18+
PointerArithmetic, RawConst, Scalar, ScalarMaybeUndef,
2019
};
2120

2221
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)]
@@ -869,10 +868,10 @@ where
869868
// We do NOT compare the types for equality, because well-typed code can
870869
// actually "transmute" `&mut T` to `&T` in an assignment without a cast.
871870
assert!(
872-
src.layout.layout == dest.layout.layout,
873-
"Layout mismatch when copying!\nsrc: {:#?}\ndest: {:#?}",
874-
src,
875-
dest
871+
mir_assign_valid_types(src.layout, dest.layout),
872+
"type mismatch when copying!\nsrc: {:?},\ndest: {:?}",
873+
src.layout.ty,
874+
dest.layout.ty,
876875
);
877876

878877
// Let us see if the layout is simple so we take a shortcut, avoid force_allocation.
@@ -923,7 +922,7 @@ where
923922
src: OpTy<'tcx, M::PointerTag>,
924923
dest: PlaceTy<'tcx, M::PointerTag>,
925924
) -> InterpResult<'tcx> {
926-
if src.layout.layout == dest.layout.layout {
925+
if mir_assign_valid_types(src.layout, dest.layout) {
927926
// Fast path: Just use normal `copy_op`
928927
return self.copy_op(src, dest);
929928
}

src/tools/build-manifest/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ static TARGETS: &[&str] = &[
5656
"aarch64-unknown-hermit",
5757
"aarch64-unknown-linux-gnu",
5858
"aarch64-unknown-linux-musl",
59+
"aarch64-unknown-none",
60+
"aarch64-unknown-none-softfloat",
5961
"aarch64-unknown-redox",
6062
"arm-linux-androideabi",
6163
"arm-unknown-linux-gnueabi",

0 commit comments

Comments
 (0)