Skip to content

Commit 8a7338a

Browse files
committed
Auto merge of rust-lang#3645 - rust-lang:rustup-2024-05-30, r=RalfJung
Automatic Rustup
2 parents ec5327d + daeb68a commit 8a7338a

File tree

400 files changed

+6654
-2709
lines changed

Some content is hidden

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

400 files changed

+6654
-2709
lines changed

.github/workflows/ci.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@ jobs:
154154

155155
- name: checkout submodules
156156
run: src/ci/scripts/checkout-submodules.sh
157-
158-
- name: install MSYS2
159-
run: src/ci/scripts/install-msys2.sh
157+
158+
- name: Setup Python
159+
uses: actions/setup-python@v5
160+
with:
161+
python-version: '3.x'
162+
if: runner.environment == 'github-hosted'
160163

161164
- name: install MinGW
162165
run: src/ci/scripts/install-mingw.sh

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4082,6 +4082,7 @@ dependencies = [
40824082
"rustc_feature",
40834083
"rustc_fluent_macro",
40844084
"rustc_hir",
4085+
"rustc_hir_pretty",
40854086
"rustc_index",
40864087
"rustc_infer",
40874088
"rustc_macros",

compiler/rustc_abi/src/layout.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ fn univariant<
970970
let mut align = if pack.is_some() { dl.i8_align } else { dl.aggregate_align };
971971
let mut max_repr_align = repr.align;
972972
let mut inverse_memory_index: IndexVec<u32, FieldIdx> = fields.indices().collect();
973-
let optimize = !repr.inhibit_struct_field_reordering_opt();
973+
let optimize = !repr.inhibit_struct_field_reordering();
974974
if optimize && fields.len() > 1 {
975975
let end = if let StructKind::MaybeUnsized = kind { fields.len() - 1 } else { fields.len() };
976976
let optimizing = &mut inverse_memory_index.raw[..end];
@@ -1007,13 +1007,15 @@ fn univariant<
10071007
// Calculates a sort key to group fields by their alignment or possibly some
10081008
// size-derived pseudo-alignment.
10091009
let alignment_group_key = |layout: &F| {
1010+
// The two branches here return values that cannot be meaningfully compared with
1011+
// each other. However, we know that consistently for all executions of
1012+
// `alignment_group_key`, one or the other branch will be taken, so this is okay.
10101013
if let Some(pack) = pack {
10111014
// Return the packed alignment in bytes.
10121015
layout.align.abi.min(pack).bytes()
10131016
} else {
1014-
// Returns `log2(effective-align)`. This is ok since `pack` applies to all
1015-
// fields equally. The calculation assumes that size is an integer multiple of
1016-
// align, except for ZSTs.
1017+
// Returns `log2(effective-align)`. The calculation assumes that size is an
1018+
// integer multiple of align, except for ZSTs.
10171019
let align = layout.align.abi.bytes();
10181020
let size = layout.size.bytes();
10191021
let niche_size = layout.largest_niche.map(|n| n.available(dl)).unwrap_or(0);

compiler/rustc_abi/src/lib.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,16 @@ impl ReprOptions {
137137
self.c() || self.int.is_some()
138138
}
139139

140-
/// Returns `true` if this `#[repr()]` should inhibit struct field reordering
141-
/// optimizations, such as with `repr(C)`, `repr(packed(1))`, or `repr(<int>)`.
142-
pub fn inhibit_struct_field_reordering_opt(&self) -> bool {
143-
if let Some(pack) = self.pack {
144-
if pack.bytes() == 1 {
145-
return true;
146-
}
147-
}
148-
140+
/// Returns `true` if this `#[repr()]` guarantees a fixed field order,
141+
/// e.g. `repr(C)` or `repr(<int>)`.
142+
pub fn inhibit_struct_field_reordering(&self) -> bool {
149143
self.flags.intersects(ReprFlags::IS_UNOPTIMISABLE) || self.int.is_some()
150144
}
151145

152146
/// Returns `true` if this type is valid for reordering and `-Z randomize-layout`
153147
/// was enabled for its declaration crate.
154148
pub fn can_randomize_type_layout(&self) -> bool {
155-
!self.inhibit_struct_field_reordering_opt()
156-
&& self.flags.contains(ReprFlags::RANDOMIZE_LAYOUT)
149+
!self.inhibit_struct_field_reordering() && self.flags.contains(ReprFlags::RANDOMIZE_LAYOUT)
157150
}
158151

159152
/// Returns `true` if this `#[repr()]` should inhibit union ABI optimisations.

compiler/rustc_ast/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ pub enum ExprKind {
13931393
/// An array (e.g, `[a, b, c, d]`).
13941394
Array(ThinVec<P<Expr>>),
13951395
/// Allow anonymous constants from an inline `const` block
1396-
ConstBlock(AnonConst),
1396+
ConstBlock(P<Expr>),
13971397
/// A function call
13981398
///
13991399
/// The first field resolves to the function itself,

compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
14111411
match kind {
14121412
ExprKind::Array(exprs) => visit_thin_exprs(exprs, vis),
14131413
ExprKind::ConstBlock(anon_const) => {
1414-
vis.visit_anon_const(anon_const);
1414+
vis.visit_expr(anon_const);
14151415
}
14161416
ExprKind::Repeat(expr, count) => {
14171417
vis.visit_expr(expr);

compiler/rustc_ast/src/visit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,10 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(
852852
ctxt: AssocCtxt,
853853
) -> V::Result {
854854
let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
855-
walk_list!(visitor, visit_attribute, attrs);
856855
try_visit!(visitor.visit_vis(vis));
857856
try_visit!(visitor.visit_ident(ident));
858857
try_visit!(kind.walk(item, ctxt, visitor));
858+
walk_list!(visitor, visit_attribute, attrs);
859859
V::Result::output()
860860
}
861861

@@ -951,7 +951,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
951951
ExprKind::Array(subexpressions) => {
952952
walk_list!(visitor, visit_expr, subexpressions);
953953
}
954-
ExprKind::ConstBlock(anon_const) => try_visit!(visitor.visit_anon_const(anon_const)),
954+
ExprKind::ConstBlock(anon_const) => try_visit!(visitor.visit_expr(anon_const)),
955955
ExprKind::Repeat(element, count) => {
956956
try_visit!(visitor.visit_expr(element));
957957
try_visit!(visitor.visit_anon_const(count));

compiler/rustc_ast_lowering/src/expr.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
7575
let kind = match &e.kind {
7676
ExprKind::Array(exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
7777
ExprKind::ConstBlock(c) => {
78-
let c = self.with_new_scopes(c.value.span, |this| hir::ConstBlock {
79-
def_id: this.local_def_id(c.id),
80-
hir_id: this.lower_node_id(c.id),
81-
body: this.lower_const_body(c.value.span, Some(&c.value)),
82-
});
83-
hir::ExprKind::ConstBlock(c)
78+
self.has_inline_consts = true;
79+
hir::ExprKind::ConstBlock(self.lower_expr(c))
8480
}
8581
ExprKind::Repeat(expr, count) => {
8682
let expr = self.lower_expr(expr);

compiler/rustc_ast_lowering/src/index.rs

-8
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,6 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
236236
});
237237
}
238238

239-
fn visit_inline_const(&mut self, constant: &'hir ConstBlock) {
240-
self.insert(DUMMY_SP, constant.hir_id, Node::ConstBlock(constant));
241-
242-
self.with_parent(constant.hir_id, |this| {
243-
intravisit::walk_inline_const(this, constant);
244-
});
245-
}
246-
247239
fn visit_expr(&mut self, expr: &'hir Expr<'hir>) {
248240
self.insert(expr.span, expr.hir_id, Node::Expr(expr));
249241

compiler/rustc_ast_lowering/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ struct LoweringContext<'a, 'hir> {
9696

9797
/// Bodies inside the owner being lowered.
9898
bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>,
99+
/// Whether there were inline consts that typeck will split out into bodies
100+
has_inline_consts: bool,
99101
/// Attributes inside the owner being lowered.
100102
attrs: SortedMap<hir::ItemLocalId, &'hir [Attribute]>,
101103
/// Collect items that were created by lowering the current owner.
@@ -158,6 +160,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
158160
item_local_id_counter: hir::ItemLocalId::ZERO,
159161
node_id_to_local_id: Default::default(),
160162
trait_map: Default::default(),
163+
has_inline_consts: false,
161164

162165
// Lowering state.
163166
catch_scope: None,
@@ -567,6 +570,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
567570

568571
let current_attrs = std::mem::take(&mut self.attrs);
569572
let current_bodies = std::mem::take(&mut self.bodies);
573+
let current_has_inline_consts = std::mem::take(&mut self.has_inline_consts);
570574
let current_node_ids = std::mem::take(&mut self.node_id_to_local_id);
571575
let current_trait_map = std::mem::take(&mut self.trait_map);
572576
let current_owner =
@@ -593,6 +597,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
593597

594598
self.attrs = current_attrs;
595599
self.bodies = current_bodies;
600+
self.has_inline_consts = current_has_inline_consts;
596601
self.node_id_to_local_id = current_node_ids;
597602
self.trait_map = current_trait_map;
598603
self.current_hir_id_owner = current_owner;
@@ -629,6 +634,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
629634
let attrs = std::mem::take(&mut self.attrs);
630635
let mut bodies = std::mem::take(&mut self.bodies);
631636
let trait_map = std::mem::take(&mut self.trait_map);
637+
let has_inline_consts = std::mem::take(&mut self.has_inline_consts);
632638

633639
#[cfg(debug_assertions)]
634640
for (id, attrs) in attrs.iter() {
@@ -646,7 +652,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
646652
self.tcx.hash_owner_nodes(node, &bodies, &attrs);
647653
let num_nodes = self.item_local_id_counter.as_usize();
648654
let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);
649-
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };
655+
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies, has_inline_consts };
650656
let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash };
651657

652658
self.arena.alloc(hir::OwnerInfo { nodes, parenting, attrs, trait_map })

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,9 @@ impl<'a> State<'a> {
380380
ast::ExprKind::Array(exprs) => {
381381
self.print_expr_vec(exprs);
382382
}
383-
ast::ExprKind::ConstBlock(anon_const) => {
384-
self.print_expr_anon_const(anon_const, attrs);
383+
ast::ExprKind::ConstBlock(expr) => {
384+
self.word_space("const");
385+
self.print_expr(expr, FixupContext::default());
385386
}
386387
ast::ExprKind::Repeat(element, count) => {
387388
self.print_expr_repeat(element, count);

compiler/rustc_codegen_cranelift/src/abi/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ pub(crate) fn codegen_drop<'tcx>(
593593
fx: &mut FunctionCx<'_, '_, 'tcx>,
594594
source_info: mir::SourceInfo,
595595
drop_place: CPlace<'tcx>,
596+
target: BasicBlock,
596597
) {
597598
let ty = drop_place.layout().ty;
598599
let drop_instance = Instance::resolve_drop_in_place(fx.tcx, ty).polymorphize(fx.tcx);
@@ -620,6 +621,12 @@ pub(crate) fn codegen_drop<'tcx>(
620621
let ptr = ptr.get_addr(fx);
621622
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable);
622623

624+
let is_null = fx.bcx.ins().icmp_imm(IntCC::Equal, drop_fn, 0);
625+
let target_block = fx.get_block(target);
626+
let continued = fx.bcx.create_block();
627+
fx.bcx.ins().brif(is_null, target_block, &[], continued, &[]);
628+
fx.bcx.switch_to_block(continued);
629+
623630
// FIXME(eddyb) perhaps move some of this logic into
624631
// `Instance::resolve_drop_in_place`?
625632
let virtual_drop = Instance {
@@ -659,6 +666,12 @@ pub(crate) fn codegen_drop<'tcx>(
659666
let (data, vtable) = drop_place.to_cvalue(fx).dyn_star_force_data_on_stack(fx);
660667
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable);
661668

669+
let is_null = fx.bcx.ins().icmp_imm(IntCC::Equal, drop_fn, 0);
670+
let target_block = fx.get_block(target);
671+
let continued = fx.bcx.create_block();
672+
fx.bcx.ins().brif(is_null, target_block, &[], continued, &[]);
673+
fx.bcx.switch_to_block(continued);
674+
662675
let virtual_drop = Instance {
663676
def: ty::InstanceDef::Virtual(drop_instance.def_id(), 0),
664677
args: drop_instance.args,
@@ -697,4 +710,7 @@ pub(crate) fn codegen_drop<'tcx>(
697710
}
698711
}
699712
}
713+
714+
let target_block = fx.get_block(target);
715+
fx.bcx.ins().jump(target_block, &[]);
700716
}

compiler/rustc_codegen_cranelift/src/base.rs

+26-17
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
548548
}
549549
TerminatorKind::Drop { place, target, unwind: _, replace: _ } => {
550550
let drop_place = codegen_place(fx, *place);
551-
crate::abi::codegen_drop(fx, source_info, drop_place);
552-
553-
let target_block = fx.get_block(*target);
554-
fx.bcx.ins().jump(target_block, &[]);
551+
crate::abi::codegen_drop(fx, source_info, drop_place, *target);
555552
}
556553
};
557554
}
@@ -619,22 +616,34 @@ fn codegen_stmt<'tcx>(
619616
Rvalue::UnaryOp(un_op, ref operand) => {
620617
let operand = codegen_operand(fx, operand);
621618
let layout = operand.layout();
622-
let val = operand.load_scalar(fx);
623619
let res = match un_op {
624-
UnOp::Not => match layout.ty.kind() {
625-
ty::Bool => {
626-
let res = fx.bcx.ins().icmp_imm(IntCC::Equal, val, 0);
627-
CValue::by_val(res, layout)
620+
UnOp::Not => {
621+
let val = operand.load_scalar(fx);
622+
match layout.ty.kind() {
623+
ty::Bool => {
624+
let res = fx.bcx.ins().icmp_imm(IntCC::Equal, val, 0);
625+
CValue::by_val(res, layout)
626+
}
627+
ty::Uint(_) | ty::Int(_) => {
628+
CValue::by_val(fx.bcx.ins().bnot(val), layout)
629+
}
630+
_ => unreachable!("un op Not for {:?}", layout.ty),
628631
}
629-
ty::Uint(_) | ty::Int(_) => {
630-
CValue::by_val(fx.bcx.ins().bnot(val), layout)
632+
}
633+
UnOp::Neg => {
634+
let val = operand.load_scalar(fx);
635+
match layout.ty.kind() {
636+
ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
637+
ty::Float(_) => CValue::by_val(fx.bcx.ins().fneg(val), layout),
638+
_ => unreachable!("un op Neg for {:?}", layout.ty),
631639
}
632-
_ => unreachable!("un op Not for {:?}", layout.ty),
633-
},
634-
UnOp::Neg => match layout.ty.kind() {
635-
ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
636-
ty::Float(_) => CValue::by_val(fx.bcx.ins().fneg(val), layout),
637-
_ => unreachable!("un op Neg for {:?}", layout.ty),
640+
}
641+
UnOp::PtrMetadata => match layout.abi {
642+
Abi::Scalar(_) => CValue::zst(dest_layout),
643+
Abi::ScalarPair(_, _) => {
644+
CValue::by_val(operand.load_scalar_pair(fx).1, dest_layout)
645+
}
646+
_ => bug!("Unexpected `PtrToMetadata` operand: {operand:?}"),
638647
},
639648
};
640649
lval.write_cvalue(fx, res);

compiler/rustc_codegen_cranelift/src/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub(crate) fn codegen_const_value<'tcx>(
100100
assert!(layout.is_sized(), "unsized const value");
101101

102102
if layout.is_zst() {
103-
return CValue::by_ref(crate::Pointer::dangling(layout.align.pref), layout);
103+
return CValue::zst(layout);
104104
}
105105

106106
match const_val {

compiler/rustc_codegen_cranelift/src/value_and_place.rs

+8
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ impl<'tcx> CValue<'tcx> {
9595
CValue(CValueInner::ByValPair(value, extra), layout)
9696
}
9797

98+
/// Create an instance of a ZST
99+
///
100+
/// The is represented by a dangling pointer of suitable alignment.
101+
pub(crate) fn zst(layout: TyAndLayout<'tcx>) -> CValue<'tcx> {
102+
assert!(layout.is_zst());
103+
CValue::by_ref(crate::Pointer::dangling(layout.align.pref), layout)
104+
}
105+
98106
pub(crate) fn layout(&self) -> TyAndLayout<'tcx> {
99107
self.1
100108
}

compiler/rustc_codegen_llvm/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ codegen_llvm_error_creating_import_library =
1818
codegen_llvm_error_writing_def_file =
1919
Error writing .DEF file: {$error}
2020
21+
codegen_llvm_fixed_x18_invalid_arch = the `-Zfixed-x18` flag is not supported on the `{$arch}` architecture
22+
2123
codegen_llvm_from_llvm_diag = {$message}
2224
2325
codegen_llvm_from_llvm_optimization_diag = {$filename}:{$line}:{$column} {$pass_name} ({$kind}): {$message}

compiler/rustc_codegen_llvm/src/errors.rs

+6
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,9 @@ pub struct MismatchedDataLayout<'a> {
254254
pub(crate) struct InvalidTargetFeaturePrefix<'a> {
255255
pub feature: &'a str,
256256
}
257+
258+
#[derive(Diagnostic)]
259+
#[diag(codegen_llvm_fixed_x18_invalid_arch)]
260+
pub(crate) struct FixedX18InvalidArch<'a> {
261+
pub arch: &'a str,
262+
}

compiler/rustc_codegen_llvm/src/llvm_util.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::back::write::create_informational_target_machine;
22
use crate::errors::{
3-
InvalidTargetFeaturePrefix, PossibleFeature, TargetFeatureDisableOrEnable,
3+
FixedX18InvalidArch, InvalidTargetFeaturePrefix, PossibleFeature, TargetFeatureDisableOrEnable,
44
UnknownCTargetFeature, UnknownCTargetFeaturePrefix, UnstableCTargetFeature,
55
};
66
use crate::llvm;
@@ -615,6 +615,15 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
615615
.flatten();
616616
features.extend(feats);
617617

618+
// -Zfixed-x18
619+
if sess.opts.unstable_opts.fixed_x18 {
620+
if sess.target.arch != "aarch64" {
621+
sess.dcx().emit_fatal(FixedX18InvalidArch { arch: &sess.target.arch });
622+
} else {
623+
features.push("+reserve-x18".into());
624+
}
625+
}
626+
618627
if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
619628
sess.dcx().emit_err(TargetFeatureDisableOrEnable {
620629
features: f,

0 commit comments

Comments
 (0)