Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix resolver cache caused falsely report errors. #1320

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions kclvm/sema/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl<'ctx> Resolver<'ctx> {
import_names: self.ctx.import_names.clone(),
node_ty_map: self.node_ty_map.clone(),
handler: self.handler.clone(),
schema_mapping: self.ctx.schema_mapping.clone(),
};
self.lint_check_scope_map();
for diag in &self.linter.handler.diagnostics {
Expand All @@ -117,7 +118,7 @@ pub struct Context {
pub pkgpath: String,
/// What schema are we in.
pub schema: Option<Rc<RefCell<SchemaType>>>,
/// What schema are we in.
/// Global schemas name and type mapping.
pub schema_mapping: IndexMap<String, Arc<RefCell<SchemaType>>>,
/// For loop local vars.
pub local_vars: Vec<String>,
Expand Down Expand Up @@ -183,7 +184,8 @@ pub fn resolve_program_with_opts(
cached_scope.update(program);
resolver.scope_map = cached_scope.scope_map.clone();
resolver.scope_map.remove(kclvm_ast::MAIN_PKG);
resolver.node_ty_map = cached_scope.node_ty_map.clone()
resolver.node_ty_map = cached_scope.node_ty_map.clone();
resolver.ctx.schema_mapping = cached_scope.schema_mapping.clone();
}
}
let scope = resolver.check_and_lint(kclvm_ast::MAIN_PKG);
Expand All @@ -193,6 +195,7 @@ pub fn resolve_program_with_opts(
cached_scope.scope_map = scope.scope_map.clone();
cached_scope.node_ty_map = scope.node_ty_map.clone();
cached_scope.scope_map.remove(kclvm_ast::MAIN_PKG);
cached_scope.schema_mapping = resolver.ctx.schema_mapping;
}
}

Expand Down
4 changes: 4 additions & 0 deletions kclvm/sema/src/resolver/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::{
};

use crate::resolver::Resolver;
use crate::ty::SchemaType;
use crate::ty::TypeRef;
use crate::{builtin::BUILTIN_FUNCTIONS, ty::TypeInferMethods};
use kclvm_ast::ast::AstIndex;
Expand Down Expand Up @@ -284,6 +285,7 @@ impl Scope {
pub struct ProgramScope {
pub scope_map: IndexMap<String, Rc<RefCell<Scope>>>,
pub import_names: IndexMap<String, IndexMap<String, String>>,
pub schema_mapping: IndexMap<String, Arc<RefCell<SchemaType>>>,
pub node_ty_map: NodeTyMap,
pub handler: Handler,
}
Expand Down Expand Up @@ -508,6 +510,7 @@ pub type KCLScopeCache = Arc<Mutex<CachedScope>>;
pub struct CachedScope {
pub program_root: String,
pub scope_map: IndexMap<String, Rc<RefCell<Scope>>>,
pub schema_mapping: IndexMap<String, Arc<RefCell<SchemaType>>>,
pub node_ty_map: NodeTyMap,
dependency_graph: DependencyGraph,
}
Expand Down Expand Up @@ -672,6 +675,7 @@ impl CachedScope {
scope_map: scope.scope_map.clone(),
node_ty_map: scope.node_ty_map.clone(),
dependency_graph: DependencyGraph::default(),
schema_mapping: scope.schema_mapping.clone(),
};
let invalidated_pkgs = cached_scope.dependency_graph.update(program);
cached_scope.invalidate_cache(invalidated_pkgs.as_ref());
Expand Down
Loading