Skip to content

Commit 03a8cc7

Browse files
committedFeb 21, 2022
Auto merge of #93505 - lcnr:substsref-vs-ty-list, r=michaelwoerister
safely `transmute<&List<Ty<'tcx>>, &List<GenericArg<'tcx>>>` This PR has 3 relevant steps which are is split in distinct commits. The first commit now interns `List<Ty<'tcx>>` and `List<GenericArg<'tcx>>` together, potentially reusing memory while allowing free conversions between these two using `List<Ty<'tcx>>::as_substs()` and `SubstsRef<'tcx>::try_as_type_list()`. Using this, we then use `&'tcx List<Ty<'tcx>>` instead of a `SubstsRef<'tcx>` for tuple fields, simplifying a bunch of code. Finally, as tuple fields and other generic arguments now use a different `TypeFoldable<'tcx>` impl, we optimize the impl for `List<Ty<'tcx>>` improving perf by slightly less than 1% in tuple heavy benchmarks.
2 parents 1103d2e + 80f56cd commit 03a8cc7

File tree

64 files changed

+289
-210
lines changed

Some content is hidden

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

64 files changed

+289
-210
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22982298
// Closure arguments are wrapped in a tuple, so we need to get the first
22992299
// from that.
23002300
if let ty::Tuple(elems) = argument_ty.kind() {
2301-
let argument_ty = elems.first()?.expect_ty();
2301+
let &argument_ty = elems.first()?;
23022302
if let ty::Ref(_, _, _) = argument_ty.kind() {
23032303
return Some(AnnotatedBorrowFnSignature::Closure {
23042304
argument_ty,

‎compiler/rustc_borrowck/src/diagnostics/region_name.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
480480
let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty<'_>)> = &mut vec![(ty, hir_ty)];
481481

482482
while let Some((ty, hir_ty)) = search_stack.pop() {
483-
match (&ty.kind(), &hir_ty.kind) {
483+
match (ty.kind(), &hir_ty.kind) {
484484
// Check if the `ty` is `&'X ..` where `'X`
485485
// is the region we are looking for -- if so, and we have a `&T`
486486
// on the RHS, then we want to highlight the `&` like so:
@@ -532,9 +532,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
532532
// The following cases don't have lifetimes, so we
533533
// just worry about trying to match up the rustc type
534534
// with the HIR types:
535-
(ty::Tuple(elem_tys), hir::TyKind::Tup(elem_hir_tys)) => {
536-
search_stack
537-
.extend(iter::zip(elem_tys.iter().map(|k| k.expect_ty()), *elem_hir_tys));
535+
(&ty::Tuple(elem_tys), hir::TyKind::Tup(elem_hir_tys)) => {
536+
search_stack.extend(iter::zip(elem_tys, *elem_hir_tys));
538537
}
539538

540539
(ty::Slice(elem_ty), hir::TyKind::Slice(elem_hir_ty))

0 commit comments

Comments
 (0)
Please sign in to comment.