@@ -4,42 +4,47 @@ The [`rustc_driver`] is essentially `rustc`'s `main()` function. It acts as
4
4
the glue for running the various phases of the compiler in the correct order,
5
5
using the interface defined in the [ ` rustc_interface ` ] crate.
6
6
7
- The ` rustc_interface ` crate provides external users with an (unstable) API
7
+ Generally the [ ` rustc_interface ` ] crate provides external users with an (unstable) API
8
8
for running code at particular times during the compilation process, allowing
9
9
third parties to effectively use ` rustc ` 's internals as a library for
10
- analyzing a crate or emulating the compiler in-process (e.g. rustdoc).
11
-
12
- For those using ` rustc ` as a library, the [ ` rustc_interface::run_compiler() ` ] [ i_rc ]
13
- function is the main entrypoint to the compiler. It takes a configuration for the compiler
14
- and a closure that takes a [ ` Compiler ` ] . ` run_compiler ` creates a ` Compiler ` from the
15
- configuration and passes it to the closure. Inside the closure, you can use the ` Compiler `
16
- to drive queries to compile a crate and get the results. This is what the ` rustc_driver ` does too.
17
- You can see a minimal example of how to use ` rustc_interface ` [ here] [ example ] .
18
-
19
- You can see what queries are currently available through the rustdocs for [ ` Compiler ` ] .
20
- You can see an example of how to use them by looking at the ` rustc_driver ` implementation,
21
- specifically the [ ` rustc_driver::run_compiler ` function] [ rd_rc ] (not to be confused with
22
- [ ` rustc_interface::run_compiler ` ] [ i_rc ] ). The ` rustc_driver::run_compiler ` function
10
+ analyzing a crate or for ad hoc emulating of the compiler (i.e. ` rustdoc `
11
+ compiling code and serving output).
12
+
13
+ More specifically the [ ` rustc_interface::run_compiler() ` ] [ i_rc ] function is the
14
+ main entrypoint for using [ ` nightly-rustc ` ] as a library. Initially
15
+ [ ` run_compiler() ` ] [ i_rc ] takes a configuration variable for the compiler and a
16
+ ` closure ` taking a yet unresolved [ ` Compiler ` ] . Operationally
17
+ [ ` run_compiler() ` ] [ i_rc ] creates a ` Compiler ` from the configuration and passes
18
+ it to the ` closure ` . Inside the ` closure ` you can use the ` Compiler ` to drive
19
+ queries to compile a crate and get the results. Providing results about the
20
+ internal state of the compiler what the [ ` rustc_driver ` ] does too. You can see
21
+ a minimal example of how to use [ ` rustc_interface ` ] [ here] [ example ] .
22
+
23
+ You can see what queries are currently available in the [ ` Compiler ` ] rustdoc.
24
+ You can see an example of how to use the queries by looking at the ` rustc_driver ` implementation,
25
+ specifically [ ` rustc_driver::run_compiler() ` ] [ rd_rc ] (not to be confused with
26
+ [ ` rustc_interface::run_compiler() ` ] [ i_rc ] ). Generally [ ` rustc_driver::run_compiler() ` ] [ i_rc ]
23
27
takes a bunch of command-line args and some other configurations and
24
28
drives the compilation to completion.
25
29
26
- ` rustc_driver::run_compiler ` also takes a [ ` Callbacks ` ] [ cb ] ,
27
- a trait that allows for custom compiler configuration,
28
- as well as allowing some custom code run after different phases of the compilation.
30
+ Finally [ ` rustc_driver::run_compiler() ` ] [ rd_rc ] also takes a [ ` Callbacks ` ] [ cb ] ,
31
+ which is a ` trait ` that allows for custom compiler configuration, as well as
32
+ allowing some custom code run after different phases of the compilation.
29
33
30
34
> ** Warning:** By its very nature, the internal compiler APIs are always going
31
35
> to be unstable. That said, we do try not to break things unnecessarily.
32
36
33
37
34
- [ cb ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/trait.Callbacks.html
35
- [ rd_rc ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver_impl/fn.run_compiler.html
36
- [ i_rc ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/fn.run_compiler.html
37
- [ example ] : https://github.com/rust-lang/rustc-dev-guide/blob/master/examples/rustc-driver-example.rs
38
- [ `rustc_interface` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/index.html
39
- [ `rustc_driver` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/
40
38
[ `Compiler` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/struct.Compiler.html
39
+ [ `rustc_driver` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/
40
+ [ `rustc_interface` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/index.html
41
41
[ `Session` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/struct.Session.html
42
- [ `TyCtxt` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html
43
42
[ `SourceMap` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/source_map/struct.SourceMap.html
44
- [ stupid-stats ] : https://github.com/nrc/stupid-stats
43
+ [ `TyCtxt` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html
45
44
[ Appendix A ] : appendix/stupid-stats.html
45
+ [ cb ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/trait.Callbacks.html
46
+ [ example ] : https://github.com/rust-lang/rustc-dev-guide/blob/master/examples/rustc-driver-example.rs
47
+ [ i_rc ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/fn.run_compiler.html
48
+ [ rd_rc ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver_impl/fn.run_compiler.html
49
+ [ stupid-stats ] : https://github.com/nrc/stupid-stats
50
+ [ `nightly-rustc` ] : https://doc.rust-lang.org/nightly/nightly-rustc/
0 commit comments