Skip to content

Commit 70adb4e

Browse files
committed
Auto merge of rust-lang#108709 - matthiaskrgr:rollup-j2tjbyx, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#104549 (add -Zexport-executable-symbols to unstable book) - rust-lang#108292 (Label opaque type for 'captures lifetime' error message) - rust-lang#108540 (Add `Atomic*::from_ptr`) - rust-lang#108634 (Add link to component dashboard) - rust-lang#108647 (Remove dead pgo.sh file) - rust-lang#108678 (Use `Option::as_slice` where applicable) - rust-lang#108681 (Improve comments in `needs_process_obligation`.) - rust-lang#108688 (Match unmatched backticks in library/) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 44cfafe + 7a228ce commit 70adb4e

Some content is hidden

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

50 files changed

+341
-324
lines changed

compiler/rustc_data_structures/src/obligation_forest/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ impl<O: ForestObligation> ObligationForest<O> {
426426
// nodes. Therefore we use a `while` loop.
427427
let mut index = 0;
428428
while let Some(node) = self.nodes.get_mut(index) {
429+
// This test is extremely hot.
429430
if node.state.get() != NodeState::Pending
430431
|| !processor.needs_process_obligation(&node.obligation)
431432
{
@@ -439,6 +440,7 @@ impl<O: ForestObligation> ObligationForest<O> {
439440
// out of sync with `nodes`. It's not very common, but it does
440441
// happen, and code in `compress` has to allow for it.
441442

443+
// This code is much less hot.
442444
match processor.process_obligation(&mut node.obligation) {
443445
ProcessResult::Unchanged => {
444446
// No change in state.

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext}
3636

3737
use std::iter;
3838
use std::mem;
39-
use std::slice;
4039

4140
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4241
pub(in super::super) fn check_casts(&mut self) {
@@ -1507,11 +1506,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15071506
let coerce = if blk.targeted_by_break {
15081507
CoerceMany::new(coerce_to_ty)
15091508
} else {
1510-
let tail_expr: &[&hir::Expr<'_>] = match tail_expr {
1511-
Some(e) => slice::from_ref(e),
1512-
None => &[],
1513-
};
1514-
CoerceMany::with_coercion_sites(coerce_to_ty, tail_expr)
1509+
CoerceMany::with_coercion_sites(coerce_to_ty, blk.expr.as_slice())
15151510
};
15161511

15171512
let prev_diverges = self.diverges.get();

compiler/rustc_hir_typeck/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![feature(min_specialization)]
66
#![feature(control_flow_enum)]
77
#![feature(drain_filter)]
8+
#![feature(option_as_slice)]
89
#![allow(rustc::potential_query_instability)]
910
#![recursion_limit = "256"]
1011

compiler/rustc_hir_typeck/src/op.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -749,14 +749,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
749749
}
750750

751751
let opname = Ident::with_dummy_span(opname);
752-
let input_types =
753-
opt_rhs.as_ref().map(|(_, ty)| std::slice::from_ref(ty)).unwrap_or_default();
752+
let (opt_rhs_expr, opt_rhs_ty) = opt_rhs.unzip();
753+
let input_types = opt_rhs_ty.as_slice();
754754
let cause = self.cause(
755755
span,
756756
traits::BinOp {
757-
rhs_span: opt_rhs.map(|(expr, _)| expr.span),
758-
is_lit: opt_rhs
759-
.map_or(false, |(expr, _)| matches!(expr.kind, hir::ExprKind::Lit(_))),
757+
rhs_span: opt_rhs_expr.map(|expr| expr.span),
758+
is_lit: opt_rhs_expr
759+
.map_or(false, |expr| matches!(expr.kind, hir::ExprKind::Lit(_))),
760760
output_ty: expected.only_has_type(self),
761761
},
762762
);

compiler/rustc_hir_typeck/src/place_op.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_middle::ty::adjustment::{AllowTwoPhase, AutoBorrow, AutoBorrowMutabili
1111
use rustc_middle::ty::{self, Ty};
1212
use rustc_span::symbol::{sym, Ident};
1313
use rustc_span::Span;
14-
use std::slice;
1514

1615
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1716
/// Type-check `*oprnd_expr` with `oprnd_expr` type-checked already.
@@ -393,11 +392,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
393392
Some(self.typeck_results.borrow().node_substs(expr.hir_id).type_at(1))
394393
}
395394
};
396-
let arg_tys = match arg_ty {
397-
None => &[],
398-
Some(ref ty) => slice::from_ref(ty),
399-
};
400-
395+
let arg_tys = arg_ty.as_slice();
401396
let method = self.try_mutable_overloaded_place_op(expr.span, base_ty, arg_tys, op);
402397
let method = match method {
403398
Some(ok) => self.register_infer_ok_obligations(ok),

compiler/rustc_infer/locales/en-US.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,6 @@ infer_prlf_defined_without_sub = the lifetime defined here...
345345
infer_prlf_must_oultive_with_sup = ...must outlive the lifetime `{$sup_symbol}` defined here
346346
infer_prlf_must_oultive_without_sup = ...must outlive the lifetime defined here
347347
infer_prlf_known_limitation = this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)
348+
349+
infer_opaque_captures_lifetime = hidden type for `{$opaque_ty}` captures lifetime that does not appear in bounds
350+
.label = opaque type defined here

compiler/rustc_infer/src/errors/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1147,3 +1147,13 @@ pub enum PlaceholderRelationLfNotSatisfied {
11471147
note: (),
11481148
},
11491149
}
1150+
1151+
#[derive(Diagnostic)]
1152+
#[diag(infer_opaque_captures_lifetime, code = "E0700")]
1153+
pub struct OpaqueCapturesLifetime<'tcx> {
1154+
#[primary_span]
1155+
pub span: Span,
1156+
#[label]
1157+
pub opaque_ty_span: Span,
1158+
pub opaque_ty: Ty<'tcx>,
1159+
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use super::lexical_region_resolve::RegionResolutionError;
4949
use super::region_constraints::GenericKind;
5050
use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs};
5151

52+
use crate::errors;
5253
use crate::infer;
5354
use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type;
5455
use crate::infer::ExpectedFound;
@@ -281,15 +282,13 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
281282
span: Span,
282283
hidden_ty: Ty<'tcx>,
283284
hidden_region: ty::Region<'tcx>,
284-
opaque_ty: ty::OpaqueTypeKey<'tcx>,
285+
opaque_ty_key: ty::OpaqueTypeKey<'tcx>,
285286
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
286-
let opaque_ty = tcx.mk_opaque(opaque_ty.def_id.to_def_id(), opaque_ty.substs);
287-
let mut err = struct_span_err!(
288-
tcx.sess,
287+
let mut err = tcx.sess.create_err(errors::OpaqueCapturesLifetime {
289288
span,
290-
E0700,
291-
"hidden type for `{opaque_ty}` captures lifetime that does not appear in bounds",
292-
);
289+
opaque_ty: tcx.mk_opaque(opaque_ty_key.def_id.to_def_id(), opaque_ty_key.substs),
290+
opaque_ty_span: tcx.def_span(opaque_ty_key.def_id),
291+
});
293292

294293
// Explain the region we are capturing.
295294
match *hidden_region {

compiler/rustc_trait_selection/src/traits/fulfill.rs

+32-24
Original file line numberDiff line numberDiff line change
@@ -212,36 +212,44 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
212212

213213
/// Identifies whether a predicate obligation needs processing.
214214
///
215-
/// This is always inlined, despite its size, because it has a single
216-
/// callsite and it is called *very* frequently.
215+
/// This is always inlined because it has a single callsite and it is
216+
/// called *very* frequently. Be careful modifying this code! Several
217+
/// compile-time benchmarks are very sensitive to even small changes.
217218
#[inline(always)]
218219
fn needs_process_obligation(&self, pending_obligation: &Self::Obligation) -> bool {
219220
// If we were stalled on some unresolved variables, first check whether
220221
// any of them have been resolved; if not, don't bother doing more work
221222
// yet.
222-
match pending_obligation.stalled_on.len() {
223-
// Match arms are in order of frequency, which matters because this
224-
// code is so hot. 1 and 0 dominate; 2+ is fairly rare.
225-
1 => {
226-
let infer_var = pending_obligation.stalled_on[0];
227-
self.selcx.infcx.ty_or_const_infer_var_changed(infer_var)
228-
}
229-
0 => {
230-
// In this case we haven't changed, but wish to make a change.
231-
true
232-
}
233-
_ => {
234-
// This `for` loop was once a call to `all()`, but this lower-level
235-
// form was a perf win. See #64545 for details.
236-
(|| {
237-
for &infer_var in &pending_obligation.stalled_on {
238-
if self.selcx.infcx.ty_or_const_infer_var_changed(infer_var) {
239-
return true;
240-
}
223+
let stalled_on = &pending_obligation.stalled_on;
224+
match stalled_on.len() {
225+
// This case is the hottest most of the time, being hit up to 99%
226+
// of the time. `keccak` and `cranelift-codegen-0.82.1` are
227+
// benchmarks that particularly stress this path.
228+
1 => self.selcx.infcx.ty_or_const_infer_var_changed(stalled_on[0]),
229+
230+
// In this case we haven't changed, but wish to make a change. Note
231+
// that this is a special case, and is not equivalent to the `_`
232+
// case below, which would return `false` for an empty `stalled_on`
233+
// vector.
234+
//
235+
// This case is usually hit only 1% of the time or less, though it
236+
// reaches 20% in `wasmparser-0.101.0`.
237+
0 => true,
238+
239+
// This case is usually hit only 1% of the time or less, though it
240+
// reaches 95% in `mime-0.3.16`, 64% in `wast-54.0.0`, and 12% in
241+
// `inflate-0.4.5`.
242+
//
243+
// The obvious way of writing this, with a call to `any()` and no
244+
// closure, is currently slower than this version.
245+
_ => (|| {
246+
for &infer_var in stalled_on {
247+
if self.selcx.infcx.ty_or_const_infer_var_changed(infer_var) {
248+
return true;
241249
}
242-
false
243-
})()
244-
}
250+
}
251+
false
252+
})(),
245253
}
246254
}
247255

library/alloc/src/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,7 @@ impl<T, I: iter::TrustedLen<Item = T>> ToRcSlice<T> for I {
21452145
Rc::from_iter_exact(self, low)
21462146
}
21472147
} else {
2148-
// TrustedLen contract guarantees that `upper_bound == `None` implies an iterator
2148+
// TrustedLen contract guarantees that `upper_bound == None` implies an iterator
21492149
// length exceeding `usize::MAX`.
21502150
// The default implementation would collect into a vec which would panic.
21512151
// Thus we panic here immediately without invoking `Vec` code.

library/alloc/src/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2895,7 +2895,7 @@ impl<T, I: iter::TrustedLen<Item = T>> ToArcSlice<T> for I {
28952895
Arc::from_iter_exact(self, low)
28962896
}
28972897
} else {
2898-
// TrustedLen contract guarantees that `upper_bound == `None` implies an iterator
2898+
// TrustedLen contract guarantees that `upper_bound == None` implies an iterator
28992899
// length exceeding `usize::MAX`.
29002900
// The default implementation would collect into a vec which would panic.
29012901
// Thus we panic here immediately without invoking `Vec` code.

library/core/src/any.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
//! let value_any = value as &dyn Any;
5757
//!
5858
//! // Try to convert our value to a `String`. If successful, we want to
59-
//! // output the String`'s length as well as its value. If not, it's a
59+
//! // output the `String`'s length as well as its value. If not, it's a
6060
//! // different type: just print it out unadorned.
6161
//! match value_any.downcast_ref::<String>() {
6262
//! Some(as_string) => {

library/core/src/cell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ pub struct RefCell<T: ?Sized> {
632632
// Stores the location of the earliest currently active borrow.
633633
// This gets updated whenever we go from having zero borrows
634634
// to having a single borrow. When a borrow occurs, this gets included
635-
// in the generated `BorrowError/`BorrowMutError`
635+
// in the generated `BorrowError`/`BorrowMutError`
636636
#[cfg(feature = "debug_refcell")]
637637
borrowed_at: Cell<Option<&'static crate::panic::Location<'static>>>,
638638
value: UnsafeCell<T>,

library/core/src/intrinsics/mir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
//! another function. The `dialect` and `phase` parameters indicate which [version of MIR][dialect
4343
//! docs] you are inserting here. Generally you'll want to use `#![custom_mir(dialect = "built")]`
4444
//! if you want your MIR to be modified by the full MIR pipeline, or `#![custom_mir(dialect =
45-
//! "runtime", phase = "optimized")] if you don't.
45+
//! "runtime", phase = "optimized")]` if you don't.
4646
//!
4747
//! [dialect docs]:
4848
//! https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.MirPhase.html

library/core/src/ptr/alignment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Alignment {
4141
/// Returns the alignment for a type.
4242
///
4343
/// This provides the same numerical value as [`mem::align_of`],
44-
/// but in an `Alignment` instead of a `usize.
44+
/// but in an `Alignment` instead of a `usize`.
4545
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
4646
#[inline]
4747
pub const fn of<T>() -> Self {

library/core/src/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2955,7 +2955,7 @@ impl<T> [T] {
29552955
// This operation is still `O(n)`.
29562956
//
29572957
// Example: We start in this state, where `r` represents "next
2958-
// read" and `w` represents "next_write`.
2958+
// read" and `w` represents "next_write".
29592959
//
29602960
// r
29612961
// +---+---+---+---+---+---+

library/core/src/slice/sort.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ where
317317
// 1. `block` - Number of elements in the block.
318318
// 2. `start` - Start pointer into the `offsets` array.
319319
// 3. `end` - End pointer into the `offsets` array.
320-
// 4. `offsets - Indices of out-of-order elements within the block.
320+
// 4. `offsets` - Indices of out-of-order elements within the block.
321321

322322
// The current block on the left side (from `l` to `l.add(block_l)`).
323323
let mut l = v.as_mut_ptr();
@@ -327,7 +327,7 @@ where
327327
let mut offsets_l = [MaybeUninit::<u8>::uninit(); BLOCK];
328328

329329
// The current block on the right side (from `r.sub(block_r)` to `r`).
330-
// SAFETY: The documentation for .add() specifically mention that `vec.as_ptr().add(vec.len())` is always safe`
330+
// SAFETY: The documentation for .add() specifically mention that `vec.as_ptr().add(vec.len())` is always safe
331331
let mut r = unsafe { l.add(v.len()) };
332332
let mut block_r = BLOCK;
333333
let mut start_r = ptr::null_mut();

0 commit comments

Comments
 (0)