Skip to content

Commit c7b86fc

Browse files
committed
Auto merge of rust-lang#3403 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 8e978c3 + 070e8ce commit c7b86fc

File tree

253 files changed

+3538
-901
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

253 files changed

+3538
-901
lines changed

.github/workflows/dependencies.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
4343
# Exit with error if open and S-waiting-on-bors
4444
if [[ "$STATE" == "OPEN" && "$WAITING_ON_BORS" == "true" ]]; then
45-
exit 1
45+
gh run cancel ${{ github.run_id }}
4646
fi
4747
4848
update:
@@ -65,7 +65,10 @@ jobs:
6565
6666
- name: cargo update
6767
# Remove first line that always just says "Updating crates.io index"
68-
run: cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log
68+
# If there are no changes, cancel the job here
69+
run: |
70+
cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log
71+
git status --porcelain | grep -q Cargo.lock || gh run cancel ${{ github.run_id }}
6972
- name: upload Cargo.lock artifact for use in PR
7073
uses: actions/upload-artifact@v3
7174
with:
@@ -131,7 +134,7 @@ jobs:
131134
# Exit with error if PR is closed
132135
STATE=$(gh pr view cargo_update --repo $GITHUB_REPOSITORY --json state --jq '.state')
133136
if [[ "$STATE" != "OPEN" ]]; then
134-
exit 1
137+
gh run cancel ${{ github.run_id }}
135138
fi
136139
137140
gh pr edit cargo_update --title "${PR_TITLE}" --body-file body.md --repo $GITHUB_REPOSITORY

compiler/rustc_ast_lowering/src/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
8181
(self.arena.alloc_from_iter(stmts), expr)
8282
}
8383

84-
fn lower_local(&mut self, l: &Local) -> &'hir hir::Local<'hir> {
84+
fn lower_local(&mut self, l: &Local) -> &'hir hir::LetStmt<'hir> {
8585
let ty = l
8686
.ty
8787
.as_ref()
@@ -97,7 +97,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
9797
let span = self.lower_span(l.span);
9898
let source = hir::LocalSource::Normal;
9999
self.lower_attrs(hir_id, &l.attrs);
100-
self.arena.alloc(hir::Local { hir_id, ty, pat, init, els, span, source })
100+
self.arena.alloc(hir::LetStmt { hir_id, ty, pat, init, els, span, source })
101101
}
102102

103103
fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode {

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
302302
});
303303
}
304304

