Skip to content

Commit f675e36

Browse files
eddybmark-i-m
authored andcommitted
Update for TyCtxt<'a, 'gcx, 'tcx> -> TyCtxt<'tcx>.
1 parent c15c609 commit f675e36

File tree

9 files changed

+27
-76
lines changed

9 files changed

+27
-76
lines changed

src/appendix/code-index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Item | Kind | Short description | Chapter |
2929
`TraitDef` | struct | This struct contains a trait's definition with type information | [The `ty` modules] | [src/librustc/ty/trait_def.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/trait_def/struct.TraitDef.html)
3030
`TraitRef` | struct | The combination of a trait and its input types (e.g. `P0: Trait<P1...Pn>`) | [Trait Solving: Goals and Clauses], [Trait Solving: Lowering impls] | [src/librustc/ty/sty.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TraitRef.html)
3131
`Ty<'tcx>` | struct | This is the internal representation of a type used for type checking | [Type checking] | [src/librustc/ty/mod.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/type.Ty.html)
32-
`TyCtxt<'cx, 'tcx, 'tcx>` | struct | The "typing context". This is the central data structure in the compiler. It is the context that you use to perform all manner of queries | [The `ty` modules] | [src/librustc/ty/context.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TyCtxt.html)
32+
`TyCtxt<'tcx>` | struct | The "typing context". This is the central data structure in the compiler. It is the context that you use to perform all manner of queries | [The `ty` modules] | [src/librustc/ty/context.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TyCtxt.html)
3333

3434
[The HIR]: ../hir.html
3535
[Identifiers in the HIR]: ../hir.html#hir-id

src/appendix/glossary.md

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ early-bound lifetime | a lifetime region that is substituted at its definiti
2525
empty type | see "uninhabited type".
2626
Fat pointer | a two word value carrying the address of some value, along with some further information necessary to put the value to use. Rust includes two kinds of "fat pointers": references to slices, and trait objects. A reference to a slice carries the starting address of the slice and its length. A trait object carries a value's address and a pointer to the trait's implementation appropriate to that value. "Fat pointers" are also known as "wide pointers", and "double pointers".
2727
free variable | a "free variable" is one that is not bound within an expression or term; see [the background chapter for more](./background.html#free-vs-bound)
28-
'gcx | the lifetime of the global arena ([see more](../ty.html))
2928
generics | the set of generic type parameters defined on a type or item
3029
HIR | the High-level IR, created by lowering and desugaring the AST ([see more](../hir.html))
3130
HirId | identifies a particular node in the HIR by combining a def-id with an "intra-definition offset".

src/compiler-debugging.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ stack backtrace:
4848

4949
If you want line numbers for the stack trace, you can enable `debug = true` in
5050
your config.toml and rebuild the compiler (`debuginfo-level = 1` will also add
51-
line numbers, but `debug = true` gives full debuginfo). Then the backtrace will
51+
line numbers, but `debug = true` gives full debuginfo). Then the backtrace will
5252
look like this:
5353

5454
```text
@@ -129,11 +129,11 @@ note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose
129129
backtrace.
130130
stack backtrace:
131131
(~~~ IRRELEVANT PART OF BACKTRACE REMOVED BY ME ~~~)
132-
7: rustc::traits::error_reporting::<impl rustc::infer::InferCtxt<'a, 'gcx,
133-
'tcx>>::report_selection_error
132+
7: rustc::traits::error_reporting::<impl rustc::infer::InferCtxt<'a, 'tcx>>
133+
::report_selection_error
134134
at /home/user/rust/src/librustc/traits/error_reporting.rs:823
135-
8: rustc::traits::error_reporting::<impl rustc::infer::InferCtxt<'a, 'gcx,
136-
'tcx>>::report_fulfillment_errors
135+
8: rustc::traits::error_reporting::<impl rustc::infer::InferCtxt<'a, 'tcx>>
136+
::report_fulfillment_errors
137137
at /home/user/rust/src/librustc/traits/error_reporting.rs:160
138138
at /home/user/rust/src/librustc/traits/error_reporting.rs:112
139139
9: rustc_typeck::check::FnCtxt::select_obligations_where_possible

src/conventions.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ to the compiler.
141141
- `cx` tends to be short for "context" and is often used as a suffix. For
142142
example, `tcx` is a common name for the [Typing Context][tcx].
143143

144-
- [`'tcx` and `'gcx`][tcx] are used as the lifetime names for the Typing
145-
Context.
144+
- [`'tcx`][tcx] is used as the lifetim names for the Typing Context.
146145

