diff --git a/planglib/core/coro.pi b/planglib/core/coro.pi index b91484fd..527f2d63 100644 --- a/planglib/core/coro.pi +++ b/planglib/core/coro.pi @@ -31,8 +31,8 @@ pub fn new_coro(f: ||=>void) Coroutine { return Coroutine{ctx:ctx, stack:p, f:f}; } -fn create_mutex() *mutex::Mutex { - let m :*mutex::Mutex ; +fn create_mutex() *mutex::MutexHandle { + let m :*mutex::MutexHandle ; let mm = &m; mutex::create_mutex(mm); return *mm; diff --git a/src/ast/compiler.rs b/src/ast/compiler.rs index 64ad3267..84a18cac 100644 --- a/src/ast/compiler.rs +++ b/src/ast/compiler.rs @@ -1,4 +1,3 @@ -use super::node::program::cycle_deps_recover; use super::node::program::ModWrapper; use super::node::program::ASSET_PATH; #[cfg(feature = "llvm")] @@ -151,7 +150,7 @@ pub fn compile_dry<'db>(db: &'db dyn Db, docs: MemDocsInput) -> Result( db: &'db dyn Db, parser_entry: FileCompileInput<'db>, diff --git a/src/ast/expects/test_diag.pi.expect b/src/ast/expects/test_diag.pi.expect index edfffd90..3209e49c 100644 --- a/src/ast/expects/test_diag.pi.expect +++ b/src/ast/expects/test_diag.pi.expect @@ -1206,6 +1206,45 @@ }, }, }, + PLDiag { + raw: PLDiagRaw { + code: Err( + ONLY_TASK_CAN_BE_AWAIT, + ), + help: None, + labels: [ + PLLabel { + file: u!(""), + txt: None, + range: Range { + start: Pos { + line: 164, + column: 11, + offset: 1731, + }, + end: Pos { + line: 164, + column: 23, + offset: 1743, + }, + }, + }, + ], + source: None, + range: Range { + start: Pos { + line: 164, + column: 5, + offset: 1725, + }, + end: Pos { + line: 164, + column: 23, + offset: 1743, + }, + }, + }, + }, PLDiag { raw: PLDiagRaw { code: Err( @@ -1230,6 +1269,45 @@ }, }, }, + PLDiag { + raw: PLDiagRaw { + code: Err( + ONLY_AWAIT_IN_ASYNC_FN, + ), + help: None, + labels: [ + PLLabel { + file: u!(""), + txt: None, + range: Range { + start: Pos { + line: 164, + column: 11, + offset: 1731, + }, + end: Pos { + line: 164, + column: 23, + offset: 1743, + }, + }, + }, + ], + source: None, + range: Range { + start: Pos { + line: 164, + column: 5, + offset: 1725, + }, + end: Pos { + line: 164, + column: 23, + offset: 1743, + }, + }, + }, + }, PLDiag { raw: PLDiagRaw { code: Warn( diff --git a/src/ast/node/program.rs b/src/ast/node/program.rs index 2f3bf977..4b28b4da 100644 --- a/src/ast/node/program.rs +++ b/src/ast/node/program.rs @@ -180,9 +180,6 @@ lazy_static::lazy_static! { }; } -mod cycle; -pub use cycle::*; - fn import_symbol( s: Ustr, x: &GlobalType, @@ -450,7 +447,7 @@ impl<'db> Program<'db> { /// `emit` function analyzes all submodules used by the current program, /// resolves all symbols from submodules into the current one, /// and compiles the current module with all sub-modules into LLVM IR or does some LSP works - #[salsa::tracked(recovery_fn=cycle_deps_recover_emit)] + #[salsa::tracked] pub fn emit(self, db: &'db dyn Db) -> ModWrapper<'db> { #[cfg(not(target_arch = "wasm32"))] let (job, pb) = if self.params(db).action(db) == ActionType::Compile { diff --git a/src/ast/node/program/cycle.rs b/src/ast/node/program/cycle.rs deleted file mode 100644 index 85f37533..00000000 --- a/src/ast/node/program/cycle.rs +++ /dev/null @@ -1,132 +0,0 @@ -use crate::ast::accumulators::Diagnostics; -use crate::ast::diag::ErrorCode; -use crate::ast::node::NodeEnum; -use crate::ast::range::Range; -use crate::utils::read_config::ConfigWrapper; - -use super::{ModWrapper, Program, ProgramNode}; - -use crate::ast::plmod::Mod; - -use crate::format_label; - -use rustc_hash::FxHashMap; -use salsa::plumbing::FromId; -use salsa::Accumulator; -// use salsa::AsId; -use ustr::ustr; - -use crate::lsp::mem_docs::FileCompileInput; - -use crate::Db; - -pub fn cycle_deps_recover_emit<'db>( - db: &'db dyn Db, - _: &salsa::Cycle, - p: Program<'db>, -) -> ModWrapper<'db> { - ModWrapper::new( - db, - Mod::new(ustr(p.params(db).file(db)), Default::default()), - ) -} - -pub fn cycle_deps_recover<'db>( - db: &'db dyn Db, - cycle: &salsa::Cycle, - i: FileCompileInput, -) -> Option> { - let key = cycle.all_participants(db.as_dyn_database()); - let mut files = FxHashMap::default(); - let mut prev_use_map = FxHashMap::default(); - let params = cycle - .participant_keys() - .enumerate() - .filter(|(i, _)| { - let key = key[*i]; - let name = db.ingredient_debug_name(key.ingredient_index()); - name != "compile_dry_file" - }) - .map(|(_, k)| Program::from_id(k.key_index())) - .last() - .unwrap(); - - let src_file_path = i.file(db); - let mut prev_file = src_file_path; - build_init_params(params, db, &mut prev_use_map); - let filtered = cycle.participant_keys().enumerate().filter(|(i, _)| { - let key = key[*i]; - let name = db.ingredient_debug_name(key.ingredient_index()); - name != "compile_dry_file" - }); - let len = filtered.count(); - while files.len() < len { - for (_, p) in cycle - .participant_keys() - .enumerate() - .filter(|(i, _)| { - let key = key[*i]; - let name = db.ingredient_debug_name(key.ingredient_index()); - name != "compile_dry_file" - }) - .map(|(u, k)| (u, Program::from_id(k.key_index()))) - { - let prog = match_node(p, db); - if let Some(r) = prev_use_map.get(p.params(db).file(db)) { - files.insert(prev_file, *r); - prev_file = p.params(db).file(db); - prev_use_map.clear(); - build_use_map(prog, db, p, &mut prev_use_map); - } - } - } - - let first_range = *files.get(&src_file_path).unwrap(); - let mut diag = first_range.new_err(ErrorCode::CYCLE_DEPENDENCY); - diag.set_source(src_file_path); - for (f, r) in files.iter() { - let msg = "import in cycle here"; - diag.add_label(*r, ustr(f), format_label!(msg)); - } - Diagnostics((src_file_path.to_string(), vec![diag])).accumulate(db); - db.report_untracked_read(); - Some(ModWrapper::new( - db, - Mod::new(ustr(src_file_path), Default::default()), - )) -} - -pub(crate) fn build_init_params( - params: Program, - db: &dyn Db, - prev_use_map: &mut FxHashMap, -) { - let prog = match_node(params, db); - build_use_map(prog, db, params, prev_use_map); -} - -pub(crate) fn match_node(params: Program, db: &dyn Db) -> ProgramNode { - match *params.entry_node(db).node(db) { - NodeEnum::Program(p) => p, - _ => panic!("not a program"), - } -} - -pub(crate) fn build_use_map( - prog: ProgramNode, - db: &dyn Db, - params: Program, - prev_use_map: &mut FxHashMap, -) { - for u in prog.uses.iter() { - let u = if let NodeEnum::UseNode(p) = *u.clone() { - p - } else { - continue; - }; - let range = u.range; - let wrapper = ConfigWrapper::new(db, params.config(db), u); - let path = wrapper.resolve_dep_path(db); - prev_use_map.insert(path.to_str().unwrap().to_string(), range); - } -} diff --git a/test/lsp_diag/test_diag.pi b/test/lsp_diag/test_diag.pi index 4fd90d71..5ee0a697 100644 --- a/test/lsp_diag/test_diag.pi +++ b/test/lsp_diag/test_diag.pi @@ -161,7 +161,7 @@ fn test_f_diag2(,) { } fn test_f_diag3(a, b:i64) void { - + await test_f_diag2(); return; }