mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-26 17:57:19 +00:00
Make HirFileId, EditionedFileId and macro files Salsa struct
And make more queries non-interned. Also flip the default for queries, now the default is to not intern and to intern a query you need to say `invoke_interned`.
This commit is contained in:
parent
02ade79631
commit
c58ddafe90
195 changed files with 1473 additions and 1525 deletions
|
|
@ -16,11 +16,11 @@ use intern::Symbol;
|
|||
use la_arena::{Arena, Idx, RawIdx};
|
||||
use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
|
||||
use salsa::{Durability, Setter};
|
||||
use span::{Edition, EditionedFileId};
|
||||
use span::Edition;
|
||||
use triomphe::Arc;
|
||||
use vfs::{AbsPathBuf, AnchoredPath, FileId, VfsPath, file_set::FileSet};
|
||||
|
||||
use crate::{CrateWorkspaceData, RootQueryDb};
|
||||
use crate::{CrateWorkspaceData, EditionedFileId, RootQueryDb};
|
||||
|
||||
pub type ProcMacroPaths = FxHashMap<CrateBuilderId, Result<(String, AbsPathBuf), String>>;
|
||||
|
||||
|
|
@ -773,8 +773,8 @@ pub(crate) fn transitive_rev_deps(db: &dyn RootQueryDb, of: Crate) -> FxHashSet<
|
|||
}
|
||||
|
||||
impl BuiltCrateData {
|
||||
pub fn root_file_id(&self) -> EditionedFileId {
|
||||
EditionedFileId::new(self.root_file_id, self.edition)
|
||||
pub fn root_file_id(&self, db: &dyn salsa::Database) -> EditionedFileId {
|
||||
EditionedFileId::new(db, self.root_file_id, self.edition)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use rustc_hash::{FxHashSet, FxHasher};
|
|||
pub use salsa::{self};
|
||||
use salsa::{Durability, Setter};
|
||||
pub use semver::{BuildMetadata, Prerelease, Version, VersionReq};
|
||||
use span::Edition;
|
||||
use syntax::{Parse, SyntaxError, ast};
|
||||
use triomphe::Arc;
|
||||
pub use vfs::{AnchoredPath, AnchoredPathBuf, FileId, VfsPath, file_set::FileSet};
|
||||
|
|
@ -151,21 +152,39 @@ impl Files {
|
|||
}
|
||||
}
|
||||
|
||||
#[salsa::interned(no_lifetime)]
|
||||
#[salsa::interned(no_lifetime, constructor=from_span)]
|
||||
pub struct EditionedFileId {
|
||||
pub editioned_file_id: span::EditionedFileId,
|
||||
}
|
||||
|
||||
impl EditionedFileId {
|
||||
pub fn file_id(&self, db: &dyn salsa::Database) -> vfs::FileId {
|
||||
// Salsa already uses the name `new`...
|
||||
#[inline]
|
||||
pub fn new(db: &dyn salsa::Database, file_id: FileId, edition: Edition) -> Self {
|
||||
EditionedFileId::from_span(db, span::EditionedFileId::new(file_id, edition))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn current_edition(db: &dyn salsa::Database, file_id: FileId) -> Self {
|
||||
EditionedFileId::new(db, file_id, Edition::CURRENT)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn file_id(self, db: &dyn salsa::Database) -> vfs::FileId {
|
||||
let id = self.editioned_file_id(db);
|
||||
id.file_id()
|
||||
}
|
||||
|
||||
fn unpack(&self, db: &dyn salsa::Database) -> (vfs::FileId, span::Edition) {
|
||||
#[inline]
|
||||
pub fn unpack(self, db: &dyn salsa::Database) -> (vfs::FileId, span::Edition) {
|
||||
let id = self.editioned_file_id(db);
|
||||
(id.file_id(), id.edition())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn edition(self, db: &dyn SourceDatabase) -> Edition {
|
||||
self.editioned_file_id(db).edition()
|
||||
}
|
||||
}
|
||||
|
||||
#[salsa::input]
|
||||
|
|
@ -189,7 +208,7 @@ pub struct SourceRootInput {
|
|||
#[query_group::query_group]
|
||||
pub trait RootQueryDb: SourceDatabase + salsa::Database {
|
||||
/// Parses the file into the syntax tree.
|
||||
#[salsa::invoke_actual(parse)]
|
||||
#[salsa::invoke(parse)]
|
||||
#[salsa::lru(128)]
|
||||
fn parse(&self, file_id: EditionedFileId) -> Parse<ast::SourceFile>;
|
||||
|
||||
|
|
@ -201,6 +220,7 @@ pub trait RootQueryDb: SourceDatabase + salsa::Database {
|
|||
fn toolchain_channel(&self, krate: Crate) -> Option<ReleaseChannel>;
|
||||
|
||||
/// Crates whose root file is in `id`.
|
||||
#[salsa::invoke_interned(source_root_crates)]
|
||||
fn source_root_crates(&self, id: SourceRootId) -> Arc<[Crate]>;
|
||||
|
||||
#[salsa::transparent]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue