Skip to content

Commit 97ab190

Browse files
authored
Merge pull request #164 from Pivot-Studio/feat/make_db_parallel
feat: make db parallel
2 parents e4174ce + 82ce647 commit 97ab190

23 files changed

+428
-246
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ast/accumulators.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{cell::RefCell, path::PathBuf, rc::Rc};
1+
use std::path::PathBuf;
22

33
use lsp_types::{
44
CompletionItem, DocumentSymbol, GotoDefinitionResponse, Hover, InlayHint, Location,
@@ -11,7 +11,7 @@ use super::diag::PLDiag;
1111
pub struct Diagnostics((String, Vec<PLDiag>));
1212

1313
#[salsa::accumulator]
14-
pub struct PLReferences(Rc<RefCell<Vec<Location>>>);
14+
pub struct PLReferences(Vec<Location>);
1515

1616
#[salsa::accumulator]
1717
pub struct GotoDef(GotoDefinitionResponse);

src/ast/builder/llvmbuilder.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::{
55
cell::{Cell, RefCell},
66
path::Path,
7-
rc::Rc,
7+
sync::Arc,
88
};
99

1010
use inkwell::{
@@ -114,19 +114,19 @@ pub fn create_llvm_deps<'ctx>(
114114

115115
#[derive(Clone)]
116116
pub struct LLVMBuilder<'a, 'ctx> {
117-
handle_table: Rc<RefCell<FxHashMap<ValueHandle, AnyValueEnum<'ctx>>>>,
118-
handle_reverse_table: Rc<RefCell<FxHashMap<AnyValueEnum<'ctx>, ValueHandle>>>,
119-
block_table: Rc<RefCell<FxHashMap<BlockHandle, BasicBlock<'ctx>>>>,
120-
block_reverse_table: Rc<RefCell<FxHashMap<BasicBlock<'ctx>, BlockHandle>>>,
117+
handle_table: Arc<RefCell<FxHashMap<ValueHandle, AnyValueEnum<'ctx>>>>,
118+
handle_reverse_table: Arc<RefCell<FxHashMap<AnyValueEnum<'ctx>, ValueHandle>>>,
119+
block_table: Arc<RefCell<FxHashMap<BlockHandle, BasicBlock<'ctx>>>>,
120+
block_reverse_table: Arc<RefCell<FxHashMap<BasicBlock<'ctx>, BlockHandle>>>,
121121
context: &'ctx Context, // llvm context
122122
builder: &'a Builder<'ctx>, // llvm builder
123123
module: &'a Module<'ctx>, // llvm module
124124
dibuilder: &'a DebugInfoBuilder<'ctx>, // debug info builder
125125
diunit: &'a DICompileUnit<'ctx>, // debug info unit
126126
targetmachine: &'a TargetMachine, // might be used in debug info
127127
discope: Cell<DIScope<'ctx>>, // debug info scope
128-
ditypes_placeholder: Rc<RefCell<FxHashMap<String, RefCell<Vec<MemberType<'ctx>>>>>>, // hold the generated debug info type place holder
129-
ditypes: Rc<RefCell<FxHashMap<String, DIType<'ctx>>>>, // hold the generated debug info type
128+
ditypes_placeholder: Arc<RefCell<FxHashMap<String, RefCell<Vec<MemberType<'ctx>>>>>>, // hold the generated debug info type place holder
129+
ditypes: Arc<RefCell<FxHashMap<String, DIType<'ctx>>>>, // hold the generated debug info type
130130
}
131131

132132
pub fn get_target_machine(level: OptimizationLevel) -> TargetMachine {
@@ -167,12 +167,12 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
167167
diunit,
168168
targetmachine: tm,
169169
discope: Cell::new(diunit.get_file().as_debug_info_scope()),
170-
ditypes: Rc::new(RefCell::new(FxHashMap::default())),
171-
ditypes_placeholder: Rc::new(RefCell::new(FxHashMap::default())),
172-
handle_table: Rc::new(RefCell::new(FxHashMap::default())),
173-
handle_reverse_table: Rc::new(RefCell::new(FxHashMap::default())),
174-
block_table: Rc::new(RefCell::new(FxHashMap::default())),
175-
block_reverse_table: Rc::new(RefCell::new(FxHashMap::default())),
170+
ditypes: Arc::new(RefCell::new(FxHashMap::default())),
171+
ditypes_placeholder: Arc::new(RefCell::new(FxHashMap::default())),
172+
handle_table: Arc::new(RefCell::new(FxHashMap::default())),
173+
handle_reverse_table: Arc::new(RefCell::new(FxHashMap::default())),
174+
block_table: Arc::new(RefCell::new(FxHashMap::default())),
175+
block_reverse_table: Arc::new(RefCell::new(FxHashMap::default())),
176176
}
177177
}
178178
fn get_llvm_value_handle(&self, value: &AnyValueEnum<'ctx>) -> ValueHandle {
@@ -580,7 +580,7 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
580580
fn get_or_add_global_value(
581581
&self,
582582
name: &str,
583-
pltype: Rc<RefCell<PLType>>,
583+
pltype: Arc<RefCell<PLType>>,
584584
ctx: &mut Ctx<'a>,
585585
) -> PointerValue<'ctx> {
586586
let global = self.get_global_var_handle(name);
@@ -776,7 +776,7 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
776776
fn get_or_add_global(
777777
&self,
778778
name: &str,
779-
pltype: Rc<RefCell<PLType>>,
779+
pltype: Arc<RefCell<PLType>>,
780780
ctx: &mut Ctx<'a>,
781781
) -> ValueHandle {
782782
self.get_llvm_value_handle(
@@ -796,9 +796,9 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
796796
&self,
797797
range: Range,
798798
v: ValueHandle,
799-
tp: Rc<RefCell<PLType>>,
799+
tp: Arc<RefCell<PLType>>,
800800
ctx: &mut Ctx<'a>,
801-
) -> Result<(ValueHandle, Rc<RefCell<PLType>>), PLDiag> {
801+
) -> Result<(ValueHandle, Arc<RefCell<PLType>>), PLDiag> {
802802
let handle = v;
803803
let v = self.get_llvm_value(handle).unwrap();
804804
if !v.is_pointer_value() {
@@ -1335,7 +1335,7 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
13351335
fn add_global(
13361336
&self,
13371337
name: &str,
1338-
pltype: Rc<RefCell<PLType>>,
1338+
pltype: Arc<RefCell<PLType>>,
13391339
ctx: &mut Ctx<'a>,
13401340
line: u32,
13411341
pltp: &PLType,

src/ast/builder/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// 2. 所有涉及llvm类型的函数(包括参数或返回值)都应该是private的
44
pub mod llvmbuilder;
55
pub mod no_op_builder;
6-
use std::{cell::RefCell, path::Path, rc::Rc};
6+
use std::{cell::RefCell, path::Path, sync::Arc};
77

88
use enum_dispatch::enum_dispatch;
99
use inkwell::{values::BasicValueEnum, FloatPredicate, IntPredicate};
@@ -35,7 +35,7 @@ pub trait IRBuilder<'a, 'ctx> {
3535
fn add_global(
3636
&self,
3737
name: &str,
38-
pltype: Rc<RefCell<PLType>>,
38+
pltype: Arc<RefCell<PLType>>,
3939
ctx: &mut Ctx<'a>,
4040
line: u32,
4141
pltp: &PLType,
@@ -116,17 +116,17 @@ pub trait IRBuilder<'a, 'ctx> {
116116
fn get_or_add_global(
117117
&self,
118118
name: &str,
119-
pltype: Rc<RefCell<PLType>>,
119+
pltype: Arc<RefCell<PLType>>,
120120
ctx: &mut Ctx<'a>,
121121
) -> ValueHandle;
122122
fn build_load(&self, ptr: ValueHandle, name: &str) -> ValueHandle;
123123
fn try_load2var(
124124
&self,
125125
range: Range,
126126
v: ValueHandle,
127-
tp: Rc<RefCell<PLType>>,
127+
tp: Arc<RefCell<PLType>>,
128128
ctx: &mut Ctx<'a>,
129-
) -> Result<(ValueHandle, Rc<RefCell<PLType>>), PLDiag>;
129+
) -> Result<(ValueHandle, Arc<RefCell<PLType>>), PLDiag>;
130130
fn get_function(&self, name: &str) -> Option<ValueHandle>;
131131
fn build_call(&self, f: ValueHandle, args: &[ValueHandle]) -> Option<ValueHandle>;
132132
fn add_function(

src/ast/builder/no_op_builder.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::Arc;
2+
13
use crate::ast::{ctx::Ctx, pltype::PLType};
24

35
use super::{IRBuilder, ValueHandle};
@@ -39,7 +41,7 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for NoOpBuilder {
3941
fn add_global(
4042
&self,
4143
_name: &str,
42-
_pltype: std::rc::Rc<std::cell::RefCell<crate::ast::pltype::PLType>>,
44+
_pltype: Arc<std::cell::RefCell<crate::ast::pltype::PLType>>,
4345
_ctx: &mut crate::ast::ctx::Ctx<'a>,
4446
_line: u32,
4547
_pltp: &crate::ast::pltype::PLType,
@@ -228,7 +230,7 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for NoOpBuilder {
228230
fn get_or_add_global(
229231
&self,
230232
_name: &str,
231-
_pltype: std::rc::Rc<std::cell::RefCell<crate::ast::pltype::PLType>>,
233+
_pltype: Arc<std::cell::RefCell<crate::ast::pltype::PLType>>,
232234
_ctx: &mut crate::ast::ctx::Ctx<'a>,
233235
) -> super::ValueHandle {
234236
0
@@ -242,12 +244,12 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for NoOpBuilder {
242244
&self,
243245
_range: crate::ast::range::Range,
244246
_v: super::ValueHandle,
245-
tp: std::rc::Rc<std::cell::RefCell<crate::ast::pltype::PLType>>,
247+
tp: Arc<std::cell::RefCell<crate::ast::pltype::PLType>>,
246248
_ctx: &mut crate::ast::ctx::Ctx<'a>,
247249
) -> Result<
248250
(
249251
super::ValueHandle,
250-
std::rc::Rc<std::cell::RefCell<crate::ast::pltype::PLType>>,
252+
Arc<std::cell::RefCell<crate::ast::pltype::PLType>>,
251253
),
252254
crate::ast::diag::PLDiag,
253255
> {

src/ast/compiler.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,16 @@ pub fn compile_dry(db: &dyn Db, docs: MemDocsInput) -> Option<ModWrapper> {
113113
if input.is_none() {
114114
return None;
115115
}
116-
compile_dry_file(db, input.unwrap())
116+
let re = compile_dry_file(db, input.unwrap());
117+
if let Some(res) = db.get_ref_str() {
118+
re.and_then(|plmod| {
119+
plmod
120+
.plmod(db)
121+
.get_refs(&res, db, &mut FxHashSet::default());
122+
Some(())
123+
});
124+
}
125+
re
117126
}
118127

119128
#[salsa::tracked]

0 commit comments

Comments
 (0)