Skip to content

Commit 16ad385

Browse files
committed
Auto merge of #145599 - jieyouxu:rollup-523cxhm, r=jieyouxu
Rollup of 15 pull requests Successful merges: - #139345 (Extend `QueryStability` to handle `IntoIterator` implementations) - #140740 (Add `-Zindirect-branch-cs-prefix`) - #142079 (nll-relate: improve hr opaque types support) - #142938 (implement std::fs::set_permissions_nofollow on unix) - #143730 (fmt of non-decimal radix untangled) - #144767 (Correct some grammar in integer documentation) - #144906 (Require approval from t-infra instead of t-release on tier bumps) - #144983 (Rehome 37 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`) - #145025 (run spellcheck as a tidy extra check in ci) - #145099 (rustc_target: Add the `32s` target feature for LoongArch) - #145166 (suggest using `pub(crate)` for E0364) - #145255 (dec2flt: Provide more valid inputs examples) - #145306 (Add tracing to various miscellaneous functions) - #145336 (Hide docs for `core::unicode`) - #145585 (Miri: fix handling of in-place argument and return place handling) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8c32e31 + 5d37e8e commit 16ad385

File tree

163 files changed

+1121
-550
lines changed

Some content is hidden

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

163 files changed

+1121
-550
lines changed

compiler/rustc_borrowck/src/type_check/relate_tys.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,13 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
124124
// by using `ty_vid rel B` and then finally and end by equating `ty_vid` to
125125
// the opaque.
126126
let mut enable_subtyping = |ty, opaque_is_expected| {
127-
let ty_vid = infcx.next_ty_var_id_in_universe(self.span(), ty::UniverseIndex::ROOT);
128-
127+
// We create the fresh inference variable in the highest universe.
128+
// In theory we could limit it to the highest universe in the args of
129+
// the opaque but that isn't really worth the effort.
130+
//
131+
// We'll make sure that the opaque type can actually name everything
132+
// in its hidden type later on.
133+
let ty_vid = infcx.next_ty_vid(self.span());
129134
let variance = if opaque_is_expected {
130135
self.ambient_variance
131136
} else {

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,15 @@ pub(crate) unsafe fn create_module<'ll>(
471471
}
472472
}
473473

