Skip to content

Commit a9842c7

Browse files
committedFeb 18, 2023
Auto merge of #108112 - nnethercote:clarify-iterator-interners, r=oli-obk,compiler-errors
Clarify iterator interners I found the iterator interners very confusing. This PR clarifies things. r? `@compiler-errors`
2 parents 231bcd1 + af32411 commit a9842c7

File tree

36 files changed

+173
-186
lines changed

36 files changed

+173
-186
lines changed
 

‎compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2589,7 +2589,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25892589
DefKind::InlineConst => substs.as_inline_const().parent_substs(),
25902590
other => bug!("unexpected item {:?}", other),
25912591
};
2592-
let parent_substs = tcx.mk_substs(parent_substs.iter());
2592+
let parent_substs = tcx.intern_substs(parent_substs);
25932593

25942594
assert_eq!(typeck_root_substs.len(), parent_substs.len());
25952595
if let Err(_) = self.eq_substs(

‎compiler/rustc_codegen_cranelift/src/codegen_i128.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub(crate) fn maybe_codegen<'tcx>(
5656
Some(fx.easy_call("__multi3", &[lhs, rhs], val_ty))
5757
}
5858
} else {
59-
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
59+
let out_ty = fx.tcx.intern_tup(&[lhs.layout().ty, fx.tcx.types.bool]);
6060
let oflow = CPlace::new_stack_slot(fx, fx.layout_of(fx.tcx.types.i32));
6161
let lhs = lhs.load_scalar(fx);
6262
let rhs = rhs.load_scalar(fx);
@@ -78,7 +78,7 @@ pub(crate) fn maybe_codegen<'tcx>(
7878
}
7979
BinOp::Add | BinOp::Sub | BinOp::Mul => {
8080
assert!(checked);
81-
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
81+
let out_ty = fx.tcx.intern_tup(&[lhs.layout().ty, fx.tcx.types.bool]);
8282
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
8383
let (param_types, args) = if fx.tcx.sess.target.is_like_windows {
8484
let (lhs_ptr, lhs_extra) = lhs.force_stack(fx);

‎compiler/rustc_codegen_cranelift/src/intrinsics/llvm_x86.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn llvm_add_sub<'tcx>(
191191
// carry0 | carry1 -> carry or borrow respectively
192192
let cb_out = fx.bcx.ins().bor(cb0, cb1);
193193

194-
let layout = fx.layout_of(fx.tcx.mk_tup([fx.tcx.types.u8, fx.tcx.types.u64].iter()));
194+
let layout = fx.layout_of(fx.tcx.intern_tup(&[fx.tcx.types.u8, fx.tcx.types.u64]));
195195
let val = CValue::by_val_pair(cb_out, c, layout);
196196
ret.write_cvalue(fx, val);
197197
}

‎compiler/rustc_codegen_cranelift/src/main_shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub(crate) fn maybe_create_entry_wrapper(
119119
tcx,
120120
ParamEnv::reveal_all(),
121121
report.def_id,
122-
tcx.mk_substs([GenericArg::from(main_ret_ty)].iter()),
122+
tcx.intern_substs(&[GenericArg::from(main_ret_ty)]),
123123
)
124124
.unwrap()
125125
.unwrap()

‎compiler/rustc_codegen_cranelift/src/num.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
289289
_ => bug!("binop {:?} on checked int/uint lhs: {:?} rhs: {:?}", bin_op, in_lhs, in_rhs),
290290
};
291291

292-
let out_layout = fx.layout_of(fx.tcx.mk_tup([in_lhs.layout().ty, fx.tcx.types.bool].iter()));
292+
let out_layout = fx.layout_of(fx.tcx.intern_tup(&[in_lhs.layout().ty, fx.tcx.types.bool]));
293293
CValue::by_val_pair(res, has_overflow, out_layout)
294294
}
295295

‎compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ use rustc_middle::ty::Instance;
2727
use std::cell::RefCell;
2828
use std::ffi::CString;
2929

30-
use std::iter;
31-
3230
pub mod mapgen;
3331

