Rename many interner functions.
(This is a large commit. The changes to `compiler/rustc_middle/src/ty/context.rs` are the most important ones.) The current naming scheme is a mess, with a mix of `_intern_`, `intern_` and `mk_` prefixes, with little consistency. In particular, in many cases it's easy to use an iterator interner when a (preferable) slice interner is available. The guiding principles of the new naming system: - No `_intern_` prefixes. - The `intern_` prefix is for internal operations. - The `mk_` prefix is for external operations. - For cases where there is a slice interner and an iterator interner, the former is `mk_foo` and the latter is `mk_foo_from_iter`. Also, `slice_interners!` and `direct_interners!` can now be `pub` or non-`pub`, which helps enforce the internal/external operations division. It's not perfect, but I think it's a clear improvement. The following lists show everything that was renamed. slice_interners - const_list - mk_const_list -> mk_const_list_from_iter - intern_const_list -> mk_const_list - substs - mk_substs -> mk_substs_from_iter - intern_substs -> mk_substs - check_substs -> check_and_mk_substs (this is a weird one) - canonical_var_infos - intern_canonical_var_infos -> mk_canonical_var_infos - poly_existential_predicates - mk_poly_existential_predicates -> mk_poly_existential_predicates_from_iter - intern_poly_existential_predicates -> mk_poly_existential_predicates - _intern_poly_existential_predicates -> intern_poly_existential_predicates - predicates - mk_predicates -> mk_predicates_from_iter - intern_predicates -> mk_predicates - _intern_predicates -> intern_predicates - projs - intern_projs -> mk_projs - place_elems - mk_place_elems -> mk_place_elems_from_iter - intern_place_elems -> mk_place_elems - bound_variable_kinds - mk_bound_variable_kinds -> mk_bound_variable_kinds_from_iter - intern_bound_variable_kinds -> mk_bound_variable_kinds direct_interners - region - intern_region (unchanged) - const - mk_const_internal -> intern_const - const_allocation - intern_const_alloc -> mk_const_alloc - layout - intern_layout -> mk_layout - adt_def - intern_adt_def -> mk_adt_def_from_data (unusual case, hard to avoid) - alloc_adt_def(!) -> mk_adt_def - external_constraints - intern_external_constraints -> mk_external_constraints Other - type_list - mk_type_list -> mk_type_list_from_iter - intern_type_list -> mk_type_list - tup - mk_tup -> mk_tup_from_iter - intern_tup -> mk_tup
This commit is contained in:
parent
29b51cdff3
commit
2200911616
111 changed files with 364 additions and 363 deletions
|
@ -54,7 +54,7 @@ fn fn_sig_for_fn_abi<'tcx>(
|
|||
sig = sig.map_bound(|mut sig| {
|
||||
let mut inputs_and_output = sig.inputs_and_output.to_vec();
|
||||
inputs_and_output[0] = tcx.mk_mut_ptr(inputs_and_output[0]);
|
||||
sig.inputs_and_output = tcx.intern_type_list(&inputs_and_output);
|
||||
sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output);
|
||||
sig
|
||||
});
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ fn fn_sig_for_fn_abi<'tcx>(
|
|||
ty::Closure(def_id, substs) => {
|
||||
let sig = substs.as_closure().sig();
|
||||
|
||||
let bound_vars = tcx.mk_bound_variable_kinds(
|
||||
let bound_vars = tcx.mk_bound_variable_kinds_from_iter(
|
||||
sig.bound_vars().iter().chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))),
|
||||
);
|
||||
let br = ty::BoundRegion {
|
||||
|
@ -88,7 +88,7 @@ fn fn_sig_for_fn_abi<'tcx>(
|
|||
ty::Generator(did, substs, _) => {
|
||||
let sig = substs.as_generator().poly_sig();
|
||||
|
||||
let bound_vars = tcx.mk_bound_variable_kinds(
|
||||
let bound_vars = tcx.mk_bound_variable_kinds_from_iter(
|
||||
sig.bound_vars().iter().chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))),
|
||||
);
|
||||
let br = ty::BoundRegion {
|
||||
|
@ -99,7 +99,7 @@ fn fn_sig_for_fn_abi<'tcx>(
|
|||
|
||||
let pin_did = tcx.require_lang_item(LangItem::Pin, None);
|
||||
let pin_adt_ref = tcx.adt_def(pin_did);
|
||||
let pin_substs = tcx.intern_substs(&[env_ty.into()]);
|
||||
let pin_substs = tcx.mk_substs(&[env_ty.into()]);
|
||||
let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs);
|
||||
|
||||
let sig = sig.skip_binder();
|
||||
|
@ -111,7 +111,7 @@ fn fn_sig_for_fn_abi<'tcx>(
|
|||
// The signature should be `Future::poll(_, &mut Context<'_>) -> Poll<Output>`
|
||||
let poll_did = tcx.require_lang_item(LangItem::Poll, None);
|
||||
let poll_adt_ref = tcx.adt_def(poll_did);
|
||||
let poll_substs = tcx.intern_substs(&[sig.return_ty.into()]);
|
||||
let poll_substs = tcx.mk_substs(&[sig.return_ty.into()]);
|
||||
let ret_ty = tcx.mk_adt(poll_adt_ref, poll_substs);
|
||||
|
||||
// We have to replace the `ResumeTy` that is used for type and borrow checking
|
||||
|
@ -133,7 +133,7 @@ fn fn_sig_for_fn_abi<'tcx>(
|
|||
// The signature should be `Generator::resume(_, Resume) -> GeneratorState<Yield, Return>`
|
||||
let state_did = tcx.require_lang_item(LangItem::GeneratorState, None);
|
||||
let state_adt_ref = tcx.adt_def(state_did);
|
||||
let state_substs = tcx.intern_substs(&[sig.yield_ty.into(), sig.return_ty.into()]);
|
||||
let state_substs = tcx.mk_substs(&[sig.yield_ty.into(), sig.return_ty.into()]);
|
||||
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);
|
||||
|
||||
(sig.resume_ty, ret_ty)
|
||||
|
|
|
@ -144,7 +144,7 @@ fn recurse_build<'tcx>(
|
|||
for &id in args.iter() {
|
||||
new_args.push(recurse_build(tcx, body, id, root_span)?);
|
||||
}
|
||||
let new_args = tcx.intern_const_list(&new_args);
|
||||
let new_args = tcx.mk_const_list(&new_args);
|
||||
tcx.mk_const(Expr::FunctionCall(fun, new_args), node.ty)
|
||||
}
|
||||
&ExprKind::Binary { op, lhs, rhs } if check_binop(op) => {
|
||||
|
|
|
@ -19,16 +19,16 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
|
|||
let mut assumed_wf_types: Vec<_> =
|
||||
tcx.assumed_wf_types(tcx.parent(def_id)).as_slice().into();
|
||||
assumed_wf_types.extend(liberated_sig.inputs_and_output);
|
||||
tcx.intern_type_list(&assumed_wf_types)
|
||||
tcx.mk_type_list(&assumed_wf_types)
|
||||
}
|
||||
DefKind::Impl { .. } => {
|
||||
match tcx.impl_trait_ref(def_id) {
|
||||
Some(trait_ref) => {
|
||||
let types: Vec<_> = trait_ref.skip_binder().substs.types().collect();
|
||||
tcx.intern_type_list(&types)
|
||||
tcx.mk_type_list(&types)
|
||||
}
|
||||
// Only the impl self type
|
||||
None => tcx.intern_type_list(&[tcx.type_of(def_id).subst_identity()]),
|
||||
None => tcx.mk_type_list(&[tcx.type_of(def_id).subst_identity()]),
|
||||
}
|
||||
}
|
||||
DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)),
|
||||
|
|
|
@ -104,23 +104,23 @@ fn layout_of_uncached<'tcx>(
|
|||
assert!(size.bits() <= 128);
|
||||
Scalar::Initialized { value, valid_range: WrappingRange::full(size) }
|
||||
};
|
||||
let scalar = |value: Primitive| tcx.intern_layout(LayoutS::scalar(cx, scalar_unit(value)));
|
||||
let scalar = |value: Primitive| tcx.mk_layout(LayoutS::scalar(cx, scalar_unit(value)));
|
||||
|
||||
let univariant = |fields: &[Layout<'_>], repr: &ReprOptions, kind| {
|
||||
Ok(tcx.intern_layout(univariant_uninterned(cx, ty, fields, repr, kind)?))
|
||||
Ok(tcx.mk_layout(univariant_uninterned(cx, ty, fields, repr, kind)?))
|
||||
};
|
||||
debug_assert!(!ty.has_non_region_infer());
|
||||
|
||||
Ok(match *ty.kind() {
|
||||
// Basic scalars.
|
||||
ty::Bool => tcx.intern_layout(LayoutS::scalar(
|
||||
ty::Bool => tcx.mk_layout(LayoutS::scalar(
|
||||
cx,
|
||||
Scalar::Initialized {
|
||||
value: Int(I8, false),
|
||||
valid_range: WrappingRange { start: 0, end: 1 },
|
||||
},
|
||||
)),
|
||||
ty::Char => tcx.intern_layout(LayoutS::scalar(
|
||||
ty::Char => tcx.mk_layout(LayoutS::scalar(
|
||||
cx,
|
||||
Scalar::Initialized {
|
||||
value: Int(I32, false),
|
||||
|
@ -136,11 +136,11 @@ fn layout_of_uncached<'tcx>(
|
|||
ty::FnPtr(_) => {
|
||||
let mut ptr = scalar_unit(Pointer(dl.instruction_address_space));
|
||||
ptr.valid_range_mut().start = 1;
|
||||
tcx.intern_layout(LayoutS::scalar(cx, ptr))
|
||||
tcx.mk_layout(LayoutS::scalar(cx, ptr))
|
||||
}
|
||||
|
||||
// The never type.
|
||||
ty::Never => tcx.intern_layout(cx.layout_of_never_type()),
|
||||
ty::Never => tcx.mk_layout(cx.layout_of_never_type()),
|
||||
|
||||
// Potentially-wide pointers.
|
||||
ty::Ref(_, pointee, _) | ty::RawPtr(ty::TypeAndMut { ty: pointee, .. }) => {
|
||||
|
@ -151,7 +151,7 @@ fn layout_of_uncached<'tcx>(
|
|||
|
||||
let pointee = tcx.normalize_erasing_regions(param_env, pointee);
|
||||
if pointee.is_sized(tcx, param_env) {
|
||||
return Ok(tcx.intern_layout(LayoutS::scalar(cx, data_ptr)));
|
||||
return Ok(tcx.mk_layout(LayoutS::scalar(cx, data_ptr)));
|
||||
}
|
||||
|
||||
let unsized_part = tcx.struct_tail_erasing_lifetimes(pointee, param_env);
|
||||
|
@ -164,7 +164,7 @@ fn layout_of_uncached<'tcx>(
|
|||
let metadata_layout = cx.layout_of(metadata_ty)?;
|
||||
// If the metadata is a 1-zst, then the pointer is thin.
|
||||
if metadata_layout.is_zst() && metadata_layout.align.abi.bytes() == 1 {
|
||||
return Ok(tcx.intern_layout(LayoutS::scalar(cx, data_ptr)));
|
||||
return Ok(tcx.mk_layout(LayoutS::scalar(cx, data_ptr)));
|
||||
}
|
||||
|
||||
let Abi::Scalar(metadata) = metadata_layout.abi else {
|
||||
|
@ -174,7 +174,7 @@ fn layout_of_uncached<'tcx>(
|
|||
} else {
|
||||
match unsized_part.kind() {
|
||||
ty::Foreign(..) => {
|
||||
return Ok(tcx.intern_layout(LayoutS::scalar(cx, data_ptr)));
|
||||
return Ok(tcx.mk_layout(LayoutS::scalar(cx, data_ptr)));
|
||||
}
|
||||
ty::Slice(_) | ty::Str => scalar_unit(Int(dl.ptr_sized_integer(), false)),
|
||||
ty::Dynamic(..) => {
|
||||
|
@ -189,7 +189,7 @@ fn layout_of_uncached<'tcx>(
|
|||
};
|
||||
|
||||
// Effectively a (ptr, meta) tuple.
|
||||
tcx.intern_layout(cx.scalar_pair(data_ptr, metadata))
|
||||
tcx.mk_layout(cx.scalar_pair(data_ptr, metadata))
|
||||
}
|
||||
|
||||
ty::Dynamic(_, _, ty::DynStar) => {
|
||||
|
@ -197,7 +197,7 @@ fn layout_of_uncached<'tcx>(
|
|||
data.valid_range_mut().start = 0;
|
||||
let mut vtable = scalar_unit(Pointer(AddressSpace::DATA));
|
||||
vtable.valid_range_mut().start = 1;
|
||||
tcx.intern_layout(cx.scalar_pair(data, vtable))
|
||||
tcx.mk_layout(cx.scalar_pair(data, vtable))
|
||||
}
|
||||
|
||||
// Arrays and slices.
|
||||
|
@ -222,7 +222,7 @@ fn layout_of_uncached<'tcx>(
|
|||
|
||||
let largest_niche = if count != 0 { element.largest_niche } else { None };
|
||||
|
||||
tcx.intern_layout(LayoutS {
|
||||
tcx.mk_layout(LayoutS {
|
||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||
fields: FieldsShape::Array { stride: element.size, count },
|
||||
abi,
|
||||
|
@ -233,7 +233,7 @@ fn layout_of_uncached<'tcx>(
|
|||
}
|
||||
ty::Slice(element) => {
|
||||
let element = cx.layout_of(element)?;
|
||||
tcx.intern_layout(LayoutS {
|
||||
tcx.mk_layout(LayoutS {
|
||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||
fields: FieldsShape::Array { stride: element.size, count: 0 },
|
||||
abi: Abi::Aggregate { sized: false },
|
||||
|
@ -242,7 +242,7 @@ fn layout_of_uncached<'tcx>(
|
|||
size: Size::ZERO,
|
||||
})
|
||||
}
|
||||
ty::Str => tcx.intern_layout(LayoutS {
|
||||
ty::Str => tcx.mk_layout(LayoutS {
|
||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||
fields: FieldsShape::Array { stride: Size::from_bytes(1), count: 0 },
|
||||
abi: Abi::Aggregate { sized: false },
|
||||
|
@ -265,7 +265,7 @@ fn layout_of_uncached<'tcx>(
|
|||
Abi::Aggregate { ref mut sized } => *sized = false,
|
||||
_ => bug!(),
|
||||
}
|
||||
tcx.intern_layout(unit)
|
||||
tcx.mk_layout(unit)
|
||||
}
|
||||
|
||||
ty::Generator(def_id, substs, _) => generator_layout(cx, ty, def_id, substs)?,
|
||||
|
@ -394,7 +394,7 @@ fn layout_of_uncached<'tcx>(
|
|||
FieldsShape::Array { stride: e_ly.size, count: e_len }
|
||||
};
|
||||
|
||||
tcx.intern_layout(LayoutS {
|
||||
tcx.mk_layout(LayoutS {
|
||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||
fields,
|
||||
abi: Abi::Vector { element: e_abi, count: e_len },
|
||||
|
@ -427,12 +427,12 @@ fn layout_of_uncached<'tcx>(
|
|||
return Err(LayoutError::Unknown(ty));
|
||||
}
|
||||
|
||||
return Ok(tcx.intern_layout(
|
||||
return Ok(tcx.mk_layout(
|
||||
cx.layout_of_union(&def.repr(), &variants).ok_or(LayoutError::Unknown(ty))?,
|
||||
));
|
||||
}
|
||||
|
||||
tcx.intern_layout(
|
||||
tcx.mk_layout(
|
||||
cx.layout_of_struct_or_enum(
|
||||
&def.repr(),
|
||||
&variants,
|
||||
|
@ -636,7 +636,7 @@ fn generator_layout<'tcx>(
|
|||
value: Primitive::Int(discr_int, false),
|
||||
valid_range: WrappingRange { start: 0, end: max_discr },
|
||||
};
|
||||
let tag_layout = cx.tcx.intern_layout(LayoutS::scalar(cx, tag));
|
||||
let tag_layout = cx.tcx.mk_layout(LayoutS::scalar(cx, tag));
|
||||
|
||||
let promoted_layouts = ineligible_locals
|
||||
.iter()
|
||||
|
@ -784,7 +784,7 @@ fn generator_layout<'tcx>(
|
|||
Abi::Aggregate { sized: true }
|
||||
};
|
||||
|
||||
let layout = tcx.intern_layout(LayoutS {
|
||||
let layout = tcx.mk_layout(LayoutS {
|
||||
variants: Variants::Multiple {
|
||||
tag,
|
||||
tag_encoding: TagEncoding::Direct,
|
||||
|
|
|
@ -303,7 +303,7 @@ fn adt_drop_tys<'tcx>(
|
|||
false,
|
||||
)
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map(|components| tcx.intern_type_list(&components))
|
||||
.map(|components| tcx.mk_type_list(&components))
|
||||
}
|
||||
// If `def_id` refers to a generic ADT, the queries above and below act as if they had been handed
|
||||
// a `tcx.make_ty(def, identity_substs)` and as such it is legal to substitute the generic parameters
|
||||
|
@ -320,7 +320,7 @@ fn adt_significant_drop_tys(
|
|||
true,
|
||||
)
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map(|components| tcx.intern_type_list(&components))
|
||||
.map(|components| tcx.mk_type_list(&components))
|
||||
}
|
||||
|
||||
pub(crate) fn provide(providers: &mut ty::query::Providers) {
|
||||
|
|
|
@ -98,12 +98,12 @@ fn impl_defaultness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Defaultness {
|
|||
fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] {
|
||||
if let Some(def_id) = def_id.as_local() {
|
||||
if matches!(tcx.representability(def_id), ty::Representability::Infinite) {
|
||||
return tcx.intern_type_list(&[tcx.ty_error_misc()]);
|
||||
return tcx.mk_type_list(&[tcx.ty_error_misc()]);
|
||||
}
|
||||
}
|
||||
let def = tcx.adt_def(def_id);
|
||||
|
||||
let result = tcx.mk_type_list(
|
||||
let result = tcx.mk_type_list_from_iter(
|
||||
def.variants()
|
||||
.iter()
|
||||
.flat_map(|v| v.fields.last())
|
||||
|
@ -226,11 +226,8 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
|
|||
None => hir::Constness::NotConst,
|
||||
};
|
||||
|
||||
let unnormalized_env = ty::ParamEnv::new(
|
||||
tcx.intern_predicates(&predicates),
|
||||
traits::Reveal::UserFacing,
|
||||
constness,
|
||||
);
|
||||
let unnormalized_env =
|
||||
ty::ParamEnv::new(tcx.mk_predicates(&predicates), traits::Reveal::UserFacing, constness);
|
||||
|
||||
let body_id = local_did.unwrap_or(CRATE_DEF_ID);
|
||||
let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id);
|
||||
|
@ -386,7 +383,7 @@ fn well_formed_types_in_env(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Predica
|
|||
}
|
||||
});
|
||||
|
||||
tcx.mk_predicates(clauses.chain(input_clauses))
|
||||
tcx.mk_predicates_from_iter(clauses.chain(input_clauses))
|
||||
}
|
||||
|
||||
fn param_env_reveal_all_normalized(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue