Skip to content

Commit

Permalink
preparation step to paralelization
Browse files Browse the repository at this point in the history
Summary:
Future operations could be quite slow, for example types in a file.
Therefore we want to run indexing in parallel.
This step just moves the mutations one level up in order to parallel indexing without any locks

Reviewed By: alanz

Differential Revision: D55063027

fbshipit-source-id: 2667021f2fc6177a3150de17ed9723c5c84a6617
  • Loading branch information
perehonchuk authored and facebook-github-bot committed Apr 5, 2024
1 parent 5df9c24 commit 5d56af7
Showing 1 changed file with 48 additions and 23 deletions.
71 changes: 48 additions & 23 deletions crates/elp/src/bin/glean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ impl IndexedFacts {
xref_facts: vec![],
}
}

fn add(
&mut self,
file_fact: FileFact,
line_fact: FileLinesFact,
facts: Option<(Vec<FunctionDeclarationFact>, XRefFact)>,
) {
self.file_facts.push(file_fact);
self.file_line_facts.push(line_fact);
if let Some((decl, xref)) = facts {
self.declaration_facts.extend(decl);
self.xref_facts.push(xref)
}
}
}

pub struct GleanIndexer {
Expand Down Expand Up @@ -320,22 +334,15 @@ impl GleanIndexer {
let source_root_id = db.file_source_root(file_id);
let source_root = db.source_root(source_root_id);
let path = source_root.path_for_file(&file_id).unwrap();
self.index_file(&db, file_id, &path, &mut ctx).unwrap();
match self.index_file(&db, file_id, &path) {
Some((file, line, facts)) => ctx.add(file, line, facts),
None => panic!("Can't find module {}", module),
}
} else {
let project_data = db.project_data(self.project_id);
for &source_root_id in &project_data.source_roots {
if let Some(app_data) = db.app_data(source_root_id) {
if app_data.app_type == AppType::App {
let source_root = db.source_root(source_root_id);
for file_id in source_root.iter() {
if let Some(path) = source_root.path_for_file(&file_id) {
if let Err(err) = self.index_file(&db, file_id, path, &mut ctx)
{
log::warn!("Error indexing file {:?}: {}", path, err);
}
}
}
}
for (file_id, path) in Self::project_files(db, self.project_id) {
match self.index_file(&db, file_id, &path) {
Some((file, line, facts)) => ctx.add(file, line, facts),
None => log::warn!("Can't find module {}", path),
}
}
}
Expand All @@ -344,29 +351,47 @@ impl GleanIndexer {
Ok(ctx)
}

fn project_files(db: &RootDatabase, project_id: ProjectId) -> Vec<(FileId, VfsPath)> {
let project_data = db.project_data(project_id);
let mut files = vec![];
for &source_root_id in &project_data.source_roots {
if let Some(app_data) = db.app_data(source_root_id) {
if app_data.app_type == AppType::App {
let source_root = db.source_root(source_root_id);
for file_id in source_root.iter() {
if let Some(path) = source_root.path_for_file(&file_id) {
files.push((file_id, path.clone()));
}
}
}
}
}
files
}

fn index_file(
&self,
db: &RootDatabase,
file_id: FileId,
path: &VfsPath,
facts: &mut IndexedFacts,
) -> Result<()> {
) -> Option<(
FileFact,
FileLinesFact,
Option<(Vec<FunctionDeclarationFact>, XRefFact)>,
)> {
let file_fact = match self.file_fact(db, file_id, path) {
Some(file_fact) => file_fact,
None => return Ok(()),
None => return None,
};
let line_fact = self.line_fact(db, file_id);
facts.file_facts.push(file_fact);
facts.file_line_facts.push(line_fact);

let module_index = db.module_index(self.project_id);
if let Some(module) = module_index.module_for_file(file_id) {
let decl = Self::declarations(db, file_id, module);
facts.declaration_facts.extend(decl);
let xref = Self::xrefs(db, file_id);
facts.xref_facts.push(xref);
return Some((file_fact, line_fact, Some((decl, xref))));
}
Ok(())
Some((file_fact, line_fact, None))
}

fn file_fact(&self, db: &RootDatabase, file_id: FileId, path: &VfsPath) -> Option<FileFact> {
Expand Down

0 comments on commit 5d56af7

Please sign in to comment.