Skip to content

Commit f54911c

Browse files
committed
Auto merge of #65454 - tmandry:rollup-0k6jiik, r=tmandry
Rollup of 14 pull requests Successful merges: - #64603 (Reducing spurious unused lifetime warnings.) - #64623 (Remove last uses of gensyms) - #65235 (don't assume we can *always* find a return type hint in async fn) - #65242 (Fix suggestion to constrain trait for method to be found) - #65265 (Cleanup librustc mir err codes) - #65293 (Optimize `try_expand_impl_trait_type`) - #65307 (Try fix incorrect "explicit lifetime name needed") - #65308 (Add long error explanation for E0574) - #65353 (save-analysis: Don't ICE when resolving qualified type paths in struct members) - #65389 (Return `false` from `needs_drop` for all zero-sized arrays.) - #65402 (Add troubleshooting section to PGO chapter in rustc book.) - #65425 (Optimize `BitIter`) - #65438 (Organize `never_type` tests) - #65444 (Implement AsRef<[T]> for List<T>) Failed merges: - #65390 (Add long error explanation for E0576) r? @ghost
2 parents 237d54f + 3182f73 commit f54911c

File tree

99 files changed

+1095
-507
lines changed

Some content is hidden

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

99 files changed

+1095
-507
lines changed

Diff for: src/doc/rustc/src/profile-guided-optimization.md

+11
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ RUSTFLAGS="-Cprofile-use=/tmp/pgo-data/merged.profdata" \
125125
cargo build --release --target=x86_64-unknown-linux-gnu
126126
```
127127

128+
### Troubleshooting
129+
130+
- It is recommended to pass `-Cllvm-args=-pgo-warn-missing-function` during the
131+
`-Cprofile-use` phase. LLVM by default does not warn if it cannot find
132+
profiling data for a given function. Enabling this warning will make it
133+
easier to spot errors in your setup.
134+
135+
- There is a [known issue](https://github.com/rust-lang/cargo/issues/7416) in
136+
Cargo prior to version 1.39 that will prevent PGO from working correctly. Be
137+
sure to use Cargo 1.39 or newer when doing PGO.
138+
128139
## Further Reading
129140

130141
`rustc`'s PGO support relies entirely on LLVM's implementation of the feature

Diff for: src/librustc/hir/lowering.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -3291,10 +3291,14 @@ impl<'a> LoweringContext<'a> {
32913291
let id = self.sess.next_node_id();
32923292
self.new_named_lifetime(id, span, hir::LifetimeName::Error)
32933293
}
3294-
// This is the normal case.
3295-
AnonymousLifetimeMode::PassThrough => self.new_implicit_lifetime(span),
3296-
3297-
AnonymousLifetimeMode::ReportError => self.new_error_lifetime(None, span),
3294+
// `PassThrough` is the normal case.
3295+
// `new_error_lifetime`, which would usually be used in the case of `ReportError`,
3296+
// is unsuitable here, as these can occur from missing lifetime parameters in a
3297+
// `PathSegment`, for which there is no associated `'_` or `&T` with no explicit
3298+
// lifetime. Instead, we simply create an implicit lifetime, which will be checked
3299+
// later, at which point a suitable error will be emitted.
3300+
| AnonymousLifetimeMode::PassThrough
3301+
| AnonymousLifetimeMode::ReportError => self.new_implicit_lifetime(span),
32983302
}
32993303
}
33003304

