Skip to content

Commit

Permalink
fix: fix compile unit cache. update cache in fn `compile_unit_with_ca…
Browse files Browse the repository at this point in the history
…che`

Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa committed Apr 9, 2024
1 parent 00eecb6 commit 96e9dcb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 2 additions & 0 deletions kclvm/tools/src/LSP/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,8 @@ fn compile_unit_cache_test() {
let compile_unit_cache = KCLCompileUnitCache::default();
let start = Instant::now();
let _ = compile_unit_with_cache(&Some(Arc::clone(&compile_unit_cache)), &path.to_string());

assert!(compile_unit_cache.read().get(&path.to_string()).is_some());
let first_compile_time = start.elapsed();

let start = Instant::now();
Expand Down
14 changes: 6 additions & 8 deletions kclvm/tools/src/LSP/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ pub(crate) fn compile_unit_with_cache(
) -> (Vec<String>, Option<LoadProgramOptions>) {
match compile_unit_cache {
Some(cache) => {
let map = cache.read();
let mut map = cache.write();
match map.get(file) {
Some(compile_unit) => compile_unit.clone(),
None => lookup_compile_unit(file, true),
None => {
let res = lookup_compile_unit(file, true);
map.insert(file.to_string(), res.clone());
res
}
}
}
None => lookup_compile_unit(file, true),
Expand All @@ -89,12 +93,6 @@ pub(crate) fn compile_with_params(
// Lookup compile unit (kcl.mod or kcl.yaml) from the entry file.
let (mut files, opt) = compile_unit_with_cache(&params.compile_unit_cache, &params.file);

if let Some(cache) = params.compile_unit_cache {
cache
.write()
.insert(params.file.clone(), (files.clone(), opt.clone()));
}

if !files.contains(&params.file) {
files.push(params.file.clone());
}
Expand Down

0 comments on commit 96e9dcb

Please sign in to comment.