1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::sync::Arc;
use mir_codebase::StubSlice;
use mir_issues::Issue;
// SourceFile input (S1)
/// Source file registered as a Salsa input.
/// Setting `text` on an existing `SourceFile` is the single write that drives
/// all downstream query invalidation.
#[salsa::input]
pub struct SourceFile {
pub path: Arc<str>,
pub text: Arc<str>,
}
// FileDefinitions (S1)
/// Result of the `collect_file_definitions` tracked query.
#[derive(Clone, Debug)]
pub struct FileDefinitions {
pub slice: Arc<StubSlice>,
pub issues: Arc<Vec<Issue>>,
}
impl FileDefinitions {
/// FQ names this file defines (classes, interfaces, traits, enums,
/// functions, constants, global vars). Lets callers that already hold a
/// `FileDefinitions` derive the symbol set without re-running the
/// `collect_file_definitions` salsa query.
pub(crate) fn defined_symbols(&self) -> rustc_hash::FxHashSet<Arc<str>> {
let mut out = rustc_hash::FxHashSet::default();
for c in self.slice.classes.iter() {
out.insert(c.fqcn.clone());
}
for i in self.slice.interfaces.iter() {
out.insert(i.fqcn.clone());
}
for t in self.slice.traits.iter() {
out.insert(t.fqcn.clone());
}
for e in self.slice.enums.iter() {
out.insert(e.fqcn.clone());
}
for f in self.slice.functions.iter() {
out.insert(f.fqn.clone());
}
for (name, _) in self.slice.constants.iter() {
out.insert(name.clone());
}
for (name, _) in self.slice.global_vars.iter() {
let gname: Arc<str> = Arc::from(name.strip_prefix('$').unwrap_or(name.as_ref()));
out.insert(gname);
}
out
}
}
impl PartialEq for FileDefinitions {
fn eq(&self, other: &Self) -> bool {
// Structural comparison on the slice lets salsa skip workspace_symbol_index
// rebuilds when file text changed but definitions are unchanged
// (e.g. comment edits, whitespace-only saves in LSP).
// Issues are deliberately excluded: diagnostics changing doesn't affect
// symbol lookups and shouldn't force the workspace index to rebuild.
if Arc::ptr_eq(&self.slice, &other.slice) {
return true;
}
*self.slice == *other.slice
}
}