3432
const UNUSED_FUNCTION_COUNTER_ID: CounterValueReference = CounterValueReference::START;
@@ -201,7 +199,7 @@ fn declare_unused_fn<'tcx>(cx: &CodegenCx<'_, 'tcx>, def_id: DefId) -> Instance<
201199
tcx.symbol_name(instance).name,
202200
cx.fn_abi_of_fn_ptr(
203201
ty::Binder::dummy(tcx.mk_fn_sig(
204-
iter::once(tcx.mk_unit()),
202+
[tcx.mk_unit()],
205203
tcx.mk_unit(),
206204
false,
207205
hir::Unsafety::Unsafe,

‎compiler/rustc_codegen_llvm/src/intrinsic.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustc_target::abi::{self, Align, HasDataLayout, Primitive};
2222
use rustc_target::spec::{HasTargetSpec, PanicStrategy};
2323

2424
use std::cmp::Ordering;
25-
use std::iter;
2625

2726
fn get_simple_intrinsic<'ll>(
2827
cx: &CodegenCx<'ll, '_>,
@@ -798,23 +797,23 @@ fn get_rust_try_fn<'ll, 'tcx>(
798797
let i8p = tcx.mk_mut_ptr(tcx.types.i8);
799798
// `unsafe fn(*mut i8) -> ()`
800799
let try_fn_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig(
801-
iter::once(i8p),
800+
[i8p],
802801
tcx.mk_unit(),
803802
false,
804803
hir::Unsafety::Unsafe,
805804
Abi::Rust,
806805
)));
807806
// `unsafe fn(*mut i8, *mut i8) -> ()`
808807
let catch_fn_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig(
809-
[i8p, i8p].iter().cloned(),
808+
[i8p, i8p],
810809
tcx.mk_unit(),
811810
false,
812811
hir::Unsafety::Unsafe,
813812
Abi::Rust,
814813
)));
815814
// `unsafe fn(unsafe fn(*mut i8) -> (), *mut i8, unsafe fn(*mut i8, *mut i8) -> ()) -> i32`
816815
let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig(
817-
[try_fn_ty, i8p, catch_fn_ty].into_iter(),
816+
[try_fn_ty, i8p, catch_fn_ty],
818817
tcx.types.i32,
819818
false,
820819
hir::Unsafety::Unsafe,

‎compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9696
let loc_ty = self
9797
.tcx
9898
.type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None))
99-
.subst(*self.tcx, self.tcx.mk_substs([self.tcx.lifetimes.re_erased.into()].iter()));
99+
.subst(*self.tcx, self.tcx.intern_substs(&[self.tcx.lifetimes.re_erased.into()]));
100100
let loc_layout = self.layout_of(loc_ty).unwrap();
101101
let location = self.allocate(loc_layout, MemoryKind::CallerLocation).unwrap();
102102

‎compiler/rustc_hir_analysis/src/astconv/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16081608
.collect::<SmallVec<[_; 8]>>();
16091609
v.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder()));
16101610
v.dedup();
1611-
let existential_predicates = tcx.mk_poly_existential_predicates(v.into_iter());
1611+
let existential_predicates = tcx.intern_poly_existential_predicates(&v);
16121612

16131613
// Use explicitly-specified region bound.
16141614
let region_bound = if !lifetime.is_elided() {
@@ -3109,7 +3109,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
31093109

31103110
debug!(?output_ty);
31113111

3112-
let fn_ty = tcx.mk_fn_sig(input_tys.into_iter(), output_ty, decl.c_variadic, unsafety, abi);
3112+
let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, unsafety, abi);
31133113
let bare_fn_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars);
31143114

31153115
if !self.allow_ty_infer() && !(visitor.0.is_empty() && infer_replacements.is_empty()) {

‎compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ pub(super) fn check_type_bounds<'tcx>(
19361936
.into()
19371937
}
19381938
});
1939-
let bound_vars = tcx.mk_bound_variable_kinds(bound_vars.into_iter());
1939+
let bound_vars = tcx.intern_bound_variable_kinds(&bound_vars);
19401940
let impl_ty_substs = tcx.intern_substs(&substs);
19411941
let container_id = impl_ty.container_id(tcx);
19421942

‎compiler/rustc_hir_analysis/src/check/intrinsic.rs

+9-21
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ use rustc_middle::ty::{self, TyCtxt};
1515
use rustc_span::symbol::{kw, sym, Symbol};
1616
use rustc_target::spec::abi::Abi;
1717

18-
use std::iter;
19-
2018
fn equate_intrinsic_type<'tcx>(
2119
tcx: TyCtxt<'tcx>,
2220
it: &hir::ForeignItem<'_>,
@@ -139,14 +137,10 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
139137
let intrinsic_name = tcx.item_name(intrinsic_id);
140138
let name_str = intrinsic_name.as_str();
141139

