From f4b55f425d947fd7cef5e2acec05076b186062b3 Mon Sep 17 00:00:00 2001 From: never Date: Wed, 8 Nov 2023 15:24:34 +0800 Subject: [PATCH] feat: support increment parser Signed-off-by: never --- kclvm/parser/src/lib.rs | 75 +++++++-- kclvm/parser/src/tests.rs | 199 ++++++++++++++++++------ kclvm/query/src/override.rs | 2 +- kclvm/query/src/query.rs | 1 + kclvm/runner/benches/bench_runner.rs | 2 +- kclvm/runner/src/lib.rs | 4 +- kclvm/runner/src/tests.rs | 13 +- kclvm/sema/src/advanced_resolver/mod.rs | 6 +- kclvm/sema/src/namer/mod.rs | 1 + kclvm/sema/src/pre_process/tests.rs | 3 + kclvm/sema/src/resolver/tests.rs | 21 ++- kclvm/tools/src/LSP/src/util.rs | 2 +- kclvm/tools/src/lint/mod.rs | 2 +- 13 files changed, 257 insertions(+), 74 deletions(-) diff --git a/kclvm/parser/src/lib.rs b/kclvm/parser/src/lib.rs index 15214e76d..d01241808 100644 --- a/kclvm/parser/src/lib.rs +++ b/kclvm/parser/src/lib.rs @@ -15,6 +15,7 @@ pub use crate::session::ParseSession; use compiler_base_macros::bug; use compiler_base_session::Session; use compiler_base_span::span::new_byte_pos; +use indexmap::IndexMap; use kclvm_ast::ast; use kclvm_config::modfile::{get_vendor_home, KCL_FILE_EXTENSION, KCL_FILE_SUFFIX, KCL_MOD_FILE}; use kclvm_error::diagnostic::Range; @@ -26,6 +27,7 @@ use kclvm_utils::pkgpath::rm_external_pkg_name; use lexer::parse_token_streams; use parser::Parser; +use std::cell::RefCell; use std::collections::HashMap; use std::path::PathBuf; use std::sync::Arc; @@ -277,33 +279,62 @@ impl Default for LoadProgramOptions { } } +/// Load the KCL program by paths and options, +/// "module_cache" is used to cache parsed asts to support incremental parse, +/// if it is None, module caching will be disabled +/// +/// # Examples +/// +/// ``` +/// use kclvm_parser::{load_program, ParseSession}; +/// use kclvm_parser::KCLModuleCache; +/// use kclvm_ast::ast::Program; +/// use std::sync::Arc; +/// +/// // Create sessions +/// let sess = Arc::new(ParseSession::default()); +/// // Create module cache +/// let module_cache = KCLModuleCache::default(); +/// // Get default args +/// let args = ExecProgramArgs::default(); +/// let opts = args.get_load_program_options(); +/// +/// // Parse kcl file +/// let kcl_path = "./src/test_data/import-01.k"; +/// let prog = load_program(sess.clone(), &[kcl_path], Some(opts), Some(module_cache.clone())).unwrap(); +/// +/// ``` pub fn load_program( sess: Arc, paths: &[&str], opts: Option, + module_cache: Option, ) -> Result { - // todo: support cache - if let Some(opts) = opts { - Loader::new(sess, paths, Some(opts)).load_main() - } else { - Loader::new(sess, paths, None).load_main() - } + Loader::new(sess, paths, opts, module_cache).load_main() } +pub type KCLModuleCache = Arc>>; struct Loader { sess: Arc, paths: Vec, opts: LoadProgramOptions, missing_pkgs: Vec, + module_cache: Option, } impl Loader { - fn new(sess: Arc, paths: &[&str], opts: Option) -> Self { + fn new( + sess: Arc, + paths: &[&str], + opts: Option, + module_cache: Option>>>, + ) -> Self { Self { sess, paths: paths.iter().map(|s| s.to_string()).collect(), opts: opts.unwrap_or_default(), missing_pkgs: Default::default(), + module_cache, } } @@ -329,8 +360,18 @@ impl Loader { // load module for (i, filename) in k_files.iter().enumerate() { - let mut m = - parse_file_with_session(self.sess.clone(), filename, maybe_k_codes[i].clone())?; + let mut m = if let Some(module_cache) = self.module_cache.as_ref() { + let m = parse_file_with_session( + self.sess.clone(), + filename, + maybe_k_codes[i].clone(), + )?; + let mut module_cache_ref = module_cache.borrow_mut(); + module_cache_ref.insert(filename.clone(), m.clone()); + m + } else { + parse_file_with_session(self.sess.clone(), filename, maybe_k_codes[i].clone())? + }; self.fix_rel_import_path(entry.path(), &mut m); pkg_files.push(m); } @@ -532,7 +573,21 @@ impl Loader { let mut pkg_files = Vec::new(); let k_files = pkg_info.k_files.clone(); for filename in k_files { - let mut m = parse_file_with_session(self.sess.clone(), filename.as_str(), None)?; + let mut m = if let Some(module_cache) = self.module_cache.as_ref() { + let module_cache_ref = module_cache.borrow(); + if let Some(module) = module_cache_ref.get(&filename) { + module.clone() + } else { + let m = parse_file_with_session(self.sess.clone(), &filename, None)?; + drop(module_cache_ref); + let mut module_cache_ref = module_cache.borrow_mut(); + module_cache_ref.insert(filename.clone(), m.clone()); + m + } + } else { + parse_file_with_session(self.sess.clone(), &filename, None)? + }; + //let mut m = parse_file_with_session(self.sess.clone(), filename.as_str(), None)?; m.pkg = pkg_info.pkg_path.clone(); m.name = "".to_string(); diff --git a/kclvm/parser/src/tests.rs b/kclvm/parser/src/tests.rs index 038692bf3..b225fd5ca 100644 --- a/kclvm/parser/src/tests.rs +++ b/kclvm/parser/src/tests.rs @@ -243,6 +243,7 @@ fn test_in_order() { } pub fn test_import_vendor() { + let module_cache = KCLModuleCache::default(); let vendor = set_vendor_home(); let sm = SourceMap::new(FilePathMapping::empty()); let sess = Arc::new(ParseSession::with_source_map(Arc::new(sm))); @@ -285,27 +286,36 @@ pub fn test_import_vendor() { .canonicalize() .unwrap(); - test_cases.into_iter().for_each(|(test_case_name, pkgs)| { - let test_case_path = dir.join(test_case_name).display().to_string(); - let m = load_program(sess.clone(), &[&test_case_path], None).unwrap(); - assert_eq!(m.pkgs.len(), pkgs.len()); - m.pkgs.into_iter().for_each(|(name, modules)| { - println!("{:?} - {:?}", test_case_name, name); - assert!(pkgs.contains(&name.as_str())); - for pkg in pkgs.clone() { - if name == pkg { - if name == "__main__" { - assert_eq!(modules.len(), 1); - assert_eq!(modules.get(0).unwrap().filename, test_case_path); - } else { - modules.into_iter().for_each(|module| { - assert!(module.filename.contains(&vendor)); - }); + let test_fn = + |test_case_name: &&str, pkgs: &Vec<&str>, module_cache: Option| { + let test_case_path = dir.join(test_case_name).display().to_string(); + let m = load_program(sess.clone(), &[&test_case_path], None, module_cache).unwrap(); + assert_eq!(m.pkgs.len(), pkgs.len()); + m.pkgs.into_iter().for_each(|(name, modules)| { + println!("{:?} - {:?}", test_case_name, name); + assert!(pkgs.contains(&name.as_str())); + for pkg in pkgs.clone() { + if name == pkg { + if name == "__main__" { + assert_eq!(modules.len(), 1); + assert_eq!(modules.get(0).unwrap().filename, test_case_path); + } else { + modules.into_iter().for_each(|module| { + assert!(module.filename.contains(&vendor)); + }); + } + break; } - break; } - } - }); + }); + }; + + test_cases + .iter() + .for_each(|(test_case_name, pkgs)| test_fn(test_case_name, pkgs, None)); + + test_cases.iter().for_each(|(test_case_name, pkgs)| { + test_fn(test_case_name, pkgs, Some(module_cache.clone())) }); } @@ -323,7 +333,7 @@ pub fn test_import_vendor_without_kclmod() { test_cases.into_iter().for_each(|(test_case_name, pkgs)| { let test_case_path = dir.join(test_case_name).display().to_string(); - let m = load_program(sess.clone(), &[&test_case_path], None).unwrap(); + let m = load_program(sess.clone(), &[&test_case_path], None, None).unwrap(); assert_eq!(m.pkgs.len(), pkgs.len()); m.pkgs.into_iter().for_each(|(name, modules)| { assert!(pkgs.contains(&name.as_str())); @@ -354,7 +364,29 @@ pub fn test_import_vendor_without_vendor_home() { .canonicalize() .unwrap(); let test_case_path = dir.join("assign.k").display().to_string(); - match load_program(sess.clone(), &[&test_case_path], None) { + match load_program(sess.clone(), &[&test_case_path], None, None) { + Ok(_) => { + let errors = sess.classification().0; + let msgs = [ + "pkgpath assign not found in the program", + "pkgpath assign.assign not found in the program", + ]; + assert_eq!(errors.len(), msgs.len()); + for (diag, m) in errors.iter().zip(msgs.iter()) { + assert_eq!(diag.messages[0].message, m.to_string()); + } + } + Err(_) => { + panic!("Unreachable code.") + } + } + + match load_program( + sess.clone(), + &[&test_case_path], + None, + Some(KCLModuleCache::default()), + ) { Ok(_) => { let errors = sess.classification().0; let msgs = [ @@ -382,7 +414,27 @@ fn test_import_vendor_with_same_internal_pkg() { .canonicalize() .unwrap(); let test_case_path = dir.join("same_name.k").display().to_string(); - match load_program(sess.clone(), &[&test_case_path], None) { + match load_program(sess.clone(), &[&test_case_path], None, None) { + Ok(_) => { + let errors = sess.classification().0; + let msgs = [ + "the `same_vendor` is found multiple times in the current package and vendor package" + ]; + assert_eq!(errors.len(), msgs.len()); + for (diag, m) in errors.iter().zip(msgs.iter()) { + assert_eq!(diag.messages[0].message, m.to_string()); + } + } + Err(_) => { + panic!("Unreachable code.") + } + } + match load_program( + sess.clone(), + &[&test_case_path], + None, + Some(KCLModuleCache::default()), + ) { Ok(_) => { let errors = sess.classification().0; let msgs = [ @@ -409,7 +461,28 @@ fn test_import_vendor_without_kclmod_and_same_name() { .canonicalize() .unwrap(); let test_case_path = dir.join("assign.k").display().to_string(); - match load_program(sess.clone(), &[&test_case_path], None) { + match load_program(sess.clone(), &[&test_case_path], None, None) { + Ok(_) => { + let errors = sess.classification().0; + let msgs = [ + "the `assign` is found multiple times in the current package and vendor package", + ]; + assert_eq!(errors.len(), msgs.len()); + for (diag, m) in errors.iter().zip(msgs.iter()) { + assert_eq!(diag.messages[0].message, m.to_string()); + } + } + Err(_) => { + panic!("Unreachable code.") + } + } + + match load_program( + sess.clone(), + &[&test_case_path], + None, + Some(KCLModuleCache::default()), + ) { Ok(_) => { let errors = sess.classification().0; let msgs = [ @@ -430,7 +503,7 @@ fn test_import_vendor_by_external_arguments() { let vendor = set_vendor_home(); let sm = SourceMap::new(FilePathMapping::empty()); let sess = Arc::new(ParseSession::with_source_map(Arc::new(sm))); - + let module_cache = KCLModuleCache::default(); let external_dir = &PathBuf::from(".") .join("testdata") .join("test_vendor") @@ -480,34 +553,45 @@ fn test_import_vendor_by_external_arguments() { .canonicalize() .unwrap(); - test_cases - .into_iter() - .for_each(|(test_case_name, dep_name, pkgs)| { - let mut opts = LoadProgramOptions::default(); - opts.package_maps.insert( - dep_name.to_string(), - external_dir.join(dep_name).display().to_string(), - ); - let test_case_path = dir.join(test_case_name).display().to_string(); - let m = load_program(sess.clone(), &[&test_case_path], None).unwrap(); + let test_fn = |test_case_name: &&str, + dep_name: &&str, + pkgs: &Vec<&str>, + module_cache: Option| { + let mut opts = LoadProgramOptions::default(); + opts.package_maps.insert( + dep_name.to_string(), + external_dir.join(dep_name).display().to_string(), + ); + let test_case_path = dir.join(test_case_name).display().to_string(); + let m = load_program(sess.clone(), &[&test_case_path], None, module_cache).unwrap(); - assert_eq!(m.pkgs.len(), pkgs.len()); - m.pkgs.into_iter().for_each(|(name, modules)| { - assert!(pkgs.contains(&name.as_str())); - for pkg in pkgs.clone() { - if name == pkg { - if name == "__main__" { - assert_eq!(modules.len(), 1); - assert_eq!(modules.get(0).unwrap().filename, test_case_path); - } else { - modules.into_iter().for_each(|module| { - assert!(module.filename.contains(&vendor)); - }); - } - break; + assert_eq!(m.pkgs.len(), pkgs.len()); + m.pkgs.into_iter().for_each(|(name, modules)| { + assert!(pkgs.contains(&name.as_str())); + for pkg in pkgs.clone() { + if name == pkg { + if name == "__main__" { + assert_eq!(modules.len(), 1); + assert_eq!(modules.get(0).unwrap().filename, test_case_path); + } else { + modules.into_iter().for_each(|module| { + assert!(module.filename.contains(&vendor)); + }); } + break; } - }); + } + }); + }; + + test_cases + .iter() + .for_each(|(test_case_name, dep_name, pkgs)| test_fn(test_case_name, dep_name, pkgs, None)); + + test_cases + .iter() + .for_each(|(test_case_name, dep_name, pkgs)| { + test_fn(test_case_name, dep_name, pkgs, Some(module_cache.clone())) }); } @@ -595,7 +679,22 @@ fn test_dir_with_k_code_list() { let mut opts = LoadProgramOptions::default(); opts.k_code_list = vec!["test_code = 1".to_string()]; - match load_program(sess.clone(), &[&testpath.display().to_string()], Some(opts)) { + match load_program( + sess.clone(), + &[&testpath.display().to_string()], + Some(opts.clone()), + None, + ) { + Ok(_) => panic!("unreachable code"), + Err(err) => assert_eq!(err, "Invalid code list"), + } + + match load_program( + sess.clone(), + &[&testpath.display().to_string()], + Some(opts), + Some(KCLModuleCache::default()), + ) { Ok(_) => panic!("unreachable code"), Err(err) => assert_eq!(err, "Invalid code list"), } diff --git a/kclvm/query/src/override.rs b/kclvm/query/src/override.rs index 091258968..9a3c284bd 100644 --- a/kclvm/query/src/override.rs +++ b/kclvm/query/src/override.rs @@ -29,7 +29,7 @@ const IMPORT_STMT_COLUMN_OFFSET: u64 = 1; /// use kclvm_parser::load_program; /// use kclvm_tools::query::r#override::apply_overrides; /// -/// let mut prog = load_program(&["config.k"], None).unwrap(); +/// let mut prog = load_program(&["config.k"], None, None).unwrap(); /// let overrides = vec![parse_override_spec("config.id=1").unwrap()]; /// let import_paths = vec!["path.to.pkg".to_string()]; /// let result = apply_overrides(&mut prog, &overrides, &import_paths, true).unwrap(); diff --git a/kclvm/query/src/query.rs b/kclvm/query/src/query.rs index 733debfe2..7cfca5e84 100644 --- a/kclvm/query/src/query.rs +++ b/kclvm/query/src/query.rs @@ -115,6 +115,7 @@ fn resolve_file(file: &str, code: Option<&str>) -> Result>> { k_code_list: vec![c.to_string()], ..Default::default() }), + None, ) { Ok(p) => p, Err(err) => { diff --git a/kclvm/runner/benches/bench_runner.rs b/kclvm/runner/benches/bench_runner.rs index c75311fdb..5863d35f6 100644 --- a/kclvm/runner/benches/bench_runner.rs +++ b/kclvm/runner/benches/bench_runner.rs @@ -35,7 +35,7 @@ fn exec(file: &str) -> Result { let opts = args.get_load_program_options(); let sess = Arc::new(ParseSession::default()); // Load AST program - let program = load_program(sess.clone(), &[file], Some(opts)).unwrap(); + let program = load_program(sess.clone(), &[file], Some(opts), None).unwrap(); // Resolve ATS, generate libs, link libs and execute. execute(sess, program, &args) } diff --git a/kclvm/runner/src/lib.rs b/kclvm/runner/src/lib.rs index ddb2f3d8a..8142e5d26 100644 --- a/kclvm/runner/src/lib.rs +++ b/kclvm/runner/src/lib.rs @@ -83,7 +83,7 @@ pub fn exec_program( let kcl_paths_str = kcl_paths.iter().map(|s| s.as_str()).collect::>(); - let mut program = load_program(sess.clone(), kcl_paths_str.as_slice(), Some(opts))?; + let mut program = load_program(sess.clone(), kcl_paths_str.as_slice(), Some(opts), None)?; if let Err(err) = apply_overrides( &mut program, @@ -187,7 +187,7 @@ pub fn exec_program( /// /// // Parse kcl file /// let kcl_path = "./src/test_datas/init_check_order_0/main.k"; -/// let prog = load_program(sess.clone(), &[kcl_path], Some(opts)).unwrap(); +/// let prog = load_program(sess.clone(), &[kcl_path], Some(opts), None).unwrap(); /// /// // Resolve ast, generate libs, link libs and execute. /// // Result is the kcl in json format. diff --git a/kclvm/runner/src/tests.rs b/kclvm/runner/src/tests.rs index a8017ae93..c7bc747a3 100644 --- a/kclvm/runner/src/tests.rs +++ b/kclvm/runner/src/tests.rs @@ -151,6 +151,7 @@ fn parse_program(test_kcl_case_path: &str) -> Program { Arc::new(ParseSession::default()), &[test_kcl_case_path], Some(opts), + None, ) .unwrap() } @@ -261,7 +262,7 @@ fn assemble_lib_for_test( let opts = args.get_load_program_options(); let sess = Arc::new(ParseSession::default()); // parse and resolve kcl - let mut program = load_program(sess, &files, Some(opts)).unwrap(); + let mut program = load_program(sess, &files, Some(opts), None).unwrap(); let scope = resolve_program(&mut program); @@ -513,7 +514,13 @@ fn test_compile_dir_recursive() { opts.recursive = true; let sess = Arc::new(ParseSession::default()); // Load AST program - let program = load_program(sess.clone(), &[&path.display().to_string()], Some(opts)).unwrap(); + let program = load_program( + sess.clone(), + &[&path.display().to_string()], + Some(opts), + None, + ) + .unwrap(); // Resolve ATS, generate libs, link libs and execute. let res = execute(sess, program, &args); assert!(res.is_ok()); @@ -562,7 +569,7 @@ fn exec(file: &str) -> Result { let opts = args.get_load_program_options(); let sess = Arc::new(ParseSession::default()); // Load AST program - let program = load_program(sess.clone(), &[file], Some(opts)).unwrap(); + let program = load_program(sess.clone(), &[file], Some(opts), None).unwrap(); // Resolve ATS, generate libs, link libs and execute. execute(sess, program, &args) } diff --git a/kclvm/sema/src/advanced_resolver/mod.rs b/kclvm/sema/src/advanced_resolver/mod.rs index 6801fbdb5..e9bef6edc 100644 --- a/kclvm/sema/src/advanced_resolver/mod.rs +++ b/kclvm/sema/src/advanced_resolver/mod.rs @@ -261,7 +261,7 @@ mod tests { let path = "src/advanced_resolver/test_data/schema_symbols.k" .to_string() .replace("/", &std::path::MAIN_SEPARATOR.to_string()); - let mut program = load_program(sess.clone(), &[&path], None).unwrap(); + let mut program = load_program(sess.clone(), &[&path], None, None).unwrap(); let gs = GlobalState::default(); let gs = Namer::find_symbols(&program, gs); let node_ty_map = resolver::resolve_program(&mut program).node_ty_map; @@ -1129,7 +1129,7 @@ mod tests { let path = "src/advanced_resolver/test_data/schema_symbols.k" .to_string() .replace("/", &std::path::MAIN_SEPARATOR.to_string()); - let mut program = load_program(sess.clone(), &[&path], None).unwrap(); + let mut program = load_program(sess.clone(), &[&path], None, None).unwrap(); let gs = GlobalState::default(); let gs = Namer::find_symbols(&program, gs); let node_ty_map = resolver::resolve_program(&mut program).node_ty_map; @@ -1205,7 +1205,7 @@ mod tests { let path = "src/advanced_resolver/test_data/schema_symbols.k" .to_string() .replace("/", &std::path::MAIN_SEPARATOR.to_string()); - let mut program = load_program(sess.clone(), &[&path], None).unwrap(); + let mut program = load_program(sess.clone(), &[&path], None, None).unwrap(); let gs = GlobalState::default(); let gs = Namer::find_symbols(&program, gs); let node_ty_map = resolver::resolve_program(&mut program).node_ty_map; diff --git a/kclvm/sema/src/namer/mod.rs b/kclvm/sema/src/namer/mod.rs index d4d068510..5c063e8c6 100644 --- a/kclvm/sema/src/namer/mod.rs +++ b/kclvm/sema/src/namer/mod.rs @@ -156,6 +156,7 @@ mod tests { sess.clone(), &["./src/namer/test_data/schema_symbols.k"], None, + None, ) .unwrap(); let gs = GlobalState::default(); diff --git a/kclvm/sema/src/pre_process/tests.rs b/kclvm/sema/src/pre_process/tests.rs index 7fa527f4d..2af8fdb43 100644 --- a/kclvm/sema/src/pre_process/tests.rs +++ b/kclvm/sema/src/pre_process/tests.rs @@ -72,6 +72,7 @@ fn test_config_merge() { "./src/pre_process/test_data/config_merge/config2.k", ], None, + None, ) .unwrap(); merge_program(&mut program); @@ -113,6 +114,7 @@ fn test_config_override() { sess, &["./src/pre_process/test_data/config_override.k"], None, + None, ) .unwrap(); merge_program(&mut program); @@ -156,6 +158,7 @@ fn test_skip_merge_program() { "./src/pre_process/test_data/config_merge/config2.k", ], None, + None, ) .unwrap(); // skip merge program and save raw config ast node diff --git a/kclvm/sema/src/resolver/tests.rs b/kclvm/sema/src/resolver/tests.rs index a7335a322..576650634 100644 --- a/kclvm/sema/src/resolver/tests.rs +++ b/kclvm/sema/src/resolver/tests.rs @@ -52,6 +52,7 @@ fn test_pkg_init_in_schema_resolve() { sess.clone(), &["./src/resolver/test_data/pkg_init_in_schema.k"], None, + None, ) .unwrap(); let scope = resolve_program(&mut program); @@ -115,6 +116,7 @@ fn test_resolve_program_redefine() { sess.clone(), &["./src/resolver/test_fail_data/redefine_import/main.k"], None, + None, ) .unwrap(); @@ -153,6 +155,7 @@ fn test_resolve_program_cycle_reference_fail() { sess.clone(), &["./src/resolver/test_fail_data/cycle_reference/file1.k"], None, + None, ) .unwrap(); let scope = resolve_program(&mut program); @@ -178,6 +181,7 @@ fn test_record_used_module() { sess.clone(), &["./src/resolver/test_data/record_used_module.k"], None, + None, ) .unwrap(); let scope = resolve_program(&mut program); @@ -292,8 +296,13 @@ fn test_resolve_program_module_optional_select_fail() { #[test] fn test_lint() { let sess = Arc::new(ParseSession::default()); - let mut program = - load_program(sess.clone(), &["./src/resolver/test_data/lint.k"], None).unwrap(); + let mut program = load_program( + sess.clone(), + &["./src/resolver/test_data/lint.k"], + None, + None, + ) + .unwrap(); let opts = Options::default(); pre_process_program(&mut program, &opts); let mut resolver = Resolver::new(&program, opts); @@ -436,6 +445,7 @@ fn test_pkg_scope() { sess.clone(), &["./src/resolver/test_data/pkg_scope.k"], None, + None, ) .unwrap(); let scope = resolve_program(&mut program); @@ -485,6 +495,7 @@ fn test_system_package() { sess.clone(), &["./src/resolver/test_data/system_package.k"], None, + None, ) .unwrap(); let scope = resolve_program(&mut program); @@ -517,6 +528,7 @@ fn test_resolve_program_import_suggest() { sess.clone(), &["./src/resolver/test_fail_data/not_found_suggest/main.k"], None, + None, ) .unwrap(); let scope = resolve_program(&mut program); @@ -540,6 +552,7 @@ fn test_resolve_assignment_in_lambda() { sess.clone(), &["./src/resolver/test_data/assign_in_lambda.k"], None, + None, ) .unwrap(); let scope = resolve_program(&mut program); @@ -558,6 +571,7 @@ fn test_resolve_function_with_default_values() { sess.clone(), &["./src/resolver/test_data/function_with_default_values.k"], None, + None, ) .unwrap(); let scope = resolve_program(&mut program); @@ -590,6 +604,7 @@ fn test_assignment_type_annotation_check_in_lambda() { sess.clone(), &["./src/resolver/test_data/annotation_check_assignment.k"], Some(opts), + None, ) .unwrap(); let scope = resolve_program(&mut program); @@ -603,6 +618,7 @@ fn test_resolve_lambda_assignment_diagnostic() { sess.clone(), &["./src/resolver/test_fail_data/lambda_ty_error.k"], None, + None, ) .unwrap(); let scope = resolve_program(&mut program); @@ -623,6 +639,7 @@ fn test_ty_check_in_dict_assign_to_schema() { sess.clone(), &["./src/resolver/test_data/attr_ty_check.k"], None, + None, ) .unwrap(); let scope = resolve_program(&mut program); diff --git a/kclvm/tools/src/LSP/src/util.rs b/kclvm/tools/src/LSP/src/util.rs index 06d5d92cf..ebf113a90 100644 --- a/kclvm/tools/src/LSP/src/util.rs +++ b/kclvm/tools/src/LSP/src/util.rs @@ -81,7 +81,7 @@ pub(crate) fn parse_param_and_compile( opt.k_code_list.append(&mut k_code_list); } let sess = Arc::new(ParseSession::default()); - let mut program = load_program(sess.clone(), &files, Some(opt)) + let mut program = load_program(sess.clone(), &files, Some(opt), None) .map_err(|err| anyhow::anyhow!("Compile failed: {}", err))?; let prog_scope = resolve_program_with_opts( diff --git a/kclvm/tools/src/lint/mod.rs b/kclvm/tools/src/lint/mod.rs index d60aac176..6d4cdc719 100644 --- a/kclvm/tools/src/lint/mod.rs +++ b/kclvm/tools/src/lint/mod.rs @@ -73,7 +73,7 @@ pub fn lint_files( let sess = Arc::new(ParseSession::default()); let mut opts = opts.unwrap_or_default(); opts.load_plugins = true; - let mut program = match load_program(sess.clone(), files, Some(opts)) { + let mut program = match load_program(sess.clone(), files, Some(opts), None) { Ok(p) => p, Err(err_str) => { return Handler::default()