305-
fn visit_local(&mut self, l: &'hir Local<'hir>) {
306-
self.insert(l.span, l.hir_id, Node::Local(l));
305+
fn visit_local(&mut self, l: &'hir LetStmt<'hir>) {
306+
self.insert(l.span, l.hir_id, Node::LetStmt(l));
307307
self.with_parent(l.hir_id, |this| {
308308
intravisit::walk_local(this, l);
309309
})

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2341,7 +2341,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23412341
debug_assert!(!a.is_empty());
23422342
self.attrs.insert(hir_id.local_id, a);
23432343
}
2344-
let local = hir::Local {
2344+
let local = hir::LetStmt {
23452345
hir_id,
23462346
init,
23472347
pat,

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
622622

623623
// FIXME: We make sure that this is a normal top-level binding,
624624
// but we could suggest `todo!()` for all uninitalized bindings in the pattern pattern
625-
if let hir::StmtKind::Let(hir::Local { span, ty, init: None, pat, .. }) =
625+
if let hir::StmtKind::Let(hir::LetStmt { span, ty, init: None, pat, .. }) =
626626
&ex.kind
627627
&& let hir::PatKind::Binding(..) = pat.kind
628628
&& span.contains(self.decl_span)
@@ -800,7 +800,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
800800
for (_, node) in tcx.hir().parent_iter(expr.hir_id) {
801801
let e = match node {
802802
hir::Node::Expr(e) => e,
803-
hir::Node::Local(hir::Local { els: Some(els), .. }) => {
803+
hir::Node::LetStmt(hir::LetStmt { els: Some(els), .. }) => {
804804
let mut finder = BreakFinder { found_breaks: vec![], found_continues: vec![] };
805805
finder.visit_block(els);
806806
if !finder.found_breaks.is_empty() {
@@ -2124,7 +2124,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21242124
hir::intravisit::walk_expr(self, e);
21252125
}
21262126

2127-
fn visit_local(&mut self, local: &'hir hir::Local<'hir>) {
2127+
fn visit_local(&mut self, local: &'hir hir::LetStmt<'hir>) {
21282128
if let hir::Pat { kind: hir::PatKind::Binding(_, hir_id, _ident, _), .. } =
21292129
local.pat
21302130
&& let Some(init) = local.init

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
558558
hir::intravisit::walk_stmt(self, stmt);
559559
let expr = match stmt.kind {
560560
hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr) => expr,
561-
hir::StmtKind::Let(hir::Local { init: Some(expr), .. }) => expr,
561+
hir::StmtKind::Let(hir::LetStmt { init: Some(expr), .. }) => expr,
562562
_ => {
563563
return;
564564
}
@@ -737,7 +737,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
737737
&& let body = self.infcx.tcx.hir().body(body_id)
738738
&& let Some(hir_id) = (BindingFinder { span: pat_span }).visit_body(body).break_value()
739739
&& let node = self.infcx.tcx.hir_node(hir_id)
740-
&& let hir::Node::Local(hir::Local {
740+
&& let hir::Node::LetStmt(hir::LetStmt {
741741
pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. },
742742
..
743743
})
@@ -1170,7 +1170,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
11701170
};
11711171

11721172
if let Some(hir_id) = hir_id
1173-
&& let hir::Node::Local(local) = self.infcx.tcx.hir_node(hir_id)
1173+
&& let hir::Node::LetStmt(local) = self.infcx.tcx.hir_node(hir_id)
11741174
{
11751175
let tables = self.infcx.tcx.typeck(def_id.as_local().unwrap());
11761176
if let Some(clone_trait) = self.infcx.tcx.lang_items().clone_trait()

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20002000
ConstraintCategory::SizedBound,
20012001
);
20022002
}
2003-
&Rvalue::NullaryOp(NullOp::UbCheck(_), _) => {}
2003+
&Rvalue::NullaryOp(NullOp::UbChecks, _) => {}
20042004

20052005
Rvalue::ShallowInitBox(operand, ty) => {
20062006
self.check_operand(operand, location);

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ fn codegen_stmt<'tcx>(
780780
NullOp::OffsetOf(fields) => {
781781
layout.offset_of_subfield(fx, fields.iter()).bytes()
782782
}
783-
NullOp::UbCheck(_) => {
783+
NullOp::UbChecks => {
784784
let val = fx.tcx.sess.opts.debug_assertions;
785785
let val = CValue::by_val(
786786
fx.bcx.ins().iconst(types::I8, i64::try_from(val).unwrap()),

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::traits::*;
99
use crate::MemFlags;
1010

1111
use rustc_middle::ty::{self, Ty, TyCtxt};
12+
use rustc_session::config::OptLevel;
1213
use rustc_span::{sym, Span};
1314
use rustc_target::abi::{
1415
call::{FnAbi, PassMode},
@@ -75,6 +76,29 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
7576
let name = bx.tcx().item_name(def_id);
7677
let name_str = name.as_str();
7778

79+
// If we're swapping something that's *not* an `OperandValue::Ref`,
80+
// then we can do it directly and avoid the alloca.
81+
// Otherwise, we'll let the fallback MIR body take care of it.
82+
if let sym::typed_swap = name {
83+
let pointee_ty = fn_args.type_at(0);
84+
let pointee_layout = bx.layout_of(pointee_ty);
85+
if !bx.is_backend_ref(pointee_layout)
86+
// But if we're not going to optimize, trying to use the fallback
87+
// body just makes things worse, so don't bother.
88+
|| bx.sess().opts.optimize == OptLevel::No
89+
// NOTE(eddyb) SPIR-V's Logical addressing model doesn't allow for arbitrary
90+
// reinterpretation of values as (chunkable) byte arrays, and the loop in the
91+
// block optimization in `ptr::swap_nonoverlapping` is hard to rewrite back
92+
// into the (unoptimized) direct swapping implementation, so we disable it.
93+
|| bx.sess().target.arch == "spirv"
94+
{
95+
let x_place = PlaceRef::new_sized(args[0].immediate(), pointee_layout);
96+
let y_place = PlaceRef::new_sized(args[1].immediate(), pointee_layout);
97+
bx.typed_place_swap(x_place, y_place);
98+
return Ok(());
99+
}
100+
}
101+
78102
let llret_ty = bx.backend_type(bx.layout_of(ret_ty));
79103
let result = PlaceRef::new_sized(llresult, fn_abi.ret.layout);
80104

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
680680
let val = layout.offset_of_subfield(bx.cx(), fields.iter()).bytes();
681681
bx.cx().const_usize(val)
682682
}
683-
mir::NullOp::UbCheck(_) => {
684-
// In codegen, we want to check for language UB and library UB
683+
mir::NullOp::UbChecks => {
685684
let val = bx.tcx().sess.opts.debug_assertions;
686685
bx.cx().const_bool(val)
687686
}

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
use super::abi::AbiBuilderMethods;
22
use super::asm::AsmBuilderMethods;
3+
use super::consts::ConstMethods;
34
use super::coverageinfo::CoverageInfoBuilderMethods;
45
use super::debuginfo::DebugInfoBuilderMethods;
56
use super::intrinsic::IntrinsicCallMethods;
67
use super::misc::MiscMethods;
7-
use super::type_::{ArgAbiMethods, BaseTypeMethods};
8+
use super::type_::{ArgAbiMethods, BaseTypeMethods, LayoutTypeMethods};
89
use super::{HasCodegen, StaticBuilderMethods};
910

1011
use crate::common::{
1112
AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,
1213
};
13-
use crate::mir::operand::OperandRef;
14+
use crate::mir::operand::{OperandRef, OperandValue};
1415
use crate::mir::place::PlaceRef;
1516
use crate::MemFlags;
1617

1718
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
1819
use rustc_middle::ty::layout::{HasParamEnv, TyAndLayout};
1920
use rustc_middle::ty::Ty;
21+
use rustc_session::config::OptLevel;
2022
use rustc_span::Span;
2123
use rustc_target::abi::call::FnAbi;
2224
use rustc_target::abi::{Abi, Align, Scalar, Size, WrappingRange};
@@ -267,6 +269,54 @@ pub trait BuilderMethods<'a, 'tcx>:
267269
flags: MemFlags,
268270
);
269271

272+
/// *Typed* copy for non-overlapping places.
273+
///
274+
/// Has a default implementation in terms of `memcpy`, but specific backends
275+
/// can override to do something smarter if possible.
276+
///
277+
/// (For example, typed load-stores with alias metadata.)
278+
fn typed_place_copy(
279+
&mut self,
280+
dst: PlaceRef<'tcx, Self::Value>,
281+
src: PlaceRef<'tcx, Self::Value>,
282+
) {
283+
debug_assert!(src.llextra.is_none());
284+
debug_assert!(dst.llextra.is_none());
285+
debug_assert_eq!(dst.layout.size, src.layout.size);
286+
if self.sess().opts.optimize == OptLevel::No && self.is_backend_immediate(dst.layout) {
287+
// If we're not optimizing, the aliasing information from `memcpy`
288+
// isn't useful, so just load-store the value for smaller code.
289+
let temp = self.load_operand(src);
290+
temp.val.store(self, dst);
291+
} else if !dst.layout.is_zst() {
292+
let bytes = self.const_usize(dst.layout.size.bytes());
293+
self.memcpy(dst.llval, dst.align, src.llval, src.align, bytes, MemFlags::empty());
294+
}
295+
}
296+
297+
/// *Typed* swap for non-overlapping places.
298+
///
299+
/// Avoids `alloca`s for Immediates and ScalarPairs.
300+
///
301+
/// FIXME: Maybe do something smarter for Ref types too?
302+
/// For now, the `typed_swap` intrinsic just doesn't call this for those
303+
/// cases (in non-debug), preferring the fallback body instead.
304+
fn typed_place_swap(
305+
&mut self,
306+
left: PlaceRef<'tcx, Self::Value>,
307+
right: PlaceRef<'tcx, Self::Value>,
308+
) {
309+
let mut temp = self.load_operand(left);
310+
if let OperandValue::Ref(..) = temp.val {
311+
// The SSA value isn't stand-alone, so we need to copy it elsewhere
312+
let alloca = PlaceRef::alloca(self, left.layout);
313+
self.typed_place_copy(alloca, left);
314+
temp = self.load_operand(alloca);
315+
}
316+
self.typed_place_copy(left, right);
317+
temp.val.store(self, right);
318+
}
319+
270320
fn select(
271321
&mut self,
272322
cond: Self::Value,

compiler/rustc_codegen_ssa/src/traits/type_.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@ pub trait LayoutTypeMethods<'tcx>: Backend<'tcx> {
120120
immediate: bool,
121121
) -> Self::Type;
122122

123+
/// A type that produces an [`OperandValue::Ref`] when loaded.
124+
///
125+
/// AKA one that's not a ZST, not `is_backend_immediate`, and
126+
/// not `is_backend_scalar_pair`. For such a type, a
127+
/// [`load_operand`] doesn't actually `load` anything.
128+
///
129+
/// [`OperandValue::Ref`]: crate::mir::operand::OperandValue::Ref
130+
/// [`load_operand`]: super::BuilderMethods::load_operand
131+
fn is_backend_ref(&self, layout: TyAndLayout<'tcx>) -> bool {
132+
!(layout.is_zst()
133+
|| self.is_backend_immediate(layout)
134+
|| self.is_backend_scalar_pair(layout))
135+
}
136+
123137
/// A type that can be used in a [`super::BuilderMethods::load`] +
124138
/// [`super::BuilderMethods::store`] pair to implement a *typed* copy,
125139
/// such as a MIR `*_0 = *_1`.

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use either::{Left, Right};
33
use rustc_hir::def::DefKind;
44
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo};
55
use rustc_middle::mir::{self, ConstAlloc, ConstValue};
6-
use rustc_middle::query::{Key, TyCtxtAt};
6+
use rustc_middle::query::TyCtxtAt;
77
use rustc_middle::traits::Reveal;
88
use rustc_middle::ty::layout::LayoutOf;
99
use rustc_middle::ty::print::with_no_trimmed_paths;
@@ -243,24 +243,6 @@ pub(crate) fn turn_into_const_value<'tcx>(
243243
op_to_const(&ecx, &mplace.into(), /* for diagnostics */ false)
244244
}
245245

246-
/// Computes the tag (if any) for a given type and variant.
247-
#[instrument(skip(tcx), level = "debug")]
248-
pub fn tag_for_variant_provider<'tcx>(
249-
tcx: TyCtxt<'tcx>,
250-
(ty, variant_index): (Ty<'tcx>, abi::VariantIdx),
251-
) -> Option<ty::ScalarInt> {
252-
assert!(ty.is_enum());
253-
254-
let ecx = InterpCx::new(
255-
tcx,
256-
ty.default_span(tcx),
257-
ty::ParamEnv::reveal_all(),
258-
crate::const_eval::DummyMachine,
259-
);
260-
261-
ecx.tag_for_variant(ty, variant_index).unwrap().map(|(tag, _tag_field)| tag)
262-
}
263-
264246
#[instrument(skip(tcx), level = "debug")]
265247
pub fn eval_to_const_value_raw_provider<'tcx>(
266248
tcx: TyCtxt<'tcx>,

compiler/rustc_const_eval/src/const_eval/mod.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
use rustc_middle::mir;
44
use rustc_middle::mir::interpret::InterpErrorInfo;
5-
use rustc_middle::query::TyCtxtAt;
6-
use rustc_middle::ty::{self, Ty};
5+
use rustc_middle::query::{Key, TyCtxtAt};
6+
use rustc_middle::ty::{self, Ty, TyCtxt};
7+
use rustc_target::abi::VariantIdx;
78

8-
use crate::interpret::format_interp_error;
9+
use crate::interpret::{format_interp_error, InterpCx};
910

1011
mod dummy_machine;
1112
mod error;
@@ -77,3 +78,21 @@ pub(crate) fn try_destructure_mir_constant_for_user_output<'tcx>(
7778

7879
Some(mir::DestructuredConstant { variant, fields })
7980
}
81+
82+
/// Computes the tag (if any) for a given type and variant.
83+
#[instrument(skip(tcx), level = "debug")]
84+
pub fn tag_for_variant_provider<'tcx>(
85+
tcx: TyCtxt<'tcx>,
86+
(ty, variant_index): (Ty<'tcx>, VariantIdx),
87+
) -> Option<ty::ScalarInt> {
88+
assert!(ty.is_enum());
89+
90+
let ecx = InterpCx::new(
91+
tcx,
92+
ty.default_span(tcx),
93+
ty::ParamEnv::reveal_all(),
94+
crate::const_eval::DummyMachine,
95+
);
96+
97+
ecx.tag_for_variant(ty, variant_index).unwrap().map(|(tag, _tag_field)| tag)
98+
}

compiler/rustc_const_eval/src/interpret/discriminant.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
3838
}
3939
None => {
4040
// No need to write the tag here, because an untagged variant is
41-
// implicitly encoded. For `Niche`-optimized enums, it's by
41+
// implicitly encoded. For `Niche`-optimized enums, this works by
4242
// simply by having a value that is outside the niche variants.
4343
// But what if the data stored here does not actually encode
4444
// this variant? That would be bad! So let's double-check...
@@ -227,8 +227,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
227227
Ok(ImmTy::from_scalar(discr_value, discr_layout))
228228
}
229229

230-
/// Computes the tag value and its field number (if any) of a given variant
231-
/// of type `ty`.
230+
/// Computes how to write the tag of a given variant of enum `ty`:
231+
/// - `None` means that nothing needs to be done as the variant is encoded implicitly
232+
/// - `Some((val, field_idx))` means that the given integer value needs to be stored at the
233+
/// given field index.
232234
pub(crate) fn tag_for_variant(
233235
&self,
234236
ty: Ty<'tcx>,

0 commit comments

Comments
 (0)