Skip to content

Commit

Permalink
Fix: fix incremental compilation unwrap panic in AdvancerResolver (#1247
Browse files Browse the repository at this point in the history
)

* fix: fix fn invalidate_module(). This error will cause the compilation cache to not be cleared correctly, causing an error in the AdvancerResolver.

Signed-off-by: he1pa <[email protected]>

* fix: fix parse cache. First update all AST information. When constructing 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]>

---------

Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa committed Apr 26, 2024
1 parent c229249 commit 8b29815
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
28 changes: 19 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
7 changes: 3 additions & 4 deletions kclvm/sema/src/resolver/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,13 +602,12 @@ impl DependencyGraph {
if let Some(pkgpaths) = self.module_map.get(&module_file).cloned() {
let mut pkg_queue = VecDeque::new();
for pkgpath in pkgpaths.iter() {
invalidated_set.insert(pkgpath.clone());
pkg_queue.push_back(self.node_map.get(pkgpath));
}

let mut old_size = 0;
while old_size < invalidated_set.len() {
old_size = invalidated_set.len();
let mut old_size: i64 = -1;
while old_size < invalidated_set.len() as i64 {
old_size = invalidated_set.len() as i64;
let cur_node = loop {
match pkg_queue.pop_front() {
Some(cur_node) => match cur_node {
Expand Down

0 comments on commit 8b29815

Please sign in to comment.