147146
- Because `crate` is a keyword, if you need a variable to represent something
148147
crate-related, often the spelling is changed to `krate`.

src/mir/visitor.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ state you will need while processing MIR:
1515

1616
```rust,ignore
1717
struct MyVisitor<...> {
18-
tcx: TyCtxt<'cx, 'tcx, 'tcx>,
18+
tcx: TyCtxt<'tcx>,
1919
...
2020
}
2121
```

src/profiling/with_perf.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ Tree
272272
: : | rustc_mir::borrow_check::nll::type_check::type_check_internal (13% total, 0% self)
273273
: : : | core::ops::function::FnOnce::call_once (5% total, 0% self)
274274
: : : : | rustc_mir::borrow_check::nll::type_check::liveness::generate (5% total, 3% self)
275-
: : : | <rustc_mir::borrow_check::nll::type_check::TypeVerifier<'a, 'b, 'gcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_mir (3% total, 0% self)
275+
: : : | <rustc_mir::borrow_check::nll::type_check::TypeVerifier<'a, 'b, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_mir (3% total, 0% self)
276276
: | rustc::mir::visit::Visitor::visit_mir (8% total, 6% self)
277-
: | <rustc_mir::borrow_check::MirBorrowckCtxt<'cx, 'gcx, 'tcx> as rustc_mir::dataflow::DataflowResultsConsumer<'cx, 'tcx>>::visit_statement_entry (5% total, 0% self)
277+
: | <rustc_mir::borrow_check::MirBorrowckCtxt<'cx, 'tcx> as rustc_mir::dataflow::DataflowResultsConsumer<'cx, 'tcx>>::visit_statement_entry (5% total, 0% self)
278278
: | rustc_mir::dataflow::do_dataflow (3% total, 0% self)
279279
```
280280

@@ -321,7 +321,7 @@ Tree
321321
| matched `{do_mir_borrowck}` (100% total, 0% self)
322322
: | rustc_mir::borrow_check::nll::compute_regions (47% total, 0% self) [...]
323323
: | rustc::mir::visit::Visitor::visit_mir (19% total, 15% self) [...]
324-
: | <rustc_mir::borrow_check::MirBorrowckCtxt<'cx, 'gcx, 'tcx> as rustc_mir::dataflow::DataflowResultsConsumer<'cx, 'tcx>>::visit_statement_entry (13% total, 0% self) [...]
324+
: | <rustc_mir::borrow_check::MirBorrowckCtxt<'cx, 'tcx> as rustc_mir::dataflow::DataflowResultsConsumer<'cx, 'tcx>>::visit_statement_entry (13% total, 0% self) [...]
325325
: | rustc_mir::dataflow::do_dataflow (8% total, 1% self) [...]
326326
```
327327

src/query.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,15 @@ on how that works).
8282
Providers always have the same signature:
8383

8484
```rust,ignore
85-
fn provider<'cx, 'tcx>(tcx: TyCtxt<'cx, 'tcx, 'tcx>,
86-
key: QUERY_KEY)
87-
-> QUERY_RESULT
88-
{
85+
fn provider<'tcx>(
86+
tcx: TyCtxt<'tcx>,
87+
key: QUERY_KEY,
88+
) -> QUERY_RESULT {
8989
...
9090
}
9191
```
9292

93-
Providers take two arguments: the `tcx` and the query key. Note also
94-
that they take the *global* tcx (i.e. they use the `'tcx` lifetime
95-
twice), rather than taking a tcx with some active inference context.
93+
Providers take two arguments: the `tcx` and the query key.
9694
They return the result of the query.
9795

9896
#### How providers are setup
@@ -103,7 +101,7 @@ is basically a big list of function pointers:
103101

