Skip to content

Fix heading levels in the query chapter #1305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2022
Merged
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
14 changes: 7 additions & 7 deletions src/query.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ compiler (for example, generating [MIR](./mir/)) currently work exactly like thi
in-depth description of what queries are and how they work.
If you intend to write a query of your own, this is a good read.

### Invoking queries
## Invoking queries

Invoking a query is simple. The [`TyCtxt`] ("type context") struct offers a method
for each defined query. For example, to invoke the `type_of`
Expand All @@ -55,7 +55,7 @@ let ty = tcx.type_of(some_def_id);

[`TyTcx`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html

### How the compiler executes a query
## How the compiler executes a query

So you may be wondering what happens when you invoke a query
method. The answer is that, for each query, the compiler maintains a
Expand All @@ -64,7 +64,7 @@ simple: we clone the return value out of the cache and return it
(therefore, you should try to ensure that the return types of queries
are cheaply cloneable; insert an `Rc` if necessary).

#### Providers
### Providers

If, however, the query is *not* in the cache, then the compiler will
try to find a suitable **provider**. A provider is a function that has
Expand Down Expand Up @@ -97,7 +97,7 @@ fn provider<'tcx>(
Providers take two arguments: the `tcx` and the query key.
They return the result of the query.

#### How providers are setup
### How providers are setup

When the tcx is created, it is given the providers by its creator using
the [`Providers`][providers_struct] struct. This struct is generated by
Expand Down Expand Up @@ -164,7 +164,7 @@ they define both a `provide` and a `provide_extern` function, through
[rustc_metadata]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_metadata/index.html
[wasm_import_module_map]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/back/symbol_export/fn.wasm_import_module_map.html

### Adding a new query
## Adding a new query

How do you add a new query?
Defining a query takes place in two steps:
Expand Down Expand Up @@ -238,7 +238,7 @@ which is used to cheaply modify MIR in place. See the definition
of `Steal` for more details. New uses of `Steal` should **not** be
added without alerting `@rust-lang/compiler`.

#### Query structs and descriptions
### Query structs and descriptions

For each query, the `rustc_queries` macro will generate a "query struct"
named after the query. This struct is a kind of placeholder
Expand Down Expand Up @@ -294,7 +294,7 @@ rustc_queries! {

`rustc_queries` macro will generate an appropriate `impl` automatically.

## External Links
## External links

Related design ideas, and tracking issues:

Expand Down