Skip to content

Commit

Permalink
fix: fix parse cache. First update all AST information. When construc…
Browse files Browse the repository at this point in the history
…ting pkg recursively, it will try to get AST information from the cache. In the previous implementation, the old version of AST was obtained in recursion, and then the new version of AST was added to the main package, resulting in inconsistent AST versions of the same file in the main package and other pkgs.

Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa committed Apr 25, 2024
1 parent 0fa4ab5 commit 925b9f3
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions kclvm/parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,22 +344,32 @@ impl Loader {
let workdir = compile_entries.get_root_path().to_string();
let mut pkgs = HashMap::new();
let mut pkg_files = Vec::new();
for entry in compile_entries.iter() {
// Get files from options with root.
// let k_files = self.get_main_files_from_pkg(entry.path(), entry.name())?;
let k_files = entry.get_k_files();
let maybe_k_codes = entry.get_k_codes();
// Load main package.
for (i, filename) in k_files.iter().enumerate() {
let mut m = if let Some(module_cache) = self.module_cache.as_ref() {
// update cache
if let Some(module_cache) = self.module_cache.as_ref() {
for entry in compile_entries.iter() {
let k_files = entry.get_k_files();
let maybe_k_codes = entry.get_k_codes();
// Load main package.
for (i, filename) in k_files.iter().enumerate() {
let m = parse_file_with_session(
self.sess.clone(),
filename,
maybe_k_codes[i].clone(),
)?;
let mut module_cache_ref = module_cache.write().unwrap();
module_cache_ref.insert(filename.clone(), m.clone());
m
}
}
}

for entry in compile_entries.iter() {
let k_files = entry.get_k_files();
let maybe_k_codes = entry.get_k_codes();
// Load main package.
for (i, filename) in k_files.iter().enumerate() {
let mut m = if let Some(module_cache) = self.module_cache.as_ref() {
let module_cache_ref = module_cache.read().unwrap();
module_cache_ref.get(filename).unwrap().clone()
} else {
parse_file_with_session(self.sess.clone(), filename, maybe_k_codes[i].clone())?
};
Expand Down Expand Up @@ -609,8 +619,10 @@ impl Loader {
let mut m = if let Some(module_cache) = self.module_cache.as_ref() {
let module_cache_ref = module_cache.read().unwrap();
if let Some(module) = module_cache_ref.get(&filename) {
eprintln!("parse get {:?}", filename);
module.clone()
} else {
eprintln!("parse not get {:?}", filename);
let m = parse_file_with_session(self.sess.clone(), &filename, None)?;
drop(module_cache_ref);
let mut module_cache_ref = module_cache.write().unwrap();
Expand Down

0 comments on commit 925b9f3

Please sign in to comment.