From cbf22e6b3cf4e05c180b7589b1c80461a8f41413 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 1 Apr 2026 08:34:50 +1100 Subject: [PATCH 1/2] Wrap some overlong comments. --- compiler/rustc_middle/src/ty/context.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 60237c98fed2c..ce2aac2bedf05 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -205,14 +205,15 @@ pub struct CtxtInterners<'tcx> { impl<'tcx> CtxtInterners<'tcx> { fn new(arena: &'tcx WorkerLocal>) -> 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), @@ -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. @@ -381,8 +383,8 @@ pub struct CommonTypes<'tcx> { pub fresh_float_tys: Vec>, /// 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>>, // Pre-interned values of the form: From d06d50c4ba4434b8a27862960dcb3fc5a4bd9df3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 1 Apr 2026 08:41:46 +1100 Subject: [PATCH 2/2] Rename some session variables from `s` to `sess`. Because `sess` is the standard name. --- compiler/rustc_middle/src/ty/context.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index ce2aac2bedf05..aaf20195b36ee 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1016,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( gcx_cell: &'tcx OnceLock>, - s: &'tcx Session, + sess: &'tcx Session, crate_types: Vec, stable_crate_id: StableCrateId, arena: &'tcx WorkerLocal>, @@ -1030,8 +1030,8 @@ impl<'tcx> TyCtxt<'tcx> { jobserver_proxy: Arc, 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); @@ -1039,7 +1039,7 @@ impl<'tcx> TyCtxt<'tcx> { 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, @@ -1047,7 +1047,7 @@ impl<'tcx> TyCtxt<'tcx> { interners, dep_graph, hooks, - prof: s.prof.clone(), + prof: sess.prof.clone(), types: common_types, lifetimes: common_lifetimes, consts: common_consts,