Use stable AST IDs

Instead of simple numbering, we hash important bits, like the name of the item.

This will allow for much better incrementality, e.g. when you add an item. Currently, this invalidates the IDs of all following items, which invalidates pretty much everything.
This commit is contained in:
Chayim Refael Friedman 2025-05-21 00:04:59 +03:00
parent 5b2c8bc9ae
commit 4bcf03e28b
22 changed files with 1220 additions and 546 deletions

View file

@ -22,9 +22,10 @@ pub const HAS_GLOBAL_SPANS: u32 = 3;
pub const RUST_ANALYZER_SPAN_SUPPORT: u32 = 4;
/// Whether literals encode their kind as an additional u32 field and idents their rawness as a u32 field.
pub const EXTENDED_LEAF_DATA: u32 = 5;
pub const HASHED_AST_ID: u32 = 6;
/// Current API version of the proc-macro protocol.
pub const CURRENT_API_VERSION: u32 = EXTENDED_LEAF_DATA;
pub const CURRENT_API_VERSION: u32 = HASHED_AST_ID;
/// Represents requests sent from the client to the proc-macro-srv.
#[derive(Debug, Serialize, Deserialize)]
@ -54,7 +55,7 @@ pub enum SpanMode {
Id,
/// Rust Analyzer-specific span handling mode.
RustAnalyzer,
RustAnalyzer { fixup_ast_id: u32 },
}
/// Represents responses sent from the proc-macro-srv to the client.
@ -201,7 +202,9 @@ type ProtocolWrite<W: Write> = for<'o, 'msg> fn(out: &'o mut W, msg: &'msg str)
#[cfg(test)]
mod tests {
use intern::{Symbol, sym};
use span::{Edition, ErasedFileAstId, Span, SpanAnchor, SyntaxContext, TextRange, TextSize};
use span::{
Edition, ROOT_ERASED_FILE_AST_ID, Span, SpanAnchor, SyntaxContext, TextRange, TextSize,
};
use tt::{
Delimiter, DelimiterKind, Ident, Leaf, Literal, Punct, Spacing, TopSubtree,
TopSubtreeBuilder,
@ -215,7 +218,7 @@ mod tests {
span::FileId::from_raw(0xe4e4e),
span::Edition::CURRENT,
),
ast_id: ErasedFileAstId::from_raw(0),
ast_id: ROOT_ERASED_FILE_AST_ID,
};
let mut builder = TopSubtreeBuilder::new(Delimiter {
@ -305,7 +308,7 @@ mod tests {
#[test]
fn test_proc_macro_rpc_works() {
let tt = fixture_token_tree();
for v in RUST_ANALYZER_SPAN_SUPPORT..=CURRENT_API_VERSION {
for v in HASHED_AST_ID..=CURRENT_API_VERSION {
let mut span_data_table = Default::default();
let task = ExpandMacro {
data: ExpandMacroData {