142-
let bound_vars = tcx.mk_bound_variable_kinds(
143-
[
144-
ty::BoundVariableKind::Region(ty::BrAnon(0, None)),
145-
ty::BoundVariableKind::Region(ty::BrEnv),
146-
]
147-
.iter()
148-
.copied(),
149-
);
140+
let bound_vars = tcx.intern_bound_variable_kinds(&[
141+
ty::BoundVariableKind::Region(ty::BrAnon(0, None)),
142+
ty::BoundVariableKind::Region(ty::BrEnv),
143+
]);
150144
let mk_va_list_ty = |mutbl| {
151145
tcx.lang_items().va_list().map(|did| {
152146
let region = tcx.mk_re_late_bound(
@@ -378,21 +372,21 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
378372
(
379373
1,
380374
vec![tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0))],
381-
tcx.mk_projection(discriminant_def_id, tcx.mk_substs([param(0).into()].iter())),
375+
tcx.mk_projection(discriminant_def_id, tcx.intern_substs(&[param(0).into()])),
382376
)
383377
}
384378

385379
kw::Try => {
386380
let mut_u8 = tcx.mk_mut_ptr(tcx.types.u8);
387381
let try_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
388-
iter::once(mut_u8),
382+
[mut_u8],
389383
tcx.mk_unit(),
390384
false,
391385
hir::Unsafety::Normal,
392386
Abi::Rust,
393387
));
394388
let catch_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
395-
[mut_u8, mut_u8].iter().cloned(),
389+
[mut_u8, mut_u8],
396390
tcx.mk_unit(),
397391
false,
398392
hir::Unsafety::Normal,
@@ -447,7 +441,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
447441
};
448442
(n_tps, 0, inputs, output, unsafety)
449443
};
450-
let sig = tcx.mk_fn_sig(inputs.into_iter(), output, false, unsafety, Abi::RustIntrinsic);
444+
let sig = tcx.mk_fn_sig(inputs, output, false, unsafety, Abi::RustIntrinsic);
451445
let sig = ty::Binder::bind_with_vars(sig, bound_vars);
452446
equate_intrinsic_type(tcx, it, n_tps, n_lts, sig)
453447
}
@@ -545,13 +539,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
545539
}
546540
};
547541

548-
let sig = tcx.mk_fn_sig(
549-
inputs.into_iter(),
550-
output,
551-
false,
552-
hir::Unsafety::Unsafe,
553-
Abi::PlatformIntrinsic,
554-
);
542+
let sig = tcx.mk_fn_sig(inputs, output, false, hir::Unsafety::Unsafe, Abi::PlatformIntrinsic);
555543
let sig = ty::Binder::dummy(sig);
556544
equate_intrinsic_type(tcx, it, n_tps, 0, sig)
557545
}

‎compiler/rustc_hir_analysis/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ use rustc_target::spec::abi::Abi;
113113
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
114114
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode};
115115

116-
use std::iter;
117116
use std::ops::Not;
118117

119118
use astconv::AstConv;
@@ -348,7 +347,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
348347
}
349348

350349
let se_ty = tcx.mk_fn_ptr(expected_return_type.map_bound(|expected_return_type| {
351-
tcx.mk_fn_sig(iter::empty(), expected_return_type, false, hir::Unsafety::Normal, Abi::Rust)
350+
tcx.mk_fn_sig([], expected_return_type, false, hir::Unsafety::Normal, Abi::Rust)
352351
}));
353352

354353
require_same_types(
@@ -434,7 +433,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
434433
}
435434

