Skip to content

Commit

Permalink
fix: fix resolver cache caused falsely report errors. Add schema mapp…
Browse files Browse the repository at this point in the history
…ing to resolver cache
  • Loading branch information
He1pa committed May 16, 2024
1 parent 9e3fc86 commit ed4bfb4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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

0 comments on commit ed4bfb4

Please sign in to comment.