Skip to content

Commit 0f14563

Browse files
committed
Auto merge of rust-lang#151490 - JonathanBrouwer:rollup-ovStnQE, r=JonathanBrouwer
Rollup of 11 pull requests Successful merges: - rust-lang#151001 (rustdoc: render doc(hidden) as a code attribute) - rust-lang#151042 (fix fallback impl for select_unpredictable intrinsic) - rust-lang#151220 (option: Use Option::map in Option::cloned) - rust-lang#151260 (Handle unevaluated ConstKind in in_operand) - rust-lang#151296 (MGCA: Fix incorrect pretty printing of valtree arrays) - rust-lang#151423 (Move assert_matches to planned stable path) - rust-lang#151441 (Fix ICE: Don't try to evaluate type_consts when eagerly collecting items) - rust-lang#151465 (codegen: clarify some variable names around function calls) - rust-lang#151468 (fix `f16` doctest FIXMEs) - rust-lang#151469 (llvm: Tolerate dead_on_return attribute changes) - rust-lang#151476 (Avoid `-> ()` in derived functions.) r? @ghost
2 parents d29e478 + d86afd2 commit 0f14563

File tree

55 files changed

+388
-246
lines changed

Some content is hidden

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

55 files changed

+388
-246
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -986,16 +986,6 @@ impl<'a> MethodDef<'a> {
986986
f(cx, span, &substructure)
987987
}
988988

989-
fn get_ret_ty(
990-
&self,
991-
cx: &ExtCtxt<'_>,
992-
trait_: &TraitDef<'_>,
993-
generics: &Generics,
994-
type_ident: Ident,
995-
) -> Box<ast::Ty> {
996-
self.ret_ty.to_ty(cx, trait_.span, type_ident, generics)
997-
}
998-
999989
fn is_static(&self) -> bool {
1000990
!self.explicit_self
1001991
}
@@ -1068,10 +1058,14 @@ impl<'a> MethodDef<'a> {
10681058
self_arg.into_iter().chain(nonself_args).collect()
10691059
};
10701060

1071-
let ret_type = self.get_ret_ty(cx, trait_, generics, type_ident);
1061+
let ret_type = if let Ty::Unit = &self.ret_ty {
1062+
ast::FnRetTy::Default(span)
1063+
} else {
1064+
ast::FnRetTy::Ty(self.ret_ty.to_ty(cx, span, type_ident, generics))
1065+
};
10721066

10731067
let method_ident = Ident::new(self.name, span);
1074-
let fn_decl = cx.fn_decl(args, ast::FnRetTy::Ty(ret_type));
1068+
let fn_decl = cx.fn_decl(args, ret_type);
10751069
let body_block = body.into_block(cx, span);
10761070

10771071
let trait_lo_sp = span.shrink_to_lo();

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,12 +1397,12 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13971397
fn call(
13981398
&mut self,
13991399
llty: &'ll Type,
1400-
fn_call_attrs: Option<&CodegenFnAttrs>,
1400+
caller_attrs: Option<&CodegenFnAttrs>,
14011401
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
14021402
llfn: &'ll Value,
14031403
args: &[&'ll Value],
14041404
funclet: Option<&Funclet<'ll>>,
1405-
instance: Option<Instance<'tcx>>,
1405+
callee_instance: Option<Instance<'tcx>>,
14061406
) -> &'ll Value {
14071407
debug!("call {:?} with args ({:?})", llfn, args);
14081408

@@ -1414,10 +1414,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14141414
}
14151415

14161416
// Emit CFI pointer type membership test
1417-
self.cfi_type_test(fn_call_attrs, fn_abi, instance, llfn);
1417+
self.cfi_type_test(caller_attrs, fn_abi, callee_instance, llfn);
14181418

14191419
// Emit KCFI operand bundle
1420-
let kcfi_bundle = self.kcfi_operand_bundle(fn_call_attrs, fn_abi, instance, llfn);
1420+
let kcfi_bundle = self.kcfi_operand_bundle(caller_attrs, fn_abi, callee_instance, llfn);
14211421
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.as_ref()) {
14221422
bundles.push(kcfi_bundle);
14231423
}
@@ -1435,17 +1435,17 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14351435
)
14361436
};
14371437