436435
let se_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig(
437-
[tcx.types.isize, tcx.mk_imm_ptr(tcx.mk_imm_ptr(tcx.types.u8))].iter().cloned(),
436+
[tcx.types.isize, tcx.mk_imm_ptr(tcx.mk_imm_ptr(tcx.types.u8))],
438437
tcx.types.isize,
439438
false,
440439
hir::Unsafety::Normal,

‎compiler/rustc_hir_typeck/src/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ fn check_lang_start_fn<'tcx>(
264264
let fn_generic = generics.param_at(0, tcx);
265265
let generic_ty = tcx.mk_ty_param(fn_generic.index, fn_generic.name);
266266
let expected_fn_sig =
267-
tcx.mk_fn_sig([].iter(), &generic_ty, false, hir::Unsafety::Normal, Abi::Rust);
267+
tcx.mk_fn_sig([], generic_ty, false, hir::Unsafety::Normal, Abi::Rust);
268268
let expected_ty = tcx.mk_fn_ptr(Binder::dummy(expected_fn_sig));
269269

270270
// we emit the same error to suggest changing the arg no matter what's wrong with the arg

‎compiler/rustc_hir_typeck/src/closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
126126
// the `closures` table.
127127
let sig = bound_sig.map_bound(|sig| {
128128
self.tcx.mk_fn_sig(
129-
iter::once(self.tcx.intern_tup(sig.inputs())),
129+
[self.tcx.intern_tup(sig.inputs())],
130130
sig.output(),
131131
sig.c_variadic,
132132
sig.unsafety,
@@ -326,7 +326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
326326
debug!(?ret_param_ty);
327327

328328
let sig = projection.rebind(self.tcx.mk_fn_sig(
329-
input_tys.iter(),
329+
input_tys,
330330
ret_param_ty,
331331
false,
332332
hir::Unsafety::Normal,

‎compiler/rustc_hir_typeck/src/generator_interior/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ pub fn resolve_interior<'a, 'tcx>(
312312

313313
// Extract type components to build the witness type.
314314
let type_list = fcx.tcx.mk_type_list(type_causes.iter().map(|cause| cause.ty));
315-
let bound_vars = fcx.tcx.mk_bound_variable_kinds(bound_vars.iter());
315+
let bound_vars = fcx.tcx.intern_bound_variable_kinds(&bound_vars);
316316
let witness =
317317
fcx.tcx.mk_generator_witness(ty::Binder::bind_with_vars(type_list, bound_vars.clone()));
318318

‎compiler/rustc_hir_typeck/src/upvar.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
301301

302302
// Build a tuple (U0..Un) of the final upvar types U0..Un
303303
// and unify the upvar tuple type in the closure with it:
304-
let final_tupled_upvars_type = self.tcx.mk_tup(final_upvar_tys.iter());
304+
let final_tupled_upvars_type = self.tcx.intern_tup(&final_upvar_tys);
305305
self.demand_suptype(span, substs.tupled_upvars_ty(), final_tupled_upvars_type);
306306

307307
let fake_reads = delegate
@@ -315,8 +315,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
315315
self.typeck_results.borrow_mut().closure_size_eval.insert(
316316
closure_def_id,
317317
ClosureSizeProfileData {
318-
before_feature_tys: self.tcx.mk_tup(before_feature_tys.into_iter()),
319-
after_feature_tys: self.tcx.mk_tup(after_feature_tys.into_iter()),
318+
before_feature_tys: self.tcx.intern_tup(&before_feature_tys),
319+
after_feature_tys: self.tcx.intern_tup(&after_feature_tys),
320320
},
321321
);
322322
}

‎compiler/rustc_metadata/src/native_libs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ impl<'tcx> Collector<'tcx> {
502502
.subst_identity()
503503
.fn_sig(self.tcx)
504504
.inputs()
505-
.map_bound(|slice| self.tcx.mk_type_list(slice.iter())),
505+
.map_bound(|slice| self.tcx.intern_type_list(slice)),
506506
);
507507

508508
argument_types

‎compiler/rustc_middle/src/mir/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -2525,14 +2525,12 @@ impl<'tcx> ConstantKind<'tcx> {
25252525
}
25262526

25272527
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
2528-
let parent_substs = if let Some(parent_hir_id) = tcx.hir().opt_parent_id(hir_id) {
2529-
if let Some(parent_did) = parent_hir_id.as_owner() {
2530-
InternalSubsts::identity_for_item(tcx, parent_did.to_def_id())
2531-
} else {
2532-
tcx.mk_substs(Vec::<GenericArg<'tcx>>::new().into_iter())
2533-
}
2528+
let parent_substs = if let Some(parent_hir_id) = tcx.hir().opt_parent_id(hir_id)
2529+
&& let Some(parent_did) = parent_hir_id.as_owner()
2530+
{
2531+
InternalSubsts::identity_for_item(tcx, parent_did.to_def_id())
25342532
} else {
2535-
tcx.mk_substs(Vec::<GenericArg<'tcx>>::new().into_iter())
2533+
tcx.intern_substs(&[])
25362534
};
25372535
debug!(?parent_substs);
25382536

0 commit comments

Comments
 (0)
Please sign in to comment.