mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Lift out workspace related data into a separate query to preserve crategraph deduplication
This commit is contained in:
parent
8905f86d8a
commit
db04f514f2
10 changed files with 98 additions and 97 deletions
|
@ -3,11 +3,15 @@
|
|||
|
||||
use std::fmt;
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
use salsa::Durability;
|
||||
use triomphe::Arc;
|
||||
use vfs::FileId;
|
||||
|
||||
use crate::{CrateGraph, SourceDatabaseFileInputExt, SourceRoot, SourceRootDatabase, SourceRootId};
|
||||
use crate::{
|
||||
CrateGraph, CrateId, CrateWorkspaceData, SourceDatabaseFileInputExt, SourceRoot,
|
||||
SourceRootDatabase, SourceRootId,
|
||||
};
|
||||
|
||||
/// Encapsulate a bunch of raw `.set` calls on the database.
|
||||
#[derive(Default)]
|
||||
|
@ -15,6 +19,7 @@ pub struct FileChange {
|
|||
pub roots: Option<Vec<SourceRoot>>,
|
||||
pub files_changed: Vec<(FileId, Option<String>)>,
|
||||
pub crate_graph: Option<CrateGraph>,
|
||||
pub ws_data: Option<FxHashMap<CrateId, Arc<CrateWorkspaceData>>>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for FileChange {
|
||||
|
@ -50,6 +55,10 @@ impl FileChange {
|
|||
self.crate_graph = Some(graph);
|
||||
}
|
||||
|
||||
pub fn set_ws_data(&mut self, data: FxHashMap<CrateId, Arc<CrateWorkspaceData>>) {
|
||||
self.ws_data = Some(data);
|
||||
}
|
||||
|
||||
pub fn apply(self, db: &mut dyn SourceRootDatabase) {
|
||||
let _p = tracing::info_span!("FileChange::apply").entered();
|
||||
if let Some(roots) = self.roots {
|
||||
|
@ -74,6 +83,9 @@ impl FileChange {
|
|||
if let Some(crate_graph) = self.crate_graph {
|
||||
db.set_crate_graph_with_durability(Arc::new(crate_graph), Durability::HIGH);
|
||||
}
|
||||
if let Some(data) = self.ws_data {
|
||||
db.set_crate_workspace_data_with_durability(Arc::new(data), Durability::HIGH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@ mod input;
|
|||
|
||||
use std::panic;
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
use salsa::Durability;
|
||||
use span::EditionedFileId;
|
||||
use syntax::{ast, Parse, SourceFile, SyntaxError};
|
||||
use triomphe::Arc;
|
||||
use vfs::FileId;
|
||||
use vfs::{AbsPathBuf, FileId};
|
||||
|
||||
pub use crate::{
|
||||
change::FileChange,
|
||||
|
@ -74,19 +75,30 @@ pub trait SourceDatabase: FileLoader + std::fmt::Debug {
|
|||
#[salsa::input]
|
||||
fn crate_graph(&self) -> Arc<CrateGraph>;
|
||||
|
||||
// FIXME: Consider removing this, making HirDatabase::target_data_layout an input query
|
||||
#[salsa::input]
|
||||
fn data_layout(&self, krate: CrateId) -> TargetLayoutLoadResult;
|
||||
|
||||
#[salsa::input]
|
||||
fn toolchain(&self, krate: CrateId) -> Option<Version>;
|
||||
fn crate_workspace_data(&self) -> Arc<FxHashMap<CrateId, Arc<CrateWorkspaceData>>>;
|
||||
|
||||
#[salsa::transparent]
|
||||
fn toolchain_channel(&self, krate: CrateId) -> Option<ReleaseChannel>;
|
||||
}
|
||||
|
||||
/// Crate related data shared by the whole workspace.
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||
pub struct CrateWorkspaceData {
|
||||
/// The working directory to run proc-macros in. This is usually the workspace root of cargo workspaces.
|
||||
pub proc_macro_cwd: Option<AbsPathBuf>,
|
||||
// FIXME: Consider removing this, making HirDatabase::target_data_layout an input query
|
||||
pub data_layout: TargetLayoutLoadResult,
|
||||
/// Toolchain version used to compile the crate.
|
||||
pub toolchain: Option<Version>,
|
||||
}
|
||||
|
||||
fn toolchain_channel(db: &dyn SourceDatabase, krate: CrateId) -> Option<ReleaseChannel> {
|
||||
db.toolchain(krate).as_ref().and_then(|v| ReleaseChannel::from_str(&v.pre))
|
||||
db.crate_workspace_data()
|
||||
.get(&krate)?
|
||||
.toolchain
|
||||
.as_ref()
|
||||
.and_then(|v| ReleaseChannel::from_str(&v.pre))
|
||||
}
|
||||
|
||||
fn parse(db: &dyn SourceDatabase, file_id: EditionedFileId) -> Parse<ast::SourceFile> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue