Skip to content

Commit c9d9c24

Browse files
committed
Insert fields from TypeAndMut into TyRef to allow layout optimization
1 parent 710b4ad commit c9d9c24

Some content is hidden

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

60 files changed

+242
-241
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,9 +888,10 @@ for ty::TypeVariants<'gcx>
888888
TyRawPtr(pointee_ty) => {
889889
pointee_ty.hash_stable(hcx, hasher);
890890
}
891-
TyRef(region, pointee_ty) => {
891+
TyRef(region, pointee_ty, mutbl) => {
892892
region.hash_stable(hcx, hasher);
893893
pointee_ty.hash_stable(hcx, hasher);
894+
mutbl.hash_stable(hcx, hasher);
894895
}
895896
TyFnDef(def_id, substs) => {
896897
def_id.hash_stable(hcx, hasher);

src/librustc/infer/error_reporting/mod.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -665,21 +665,22 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
665665

666666
fn push_ty_ref<'tcx>(
667667
r: &ty::Region<'tcx>,
668-
tnm: &ty::TypeAndMut<'tcx>,
668+
ty: Ty<'tcx>,
669+
mutbl: hir::Mutability,
669670
s: &mut DiagnosticStyledString,
670671
) {
671672
let r = &format!("{}", r);
672673
s.push_highlighted(format!(
673674
"&{}{}{}",
674675
r,
675676
if r == "" { "" } else { " " },
676-
if tnm.mutbl == hir::MutMutable {
677+
if mutbl == hir::MutMutable {
677678
"mut "
678679
} else {
679680
""
680681
}
681682
));
682-
s.push_normal(format!("{}", tnm.ty));
683+
s.push_normal(format!("{}", ty));
683684
}
684685

685686
match (&t1.sty, &t2.sty) {
@@ -803,24 +804,25 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
803804
}
804805

805806
// When finding T != &T, highlight only the borrow
806-
(&ty::TyRef(r1, ref tnm1), _) if equals(&tnm1.ty, &t2) => {
807+
(&ty::TyRef(r1, ref_ty1, mutbl1), _) if equals(&ref_ty1, &t2) => {
807808
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
808-
push_ty_ref(&r1, tnm1, &mut values.0);
809+
push_ty_ref(&r1, ref_ty1, mutbl1, &mut values.0);
809810
values.1.push_normal(format!("{}", t2));
810811
values
811812
}
812-
(_, &ty::TyRef(r2, ref tnm2)) if equals(&t1, &tnm2.ty) => {
813+
(_, &ty::TyRef(r2, ref_ty2, mutbl2)) if equals(&t1, &ref_ty2) => {
813814
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
814815
values.0.push_normal(format!("{}", t1));
815-
push_ty_ref(&r2, tnm2, &mut values.1);
816+
push_ty_ref(&r2, ref_ty2, mutbl2, &mut values.1);
816817
values
817818
}
818819

819820
// When encountering &T != &mut T, highlight only the borrow
820-
(&ty::TyRef(r1, ref tnm1), &ty::TyRef(r2, ref tnm2)) if equals(&tnm1.ty, &tnm2.ty) => {
821+
(&ty::TyRef(r1, ref_ty1, mutbl1),
822+
&ty::TyRef(r2, ref_ty2, mutbl2)) if equals(&ref_ty1, &ref_ty2) => {
821823
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
822-
push_ty_ref(&r1, tnm1, &mut values.0);
823-
push_ty_ref(&r2, tnm2, &mut values.1);
824+
push_ty_ref(&r1, ref_ty1, mutbl1, &mut values.0);
825+
push_ty_ref(&r2, ref_ty2, mutbl2, &mut values.1);
824826
values
825827
}
826828

src/librustc/middle/expr_use_visitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
456456
// make sure that the thing we are pointing out stays valid
457457
// for the lifetime `scope_r` of the resulting ptr:
458458
let expr_ty = return_if_err!(self.mc.expr_ty(expr));
459-
if let ty::TyRef(r, _) = expr_ty.sty {
459+
if let ty::TyRef(r, _, _) = expr_ty.sty {
460460
let bk = ty::BorrowKind::from_mutbl(m);
461461
self.borrow_expr(&base, r, bk, AddrOf);
462462
}
@@ -859,7 +859,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
859859
// It is also a borrow or copy/move of the value being matched.
860860
match bm {
861861
ty::BindByReference(m) => {
862-
if let ty::TyRef(r, _) = pat_ty.sty {
862+
if let ty::TyRef(r, _, _) = pat_ty.sty {
863863
let bk = ty::BorrowKind::from_mutbl(m);
864864
delegate.borrow(pat.id, pat.span, &cmt_pat, r, bk, RefBinding);
865865
}

src/librustc/middle/mem_categorization.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10121012
let base_ty = self.expr_ty_adjusted(base)?;
10131013

10141014
let (region, mutbl) = match base_ty.sty {
1015-
ty::TyRef(region, mt) => (region, mt.mutbl),
1015+
ty::TyRef(region, _, mutbl) => (region, mutbl),
10161016
_ => {
10171017
span_bug!(expr.span, "cat_overloaded_place: base is not a reference")
10181018
}
@@ -1046,8 +1046,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10461046
let ptr = match base_cmt.ty.sty {
10471047
ty::TyAdt(def, ..) if def.is_box() => Unique,
10481048
ty::TyRawPtr(ref mt) => UnsafePtr(mt.mutbl),
1049-
ty::TyRef(r, mt) => {
1050-
let bk = ty::BorrowKind::from_mutbl(mt.mutbl);
1049+
ty::TyRef(r, _, mutbl) => {
1050+
let bk = ty::BorrowKind::from_mutbl(mutbl);
10511051
if implicit { Implicit(bk, r) } else { BorrowedPtr(bk, r) }
10521052
}
10531053
ref ty => bug!("unexpected type in cat_deref: {:?}", ty)

src/librustc/mir/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use mir::interpret::{Value, PrimVal, EvalErrorKind};
2929
use ty::subst::{Subst, Substs};
3030
use ty::{self, AdtDef, CanonicalTy, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt};
3131
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
32-
use ty::TypeAndMut;
3332
use util::ppaux;
3433
use std::slice;
3534
use hir::{self, InlineAsm};
@@ -1905,9 +1904,8 @@ pub fn print_miri_value<W: Write>(value: Value, ty: Ty, f: &mut W) -> fmt::Resul
19051904
write!(f, "{:?}", ::std::char::from_u32(n as u32).unwrap()),
19061905
(Value::ByVal(PrimVal::Undef), &TyFnDef(did, _)) =>
19071906
write!(f, "{}", item_path_str(did)),
1908-
(Value::ByValPair(PrimVal::Ptr(ptr), PrimVal::Bytes(len)), &TyRef(_, TypeAndMut {
1909-
ty: &ty::TyS { sty: TyStr, .. }, ..
1910-
})) => {
1907+
(Value::ByValPair(PrimVal::Ptr(ptr), PrimVal::Bytes(len)),
1908+
&TyRef(_, &ty::TyS { sty: TyStr, .. }, _)) => {
19111909
ty::tls::with(|tcx| {
19121910
let alloc = tcx
19131911
.interpret_interner

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,9 +878,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
878878
let mut trait_type = trait_ref.self_ty();
879879

880880
for refs_remaining in 0..refs_number {
881-
if let ty::TypeVariants::TyRef(_, ty::TypeAndMut{ ty: t_type, mutbl: _ }) =
882-
trait_type.sty {
883-
881+
if let ty::TypeVariants::TyRef(_, t_type, _) = trait_type.sty {
884882
trait_type = t_type;
885883

886884
let substs = self.tcx.mk_substs_trait(trait_type, &[]);

src/librustc/traits/select.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,14 +2167,14 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21672167

21682168
ty::TyUint(_) | ty::TyInt(_) | ty::TyBool | ty::TyFloat(_) |
21692169
ty::TyChar | ty::TyRawPtr(..) | ty::TyNever |
2170-
ty::TyRef(_, ty::TypeAndMut { ty: _, mutbl: hir::MutImmutable }) => {
2170+
ty::TyRef(_, _, hir::MutImmutable) => {
21712171
// Implementations provided in libcore
21722172
None
21732173
}
21742174

21752175
ty::TyDynamic(..) | ty::TyStr | ty::TySlice(..) |
21762176
ty::TyGenerator(..) | ty::TyGeneratorWitness(..) | ty::TyForeign(..) |
2177-
ty::TyRef(_, ty::TypeAndMut { ty: _, mutbl: hir::MutMutable }) => {
2177+
ty::TyRef(_, _, hir::MutMutable) => {
21782178
Never
21792179
}
21802180

@@ -2263,7 +2263,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
22632263
}
22642264

22652265
ty::TyRawPtr(ty::TypeAndMut { ty: element_ty, ..}) |
2266-
ty::TyRef(_, ty::TypeAndMut { ty: element_ty, ..}) => {
2266+
ty::TyRef(_, element_ty, _) => {
22672267
vec![element_ty]
22682268
},
22692269

src/librustc/ty/cast.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ pub enum CastTy<'tcx> {
3636
/// Function Pointers
3737
FnPtr,
3838
/// Raw pointers
39-
Ptr(&'tcx ty::TypeAndMut<'tcx>),
39+
Ptr(ty::TypeAndMut<'tcx>),
4040
/// References
41-
RPtr(&'tcx ty::TypeAndMut<'tcx>),
41+
RPtr(ty::TypeAndMut<'tcx>),
4242
}
4343

4444
/// Cast Kind. See RFC 401 (or librustc_typeck/check/cast.rs)
@@ -69,8 +69,8 @@ impl<'tcx> CastTy<'tcx> {
6969
ty::TyFloat(_) => Some(CastTy::Float),
7070
ty::TyAdt(d,_) if d.is_enum() && d.is_payloadfree() =>
7171
Some(CastTy::Int(IntTy::CEnum)),
72-
ty::TyRawPtr(ref mt) => Some(CastTy::Ptr(mt)),
73-
ty::TyRef(_, ref mt) => Some(CastTy::RPtr(mt)),
72+
ty::TyRawPtr(mt) => Some(CastTy::Ptr(mt)),
73+
ty::TyRef(_, ty, mutbl) => Some(CastTy::RPtr(ty::TypeAndMut { ty, mutbl })),
7474
ty::TyFnPtr(..) => Some(CastTy::FnPtr),
7575
_ => None,
7676
}

src/librustc/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2351,7 +2351,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23512351
}
23522352

23532353
pub fn mk_ref(self, r: Region<'tcx>, tm: TypeAndMut<'tcx>) -> Ty<'tcx> {
2354-
self.mk_ty(TyRef(r, tm))
2354+
self.mk_ty(TyRef(r, tm.ty, tm.mutbl))
23552355
}
23562356

23572357
pub fn mk_mut_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {

src/librustc/ty/error.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,17 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
189189
}
190190
ty::TySlice(_) => "slice".to_string(),
191191
ty::TyRawPtr(_) => "*-ptr".to_string(),
192-
ty::TyRef(region, tymut) => {
192+
ty::TyRef(region, ty, mutbl) => {
193+
let tymut = ty::TypeAndMut { ty, mutbl };
193194
let tymut_string = tymut.to_string();
194195
if tymut_string == "_" || //unknown type name,
195196
tymut_string.len() > 10 || //name longer than saying "reference",
196197
region.to_string() != "" //... or a complex type
197198
{
198-
match tymut {
199-
ty::TypeAndMut{mutbl, ..} => {
200-
format!("{}reference", match mutbl {
201-
hir::Mutability::MutMutable => "mutable ",
202-
_ => ""
203-
})
204-
}
205-
}
199+
format!("{}reference", match mutbl {
200+
hir::Mutability::MutMutable => "mutable ",
201+
_ => ""
202+
})
206203
} else {
207204
format!("&{}", tymut_string)
208205
}

0 commit comments

Comments
 (0)