Skip to content

Commit 7740f9a

Browse files
committed
Auto merge of #107869 - nnethercote:reduce-interning, r=compiler-errors
Reduce interning r? `@compiler-errors`
2 parents 59083c5 + e261665 commit 7740f9a

File tree

30 files changed

+173
-114
lines changed

30 files changed

+173
-114
lines changed

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
385385
calculate_debuginfo_offset(bx, local, &var, base);
386386

387387
// Create a variable which will be a pointer to the actual value
388-
let ptr_ty = bx.tcx().mk_ty(ty::RawPtr(ty::TypeAndMut {
389-
mutbl: mir::Mutability::Mut,
390-
ty: place.layout.ty,
391-
}));
388+
let ptr_ty = bx
389+
.tcx()
390+
.mk_ptr(ty::TypeAndMut { mutbl: mir::Mutability::Mut, ty: place.layout.ty });
392391
let ptr_layout = bx.layout_of(ptr_ty);
393392
let alloca = PlaceRef::alloca(bx, ptr_layout);
394393
bx.set_var_name(alloca.llval, &(var.name.to_string() + ".dbg.spill"));

compiler/rustc_const_eval/src/const_eval/valtrees.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn get_info_on_unsized_field<'tcx>(
193193

194194
// Have to adjust type for ty::Str
195195
let unsized_inner_ty = match unsized_inner_ty.kind() {
196-
ty::Str => tcx.mk_ty(ty::Uint(ty::UintTy::U8)),
196+
ty::Str => tcx.types.u8,
197197
_ => unsized_inner_ty,
198198
};
199199

@@ -216,7 +216,7 @@ fn create_pointee_place<'tcx>(
216216

217217
let (unsized_inner_ty, num_elems) = get_info_on_unsized_field(ty, valtree, tcx);
218218
let unsized_inner_ty = match unsized_inner_ty.kind() {
219-
ty::Str => tcx.mk_ty(ty::Uint(ty::UintTy::U8)),
219+
ty::Str => tcx.types.u8,
220220
_ => unsized_inner_ty,
221221
};
222222
let unsized_inner_ty_size =

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ impl Qualif for CustomEq {
217217

218218
fn in_adt_inherently<'tcx>(
219219
cx: &ConstCx<'_, 'tcx>,
220-
adt: AdtDef<'tcx>,
220+
def: AdtDef<'tcx>,
221221
substs: SubstsRef<'tcx>,
222222
) -> bool {
223-
let ty = cx.tcx.mk_ty(ty::Adt(adt, substs));
223+
let ty = cx.tcx.mk_adt(def, substs);
224224
!ty.is_structural_eq_shallow(cx.tcx)
225225
}
226226
}

compiler/rustc_hir_analysis/src/astconv/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12501250
//
12511251
// Calling `skip_binder` is okay, because `add_bounds` expects the `param_ty`
12521252
// parameter to have a skipped binder.
1253-
let param_ty = tcx.mk_ty(ty::Alias(ty::Projection, projection_ty.skip_binder()));
1253+
let param_ty = tcx.mk_alias(ty::Projection, projection_ty.skip_binder());
12541254
self.add_bounds(param_ty, ast_bounds.iter(), bounds, candidate.bound_vars());
12551255
}
12561256
}
@@ -2930,7 +2930,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29302930
}
29312931
};
29322932

