Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,15 @@ pub struct CtxtInterners<'tcx> {

impl<'tcx> CtxtInterners<'tcx> {
fn new(arena: &'tcx WorkerLocal<Arena<'tcx>>) -> CtxtInterners<'tcx> {
// Default interner size - this value has been chosen empirically, and may need to be adjusted
// as the compiler evolves.
// Default interner size - this value has been chosen empirically, and may need to be
// adjusted as the compiler evolves.
const N: usize = 2048;
CtxtInterners {
arena,
// The factors have been chosen by @FractalFir based on observed interner sizes, and local perf runs.
// To get the interner sizes, insert `eprintln` printing the size of the interner in functions like `intern_ty`.
// Bigger benchmarks tend to give more accurate ratios, so use something like `x perf eprintln --includes cargo`.
// The factors have been chosen by @FractalFir based on observed interner sizes, and
// local perf runs. To get the interner sizes, insert `eprintln` printing the size of
// the interner in functions like `intern_ty`. Bigger benchmarks tend to give more
// accurate ratios, so use something like `x perf eprintln --includes cargo`.
type_: InternedSet::with_capacity(N * 16),
const_lists: InternedSet::with_capacity(N * 4),
args: InternedSet::with_capacity(N * 4),
Expand Down Expand Up @@ -326,11 +327,12 @@ const NUM_PREINTERNED_ANON_BOUND_TYS_I: u32 = 3;
// From general profiling of the *max vars during canonicalization* of a value:
// - about 90% of the time, there are no canonical vars
// - about 9% of the time, there is only one canonical var
// - there are rarely more than 3-5 canonical vars (with exceptions in particularly pathological cases)
// - there are rarely more than 3-5 canonical vars (with exceptions in particularly pathological
// cases)
// This may not match the number of bound vars found in `for`s.
// Given that this is all heap interned, it seems likely that interning fewer
// vars here won't make an appreciable difference. Though, if we were to inline the data (in an array),
// we may want to consider reducing the number for canonicalized vars down to 4 or so.
// vars here won't make an appreciable difference. Though, if we were to inline the data (in an
// array), we may want to consider reducing the number for canonicalized vars down to 4 or so.
const NUM_PREINTERNED_ANON_BOUND_TYS_V: u32 = 20;

// This number may seem high, but it is reached in all but the smallest crates.
Expand Down Expand Up @@ -381,8 +383,8 @@ pub struct CommonTypes<'tcx> {
pub fresh_float_tys: Vec<Ty<'tcx>>,

/// Pre-interned values of the form:
/// `Bound(BoundVarIndexKind::Bound(DebruijnIndex(i)), BoundTy { var: v, kind: BoundTyKind::Anon})`
/// for small values of `i` and `v`.
/// `Bound(BoundVarIndexKind::Bound(DebruijnIndex(i)), BoundTy { var: v, kind:
/// BoundTyKind::Anon})` for small values of `i` and `v`.
pub anon_bound_tys: Vec<Vec<Ty<'tcx>>>,

// Pre-interned values of the form:
Expand Down Expand Up @@ -1014,7 +1016,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// has a valid reference to the context, to allow formatting values that need it.
pub fn create_global_ctxt<T>(
gcx_cell: &'tcx OnceLock<GlobalCtxt<'tcx>>,
s: &'tcx Session,
sess: &'tcx Session,
crate_types: Vec<CrateType>,
stable_crate_id: StableCrateId,
arena: &'tcx WorkerLocal<Arena<'tcx>>,
Expand All @@ -1028,24 +1030,24 @@ impl<'tcx> TyCtxt<'tcx> {
jobserver_proxy: Arc<Proxy>,
f: impl FnOnce(TyCtxt<'tcx>) -> T,
) -> T {
let data_layout = s.target.parse_data_layout().unwrap_or_else(|err| {
s.dcx().emit_fatal(err);
let data_layout = sess.target.parse_data_layout().unwrap_or_else(|err| {
sess.dcx().emit_fatal(err);
});
let interners = CtxtInterners::new(arena);
let common_types = CommonTypes::new(&interners);
let common_lifetimes = CommonLifetimes::new(&interners);
let common_consts = CommonConsts::new(&interners, &common_types);

let gcx = gcx_cell.get_or_init(|| GlobalCtxt {
sess: s,
sess,
crate_types,
stable_crate_id,
arena,
hir_arena,
interners,
dep_graph,
hooks,
prof: s.prof.clone(),
prof: sess.prof.clone(),
types: common_types,
lifetimes: common_lifetimes,
consts: common_consts,
Expand Down
Loading