Skip to content

Commit 394aa87

Browse files
committed
Auto merge of #3447 - rust-lang:rustup-2024-04-04, r=saethlin
Automatic Rustup
2 parents 9250984 + 9c33414 commit 394aa87

File tree

402 files changed

+2991
-3004
lines changed

Some content is hidden

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

402 files changed

+2991
-3004
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,8 @@ impl Expr {
12761276
ExprKind::While(..) => ExprPrecedence::While,
12771277
ExprKind::ForLoop { .. } => ExprPrecedence::ForLoop,
12781278
ExprKind::Loop(..) => ExprPrecedence::Loop,
1279-
ExprKind::Match(..) => ExprPrecedence::Match,
1279+
ExprKind::Match(_, _, MatchKind::Prefix) => ExprPrecedence::Match,
1280+
ExprKind::Match(_, _, MatchKind::Postfix) => ExprPrecedence::PostfixMatch,
12801281
ExprKind::Closure(..) => ExprPrecedence::Closure,
12811282
ExprKind::Block(..) => ExprPrecedence::Block,
12821283
ExprKind::TryBlock(..) => ExprPrecedence::TryBlock,

compiler/rustc_ast/src/ptr.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
//! The AST pointer.
22
//!
3-
//! Provides `P<T>`, a frozen owned smart pointer.
3+
//! Provides [`P<T>`][struct@P], an owned smart pointer.
44
//!
55
//! # Motivations and benefits
66
//!
77
//! * **Identity**: sharing AST nodes is problematic for the various analysis
88
//! passes (e.g., one may be able to bypass the borrow checker with a shared
99
//! `ExprKind::AddrOf` node taking a mutable borrow).
1010
//!
11-
//! * **Immutability**: `P<T>` disallows mutating its inner `T`, unlike `Box<T>`
12-
//! (unless it contains an `Unsafe` interior, but that may be denied later).
13-
//! This mainly prevents mistakes, but also enforces a kind of "purity".
14-
//!
1511
//! * **Efficiency**: folding can reuse allocation space for `P<T>` and `Vec<T>`,
1612
//! the latter even when the input and output types differ (as it would be the
1713
//! case with arenas or a GADT AST using type parameters to toggle features).
1814
//!
19-
//! * **Maintainability**: `P<T>` provides a fixed interface - `Deref`,
20-
//! `and_then` and `map` - which can remain fully functional even if the
21-
//! implementation changes (using a special thread-local heap, for example).
22-
//! Moreover, a switch to, e.g., `P<'a, T>` would be easy and mostly automated.
15+
//! * **Maintainability**: `P<T>` provides an interface, which can remain fully
16+
//! functional even if the implementation changes (using a special thread-local
17+
//! heap, for example). Moreover, a switch to, e.g., `P<'a, T>` would be easy
18+
//! and mostly automated.
2319
2420
use std::fmt::{self, Debug, Display};
2521
use std::ops::{Deref, DerefMut};
@@ -29,6 +25,8 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
2925

3026
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3127
/// An owned smart pointer.
28+
///
29+
/// See the [module level documentation][crate::ptr] for details.
3230
pub struct P<T: ?Sized> {
3331
ptr: Box<T>,
3432
}

compiler/rustc_ast/src/util/parser.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ pub enum ExprPrecedence {
281281
ForLoop,
282282
Loop,
283283
Match,
284+
PostfixMatch,
284285
ConstBlock,
285286
Block,
286287
TryBlock,
@@ -334,7 +335,8 @@ impl ExprPrecedence {
334335
| ExprPrecedence::InlineAsm
335336
| ExprPrecedence::Mac
336337
| ExprPrecedence::FormatArgs
337-
| ExprPrecedence::OffsetOf => PREC_POSTFIX,
338+
| ExprPrecedence::OffsetOf
339+
| ExprPrecedence::PostfixMatch => PREC_POSTFIX,
338340

339341
// Never need parens
340342
ExprPrecedence::Array
@@ -390,7 +392,8 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
390392
| ast::ExprKind::Cast(x, _)
391393
| ast::ExprKind::Type(x, _)
392394
| ast::ExprKind::Field(x, _)
393-
| ast::ExprKind::Index(x, _, _) => {
395+
| ast::ExprKind::Index(x, _, _)
396+
| ast::ExprKind::Match(x, _, ast::MatchKind::Postfix) => {
394397
// &X { y: 1 }, X { y: 1 }.y
395398
contains_exterior_struct_lit(x)
396399
}

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_hir as hir;
33
use rustc_hir::def_id::{LocalDefId, LocalDefIdMap};
44
use rustc_hir::intravisit::Visitor;
55
use rustc_hir::*;
6-
use rustc_index::{Idx, IndexVec};
6+
use rustc_index::IndexVec;
77
use rustc_middle::span_bug;
88
use rustc_middle::ty::TyCtxt;
99
use rustc_span::{Span, DUMMY_SP};
@@ -31,7 +31,7 @@ pub(super) fn index_hir<'hir>(
3131
bodies: &SortedMap<ItemLocalId, &'hir Body<'hir>>,
3232
num_nodes: usize,
3333
) -> (IndexVec<ItemLocalId, ParentedNode<'hir>>, LocalDefIdMap<ItemLocalId>) {
34-
let zero_id = ItemLocalId::new(0);
34+
let zero_id = ItemLocalId::ZERO;
3535
let err_node = ParentedNode { parent: zero_id, node: Node::Err(item.span()) };
3636
let mut nodes = IndexVec::from_elem_n(err_node, num_nodes);
3737
// This node's parent should never be accessed: the owner's parent is computed by the
@@ -112,7 +112,9 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
112112
}
113113

114114
fn insert_nested(&mut self, item: LocalDefId) {
115-
self.parenting.insert(item, self.parent_node);
115+
if self.parent_node.as_u32() != 0 {
116+
self.parenting.insert(item, self.parent_node);
117+
}
116118
}
117119
}
118120

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir as hir;
1111
use rustc_hir::def::{DefKind, Res};
1212
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
1313
use rustc_hir::PredicateOrigin;
14-
use rustc_index::{Idx, IndexSlice, IndexVec};
14+
use rustc_index::{IndexSlice, IndexVec};
1515
use rustc_middle::span_bug;
1616
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
1717
use rustc_span::edit_distance::find_best_match_for_name;
@@ -563,7 +563,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
563563
let kind =
564564
this.lower_use_tree(use_tree, &prefix, id, vis_span, &mut ident, attrs);
565565
if let Some(attrs) = attrs {
566-
this.attrs.insert(hir::ItemLocalId::new(0), attrs);
566+
this.attrs.insert(hir::ItemLocalId::ZERO, attrs);
567567
}
568568

569569
let item = hir::Item {

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
157157
attrs: SortedMap::default(),
158158
children: Vec::default(),
159159
current_hir_id_owner: hir::CRATE_OWNER_ID,
160-
item_local_id_counter: hir::ItemLocalId::new(0),
160+
item_local_id_counter: hir::ItemLocalId::ZERO,
161161
node_id_to_local_id: Default::default(),
162162
trait_map: Default::default(),
163163

@@ -583,7 +583,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
583583
// and the caller to refer to some of the subdefinitions' nodes' `LocalDefId`s.
584584

585585
// Always allocate the first `HirId` for the owner itself.
586-
let _old = self.node_id_to_local_id.insert(owner, hir::ItemLocalId::new(0));
586+
let _old = self.node_id_to_local_id.insert(owner, hir::ItemLocalId::ZERO);
587587
debug_assert_eq!(_old, None);
588588

589589
let item = f(self);
@@ -677,7 +677,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
677677
v.insert(local_id);
678678
self.item_local_id_counter.increment_by(1);
679679

680-
assert_ne!(local_id, hir::ItemLocalId::new(0));
680+
assert_ne!(local_id, hir::ItemLocalId::ZERO);
681681
if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
682682
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
683683
}
@@ -696,7 +696,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
696696
fn next_id(&mut self) -> hir::HirId {
697697
let owner = self.current_hir_id_owner;
698698
let local_id = self.item_local_id_counter;
699-
assert_ne!(local_id, hir::ItemLocalId::new(0));
699+
assert_ne!(local_id, hir::ItemLocalId::ZERO);
700700
self.item_local_id_counter.increment_by(1);
701701
hir::HirId { owner, local_id }
702702
}

compiler/rustc_borrowck/src/borrow_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl<'tcx> BorrowSet<'tcx> {
159159
}
160160

161161
pub(crate) fn indices(&self) -> impl Iterator<Item = BorrowIndex> {
162-
BorrowIndex::from_usize(0)..BorrowIndex::from_usize(self.len())
162+
BorrowIndex::ZERO..BorrowIndex::from_usize(self.len())
163163
}
164164

165165
pub(crate) fn iter_enumerated(&self) -> impl Iterator<Item = (BorrowIndex, &BorrowData<'tcx>)> {

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22612261
}
22622262
}
22632263

2264-
CastKind::PointerExposeAddress => {
2264+
CastKind::PointerExposeProvenance => {
22652265
let ty_from = op.ty(body, tcx);
22662266
let cast_ty_from = CastTy::from_ty(ty_from);
22672267
let cast_ty_to = CastTy::from_ty(*ty);
@@ -2271,7 +2271,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22712271
span_mirbug!(
22722272
self,
22732273
rvalue,
2274-
"Invalid PointerExposeAddress cast {:?} -> {:?}",
2274+
"Invalid PointerExposeProvenance cast {:?} -> {:?}",
22752275
ty_from,
22762276
ty
22772277
)

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ fn codegen_stmt<'tcx>(
649649
| CastKind::IntToFloat
650650
| CastKind::FnPtrToPtr
651651
| CastKind::PtrToPtr
652-
| CastKind::PointerExposeAddress
652+
| CastKind::PointerExposeProvenance
653653
| CastKind::PointerWithExposedProvenance,
654654
ref operand,
655655
to_ty,

compiler/rustc_codegen_cranelift/src/intrinsics/llvm_x86.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ fn llvm_add_sub<'tcx>(
13931393

13941394
// c + carry -> c + first intermediate carry or borrow respectively
13951395
let int0 = crate::num::codegen_checked_int_binop(fx, bin_op, a, b);
1396-
let c = int0.value_field(fx, FieldIdx::new(0));
1396+
let c = int0.value_field(fx, FieldIdx::ZERO);
13971397
let cb0 = int0.value_field(fx, FieldIdx::new(1)).load_scalar(fx);
13981398

13991399
// c + carry -> c + second intermediate carry or borrow respectively

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
965965
});
966966
}
967967