1438-
if let Some(instance) = instance {
1438+
if let Some(callee_instance) = callee_instance {
14391439
// Attributes on the function definition being called
1440-
let fn_defn_attrs = self.cx.tcx.codegen_fn_attrs(instance.def_id());
1441-
if let Some(fn_call_attrs) = fn_call_attrs
1440+
let callee_attrs = self.cx.tcx.codegen_fn_attrs(callee_instance.def_id());
1441+
if let Some(caller_attrs) = caller_attrs
14421442
// If there is an inline attribute and a target feature that matches
14431443
// we will add the attribute to the callsite otherwise we'll omit
14441444
// this and not add the attribute to prevent soundness issues.
1445-
&& let Some(inlining_rule) = attributes::inline_attr(&self.cx, self.cx.tcx, instance)
1445+
&& let Some(inlining_rule) = attributes::inline_attr(&self.cx, self.cx.tcx, callee_instance)
14461446
&& self.cx.tcx.is_target_feature_call_safe(
1447-
&fn_defn_attrs.target_features,
1448-
&fn_call_attrs.target_features.iter().cloned().chain(
1447+
&callee_attrs.target_features,
1448+
&caller_attrs.target_features.iter().cloned().chain(
14491449
self.cx.tcx.sess.target_features.iter().map(|feat| TargetFeature {
14501450
name: *feat,
14511451
kind: TargetFeatureKind::Implied,
@@ -1470,14 +1470,15 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14701470
fn tail_call(
14711471
&mut self,
14721472
llty: Self::Type,
1473-
fn_attrs: Option<&CodegenFnAttrs>,
1473+
caller_attrs: Option<&CodegenFnAttrs>,
14741474
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
14751475
llfn: Self::Value,
14761476
args: &[Self::Value],
14771477
funclet: Option<&Self::Funclet>,
1478-
instance: Option<Instance<'tcx>>,
1478+
callee_instance: Option<Instance<'tcx>>,
14791479
) {
1480-
let call = self.call(llty, fn_attrs, Some(fn_abi), llfn, args, funclet, instance);
1480+
let call =
1481+
self.call(llty, caller_attrs, Some(fn_abi), llfn, args, funclet, callee_instance);
14811482
llvm::LLVMSetTailCallKind(call, llvm::TailCallKind::MustTail);
14821483

14831484
match &fn_abi.ret.mode {

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
199199
// do an invoke, otherwise do a call.
200200
let fn_ty = bx.fn_decl_backend_type(fn_abi);
201201

202-
let fn_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() {
202+
let caller_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() {
203203
Some(bx.tcx().codegen_instance_attrs(fx.instance.def))
204204
} else {
205205
None
206206
};
207-
let fn_attrs = fn_attrs.as_deref();
207+
let caller_attrs = caller_attrs.as_deref();
208208

209209
if !fn_abi.can_unwind {
210210
unwind = mir::UnwindAction::Unreachable;
@@ -233,7 +233,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
233233
};
234234

235235
if kind == CallKind::Tail {
236-
bx.tail_call(fn_ty, fn_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance);
236+
bx.tail_call(fn_ty, caller_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance);
237237
return MergingSucc::False;
238238
}
239239

@@ -245,7 +245,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
245245
};
246246
let invokeret = bx.invoke(
247247
fn_ty,
248-
fn_attrs,
248+
caller_attrs,
249249
Some(fn_abi),
250250
fn_ptr,
251251
llargs,
@@ -268,8 +268,15 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
268268
}
269269
MergingSucc::False
270270
} else {
271-
let llret =
272-
bx.call(fn_ty, fn_attrs, Some(fn_abi), fn_ptr, llargs, self.funclet(fx), instance);
271+
let llret = bx.call(
272+
fn_ty,
273+
caller_attrs,
274+
Some(fn_abi),
275+
fn_ptr,
276+
llargs,
277+
self.funclet(fx),
278+
instance,
279+
);
273280
if fx.mir[self.bb].is_cleanup {
274281
bx.apply_attrs_to_cleanup_callsite(llret);
275282
}

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,13 @@ pub trait BuilderMethods<'a, 'tcx>:
600600
///
601601
/// ## Arguments
602602
///
603-
/// The `fn_attrs`, `fn_abi`, and `instance` arguments are Options because they are advisory.
604-
/// They relate to optional codegen enhancements like LLVM CFI, and do not affect ABI per se.
605-
/// Any ABI-related transformations should be handled by different, earlier stages of codegen.
606-
/// For instance, in the caller of `BuilderMethods::call`.
603+
/// `caller_attrs` are the attributes of the surrounding caller; they have nothing to do with
604+
/// the callee.
605+
///
606+
/// The `caller_attrs`, `fn_abi`, and `callee_instance` arguments are Options because they are
607+
/// advisory. They relate to optional codegen enhancements like LLVM CFI, and do not affect ABI
608+
/// per se. Any ABI-related transformations should be handled by different, earlier stages of
609+
/// codegen. For instance, in the caller of `BuilderMethods::call`.
607610
///
608611
/// This means that a codegen backend which disregards `fn_attrs`, `fn_abi`, and `instance`
609612
/// should still do correct codegen, and code should not be miscompiled if they are omitted.
@@ -620,23 +623,23 @@ pub trait BuilderMethods<'a, 'tcx>:
620623
fn call(
621624
&mut self,
622625
llty: Self::Type,
623-
fn_attrs: Option<&CodegenFnAttrs>,
626+
caller_attrs: Option<&CodegenFnAttrs>,
624627
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
625628
fn_val: Self::Value,
626629
args: &[Self::Value],
627630
funclet: Option<&Self::Funclet>,
628-
instance: Option<Instance<'tcx>>,
631+
callee_instance: Option<Instance<'tcx>>,
629632
) -> Self::Value;
630633

631634
fn tail_call(
632635
&mut self,
633636
llty: Self::Type,
634-
fn_attrs: Option<&CodegenFnAttrs>,
637+
caller_attrs: Option<&CodegenFnAttrs>,
635638
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
636639
llfn: Self::Value,
637640
args: &[Self::Value],
638641
funclet: Option<&Self::Funclet>,
639-
instance: Option<Instance<'tcx>>,
642+
callee_instance: Option<Instance<'tcx>>,
640643
);
641644

642645
fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,18 @@ where
343343

344344
// Check the qualifs of the value of `const` items.
345345
let uneval = match constant.const_ {
346-
Const::Ty(_, ct)
347-
if matches!(
348-
ct.kind(),
349-
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) | ty::ConstKind::Value(_)
350-
) =>
351-
{
352-
None
353-
}
354-
Const::Ty(_, c) => {
355-
bug!("expected ConstKind::Param or ConstKind::Value here, found {:?}", c)
356-
}
346+
Const::Ty(_, ct) => match ct.kind() {
347+
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => None,
348+
// Unevaluated consts in MIR bodies don't have associated MIR (e.g. `#[type_const]`).
349+
ty::ConstKind::Unevaluated(_) => None,
350+
// FIXME(mgca): Investigate whether using `None` for `ConstKind::Value` is overly
351+
// strict, and if instead we should be doing some kind of value-based analysis.
352+
ty::ConstKind::Value(_) => None,
353+
_ => bug!(
354+
"expected ConstKind::Param, ConstKind::Value, ConstKind::Unevaluated, or ConstKind::Error here, found {:?}",
355+
ct
356+
),
357+
},
357358
Const::Unevaluated(uv, _) => Some(uv),
358359
Const::Val(..) => None,
359360
};
@@ -364,10 +365,8 @@ where
364365
// check performed after the promotion. Verify that with an assertion.
365366
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
366367

367-
// Don't peak inside trait associated constants, also `#[type_const] const` items
368-
// don't have bodies so there's nothing to look at
369-
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() && !cx.tcx.is_type_const(def)
370-
{
368+
// Don't peak inside trait associated constants.
369+
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() {
371370
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def);
372371

373372
if !Q::in_qualifs(&qualifs) {

compiler/rustc_data_structures/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@
4141
// have to worry about it being moved to a different module in std during stabilization.
4242
// FIXME(#151359): Remove this when `feature(assert_matches)` is stable in stage0.
4343
// (This doesn't necessarily need to be fixed during the beta bump itself.)
44+
#[cfg(bootstrap)]
4445
pub use std::assert_matches::{assert_matches, debug_assert_matches};
4546
use std::fmt;
47+
#[cfg(not(bootstrap))]
48+
pub use std::{assert_matches, debug_assert_matches};
4649

4750
pub use atomic_ref::AtomicRef;
4851
pub use ena::{snapshot_vec, undo_log, unify};

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,12 @@ LLVMRustCreateAttrNoValue(LLVMContextRef C, LLVMRustAttributeKind RustAttr) {
527527
*unwrap(C), CaptureInfo(CaptureComponents::Address |
528528
CaptureComponents::ReadProvenance)));
529529
}
530+
#endif
531+
#if LLVM_VERSION_GE(23, 0)
532+
if (RustAttr == LLVMRustAttributeKind::DeadOnReturn) {
533+
return wrap(Attribute::getWithDeadOnReturnInfo(*unwrap(C),
534+
llvm::DeadOnReturnInfo()));
535+
}
530536
#endif
531537
return wrap(Attribute::get(*unwrap(C), fromRust(RustAttr)));
532538
}

compiler/rustc_middle/src/ty/consts/valtree.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,12 @@ impl<'tcx> Value<'tcx> {
147147
_ => return None,
148148
}
149149

150-
Some(tcx.arena.alloc_from_iter(self.to_branch().into_iter().map(|ct| ct.to_leaf().to_u8())))
150+
// We create an iterator that yields `Option<u8>`
151+
let iterator = self.to_branch().into_iter().map(|ct| Some(ct.try_to_leaf()?.to_u8()));
152+
// If there is `None` in the iterator, then the array is not a valid array of u8s and we return `None`
153+
let bytes: Vec<u8> = iterator.collect::<Option<Vec<u8>>>()?;
154+
155+
Some(tcx.arena.alloc_from_iter(bytes))
151156
}
152157

153158
/// Converts to a `ValTreeKind::Leaf` value, `panic`'ing

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,14 +1911,16 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
19111911
return Ok(());
19121912
}
19131913
},
1914-
(ty::ValTreeKind::Branch(_), ty::Array(t, _)) if t == u8_type => {
1915-
let bytes = cv.try_to_raw_bytes(self.tcx()).unwrap_or_else(|| {
1916-
bug!("expected to convert valtree to raw bytes for type {:?}", t)
1917-
});
1914+
// If it is a branch with an array, and this array can be printed as raw bytes, then dump its bytes
1915+
(ty::ValTreeKind::Branch(_), ty::Array(t, _))
1916+
if t == u8_type
1917+
&& let Some(bytes) = cv.try_to_raw_bytes(self.tcx()) =>
1918+
{
19181919
write!(self, "*")?;
19191920
self.pretty_print_byte_str(bytes)?;
19201921
return Ok(());
19211922
}
1923+
// Otherwise, print the array separated by commas (or if it's a tuple)
19221924
(ty::ValTreeKind::Branch(fields), ty::Array(..) | ty::Tuple(..)) => {
19231925
let fields_iter = fields.iter().copied();
19241926

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,11 +1563,22 @@ impl<'v> RootCollector<'_, 'v> {
15631563
// If we're collecting items eagerly, then recurse into all constants.
15641564
// Otherwise the value is only collected when explicitly mentioned in other items.
15651565
if self.strategy == MonoItemCollectionStrategy::Eager {
1566-
if !self.tcx.generics_of(id.owner_id).own_requires_monomorphization()
1567-
&& let Ok(val) = self.tcx.const_eval_poly(id.owner_id.to_def_id())
1568-
{
1569-
collect_const_value(self.tcx, val, self.output);
1566+
let def_id = id.owner_id.to_def_id();
1567+
// Type Consts don't have bodies to evaluate
1568+
// nor do they make sense as a static.
1569+
if self.tcx.is_type_const(def_id) {
1570+
// FIXME(mgca): Is this actually what we want? We may want to
1571+
// normalize to a ValTree then convert to a const allocation and
1572+
// collect that?
1573+
return;
1574+
}
1575+
if self.tcx.generics_of(id.owner_id).own_requires_monomorphization() {
1576+
return;
15701577
}
1578+
let Ok(val) = self.tcx.const_eval_poly(def_id) else {
1579+
return;
1580+
};
1581+
collect_const_value(self.tcx, val, self.output);
15711582
}
15721583
}
15731584
DefKind::Impl { of_trait: true } => {

0 commit comments

Comments
 (0)