Skip to content

Commit c625880

Browse files
committed
Improve comments on TyCtxt and GlobalCtxt.
1 parent 789dd0b commit c625880

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

compiler/rustc_middle/src/ty/context.rs

+12
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,17 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
478478
/// [rustc dev guide] for more details.
479479
///
480480
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/ty.html
481+
///
482+
/// An implementation detail: `TyCtxt` is a wrapper type for [GlobalCtxt],
483+
/// which is the struct that actually holds all the data. `TyCtxt` derefs to
484+
/// `GlobalCtxt`, and in practice `TyCtxt` is passed around everywhere, and all
485+
/// operations are done via `TyCtxt`. A `TyCtxt` is obtained for a `GlobalCtxt`
486+
/// by calling `enter` with a closure `f`. That function creates both the
487+
/// `TyCtxt`, and an `ImplicitCtxt` around it that is put into TLS. Within `f`:
488+
/// - The `ImplicitCtxt` is available implicitly via TLS.
489+
/// - The `TyCtxt` is available explicitly via the `tcx` parameter, and also
490+
/// implicitly within the `ImplicitCtxt`. Explicit access is preferred when
491+
/// possible.
481492
#[derive(Copy, Clone)]
482493
#[rustc_diagnostic_item = "TyCtxt"]
483494
#[rustc_pass_by_value]
@@ -493,6 +504,7 @@ impl<'tcx> Deref for TyCtxt<'tcx> {
493504
}
494505
}
495506

507+
/// See [TyCtxt] for details about this type.
496508
pub struct GlobalCtxt<'tcx> {
497509
pub arena: &'tcx WorkerLocal<Arena<'tcx>>,
498510
pub hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,

0 commit comments

Comments
 (0)