968-
sym::simd_expose_addr | sym::simd_with_exposed_provenance | sym::simd_cast_ptr => {
968+
sym::simd_expose_provenance | sym::simd_with_exposed_provenance | sym::simd_cast_ptr => {
969969
intrinsic_args!(fx, args => (arg); intrinsic);
970970
ret.write_cvalue_transmute(fx, arg);
971971
}

compiler/rustc_codegen_cranelift/src/vtable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
6161
if ty.is_dyn_star() {
6262
let inner_layout = fx.layout_of(arg.layout().ty.builtin_deref(true).unwrap().ty);
6363
let dyn_star = CPlace::for_ptr(Pointer::new(arg.load_scalar(fx)), inner_layout);
64-
let ptr = dyn_star.place_field(fx, FieldIdx::new(0)).to_ptr();
64+
let ptr = dyn_star.place_field(fx, FieldIdx::ZERO).to_ptr();
6565
let vtable =
6666
dyn_star.place_field(fx, FieldIdx::new(1)).to_cvalue(fx).load_scalar(fx);
6767
break 'block (ptr, vtable);

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 51 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ pub use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
1616
use rustc_middle::ty::Ty;
1717
use rustc_session::config;
1818
pub use rustc_target::abi::call::*;
19-
use rustc_target::abi::{self, HasDataLayout, Int};
19+
use rustc_target::abi::{self, HasDataLayout, Int, Size};
2020
pub use rustc_target::spec::abi::Abi;
2121
use rustc_target::spec::SanitizerSet;
2222

2323
use libc::c_uint;
2424
use smallvec::SmallVec;
2525

26+
use std::cmp;
27+
2628
pub trait ArgAttributesExt {
2729
fn apply_attrs_to_llfn(&self, idx: AttributePlace, cx: &CodegenCx<'_, '_>, llfn: &Value);
2830
fn apply_attrs_to_callsite(
@@ -130,42 +132,36 @@ impl LlvmType for Reg {
130132
impl LlvmType for CastTarget {
131133
fn llvm_type<'ll>(&self, cx: &CodegenCx<'ll, '_>) -> &'ll Type {
132134
let rest_ll_unit = self.rest.unit.llvm_type(cx);
133-
let (rest_count, rem_bytes) = if self.rest.unit.size.bytes() == 0 {
134-
(0, 0)
135+
let rest_count = if self.rest.total == Size::ZERO {
136+
0
135137
} else {
136-
(
137-
self.rest.total.bytes() / self.rest.unit.size.bytes(),
138-
self.rest.total.bytes() % self.rest.unit.size.bytes(),
139-
)
138+
assert_ne!(
139+
self.rest.unit.size,
140+
Size::ZERO,
141+
"total size {:?} cannot be divided into units of zero size",
142+
self.rest.total
143+
);
144+
if self.rest.total.bytes() % self.rest.unit.size.bytes() != 0 {
145+
assert_eq!(self.rest.unit.kind, RegKind::Integer, "only int regs can be split");
146+
}
147+
self.rest.total.bytes().div_ceil(self.rest.unit.size.bytes())
140148
};
141149

150+
// Simplify to a single unit or an array if there's no prefix.
151+
// This produces the same layout, but using a simpler type.
142152
if self.prefix.iter().all(|x| x.is_none()) {
143-
// Simplify to a single unit when there is no prefix and size <= unit size
144-
if self.rest.total <= self.rest.unit.size {
153+
if rest_count == 1 {
145154
return rest_ll_unit;
146155
}
147156

148-
// Simplify to array when all chunks are the same size and type
149-
if rem_bytes == 0 {
150-
return cx.type_array(rest_ll_unit, rest_count);
151-
}
152-
}
153-
154-
// Create list of fields in the main structure
155-
let mut args: Vec<_> = self
156-
.prefix
157-
.iter()
158-
.flat_map(|option_reg| option_reg.map(|reg| reg.llvm_type(cx)))
159-
.chain((0..rest_count).map(|_| rest_ll_unit))
160-
.collect();
161-
162-
// Append final integer
163-
if rem_bytes != 0 {
164-
// Only integers can be really split further.
165-
assert_eq!(self.rest.unit.kind, RegKind::Integer);
166-
args.push(cx.type_ix(rem_bytes * 8));
157+
return cx.type_array(rest_ll_unit, rest_count);
167158
}
168159

160+
// Generate a struct type with the prefix and the "rest" arguments.
161+
let prefix_args =
162+
self.prefix.iter().flat_map(|option_reg| option_reg.map(|reg| reg.llvm_type(cx)));
163+
let rest_args = (0..rest_count).map(|_| rest_ll_unit);
164+
let args: Vec<_> = prefix_args.chain(rest_args).collect();
169165
cx.type_struct(&args, false)
170166
}
171167
}
@@ -215,47 +211,33 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
215211
bug!("unsized `ArgAbi` must be handled through `store_fn_arg`");
216212
}
217213
PassMode::Cast { cast, pad_i32: _ } => {
218-
// FIXME(eddyb): Figure out when the simpler Store is safe, clang
219-
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
220-
let can_store_through_cast_ptr = false;
221-
if can_store_through_cast_ptr {
222-
bx.store(val, dst.llval, self.layout.align.abi);
223-
} else {
224-
// The actual return type is a struct, but the ABI
225-
// adaptation code has cast it into some scalar type. The
226-
// code that follows is the only reliable way I have
227-
// found to do a transform like i64 -> {i32,i32}.
228-
// Basically we dump the data onto the stack then memcpy it.
229-
//
230-
// Other approaches I tried:
231-
// - Casting rust ret pointer to the foreign type and using Store
232-
// is (a) unsafe if size of foreign type > size of rust type and
233-
// (b) runs afoul of strict aliasing rules, yielding invalid
234-
// assembly under -O (specifically, the store gets removed).
235-
// - Truncating foreign type to correct integral type and then
236-
// bitcasting to the struct type yields invalid cast errors.
237-
238-
// We instead thus allocate some scratch space...
239-
let scratch_size = cast.size(bx);
240-
let scratch_align = cast.align(bx);
241-
let llscratch = bx.alloca(cast.llvm_type(bx), scratch_align);
242-
bx.lifetime_start(llscratch, scratch_size);
243-
244-
// ... where we first store the value...
245-
bx.store(val, llscratch, scratch_align);
246-
247-
// ... and then memcpy it to the intended destination.
248-
bx.memcpy(
249-
dst.llval,
250-
self.layout.align.abi,
251-
llscratch,
252-
scratch_align,
253-
bx.const_usize(self.layout.size.bytes()),
254-
MemFlags::empty(),
255-
);
256-
257-
bx.lifetime_end(llscratch, scratch_size);
258-
}
214+
// The ABI mandates that the value is passed as a different struct representation.
215+
// Spill and reload it from the stack to convert from the ABI representation to
216+
// the Rust representation.
217+
let scratch_size = cast.size(bx);
218+
let scratch_align = cast.align(bx);
219+
// Note that the ABI type may be either larger or smaller than the Rust type,
220+
// due to the presence or absence of trailing padding. For example:
221+
// - On some ABIs, the Rust layout { f64, f32, <f32 padding> } may omit padding
222+
// when passed by value, making it smaller.
223+
// - On some ABIs, the Rust layout { u16, u16, u16 } may be padded up to 8 bytes
224+
// when passed by value, making it larger.
225+
let copy_bytes = cmp::min(scratch_size.bytes(), self.layout.size.bytes());
226+
// Allocate some scratch space...
227+
let llscratch = bx.alloca(cast.llvm_type(bx), scratch_align);
228+
bx.lifetime_start(llscratch, scratch_size);
229+
// ...store the value...
230+
bx.store(val, llscratch, scratch_align);
231+
// ... and then memcpy it to the intended destination.
232+
bx.memcpy(
233+
dst.llval,
234+
self.layout.align.abi,
235+
llscratch,
236+
scratch_align,
237+
bx.const_usize(copy_bytes),
238+
MemFlags::empty(),
239+
);
240+
bx.lifetime_end(llscratch, scratch_size);
259241
}
260242
_ => {
261243
OperandRef::from_immediate_or_packed_pair(bx, val, self.layout).val.store(bx, dst);

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
21112111
return Ok(args[0].immediate());
21122112
}
21132113

2114-
if name == sym::simd_expose_addr {
2114+
if name == sym::simd_expose_provenance {
21152115
let (out_len, out_elem) = require_simd!(ret_ty, SimdReturn);
21162116
require!(
21172117
in_len == out_len,

0 commit comments

Comments
 (0)