Diff for: src/librustc/middle/resolve_lifetime.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -708,15 +708,22 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
708708
match param.kind {
709709
GenericParamKind::Lifetime { .. } => {
710710
let (name, reg) = Region::early(&self.tcx.hir(), &mut index, &param);
711+
let def_id = if let Region::EarlyBound(_ ,def_id , _) = reg {
712+
def_id
713+
} else {
714+
bug!();
715+
};
711716
if let hir::ParamName::Plain(param_name) = name {
712717
if param_name.name == kw::UnderscoreLifetime {
713718
// Pick the elided lifetime "definition" if one exists
714719
// and use it to make an elision scope.
720+
self.lifetime_uses.insert(def_id.clone(), LifetimeUseSet::Many);
715721
elision = Some(reg);
716722
} else {
717723
lifetimes.insert(name, reg);
718724
}
719725
} else {
726+
self.lifetime_uses.insert(def_id.clone(), LifetimeUseSet::Many);
720727
lifetimes.insert(name, reg);
721728
}
722729
}
@@ -1615,7 +1622,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
16151622
_ => None,
16161623
} {
16171624
debug!("id = {:?} span = {:?} name = {:?}", id, span, name);
1618-
16191625
if name.name == kw::UnderscoreLifetime {
16201626
continue;
16211627
}

Diff for: src/librustc/ty/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,13 @@ impl<T> Deref for List<T> {
701701
type Target = [T];
702702
#[inline(always)]
703703
fn deref(&self) -> &[T] {
704+
self.as_ref()
705+
}
706+
}
707+
708+
impl<T> AsRef<[T]> for List<T> {
709+
#[inline(always)]
710+
fn as_ref(&self) -> &[T] {
704711
unsafe {
705712
slice::from_raw_parts(self.data.as_ptr(), self.len)
706713
}

Diff for: src/librustc/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ impl<F: fmt::Write> FmtPrinter<'_, 'tcx, F> {
14831483
}
14841484

14851485
// Replace any anonymous late-bound regions with named
1486-
// variants, using gensym'd identifiers, so that we can
1486+
// variants, using new unique identifiers, so that we can
14871487
// clearly differentiate between named and unnamed regions in
14881488
// the output. We'll probably want to tweak this over time to
14891489
// decide just how much information to give.

Diff for: src/librustc/ty/util.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,9 @@ impl<'tcx> TyCtxt<'tcx> {
697697
// that type, and when we finish expanding that type we remove the
698698
// its DefId.
699699
seen_opaque_tys: FxHashSet<DefId>,
700+
// Cache of all expansions we've seen so far. This is a critical
701+
// optimization for some large types produced by async fn trees.
702+
expanded_cache: FxHashMap<(DefId, SubstsRef<'tcx>), Ty<'tcx>>,
700703
primary_def_id: DefId,
701704
found_recursion: bool,
702705
tcx: TyCtxt<'tcx>,
@@ -713,9 +716,16 @@ impl<'tcx> TyCtxt<'tcx> {
713716
}
714717
let substs = substs.fold_with(self);
715718
if self.seen_opaque_tys.insert(def_id) {
716-
let generic_ty = self.tcx.type_of(def_id);
717-
let concrete_ty = generic_ty.subst(self.tcx, substs);
718-
let expanded_ty = self.fold_ty(concrete_ty);
719+
let expanded_ty = match self.expanded_cache.get(&(def_id, substs)) {
720+
Some(expanded_ty) => expanded_ty,
721+
None => {
722+
let generic_ty = self.tcx.type_of(def_id);
723+
let concrete_ty = generic_ty.subst(self.tcx, substs);
724+
let expanded_ty = self.fold_ty(concrete_ty);
725+
self.expanded_cache.insert((def_id, substs), expanded_ty);
726+
expanded_ty
727+
}
728+
};
719729
self.seen_opaque_tys.remove(&def_id);
720730
Some(expanded_ty)
721731
} else {
@@ -735,14 +745,17 @@ impl<'tcx> TyCtxt<'tcx> {
735745
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
736746
if let ty::Opaque(def_id, substs) = t.kind {
737747
self.expand_opaque_ty(def_id, substs).unwrap_or(t)
738-
} else {
748+
} else if t.has_projections() {
739749
t.super_fold_with(self)
750+
} else {
751+
t
740752
}
741753
}
742754
}
743755

744756
let mut visitor = OpaqueTypeExpander {
745757
seen_opaque_tys: FxHashSet::default(),
758+
expanded_cache: FxHashMap::default(),
746759
primary_def_id: def_id,
747760
found_recursion: false,
748761
tcx: self,
@@ -1096,6 +1109,9 @@ fn needs_drop_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>
10961109

10971110
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
10981111

1112+
// Zero-length arrays never contain anything to drop.
1113+
ty::Array(_, len) if len.try_eval_usize(tcx, param_env) == Some(0) => false,
1114+
10991115
// Structural recursion.
11001116
ty::Array(ty, _) | ty::Slice(ty) => needs_drop(ty),
11011117

Diff for: src/librustc_index/bit_set.rs

+42-21
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,7 @@ impl<T: Idx> BitSet<T> {
168168
/// Iterates over the indices of set bits in a sorted order.
169169
#[inline]
170170
pub fn iter(&self) -> BitIter<'_, T> {
171-
BitIter {
172-
cur: None,
173-
iter: self.words.iter().enumerate(),
174-
marker: PhantomData,
175-
}
171+
BitIter::new(&self.words)
176172
}
177173

178174
/// Duplicates the set as a hybrid set.
@@ -291,26 +287,55 @@ impl<T: Idx> ToString for BitSet<T> {
291287
}
292288

293289
pub struct BitIter<'a, T: Idx> {
294-
cur: Option<(Word, usize)>,
295-
iter: iter::Enumerate<slice::Iter<'a, Word>>,
290+
/// A copy of the current word, but with any already-visited bits cleared.
291+
/// (This lets us use `trailing_zeros()` to find the next set bit.) When it
292+
/// is reduced to 0, we move onto the next word.
293+
word: Word,
294+
295+
/// The offset (measured in bits) of the current word.
296+
offset: usize,
297+
298+
/// Underlying iterator over the words.
299+
iter: slice::Iter<'a, Word>,
300+
296301
marker: PhantomData<T>
297302
}
298303

304+
impl<'a, T: Idx> BitIter<'a, T> {
305+
#[inline]
306+
fn new(words: &'a [Word]) -> BitIter<'a, T> {
307+
// We initialize `word` and `offset` to degenerate values. On the first
308+
// call to `next()` we will fall through to getting the first word from
309+
// `iter`, which sets `word` to the first word (if there is one) and
310+
// `offset` to 0. Doing it this way saves us from having to maintain
311+
// additional state about whether we have started.
312+
BitIter {
313+
word: 0,
314+
offset: std::usize::MAX - (WORD_BITS - 1),
315+
iter: words.iter(),
316+
marker: PhantomData,
317+
}
318+
}
319+
}
320+
299321
impl<'a, T: Idx> Iterator for BitIter<'a, T> {
300322
type Item = T;
301323
fn next(&mut self) -> Option<T> {
302324
loop {
303-
if let Some((ref mut word, offset)) = self.cur {
304-
let bit_pos = word.trailing_zeros() as usize;
305-
if bit_pos != WORD_BITS {
306-
let bit = 1 << bit_pos;
307-
*word ^= bit;
308-
return Some(T::new(bit_pos + offset))
309-
}
325+
if self.word != 0 {
326+
// Get the position of the next set bit in the current word,
327+
// then clear the bit.
328+
let bit_pos = self.word.trailing_zeros() as usize;
329+
let bit = 1 << bit_pos;
330+
self.word ^= bit;
331+
return Some(T::new(bit_pos + self.offset))
310332
}
311333

312-
let (i, word) = self.iter.next()?;
313-
self.cur = Some((*word, WORD_BITS * i));
334+
// Move onto the next word. `wrapping_add()` is needed to handle
335+
// the degenerate initial value given to `offset` in `new()`.
336+
let word = self.iter.next()?;
337+
self.word = *word;
338+
self.offset = self.offset.wrapping_add(WORD_BITS);
314339
}
315340
}
316341
}
@@ -851,11 +876,7 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> {
851876
pub fn iter(&self, row: R) -> BitIter<'_, C> {
852877
assert!(row.index() < self.num_rows);
853878
let (start, end) = self.range(row);
854-
BitIter {
855-
cur: None,
856-
iter: self.words[start..end].iter().enumerate(),
857-
marker: PhantomData,
858-
}
879+
BitIter::new(&self.words[start..end])
859880
}
860881

861882
/// Returns the number of elements in `row`.

Diff for: src/librustc_mir/dataflow/impls/indirect_mutation.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,16 @@ impl<'tcx> TransferFunction<'_, '_, 'tcx> {
104104
kind: mir::BorrowKind,
105105
borrowed_place: &mir::Place<'tcx>,
106106
) -> bool {
107-
let borrowed_ty = borrowed_place.ty(self.body, self.tcx).ty;
108-
109-
// Zero-sized types cannot be mutated, since there is nothing inside to mutate.
110-
//
111-
// FIXME: For now, we only exempt arrays of length zero. We need to carefully
112-
// consider the effects before extending this to all ZSTs.
113-
if let ty::Array(_, len) = borrowed_ty.kind {
114-
if len.try_eval_usize(self.tcx, self.param_env) == Some(0) {
115-
return false;
116-
}
117-
}
118-
119107
match kind {
120108
mir::BorrowKind::Mut { .. } => true,
121109

122110
| mir::BorrowKind::Shared
123111
| mir::BorrowKind::Shallow
124112
| mir::BorrowKind::Unique
125-
=> !borrowed_ty.is_freeze(self.tcx, self.param_env, DUMMY_SP),
113+
=> !borrowed_place
114+
.ty(self.body, self.tcx)
115+
.ty
116+
.is_freeze(self.tcx, self.param_env, DUMMY_SP),
126117
}
127118
}
128119
}

0 commit comments

Comments
 (0)