474+
if sess.opts.unstable_opts.indirect_branch_cs_prefix {
475+
llvm::add_module_flag_u32(
476+
llmod,
477+
llvm::ModuleFlagMergeBehavior::Override,
478+
"indirect_branch_cs_prefix",
479+
1,
480+
);
481+
}
482+
474483
match (sess.opts.unstable_opts.small_data_threshold, sess.target.small_data_threshold_support())
475484
{
476485
// Set up the small-data optimization limit for architectures that use

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
277277
{
278278
None
279279
}
280+
("loongarch32" | "loongarch64", "32s") if get_version().0 < 21 => None,
280281
// Filter out features that are not supported by the current LLVM version
281282
("riscv32" | "riscv64", "zacas") if get_version().0 < 20 => None,
282283
(

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ fn parse_rust_feature_flag<'a>(
180180
while let Some(new_feature) = new_features.pop() {
181181
if features.insert(new_feature) {
182182
if let Some(implied_features) = inverse_implied_features.get(&new_feature) {
183+
#[allow(rustc::potential_query_instability)]
183184
new_features.extend(implied_features)
184185
}
185186
}

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ use crate::{enter_trace_span, fluent_generated as fluent};
2727
pub enum FnArg<'tcx, Prov: Provenance = CtfeProvenance> {
2828
/// Pass a copy of the given operand.
2929
Copy(OpTy<'tcx, Prov>),
30-
/// Allow for the argument to be passed in-place: destroy the value originally stored at that place and
31-
/// make the place inaccessible for the duration of the function call.
30+
/// Allow for the argument to be passed in-place: destroy the value originally stored at that
31+
/// place and make the place inaccessible for the duration of the function call. This *must* be
32+
/// an in-memory place so that we can do the proper alias checks.
3233
InPlace(MPlaceTy<'tcx, Prov>),
3334
}
3435

@@ -379,6 +380,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
379380
}
380381
}
381382

383+
// *Before* pushing the new frame, determine whether the return destination is in memory.
384+
// Need to use `place_to_op` to be *sure* we get the mplace if there is one.
385+
let destination_mplace = self.place_to_op(destination)?.as_mplace_or_imm().left();
386+
387+
// Push the "raw" frame -- this leaves locals uninitialized.
382388
self.push_stack_frame_raw(instance, body, destination, cont)?;
383389

384390
// If an error is raised here, pop the frame again to get an accurate backtrace.
@@ -496,7 +502,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
496502

497503
// Protect return place for in-place return value passing.
498504
// We only need to protect anything if this is actually an in-memory place.
499-
if let Left(mplace) = destination.as_mplace_or_local() {
505+
if let Some(mplace) = destination_mplace {
500506
M::protect_in_place_function_argument(self, &mplace)?;
501507
}
502508

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
325325
let _trace = enter_trace_span!(
326326
M,
327327
"instantiate_from_frame_and_normalize_erasing_regions",
328-
"{}",
329-
frame.instance
328+
%frame.instance
330329
);
331330
frame
332331
.instance
@@ -583,6 +582,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
583582
span: Span,
584583
layout: Option<TyAndLayout<'tcx>>,
585584
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
585+
let _trace = enter_trace_span!(M, const_eval::eval_mir_constant, ?val);
586586
let const_val = val.eval(*self.tcx, self.typing_env, span).map_err(|err| {
587587
if M::ALL_CONSTS_ARE_PRECHECKED {
588588
match err {

compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ impl<'tcx, Prov: Provenance> PlaceTy<'tcx, Prov> {
234234
}
235235

236236
/// A place is either an mplace or some local.
237+
///
238+
/// Note that the return value can be different even for logically identical places!
239+
/// Specifically, if a local is stored in-memory, this may return `Local` or `MPlaceTy`
240+
/// depending on how the place was constructed. In other words, seeing `Local` here does *not*
241+
/// imply that this place does not point to memory. Every caller must therefore always handle
242+
/// both cases.
237243
#[inline(always)]
238244
pub fn as_mplace_or_local(
239245
&self,

compiler/rustc_const_eval/src/interpret/stack.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use super::{
2020
MemoryKind, Operand, PlaceTy, Pointer, Provenance, ReturnAction, Scalar, from_known_layout,
2121
interp_ok, throw_ub, throw_unsup,
2222
};
23-
use crate::errors;
23+
use crate::{enter_trace_span, errors};
2424

2525
// The Phantomdata exists to prevent this type from being `Send`. If it were sent across a thread
2626
// boundary and dropped in the other thread, it would exit the span in the other thread.
@@ -386,6 +386,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
386386

387387
// Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
388388
for &const_ in body.required_consts() {
389+
// We can't use `eval_mir_constant` here as that assumes that all required consts have
390+
// already been checked, so we need a separate tracing call.
391+
let _trace = enter_trace_span!(M, const_eval::required_consts, ?const_.const_);
389392
let c =
390393
self.instantiate_from_current_frame_and_normalize_erasing_regions(const_.const_)?;
391394
c.eval(*self.tcx, self.typing_env, const_.span).map_err(|err| {

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
use either::Either;
66
use rustc_abi::{FIRST_VARIANT, FieldIdx};
7+
use rustc_data_structures::fx::FxHashSet;
78
use rustc_index::IndexSlice;
89
use rustc_middle::ty::{self, Instance, Ty};
910
use rustc_middle::{bug, mir, span_bug};
@@ -389,8 +390,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
389390

390391
/// Evaluate the arguments of a function call
391392
fn eval_fn_call_argument(
392-
&self,
393+
&mut self,
393394
op: &mir::Operand<'tcx>,
395+
move_definitely_disjoint: bool,
394396
) -> InterpResult<'tcx, FnArg<'tcx, M::Provenance>> {
395397
interp_ok(match op {
396398
mir::Operand::Copy(_) | mir::Operand::Constant(_) => {
@@ -399,24 +401,19 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
399401
FnArg::Copy(op)
400402
}
401403
mir::Operand::Move(place) => {
402-
// If this place lives in memory, preserve its location.
403-
// We call `place_to_op` which will be an `MPlaceTy` whenever there exists
404-
// an mplace for this place. (This is in contrast to `PlaceTy::as_mplace_or_local`
405-
// which can return a local even if that has an mplace.)
406404
let place = self.eval_place(*place)?;
407-
let op = self.place_to_op(&place)?;
408-
409-
match op.as_mplace_or_imm() {
410-
Either::Left(mplace) => FnArg::InPlace(mplace),
411-
Either::Right(_imm) => {
412-
// This argument doesn't live in memory, so there's no place
413-
// to make inaccessible during the call.
414-
// We rely on there not being any stray `PlaceTy` that would let the
415-
// caller directly access this local!
416-
// This is also crucial for tail calls, where we want the `FnArg` to
417-
// stay valid when the old stack frame gets popped.
418-
FnArg::Copy(op)
405+
if move_definitely_disjoint {
406+
// We still have to ensure that no *other* pointers are used to access this place,
407+
// so *if* it is in memory then we have to treat it as `InPlace`.
408+
// Use `place_to_op` to guarantee that we notice it being in memory.
409+
let op = self.place_to_op(&place)?;
410+
match op.as_mplace_or_imm() {
411+
Either::Left(mplace) => FnArg::InPlace(mplace),
412+
Either::Right(_imm) => FnArg::Copy(op),
419413
}
414+
} else {
415+
// We have to force this into memory to detect aliasing among `Move` arguments.
416+
FnArg::InPlace(self.force_allocation(&place)?)
420417
}
421418
}
422419
})
@@ -425,18 +422,46 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
425422
/// Shared part of `Call` and `TailCall` implementation — finding and evaluating all the
426423
/// necessary information about callee and arguments to make a call.
427424
fn eval_callee_and_args(
428-
&self,
425+
&mut self,
429426
terminator: &mir::Terminator<'tcx>,
430427
func: &mir::Operand<'tcx>,
431428
args: &[Spanned<mir::Operand<'tcx>>],
432429
) -> InterpResult<'tcx, EvaluatedCalleeAndArgs<'tcx, M>> {
433430
let func = self.eval_operand(func, None)?;
431+
432+
// Evaluating function call arguments. The tricky part here is dealing with `Move`
433+
// arguments: we have to ensure no two such arguments alias. This would be most easily done
434+
// by just forcing them all into memory and then doing the usual in-place argument
435+
// protection, but then we'd force *a lot* of arguments into memory. So we do some syntactic
436+
// pre-processing here where if all `move` arguments are syntactically distinct local
437+
// variables (and none is indirect), we can skip the in-memory forcing.
438+
let move_definitely_disjoint = 'move_definitely_disjoint: {
439+
let mut previous_locals = FxHashSet::<mir::Local>::default();
440+
for arg in args {
441+
let mir::Operand::Move(place) = arg.node else {
442+
continue; // we can skip non-`Move` arguments.
443+
};
444+
if place.is_indirect_first_projection() {
445+
// An indirect `Move` argument could alias with anything else...
446+
break 'move_definitely_disjoint false;
447+
}
448+
if !previous_locals.insert(place.local) {
449+
// This local is the base for two arguments! They might overlap.
450+
break 'move_definitely_disjoint false;
451+
}
452+
}
453+
// We found no violation so they are all definitely disjoint.
454+
true
455+
};
434456
let args = args
435457
.iter()
436-
.map(|arg| self.eval_fn_call_argument(&arg.node))
458+
.map(|arg| self.eval_fn_call_argument(&arg.node, move_definitely_disjoint))
437459
.collect::<InterpResult<'tcx, Vec<_>>>()?;
438460

439-
let fn_sig_binder = func.layout.ty.fn_sig(*self.tcx);
461+
let fn_sig_binder = {
462+
let _trace = enter_trace_span!(M, "fn_sig", ty = ?func.layout.ty.kind());
463+
func.layout.ty.fn_sig(*self.tcx)
464+
};
440465
let fn_sig = self.tcx.normalize_erasing_late_bound_regions(self.typing_env, fn_sig_binder);
441466
let extra_args = &args[fn_sig.inputs().len()..];
442467
let extra_args =

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
14181418
let _trace = enter_trace_span!(
14191419
M,
14201420
"validate_operand",
1421-
"recursive={recursive}, reset_provenance_and_padding={reset_provenance_and_padding}, val={val:?}"
1421+
recursive,
1422+
reset_provenance_and_padding,
1423+
?val,
14221424
);
14231425

14241426
// Note that we *could* actually be in CTFE here with `-Zextra-const-ub-checks`, but it's

0 commit comments

Comments
 (0)