From 751430dd47988431d695c11832291008cd99ce79 Mon Sep 17 00:00:00 2001 From: he1pa <18012015693@163.com> Date: Thu, 16 May 2024 14:09:57 +0800 Subject: [PATCH] fix: fix resolver cache caused falsely report errors. Add schema mapping to resolver cache Signed-off-by: he1pa <18012015693@163.com> --- kclvm/sema/src/resolver/mod.rs | 7 +++++-- kclvm/sema/src/resolver/scope.rs | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/kclvm/sema/src/resolver/mod.rs b/kclvm/sema/src/resolver/mod.rs index b18c776f7..a49f1523b 100644 --- a/kclvm/sema/src/resolver/mod.rs +++ b/kclvm/sema/src/resolver/mod.rs @@ -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 { @@ -117,7 +118,7 @@ pub struct Context { pub pkgpath: String, /// What schema are we in. pub schema: Option>>, - /// What schema are we in. + /// Global schemas name and type mapping. pub schema_mapping: IndexMap>>, /// For loop local vars. pub local_vars: Vec, @@ -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); @@ -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; } } diff --git a/kclvm/sema/src/resolver/scope.rs b/kclvm/sema/src/resolver/scope.rs index 4edbdb468..e543af75a 100644 --- a/kclvm/sema/src/resolver/scope.rs +++ b/kclvm/sema/src/resolver/scope.rs @@ -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; @@ -284,6 +285,7 @@ impl Scope { pub struct ProgramScope { pub scope_map: IndexMap>>, pub import_names: IndexMap>, + pub schema_mapping: IndexMap>>, pub node_ty_map: NodeTyMap, pub handler: Handler, } @@ -508,6 +510,7 @@ pub type KCLScopeCache = Arc>; pub struct CachedScope { pub program_root: String, pub scope_map: IndexMap>>, + pub schema_mapping: IndexMap>>, pub node_ty_map: NodeTyMap, dependency_graph: DependencyGraph, } @@ -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());