Skip to content

Commit

Permalink
minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
Noratrieb committed Sep 24, 2024
1 parent 226a2d4 commit 3eb02eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/rustc-driver/getting-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ otherwise be printed to stderr.

To get diagnostics from the compiler,
configure [`rustc_interface::Config`] to output diagnostic to a buffer,
and run [`TyCtxt.analysis`]. The following was tested
with <!-- date-check: jan 2024 --> `nightly-2024-01-19`:
and run [`TyCtxt.analysis`].
The following was tested with <!-- date-check: jan 2024 --> `nightly-2024-01-19`:

```rust
{{#include ../examples/rustc-driver-getting-diagnostics.rs}}
```

[`rustc_interface`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/index.html
[`rustc_interface::Config`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/struct.Config.html
[`TyCtxt.analysis`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/passes/fn.analysis.html
[`TyCtxt.analysis`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/passes/fn.analysis.html
33 changes: 16 additions & 17 deletions src/rustc-driver/intro.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `rustc_driver` and `rustc_interface`

The [`rustc_driver`] is essentially `rustc`'s `main` function. It acts as
the glue for running the various phases of the compiler in the correct order,
The [`rustc_driver`] is essentially `rustc`'s `main` function.
It acts as the glue for running the various phases of the compiler in the correct order,
using the interface defined in the [`rustc_interface`] crate.

Generally the [`rustc_interface`] crate provides external users with an (unstable) API
Expand All @@ -11,26 +11,25 @@ analyzing a crate or for ad hoc emulating of the compiler (i.e. `rustdoc`
compiling code and serving output).

More specifically the [`rustc_interface::run_compiler`][i_rc] function is the
main entrypoint for using [`nightly-rustc`] as a library. Initially
[`run_compiler`][i_rc] takes a configuration variable for the compiler and a
`closure` taking a yet unresolved [`Compiler`]. Operationally
[`run_compiler`][i_rc] creates a `Compiler` from the configuration and passes
main entrypoint for using [`nightly-rustc`] as a library.
Initially [`run_compiler`][i_rc] takes a configuration variable for the compiler
and a `closure` taking a yet unresolved [`Compiler`].
Operationally [`run_compiler`][i_rc] creates a `Compiler` from the configuration and passes
it to the `closure`. Inside the `closure` you can use the `Compiler` to drive
queries to compile a crate and get the results. Providing results about the
internal state of the compiler what the [`rustc_driver`] does too. You can see
a minimal example of how to use [`rustc_interface`] [here][example].
queries to compile a crate and get the results.
Providing results about the internal state of the compiler what the [`rustc_driver`] does too.
You can see a minimal example of how to use [`rustc_interface`] [here][example].

You can see what queries are currently available in the [`Compiler`] rustdocs.
You can see an example of how to use the queries by looking at the
`rustc_driver` implementation, specifically
[`rustc_driver::run_compiler`][rd_rc] (not to be confused with
[`rustc_interface::run_compiler`][i_rc]). Generally
[`rustc_driver::run_compiler`][i_rc] takes a bunch of command-line args and
some other configurations and drives the compilation to completion.
You can see an example of how to use the queries by looking at the `rustc_driver` implementation,
specifically [`rustc_driver::run_compiler`][rd_rc]
(not to be confused with [`rustc_interface::run_compiler`][i_rc]).
Generally [`rustc_driver::run_compiler`][i_rc] takes a bunch of command-line args
and some other configurations and drives the compilation to completion.

Finally [`rustc_driver::run_compiler`][rd_rc] also takes a [`Callbacks`][cb],
which is a `trait` that allows for custom compiler configuration, as well as
allowing custom code to run after different phases of the compilation.
which is a `trait` that allows for custom compiler configuration,
as well as allowing custom code to run after different phases of the compilation.

> **Warning:** By its very nature, the internal compiler APIs are always going
> to be unstable. That said, we do try not to break things unnecessarily.
Expand Down

0 comments on commit 3eb02eb

Please sign in to comment.