diff --git a/README.md b/README.md index 5a9aaa27d..e0026ce0f 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ ## 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.12.0-nightly-2024-12-15" +rustc_plugin = "=0.13.0-nightly-2025-02-04" ``` 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. @@ -28,7 +28,7 @@ We will treat a change to the nightly version as a breaking change, so the seman * [`Cargo.toml`](https://github.com/cognitive-engineering-lab/rustc_plugin/blob/main/crates/rustc_plugin/examples/print-all-items/Cargo.toml): normal Cargo manifest. Make sure to specify `rustc_private = true` to get Rust Analyzer support for the rustc API. * [`src/`](https://github.com/cognitive-engineering-lab/rustc_plugin/tree/main/crates/rustc_plugin/examples/print-all-items/src) * [`bin/`](https://github.com/cognitive-engineering-lab/rustc_plugin/tree/main/crates/rustc_plugin/examples/print-all-items/src/bin) - * [`cargo-print-all-items.rs`](https://github.com/cognitive-engineering-lab/rustc_plugin/blob/main/crates/rustc_plugin/examples/print-all-items/src/bin/cargo-print-all-items.rs): the CLI binary run directly by the user, e.g. by invoking `cargo print-all-items`. + * [`cargo-print-all-items.rs`](https://github.com/cognitive-engineering-lab/rustc_plugin/blob/main/crates/rustc_plugin/examples/print-all-items/src/bin/cargo-print-all-items.rs): the CLI binary run directly by the user, e.g. by invoking `cargo print-all-items`. * [`print-all-items-driver.rs`](https://github.com/cognitive-engineering-lab/rustc_plugin/blob/main/crates/rustc_plugin/examples/print-all-items/src/bin/print-all-items-driver.rs): the implementation binary used by the CLI. * [`lib.rs`](https://github.com/cognitive-engineering-lab/rustc_plugin/blob/main/crates/rustc_plugin/examples/print-all-items/src/lib.rs): Your plugin implementation, which exports a data structure that implements the `RustcPlugin` trait. @@ -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.13 (`nightly-2025-02-04`) - rustc 1.86 * 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 @@ -59,6 +60,6 @@ Normally, Rust libraries have a [minimum supported Rust version][msrv] because t [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.12.0-nightly-2024-12-15/rustc_plugin/ -[docs-utils]: https://cognitive-engineering-lab.github.io/rustc_plugin/v0.12.0-nightly-2024-12-15/rustc_utils/ +[docs]: https://cognitive-engineering-lab.github.io/rustc_plugin/v0.13.0-nightly-2025-02-04/rustc_plugin/ +[docs-utils]: https://cognitive-engineering-lab.github.io/rustc_plugin/v0.13.0-nightly-2025-02-04/rustc_utils/ [msrv]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field diff --git a/crates/rustc_plugin/Cargo.toml b/crates/rustc_plugin/Cargo.toml index 39d4bffde..bdc1c2ab1 100644 --- a/crates/rustc_plugin/Cargo.toml +++ b/crates/rustc_plugin/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustc_plugin" -version = "0.12.0-nightly-2024-12-15" +version = "0.13.0-nightly-2025-02-04" edition = "2021" authors = ["Will Crichton "] description = "A framework for writing plugins that integrate with the Rust compiler" @@ -18,7 +18,8 @@ serde = "1" serde_json = "1" [dev-dependencies] -anyhow = {version = "1", features = ["backtrace"]} +anyhow = { version = "1", features = ["backtrace"] } +serial_test = "3.2" [build-dependencies] toml = "0.7" 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 2451c2f1d..43be4bb49 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-12-15" +channel = "nightly-2025-02-04" 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 7022fb7e8..0a6a7f28a 100644 --- a/crates/rustc_plugin/examples/print-all-items/src/lib.rs +++ b/crates/rustc_plugin/examples/print-all-items/src/lib.rs @@ -62,8 +62,7 @@ impl RustcPlugin for PrintAllItemsPlugin { plugin_args: Self::Args, ) -> rustc_interface::interface::Result<()> { let mut callbacks = PrintAllItemsCallbacks { args: plugin_args }; - let compiler = rustc_driver::RunCompiler::new(&compiler_args, &mut callbacks); - compiler.run(); + rustc_driver::run_compiler(&compiler_args, &mut callbacks); Ok(()) } } diff --git a/crates/rustc_plugin/src/driver.rs b/crates/rustc_plugin/src/driver.rs index 4c93beb4c..c3137de80 100644 --- a/crates/rustc_plugin/src/driver.rs +++ b/crates/rustc_plugin/src/driver.rs @@ -152,7 +152,7 @@ pub fn driver_main(plugin: T) { log::debug!("Running plugin..."); let plugin_args: T::Args = serde_json::from_str(&env::var(PLUGIN_ARGS).unwrap()).unwrap(); - plugin.run(args, plugin_args) + plugin.run(args, plugin_args).expect("plugin failure"); } else { log::debug!( "Running normal Rust. Relevant variables:\ @@ -161,8 +161,7 @@ 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(); - Ok(()) + rustc_driver::run_compiler(&args, &mut DefaultCallbacks); } })) } diff --git a/crates/rustc_plugin/tests/test_example.rs b/crates/rustc_plugin/tests/test_example.rs index a069e68d5..2b51ff6b5 100644 --- a/crates/rustc_plugin/tests/test_example.rs +++ b/crates/rustc_plugin/tests/test_example.rs @@ -1,6 +1,7 @@ use std::{env, fs, path::Path, process::Command, sync::Once}; use anyhow::{ensure, Context, Result}; +use serial_test::serial; static SETUP: Once = Once::new(); @@ -57,6 +58,7 @@ fn run(dir: &str, f: impl FnOnce(&mut Command)) -> Result { // TODO: why do these tests need to be run sequentially? #[test] +#[serial] fn basic() -> Result<()> { let output = run("workspaces/basic", |_cmd| {})?; assert!(output.contains(r#"There is an item "add" of type "function""#)); @@ -64,6 +66,7 @@ fn basic() -> Result<()> { } #[test] +#[serial] fn arg() -> Result<()> { let output = run("workspaces/basic", |cmd| { cmd.arg("-a"); @@ -73,6 +76,7 @@ fn arg() -> Result<()> { } #[test] +#[serial] fn feature() -> Result<()> { let output = run("workspaces/basic", |cmd| { cmd.args(["--", "--features", "sub"]); @@ -85,6 +89,7 @@ fn feature() -> Result<()> { } #[test] +#[serial] fn multi() -> Result<()> { run("workspaces/multi", |_cmd| {})?; Ok(()) diff --git a/crates/rustc_utils/Cargo.toml b/crates/rustc_utils/Cargo.toml index cd71402e8..0f3f5d1c7 100644 --- a/crates/rustc_utils/Cargo.toml +++ b/crates/rustc_utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustc_utils" -version = "0.12.0-nightly-2024-12-15" +version = "0.13.0-nightly-2025-02-04" edition = "2021" authors = ["Will Crichton "] description = "Utilities for working with the Rust compiler" @@ -23,13 +23,15 @@ anyhow = "1" log = "0.4" intervaltree = "0.2" cfg-if = "1" -serde = {version = "1", features = ["derive"], optional = true} -textwrap = {version = "0.16", optional = true} -regex = {version = "1", optional = true} -ts-rs = {version = "7", optional = true} -indexical = {version = "0.3.1", default-features = false, features = ["rustc"], optional = true} +serde = { version = "1", features = ["derive"], optional = true } +textwrap = { version = "0.16", optional = true } +regex = { version = "1", optional = true } +ts-rs = { version = "7", optional = true } +indexical = { version = "0.3.1", default-features = false, features = [ + "rustc", +], optional = true } [dev-dependencies] -rustc_utils = {path = ".", features = ["test"]} +rustc_utils = { path = ".", features = ["test"] } test-log = "0.2" -env_logger = {version = "0.9", default-features = false} +env_logger = { version = "0.9", default-features = false } diff --git a/crates/rustc_utils/src/mir/control_dependencies.rs b/crates/rustc_utils/src/mir/control_dependencies.rs index 0587d1473..e4c537a62 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, SparseBitMatrix}, + bit_set::{DenseBitSet, SparseBitMatrix}, Idx, }; use smallvec::SmallVec; @@ -21,7 +21,7 @@ use smallvec::SmallVec; struct ReversedGraph<'a, G: ControlFlowGraph> { graph: &'a G, exit: G::Node, - unreachable: BitSet, + unreachable: DenseBitSet, } impl DirectedGraph for ReversedGraph<'_, G> { @@ -76,7 +76,7 @@ impl PostDominators { let mut reversed = ReversedGraph { graph, exit, - unreachable: BitSet::new_empty(num_nodes), + unreachable: DenseBitSet::new_empty(num_nodes), }; let reachable = iterate::post_order_from(&reversed, exit); @@ -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<&BitSet> { + pub fn dependent_on(&self, node: Node) -> Option<&DenseBitSet> { self.0.row(node) } } diff --git a/crates/rustc_utils/src/test_utils.rs b/crates/rustc_utils/src/test_utils.rs index 86518cfcf..7d51bc572 100644 --- a/crates/rustc_utils/src/test_utils.rs +++ b/crates/rustc_utils/src/test_utils.rs @@ -95,6 +95,7 @@ impl CompileBuilder { pub fn compile(&self, f: impl for<'tcx> FnOnce(CompileResult<'tcx>) + Send) { let mut callbacks = TestCallbacks { callback: Some(move |tcx: TyCtxt<'_>| f(CompileResult { tcx })), + file_loader: Some(StringLoader(self.input.clone())), }; let args = [ "rustc", @@ -116,9 +117,7 @@ impl CompileBuilder { .collect::>(); 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(); + rustc_driver::run_compiler(&args, &mut callbacks); }) .unwrap(); } @@ -152,7 +151,7 @@ impl<'tcx> CompileResult<'tcx> { let body_id = hir .items() .find_map(|id| match hir.item(id).kind { - ItemKind::Fn(_, _, body) => Some(body), + ItemKind::Fn { body, .. } => Some(body), _ => None, }) .unwrap(); @@ -180,16 +179,22 @@ impl<'tcx> CompileResult<'tcx> { } } -struct TestCallbacks { +struct TestCallbacks { callback: Option, + file_loader: Option, } -impl rustc_driver::Callbacks for TestCallbacks +impl rustc_driver::Callbacks for TestCallbacks where Cb: FnOnce(TyCtxt<'_>), + Fl: FileLoader + Send + Sync + 'static, { fn config(&mut self, config: &mut rustc_interface::Config) { config.override_queries = Some(borrowck_facts::override_queries); + config.file_loader = self + .file_loader + .take() + .map(|fl| Box::new(fl) as Box<(dyn FileLoader + Send + Sync)>); } fn after_analysis( diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 64878662b..4652898ad 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-12-15" +channel = "nightly-2025-02-04" components = ["clippy", "rust-src", "rustc-dev", "llvm-tools-preview"]