2933-
tcx.mk_ty(ty::Array(self.ast_ty_to_ty(ty), length))
2933+
tcx.mk_array_with_const_len(self.ast_ty_to_ty(ty), length)
29342934
}
29352935
hir::TyKind::Typeof(e) => {
29362936
let ty_erased = tcx.type_of(e.def_id);

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1927,10 +1927,10 @@ pub(super) fn check_type_bounds<'tcx>(
19271927
let kind = ty::BoundTyKind::Param(param.def_id, param.name);
19281928
let bound_var = ty::BoundVariableKind::Ty(kind);
19291929
bound_vars.push(bound_var);
1930-
tcx.mk_ty(ty::Bound(
1930+
tcx.mk_bound(
19311931
ty::INNERMOST,
19321932
ty::BoundTy { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind },
1933-
))
1933+
)
19341934
.into()
19351935
}
19361936
GenericParamDefKind::Lifetime => {

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
603603
// our example, the type was `Self`, which will also be
604604
// `Self` in the GAT.
605605
let ty_param = gat_generics.param_at(*ty_idx, tcx);
606-
let ty_param = tcx
607-
.mk_ty(ty::Param(ty::ParamTy { index: ty_param.index, name: ty_param.name }));
606+
let ty_param = tcx.mk_ty_param(ty_param.index, ty_param.name);
608607
// Same for the region. In our example, 'a corresponds
609608
// to the 'me parameter.
610609
let region_param = gat_generics.param_at(*region_a_idx, tcx);

compiler/rustc_hir_typeck/src/check.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,7 @@ fn check_lang_start_fn<'tcx>(
264264
// for example `start`'s generic should be a type parameter
265265
let generics = tcx.generics_of(def_id);
266266
let fn_generic = generics.param_at(0, tcx);
267-
let generic_tykind =
268-
ty::Param(ty::ParamTy { index: fn_generic.index, name: fn_generic.name });
269-
let generic_ty = tcx.mk_ty(generic_tykind);
267+
let generic_ty = tcx.mk_ty_param(fn_generic.index, fn_generic.name);
270268
let expected_fn_sig =
271269
tcx.mk_fn_sig([].iter(), &generic_ty, false, hir::Unsafety::Normal, Abi::Rust);
272270
let expected_ty = tcx.mk_fn_ptr(Binder::dummy(expected_fn_sig));

compiler/rustc_hir_typeck/src/demand.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
273273
ct_op: |c| c,
274274
ty_op: |t| match *t.kind() {
275275
ty::Infer(ty::TyVar(_)) => self.tcx.mk_ty_var(ty::TyVid::from_u32(0)),
276-
ty::Infer(ty::IntVar(_)) => {
277-
self.tcx.mk_ty_infer(ty::IntVar(ty::IntVid { index: 0 }))
278-
}
279-
ty::Infer(ty::FloatVar(_)) => {
280-
self.tcx.mk_ty_infer(ty::FloatVar(ty::FloatVid { index: 0 }))
281-
}
276+
ty::Infer(ty::IntVar(_)) => self.tcx.mk_int_var(ty::IntVid { index: 0 }),
277+
ty::Infer(ty::FloatVar(_)) => self.tcx.mk_float_var(ty::FloatVid { index: 0 }),
282278
_ => t,
283279
},
284280
};

compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14291429

14301430
self.check_repeat_element_needs_copy_bound(element, count, element_ty);
14311431

1432-
tcx.mk_ty(ty::Array(t, count))
1432+
tcx.mk_array_with_const_len(t, count)
14331433
}
14341434

14351435
fn check_repeat_element_needs_copy_bound(

compiler/rustc_hir_typeck/src/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12961296
)
12971297
});
12981298
let element_tys = tcx.mk_type_list(element_tys_iter);
1299-
let pat_ty = tcx.mk_ty(ty::Tuple(element_tys));
1299+
let pat_ty = tcx.intern_tup(element_tys);
13001300
if let Some(mut err) = self.demand_eqtype_pat_diag(span, expected, pat_ty, ti) {
13011301
let reported = err.emit();
13021302
// Walk subpatterns with an expected type of `err` in this case to silence

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
752752
self.fold_ty(bound_to)
753753
} else {
754754
let var = self.canonical_var(info, ty_var.into());
755-
self.tcx().mk_ty(ty::Bound(self.binder_index, var.into()))
755+
self.tcx().mk_bound(self.binder_index, var.into())
756756
}
757757
}
758758

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'tcx> InferCtxt<'tcx> {
124124
CanonicalVarKind::PlaceholderTy(ty::PlaceholderType { universe, name }) => {
125125
let universe_mapped = universe_map(universe);
126126
let placeholder_mapped = ty::PlaceholderType { universe: universe_mapped, name };
127-
self.tcx.mk_ty(ty::Placeholder(placeholder_mapped)).into()
127+
self.tcx.mk_placeholder(placeholder_mapped).into()
128128
}
129129

130130
CanonicalVarKind::Region(ui) => self

compiler/rustc_infer/src/infer/freshen.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,9 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
5858
}
5959
}
6060