104102
```rust,ignore
105103
struct Providers {
106-
type_of: for<'cx, 'tcx> fn(TyCtxt<'cx, 'tcx, 'tcx>, DefId) -> Ty<'tcx>,
104+
type_of: for<'tcx> fn(TyCtxt<'tcx>, DefId) -> Ty<'tcx>,
107105
...
108106
}
109107
```
@@ -144,7 +142,7 @@ pub fn provide(providers: &mut Providers) {
144142
};
145143
}
146144
147-
fn fubar<'cx, 'tcx>(tcx: TyCtxt<'cx, 'tcx>, key: DefId) -> Fubar<'tcx> { ... }
145+
fn fubar<'tcx>(tcx: TyCtxt<'tcx>, key: DefId) -> Fubar<'tcx> { ... }
148146
```
149147

150148
N.B. Most of the `rustc_*` crates only provide **local

src/ty.md

+7-51
Original file line numberDiff line numberDiff line change
@@ -11,63 +11,19 @@ compiler. It is the context that you use to perform all manner of
1111
queries. The struct `TyCtxt` defines a reference to this shared context:
1212

1313
```rust,ignore
14-
tcx: TyCtxt<'a, 'gcx, 'tcx>
15-
// -- ---- ----
16-
// | | |
17-
// | | innermost arena lifetime (if any)
18-
// | "global arena" lifetime
19-
// lifetime of this reference
14+
tcx: TyCtxt<'tcx>
15+
// ----
16+
// |
17+
// arena lifetime
2018
```
2119

22-
As you can see, the `TyCtxt` type takes three lifetime parameters.
23-
These lifetimes are perhaps the most complex thing to understand about
24-
the tcx. During Rust compilation, we allocate most of our memory in
20+
As you can see, the `TyCtxt` type takes a lifetime parameter.
21+
During Rust compilation, we allocate most of our memory in
2522
**arenas**, which are basically pools of memory that get freed all at
26-
once. When you see a reference with a lifetime like `'tcx` or `'gcx`,
23+
once. When you see a reference with a lifetime like `'tcx`,
2724
you know that it refers to arena-allocated data (or data that lives as
2825
long as the arenas, anyhow).
2926

30-
We use two distinct levels of arenas. The outer level is the "global
31-
arena". This arena lasts for the entire compilation: so anything you
32-
allocate in there is only freed once compilation is basically over
33-
(actually, when we shift to executing LLVM).
34-
35-
To reduce peak memory usage, when we do type inference, we also use an
36-
inner level of arena. These arenas get thrown away once type inference
37-
is over. This is done because type inference generates a lot of
38-
"throw-away" types that are not particularly interesting after type
39-
inference completes, so keeping around those allocations would be
40-
wasteful.
41-
42-
Often, we wish to write code that explicitly asserts that it is not
43-
taking place during inference. In that case, there is no "local"
44-
arena, and all the types that you can access are allocated in the
45-
global arena. To express this, the idea is to use the same lifetime
46-
for the `'gcx` and `'tcx` parameters of `TyCtxt`. Just to be a touch
47-
confusing, we tend to use the name `'tcx` in such contexts. Here is an
48-
example:
49-
50-
```rust,ignore
51-
fn not_in_inference<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
52-
// ---- ----
53-
// Using the same lifetime here asserts
54-
// that the innermost arena accessible through
55-
// this reference *is* the global arena.
56-
}
57-
```
58-
59-
In contrast, if we want to code that can be usable during type inference, then
60-
you need to declare a distinct `'gcx` and `'tcx` lifetime parameter:
61-
62-
```rust,ignore
63-
fn maybe_in_inference<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) {
64-
// ---- ----
65-
// Using different lifetimes here means that
66-
// the innermost arena *may* be distinct
67-
// from the global arena (but doesn't have to be).
68-
}
69-
```
70-
7127
### Allocating and working with types
7228

7329
Rust types are represented using the `Ty<'tcx>` defined in the `ty`

src/type-inference.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ function and disposed of after it returns.
5050

5151
[ty-ch]: ty.html
5252

53-
Within the closure, `infcx` has the type `InferCtxt<'cx, 'gcx, 'tcx>`
54-
for some fresh `'cx` and `'tcx` – the latter corresponds to the lifetime of
55-
this temporary arena, and the `'cx` is the lifetime of the `InferCtxt` itself.
53+
Within the closure, `infcx` has the type `InferCtxt<'cx, 'tcx>` for some
54+
fresh `'cx`, while `'tcx` is the same as outside the inference context.
5655
(Again, see the [`ty` chapter][ty-ch] for more details on this setup.)
5756

5857
The `tcx.infer_ctxt` method actually returns a builder, which means

0 commit comments

Comments
 (0)