diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 48bce9eb191d..ca9e9719add4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -69,7 +69,7 @@ jobs: run: echo "::add-matcher::.github/rust.json" - name: Test - run: cargo test --features sysroot-abi -p proc-macro-srv -p proc-macro-srv-cli -p proc-macro-api -- --quiet + run: cargo test --features in-rust-tree -p proc-macro-srv -p proc-macro-srv-cli -p proc-macro-api -- --quiet - name: Check salsa dependency run: "! (cargo tree -p proc-macro-srv-cli -p proc-macro-srv -p proc-macro-srv-cli -p proc-macro-api -i salsa)" diff --git a/.github/workflows/rustdoc.yaml b/.github/workflows/rustdoc.yaml index c5588a29f676..7039f78eb1b7 100644 --- a/.github/workflows/rustdoc.yaml +++ b/.github/workflows/rustdoc.yaml @@ -31,7 +31,7 @@ jobs: - name: Deploy Docs if: github.event_name == 'push' && github.repository == 'rust-lang/rust-analyzer' && github.ref == 'refs/heads/master' - uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0 + uses: peaceiris/actions-gh-pages@84c30a85c19949d7eee79c4ff27748b70285e453 # v4.1.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_branch: gh-pages diff --git a/crates/load-cargo/Cargo.toml b/crates/load-cargo/Cargo.toml index 91b012e05071..7b5e51fba5f1 100644 --- a/crates/load-cargo/Cargo.toml +++ b/crates/load-cargo/Cargo.toml @@ -30,7 +30,7 @@ vfs.workspace = true intern.workspace = true [features] -in-rust-tree = ["hir-expand/in-rust-tree"] +in-rust-tree = ["hir-expand/in-rust-tree", "proc-macro-api/in-rust-tree"] [lints] workspace = true diff --git a/crates/proc-macro-api/Cargo.toml b/crates/proc-macro-api/Cargo.toml index 2cb76ef6b7e7..7342e0ecdcf6 100644 --- a/crates/proc-macro-api/Cargo.toml +++ b/crates/proc-macro-api/Cargo.toml @@ -34,7 +34,7 @@ semver.workspace = true rayon.workspace = true [features] -sysroot-abi = ["proc-macro-srv", "proc-macro-srv/sysroot-abi"] +in-rust-tree = ["proc-macro-srv", "proc-macro-srv/in-rust-tree"] default = [] [lints] diff --git a/crates/proc-macro-api/src/legacy_protocol/msg.rs b/crates/proc-macro-api/src/legacy_protocol/msg.rs index b647e6cf8aad..9b71a8b70c8f 100644 --- a/crates/proc-macro-api/src/legacy_protocol/msg.rs +++ b/crates/proc-macro-api/src/legacy_protocol/msg.rs @@ -384,7 +384,7 @@ mod tests { } #[test] - #[cfg(feature = "sysroot-abi")] + #[cfg(feature = "in-rust-tree")] fn test_proc_macro_rpc_works_ts() { for tt in [ fixture_token_tree_top_many_none, diff --git a/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs b/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs index 248de70f0e71..3015bd0c0ecc 100644 --- a/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs +++ b/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs @@ -34,7 +34,7 @@ //! as we don't have bincode in Cargo.toml yet, lets stick with serde_json for //! the time being. -#[cfg(feature = "sysroot-abi")] +#[cfg(feature = "in-rust-tree")] use proc_macro_srv::TokenStream; use std::collections::VecDeque; @@ -195,7 +195,7 @@ impl FlatTree { } } -#[cfg(feature = "sysroot-abi")] +#[cfg(feature = "in-rust-tree")] impl FlatTree { pub fn from_tokenstream( tokenstream: proc_macro_srv::TokenStream, @@ -591,7 +591,7 @@ impl<'a, T: SpanTransformer, U> Writer<'a, '_, T, U> { T::token_id_of(self.span_data_table, span) } - #[cfg(feature = "sysroot-abi")] + #[cfg(feature = "in-rust-tree")] pub(crate) fn intern(&mut self, text: &'a str) -> u32 { let table = &mut self.text; *self.string_table.entry(text.into()).or_insert_with(|| { @@ -611,7 +611,7 @@ impl<'a, T: SpanTransformer, U> Writer<'a, '_, T, U> { } } -#[cfg(feature = "sysroot-abi")] +#[cfg(feature = "in-rust-tree")] impl<'a, T: SpanTransformer> Writer<'a, '_, T, Option>> { @@ -852,7 +852,7 @@ impl> Reader<'_, T> { } } -#[cfg(feature = "sysroot-abi")] +#[cfg(feature = "in-rust-tree")] impl Reader<'_, T> { pub(crate) fn read_tokenstream( self, diff --git a/crates/proc-macro-api/src/lib.rs b/crates/proc-macro-api/src/lib.rs index a3d6ac5dd62b..149f6e44f9be 100644 --- a/crates/proc-macro-api/src/lib.rs +++ b/crates/proc-macro-api/src/lib.rs @@ -5,14 +5,14 @@ //! is used to provide basic infrastructure for communication between two //! processes: Client (RA itself), Server (the external program) -#![cfg_attr(not(feature = "sysroot-abi"), allow(unused_crate_dependencies))] +#![cfg_attr(not(feature = "in-rust-tree"), allow(unused_crate_dependencies))] #![cfg_attr( - feature = "sysroot-abi", + feature = "in-rust-tree", feature(proc_macro_internals, proc_macro_diagnostic, proc_macro_span, rustc_private) )] #![allow(internal_features, unused_features)] -#[cfg(feature = "sysroot-abi")] +#[cfg(feature = "in-rust-tree")] extern crate rustc_driver as _; pub mod bidirectional_protocol; diff --git a/crates/proc-macro-srv-cli/Cargo.toml b/crates/proc-macro-srv-cli/Cargo.toml index 4641f0878371..44e19f2d3c3b 100644 --- a/crates/proc-macro-srv-cli/Cargo.toml +++ b/crates/proc-macro-srv-cli/Cargo.toml @@ -31,8 +31,8 @@ proc-macro-test.path = "../proc-macro-srv/proc-macro-test" [features] default = [] -# default = ["sysroot-abi"] -sysroot-abi = ["proc-macro-srv/sysroot-abi", "proc-macro-api/sysroot-abi"] +# default = ["in-rust-tree"] +in-rust-tree = ["proc-macro-srv/in-rust-tree", "proc-macro-api/in-rust-tree"] [[bin]] diff --git a/crates/proc-macro-srv-cli/README.md b/crates/proc-macro-srv-cli/README.md index 02a67ac3ecc1..93a3c7ffc2dd 100644 --- a/crates/proc-macro-srv-cli/README.md +++ b/crates/proc-macro-srv-cli/README.md @@ -9,12 +9,12 @@ rust-analyzer uses a RPC (via stdio) client-server architecture for procedural m 1. Proc macros are dynamic libraries that can segfault, bringing down the entire process, so running them out of process allows rust-analyzer to recover from fatal errors. 2. Proc macro dylibs are compiled against a specific rustc version and require matching internal APIs to load and execute, as such having this binary shipped as a rustup component allows us to always match the rustc version irrespective of the rust-analyzer version used. -## The `sysroot-abi` Feature +## The `in-rust-tree` Feature -**The `sysroot-abi` feature is required for the binary to actually function.** Without it, the binary will return an error: +**The `in-rust-tree` feature is required for the binary to actually function.** Without it, the binary will return an error: ``` -proc-macro-srv-cli needs to be compiled with the `sysroot-abi` feature to function +proc-macro-srv-cli needs to be compiled with the `in-rust-tree` feature to function ``` This feature is necessary because the proc-macro server needs access to unstable rustc internals (`proc_macro_internals`, `proc_macro_diagnostic`, `proc_macro_span`) which are only available on nightly or with `RUSTC_BOOTSTRAP=1`. @@ -24,10 +24,10 @@ rust-analyzer is a stable toolchain project though, so the feature flag is used ```bash # Using nightly toolchain -cargo build -p proc-macro-srv-cli --features sysroot-abi +cargo build -p proc-macro-srv-cli --features in-rust-tree # Or with RUSTC_BOOTSTRAP on stable -RUSTC_BOOTSTRAP=1 cargo build -p proc-macro-srv-cli --features sysroot-abi +RUSTC_BOOTSTRAP=1 cargo build -p proc-macro-srv-cli --features in-rust-tree ``` ### Installing the proc-macro server @@ -42,7 +42,7 @@ cargo xtask install --proc-macro-server ## Testing ```bash -cargo test --features sysroot-abi -p proc-macro-srv -p proc-macro-srv-cli -p proc-macro-api +cargo test --features in-rust-tree -p proc-macro-srv -p proc-macro-srv-cli -p proc-macro-api ``` The tests use a test proc macro dylib built by the `proc-macro-test` crate, which compiles a small proc macro implementation during build time. diff --git a/crates/proc-macro-srv-cli/src/lib.rs b/crates/proc-macro-srv-cli/src/lib.rs index d540146c78da..c330928fbc9c 100644 --- a/crates/proc-macro-srv-cli/src/lib.rs +++ b/crates/proc-macro-srv-cli/src/lib.rs @@ -2,7 +2,7 @@ //! //! This module exposes the server main loop and protocol format for integration testing. -#![cfg(feature = "sysroot-abi")] +#![cfg(feature = "in-rust-tree")] #![feature(rustc_private)] extern crate rustc_driver as _; diff --git a/crates/proc-macro-srv-cli/src/main.rs b/crates/proc-macro-srv-cli/src/main.rs index 20b1c73ebf2d..926633df628d 100644 --- a/crates/proc-macro-srv-cli/src/main.rs +++ b/crates/proc-macro-srv-cli/src/main.rs @@ -1,10 +1,10 @@ //! A standalone binary for `proc-macro-srv`. //! Driver for proc macro server -#![cfg_attr(feature = "sysroot-abi", feature(rustc_private))] -#![cfg_attr(not(feature = "sysroot-abi"), allow(unused_crate_dependencies))] +#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))] +#![cfg_attr(not(feature = "in-rust-tree"), allow(unused_crate_dependencies))] #![allow(clippy::print_stdout, clippy::print_stderr)] -#[cfg(feature = "sysroot-abi")] +#[cfg(feature = "in-rust-tree")] extern crate rustc_driver as _; mod version; @@ -12,7 +12,7 @@ mod version; use clap::{Command, ValueEnum}; use proc_macro_api::ProtocolFormat; -#[cfg(feature = "sysroot-abi")] +#[cfg(feature = "in-rust-tree")] use proc_macro_srv_cli::main_loop::run; fn main() -> std::io::Result<()> { @@ -91,7 +91,7 @@ impl ValueEnum for ProtocolFormatArg { } } -#[cfg(not(feature = "sysroot-abi"))] +#[cfg(not(feature = "in-rust-tree"))] fn run( _: &mut std::io::BufReader, _: &mut std::io::Stdout, @@ -99,7 +99,7 @@ fn run( ) -> std::io::Result<()> { Err(std::io::Error::new( std::io::ErrorKind::Unsupported, - "proc-macro-srv-cli needs to be compiled with the `sysroot-abi` feature to function" + "proc-macro-srv-cli needs to be compiled with the `in-rust-tree` feature to function" .to_owned(), )) } diff --git a/crates/proc-macro-srv-cli/tests/bidirectional_postcard.rs b/crates/proc-macro-srv-cli/tests/bidirectional_postcard.rs index 4c50f06f4a0b..9c55eed08e52 100644 --- a/crates/proc-macro-srv-cli/tests/bidirectional_postcard.rs +++ b/crates/proc-macro-srv-cli/tests/bidirectional_postcard.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "sysroot-abi")] +#![cfg(feature = "in-rust-tree")] #![feature(rustc_private)] extern crate rustc_driver as _; diff --git a/crates/proc-macro-srv-cli/tests/common/utils.rs b/crates/proc-macro-srv-cli/tests/common/utils.rs index 051f28aee2ef..b78e10745274 100644 --- a/crates/proc-macro-srv-cli/tests/common/utils.rs +++ b/crates/proc-macro-srv-cli/tests/common/utils.rs @@ -135,6 +135,11 @@ pub(crate) fn proc_macro_test_dylib_path() -> Utf8PathBuf { path.into() } +fn make_ctx() -> SyntaxContext { + // SAFETY: Tests do not use a Database, so this won't ever be used within salsa. + unsafe { SyntaxContext::from_u32(0) } +} + /// Creates a simple empty token tree suitable for testing. pub(crate) fn create_empty_token_tree( version: u32, @@ -144,8 +149,7 @@ pub(crate) fn create_empty_token_tree( file_id: EditionedFileId::new(FileId::from_raw(0), Edition::CURRENT), ast_id: span::ROOT_ERASED_FILE_AST_ID, }; - let span = - Span { range: TextRange::empty(0.into()), anchor, ctx: SyntaxContext::from_u32_safe(0) }; + let span = Span { range: TextRange::empty(0.into()), anchor, ctx: make_ctx() }; let builder = TopSubtreeBuilder::new(Delimiter { open: span, diff --git a/crates/proc-macro-srv-cli/tests/legacy_json.rs b/crates/proc-macro-srv-cli/tests/legacy_json.rs index b807fd46d42c..f5cbaa7421eb 100644 --- a/crates/proc-macro-srv-cli/tests/legacy_json.rs +++ b/crates/proc-macro-srv-cli/tests/legacy_json.rs @@ -3,7 +3,7 @@ //! These tests exercise the full client-server RPC procedure using in-memory //! channels without needing to spawn the actual server and client processes. -#![cfg(feature = "sysroot-abi")] +#![cfg(feature = "in-rust-tree")] #![feature(rustc_private)] extern crate rustc_driver as _; diff --git a/crates/proc-macro-srv/Cargo.toml b/crates/proc-macro-srv/Cargo.toml index 466754209043..a161d796936a 100644 --- a/crates/proc-macro-srv/Cargo.toml +++ b/crates/proc-macro-srv/Cargo.toml @@ -36,8 +36,8 @@ proc-macro-test.path = "./proc-macro-test" [features] default = [] -# default = ["sysroot-abi"] -sysroot-abi = [] +# default = ["in-rust-tree"] +in-rust-tree = [] [lints] workspace = true diff --git a/crates/proc-macro-srv/src/lib.rs b/crates/proc-macro-srv/src/lib.rs index e989eb62dd00..7562a2e6648b 100644 --- a/crates/proc-macro-srv/src/lib.rs +++ b/crates/proc-macro-srv/src/lib.rs @@ -8,7 +8,7 @@ //! * We use `tt` for proc-macro `TokenStream` server, it is easier to manipulate and interact with //! RA than `proc-macro2` token stream. -#![cfg(feature = "sysroot-abi")] +#![cfg(feature = "in-rust-tree")] #![feature(proc_macro_internals, proc_macro_diagnostic, proc_macro_span, rustc_private)] #![expect(unreachable_pub, internal_features, clippy::disallowed_types, clippy::print_stderr)] #![allow(unused_features, unused_crate_dependencies)] diff --git a/crates/proc-macro-srv/src/tests/utils.rs b/crates/proc-macro-srv/src/tests/utils.rs index 394cbefc12b2..9780bcf3481b 100644 --- a/crates/proc-macro-srv/src/tests/utils.rs +++ b/crates/proc-macro-srv/src/tests/utils.rs @@ -11,6 +11,11 @@ use crate::{ token_stream::TokenStream, }; +fn make_ctx() -> SyntaxContext { + // SAFETY: Tests do not use a Database, so this won't ever be used within salsa. + unsafe { SyntaxContext::from_u32(0) } +} + fn parse_string(call_site: SpanId, src: &str) -> TokenStream { TokenStream::from_str(src, call_site).unwrap() } @@ -86,7 +91,7 @@ fn assert_expand_impl( file_id: EditionedFileId::current_edition(FileId::from_raw(41)), ast_id: ROOT_ERASED_FILE_AST_ID, }, - ctx: SyntaxContext::from_u32_safe(0), + ctx: make_ctx(), }; let call_site = Span { range: TextRange::new(0.into(), 100.into()), @@ -94,7 +99,7 @@ fn assert_expand_impl( file_id: EditionedFileId::current_edition(FileId::from_raw(42)), ast_id: ROOT_ERASED_FILE_AST_ID, }, - ctx: SyntaxContext::from_u32_safe(0), + ctx: make_ctx(), }; let mixed_site = call_site; @@ -189,7 +194,7 @@ pub fn assert_expand_with_callback( file_id: EditionedFileId::current_edition(FileId::from_raw(41)), ast_id: ROOT_ERASED_FILE_AST_ID, }, - ctx: SyntaxContext::from_u32_safe(0), + ctx: make_ctx(), }; let call_site = Span { range: TextRange::new(0.into(), 100.into()), @@ -197,7 +202,7 @@ pub fn assert_expand_with_callback( file_id: EditionedFileId::current_edition(FileId::from_raw(42)), ast_id: ROOT_ERASED_FILE_AST_ID, }, - ctx: SyntaxContext::from_u32_safe(0), + ctx: make_ctx(), }; let mixed_site = call_site; diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 174538484329..27d9576e29d0 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -108,6 +108,7 @@ in-rust-tree = [ "ide/in-rust-tree", "load-cargo/in-rust-tree", "parser/in-rust-tree", + "proc-macro-api/in-rust-tree", "syntax/in-rust-tree", ] dhat = ["dep:dhat"] diff --git a/crates/span/src/hygiene.rs b/crates/span/src/hygiene.rs index 2d9757b5ae9f..70b0447569bf 100644 --- a/crates/span/src/hygiene.rs +++ b/crates/span/src/hygiene.rs @@ -460,13 +460,6 @@ impl SyntaxContext { pub const unsafe fn from_u32(u32: u32) -> Self { Self(u32) } - - /// Alternative to [`from_u32`] that is safe to call. - /// - /// The split exists to keep API parity. - pub const fn from_u32_safe(u32: u32) -> Self { - Self(u32) - } } /// A property of a macro expansion that determines how identifiers diff --git a/rust-version b/rust-version index 4b1ba970b7c4..97203a4da202 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -ba0949ab745985a442e274ba52e8fb348cb0c662 +43a4909ee98ed4d006d9d773f5d94dc58e34f846 diff --git a/xtask/src/install.rs b/xtask/src/install.rs index a803b4e943a6..bbb6d9aeac25 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs @@ -179,7 +179,7 @@ fn install_proc_macro_server(sh: &Shell, opts: ProcMacroServerOpt) -> anyhow::Re let mut cmd = cmd!( sh, - "cargo install --path crates/proc-macro-srv-cli --profile={profile} --locked --force --features sysroot-abi" + "cargo install --path crates/proc-macro-srv-cli --profile={profile} --locked --force --features in-rust-tree" ); if std::env::var_os("RUSTUP_TOOLCHAIN").is_none() { cmd = cmd.env("RUSTUP_TOOLCHAIN", "nightly");