61-
fn freshen_ty<F>(
62-
&mut self,
63-
opt_ty: Option<Ty<'tcx>>,
64-
key: ty::InferTy,
65-
freshener: F,
66-
) -> Ty<'tcx>
61+
fn freshen_ty<F>(&mut self, opt_ty: Option<Ty<'tcx>>, key: ty::InferTy, mk_fresh: F) -> Ty<'tcx>
6762
where
68-
F: FnOnce(u32) -> ty::InferTy,
63+
F: FnOnce(u32) -> Ty<'tcx>,
6964
{
7065
if let Some(ty) = opt_ty {
7166
return ty.fold_with(self);
@@ -76,7 +71,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
7671
Entry::Vacant(entry) => {
7772
let index = self.ty_freshen_count;
7873
self.ty_freshen_count += 1;
79-
let t = self.infcx.tcx.mk_ty_infer(freshener(index));
74+
let t = mk_fresh(index);
8075
entry.insert(t);
8176
t
8277
}
@@ -204,7 +199,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
204199
match v {
205200
ty::TyVar(v) => {
206201
let opt_ty = self.infcx.inner.borrow_mut().type_variables().probe(v).known();
207-
Some(self.freshen_ty(opt_ty, ty::TyVar(v), ty::FreshTy))
202+
Some(self.freshen_ty(opt_ty, ty::TyVar(v), |n| self.infcx.tcx.mk_fresh_ty(n)))
208203
}
209204

210205
ty::IntVar(v) => Some(
@@ -216,7 +211,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
216211
.probe_value(v)
217212
.map(|v| v.to_type(self.infcx.tcx)),
218213
ty::IntVar(v),
219-
ty::FreshIntTy,
214+
|n| self.infcx.tcx.mk_fresh_int_ty(n),
220215
),
221216
),
222217

@@ -229,7 +224,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
229224
.probe_value(v)
230225
.map(|v| v.to_type(self.infcx.tcx)),
231226
ty::FloatVar(v),
232-
ty::FreshFloatTy,
227+
|n| self.infcx.tcx.mk_fresh_float_ty(n),
233228
),
234229
),
235230

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ impl<'tcx> InferCtxt<'tcx> {
8888
}))
8989
},
9090
types: &mut |bound_ty: ty::BoundTy| {
91-
self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
91+
self.tcx.mk_placeholder(ty::PlaceholderType {
9292
universe: next_universe,
9393
name: bound_ty.kind,
94-
}))
94+
})
9595
},
9696
consts: &mut |bound_var: ty::BoundVar, ty| {
9797
self.tcx

compiler/rustc_infer/src/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2071,14 +2071,14 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
20712071

20722072
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
20732073
if let ty::Infer(_) = t.kind() {
2074-
self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
2074+
self.tcx.mk_placeholder(ty::PlaceholderType {
20752075
universe: ty::UniverseIndex::ROOT,
20762076
name: ty::BoundTyKind::Anon({
20772077
let idx = self.idx;
20782078
self.idx += 1;
20792079
idx
20802080
}),
2081-
}))
2081+
})
20822082
} else {
20832083
t.super_fold_with(self)
20842084
}

compiler/rustc_middle/src/infer/canonical.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,9 @@ impl<'tcx> CanonicalVarValues<'tcx> {
345345
var_values: tcx.mk_substs(infos.iter().enumerate().map(
346346
|(i, info)| -> ty::GenericArg<'tcx> {
347347
match info.kind {
348-
CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => tcx
349-
.mk_ty(ty::Bound(ty::INNERMOST, ty::BoundVar::from_usize(i).into()))
350-
.into(),
348+
CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => {
349+
tcx.mk_bound(ty::INNERMOST, ty::BoundVar::from_usize(i).into()).into()
350+
}
351351
CanonicalVarKind::Region(_) | CanonicalVarKind::PlaceholderRegion(_) => {
352352
let br = ty::BoundRegion {
353353
var: ty::BoundVar::from_usize(i),

compiler/rustc_middle/src/mir/tcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'tcx> Rvalue<'tcx> {
162162
match *self {
163163
Rvalue::Use(ref operand) => operand.ty(local_decls, tcx),
164164
Rvalue::Repeat(ref operand, count) => {
165-
tcx.mk_ty(ty::Array(operand.ty(local_decls, tcx), count))
165+
tcx.mk_array_with_const_len(operand.ty(local_decls, tcx), count)
166166
}
167167
Rvalue::ThreadLocalRef(did) => {
168168
let static_ty = tcx.type_of(did);

0 commit comments

Comments
 (0)