diff --git a/README.md b/README.md index cb0092c9..6292a527 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,14 @@ [![docs](https://img.shields.io/badge/docs-built-blue)][docs] -`rustc_plugin` is a framework for writing programs that use the Rust compiler API. We wrote `rustc_plugin` to support our research on experimental Rust tools like [Flowistry] and [Aquascope]. `rustc_plugin` is a kind of generalized version of the infrastructure in [Clippy]. +`rustc_plugin` is a framework for writing programs that use the Rust compiler API. We wrote `rustc_plugin` to support our research on experimental Rust tools like [Flowistry], [Aquascope], [Paralegal], and [Argus]. `rustc_plugin` provides a kind of generalized version of the Cargo integration infrastructure in [Clippy], along with a miscellany of utilities in the `rustc_utils` crate. ## Installation The Rust compiler's interface is not stable, so the only sensible way to develop a Rust compiler plugin is by pinning to a specific nightly. Each version of `rustc_plugin` is pinned to one nightly, and you *have* to use the same nightly version that we do. Therefore each release of `rustc_plugin` has a semantic version number (e.g. `0.1.0`) and the nightly version is added as a prerelease label (e.g. `-nightly-2023-08-25`). You can add a dependency to your `Cargo.toml` like this: ```toml -rustc_plugin = "=0.11.0-nightly-2024-12-01" +rustc_plugin = "=0.12.0-nightly-2024-12-15" ``` We will treat a change to the nightly version as a breaking change, so the semantic version will be correspondingly updated as a breaking update. @@ -44,6 +44,7 @@ The `rustc_plugin` framework is responsible for marshalling arguments from the t Normally, Rust libraries have a [minimum supported Rust version][msrv] because they promise to not use any breaking features implemented after that version. Rust compiler plugins are the opposite — they have a **maximum** supported Rust version (MaxSRV). A compiler plugin cannot analyze programs that use features implemented after the release date of the plugin's toolchain. The MaxSRV for every version of `rustc_plugin` is listed below: +* v0.12 (`nightly-2024-12-15`) - rustc 1.84 * v0.11 (`nightly-2024-12-01`) - rustc 1.84 * v0.10 (`nightly-2024-05-20`) - rustc 1.79 * v0.9 (`nightly-2024-01-24`) - rustc 1.76 @@ -54,9 +55,10 @@ Normally, Rust libraries have a [minimum supported Rust version][msrv] because t [Flowistry]: https://github.com/willcrichton/flowistry/ [Aquascope]: https://github.com/cognitive-engineering-lab/aquascope +[Paralegal]: https://github.com/brownsys/paralegal +[Argus]: https://github.com/cognitive-engineering-lab/argus [Clippy]: https://github.com/rust-lang/rust-clippy [example]: https://github.com/cognitive-engineering-lab/rustc_plugin/tree/main/crates/rustc_plugin/examples/print-all-items [docs]: https://cognitive-engineering-lab.github.io/rustc_plugin/v0.11.0-nightly-2024-12-01/rustc_plugin/ [docs-utils]: https://cognitive-engineering-lab.github.io/rustc_plugin/v0.11.0-nightly-2024-12-01/rustc_utils/ [msrv]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field - diff --git a/crates/rustc_plugin/examples/print-all-items/rust-toolchain.toml b/crates/rustc_plugin/examples/print-all-items/rust-toolchain.toml index 3d17d42e..2451c2f1 100644 --- a/crates/rustc_plugin/examples/print-all-items/rust-toolchain.toml +++ b/crates/rustc_plugin/examples/print-all-items/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-01-24" +channel = "nightly-2024-12-15" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/crates/rustc_plugin/examples/print-all-items/src/lib.rs b/crates/rustc_plugin/examples/print-all-items/src/lib.rs index 882d1e48..7022fb7e 100644 --- a/crates/rustc_plugin/examples/print-all-items/src/lib.rs +++ b/crates/rustc_plugin/examples/print-all-items/src/lib.rs @@ -63,7 +63,8 @@ impl RustcPlugin for PrintAllItemsPlugin { ) -> rustc_interface::interface::Result<()> { let mut callbacks = PrintAllItemsCallbacks { args: plugin_args }; let compiler = rustc_driver::RunCompiler::new(&compiler_args, &mut callbacks); - compiler.run() + compiler.run(); + Ok(()) } } @@ -75,10 +76,10 @@ impl rustc_driver::Callbacks for PrintAllItemsCallbacks { // At the top-level, the Rustc API uses an event-based interface for // accessing the compiler at different stages of compilation. In this callback, // all the type-checking has completed. - fn after_analysis<'tcx>( + fn after_analysis( &mut self, _compiler: &rustc_interface::interface::Compiler, - tcx: TyCtxt<'tcx>, + tcx: TyCtxt<'_>, ) -> rustc_driver::Compilation { // We call our top-level function with access to the type context `tcx` and the CLI arguments. print_all_items(tcx, &self.args); diff --git a/crates/rustc_plugin/src/driver.rs b/crates/rustc_plugin/src/driver.rs index e9ff3dbb..4c93beb4 100644 --- a/crates/rustc_plugin/src/driver.rs +++ b/crates/rustc_plugin/src/driver.rs @@ -161,7 +161,8 @@ run_on_all_crates={run_on_all_crates}, \ primary_package={primary_package}, \ is_target_crate={is_target_crate}" ); - rustc_driver::RunCompiler::new(&args, &mut DefaultCallbacks).run() + rustc_driver::RunCompiler::new(&args, &mut DefaultCallbacks).run(); + Ok(()) } })) } diff --git a/crates/rustc_utils/src/hir/ty.rs b/crates/rustc_utils/src/hir/ty.rs index ab58a810..0c3045e4 100644 --- a/crates/rustc_utils/src/hir/ty.rs +++ b/crates/rustc_utils/src/hir/ty.rs @@ -51,7 +51,7 @@ impl<'tcx> TyExt<'tcx> for Ty<'tcx> { fn is_copyable(self, tcx: TyCtxt<'tcx>, typing_env: TypingEnv<'tcx>) -> bool { let ty = tcx.erase_regions(self); - ty.is_copy_modulo_regions(tcx, typing_env) + tcx.type_is_copy_modulo_regions(typing_env, ty) } } diff --git a/crates/rustc_utils/src/mir/control_dependencies.rs b/crates/rustc_utils/src/mir/control_dependencies.rs index 7167a4be..0587d147 100644 --- a/crates/rustc_utils/src/mir/control_dependencies.rs +++ b/crates/rustc_utils/src/mir/control_dependencies.rs @@ -13,7 +13,7 @@ use rustc_data_structures::graph::{ DirectedGraph, Predecessors, StartNode, Successors, }; use rustc_index::{ - bit_set::{BitSet, ChunkedBitSet, SparseBitMatrix}, + bit_set::{BitSet, SparseBitMatrix}, Idx, }; use smallvec::SmallVec; @@ -194,7 +194,7 @@ impl ControlDependencies { } /// Returns the set of all node that are control-dependent on the given `node`. - pub fn dependent_on(&self, node: Node) -> Option<&ChunkedBitSet> { + pub fn dependent_on(&self, node: Node) -> Option<&BitSet> { self.0.row(node) } } diff --git a/crates/rustc_utils/src/test_utils.rs b/crates/rustc_utils/src/test_utils.rs index ebadc0e3..86518cfc 100644 --- a/crates/rustc_utils/src/test_utils.rs +++ b/crates/rustc_utils/src/test_utils.rs @@ -118,9 +118,8 @@ impl CompileBuilder { rustc_driver::catch_fatal_errors(|| { let mut compiler = rustc_driver::RunCompiler::new(&args, &mut callbacks); compiler.set_file_loader(Some(Box::new(StringLoader(self.input.clone())))); - compiler.run() + compiler.run(); }) - .unwrap() .unwrap(); } } @@ -193,15 +192,13 @@ where config.override_queries = Some(borrowck_facts::override_queries); } - fn after_expansion<'tcx>( + fn after_analysis( &mut self, _compiler: &rustc_interface::interface::Compiler, - queries: &'tcx rustc_interface::Queries<'tcx>, + tcx: TyCtxt<'_>, ) -> rustc_driver::Compilation { - queries.global_ctxt().unwrap().enter(|tcx| { - let callback = self.callback.take().unwrap(); - callback(tcx); - }); + let callback = self.callback.take().unwrap(); + callback(tcx); rustc_driver::Compilation::Stop } } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 1d3f18d3..64878662 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-12-01" +channel = "nightly-2024-12-15" components = ["clippy", "rust-src", "rustc-dev", "llvm-tools-preview"]