diff --git a/compiler/benches/run-cek.rs b/compiler/benches/run-cek.rs index c69d0c7..16f27ee 100644 --- a/compiler/benches/run-cek.rs +++ b/compiler/benches/run-cek.rs @@ -1,6 +1,6 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use homer_compiler::*; -use std::sync::Arc; +use std::rc::Rc; use std::time::Duration; const ADDRESS_VAR: &str = "HOMER_BENCH"; @@ -24,8 +24,8 @@ pub fn criterion_benchmark(c: &mut Criterion) { let db = &mut build::CompilerDB::new(); let uri = build::Uri::new("bench.doh"); - let input = Arc::new(std::fs::read_to_string(std::path::Path::new(path)).unwrap()); - db.set_input(uri, Arc::clone(&input)); + let input = Rc::new(std::fs::read_to_string(std::path::Path::new(path)).unwrap()); + db.set_input(uri, Rc::clone(&input)); let mut success = true; db.with_diagnostics(uri, |diagnostics| { for diagnostic in diagnostics { diff --git a/compiler/src/ast/debug.rs b/compiler/src/ast/debug.rs index 9f22e03..6b4864f 100644 --- a/compiler/src/ast/debug.rs +++ b/compiler/src/ast/debug.rs @@ -135,7 +135,7 @@ macro_rules! derive_fmt_debug { ($type_name:ident) => { impl std::fmt::Debug for $type_name { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - crate::ast::DebugWriter::fmt(self, f) + $crate::ast::DebugWriter::fmt(self, f) } } }; diff --git a/compiler/src/bin/homer-ide.rs b/compiler/src/bin/homer-ide.rs index 642cab0..b3f7db3 100644 --- a/compiler/src/bin/homer-ide.rs +++ b/compiler/src/bin/homer-ide.rs @@ -1,5 +1,5 @@ use std::error::Error; -use std::sync::Arc; +use std::rc::Rc; use log::info; use lsp_server::{Connection, Message, Response}; @@ -123,7 +123,7 @@ impl Server { fn validate_document(&mut self, lsp_uri: Url, input: String, print_module: bool) -> Result<()> { let uri = build::Uri::new(lsp_uri.as_str()); info!("Received text for {:?}", uri); - self.db.set_input(uri, Arc::new(input)); + self.db.set_input(uri, Rc::new(input)); let diagnostics: Vec<_> = self.db.with_diagnostics(uri, |diagnostics| { diagnostics.map(homer_compiler::diagnostic::Diagnostic::to_lsp).collect() @@ -225,7 +225,7 @@ impl Server { }; let notification = lsp_server::Notification::new( ShowMessage::METHOD.to_owned(), - serde_json::to_value(&message_params)?, + serde_json::to_value(message_params)?, ); if let Err(error) = self.connection.sender.send(Message::from(notification)) { info!("Failed to send message: {:?}", error); @@ -288,6 +288,7 @@ impl Server { } } + #[allow(clippy::type_complexity)] fn dispatch_request( &self, request: lsp_server::Request, diff --git a/compiler/src/bin/homer-run.rs b/compiler/src/bin/homer-run.rs index 3c50a65..648ec2c 100644 --- a/compiler/src/bin/homer-run.rs +++ b/compiler/src/bin/homer-run.rs @@ -1,5 +1,5 @@ use homer_compiler::{build, cek, syntax}; -use std::sync::Arc; +use std::rc::Rc; #[allow(clippy::iter_nth_zero)] fn run() -> std::io::Result { @@ -10,8 +10,8 @@ fn run() -> std::io::Result { }; let db = &mut build::CompilerDB::new(); let uri = build::Uri::new(&path); - let input = Arc::new(std::fs::read_to_string(path)?); - db.set_input(uri, Arc::clone(&input)); + let input = Rc::new(std::fs::read_to_string(path)?); + db.set_input(uri, Rc::clone(&input)); let mut success = true; db.with_diagnostics(uri, |diagnostics| { diff --git a/compiler/src/build.rs b/compiler/src/build.rs index 45cc9bb..2f266a2 100644 --- a/compiler/src/build.rs +++ b/compiler/src/build.rs @@ -2,7 +2,7 @@ use crate::{anf, checker, diagnostic, syntax}; use checker::SymbolInfo; use diagnostic::Diagnostic; use std::fmt; -use std::sync::Arc; +use std::rc::Rc; use syntax::Module; #[derive(Copy, Clone, Eq, Hash, PartialEq)] @@ -24,24 +24,24 @@ impl fmt::Debug for Uri { } } -type CheckedModuleOutcome = (Option>, Arc>, Arc>); +type CheckedModuleOutcome = (Option>, Rc>, Rc>); #[salsa::query_group(CompilerStorage)] trait Compiler: salsa::Database { #[salsa::input] - fn input(&self, uri: Uri) -> Arc; + fn input(&self, uri: Uri) -> Rc; - fn parsed_module(&self, uri: Uri) -> (Option>, Arc>); + fn parsed_module(&self, uri: Uri) -> (Option>, Rc>); fn checked_module(&self, uri: Uri) -> CheckedModuleOutcome; - fn anf_module(&self, uri: Uri) -> Option>; + fn anf_module(&self, uri: Uri) -> Option>; } -fn parsed_module(db: &dyn Compiler, uri: Uri) -> (Option>, Arc>) { +fn parsed_module(db: &dyn Compiler, uri: Uri) -> (Option>, Rc>) { let input = db.input(uri); let (opt_parsed_module, diagnostics) = Module::parse(&input); - (opt_parsed_module.map(Arc::new), Arc::new(diagnostics)) + (opt_parsed_module.map(Rc::new), Rc::new(diagnostics)) } fn checked_module(db: &dyn Compiler, uri: Uri) -> CheckedModuleOutcome { @@ -52,11 +52,11 @@ fn checked_module(db: &dyn Compiler, uri: Uri) -> CheckedModuleOutcome { Ok((checked_module, symbols)) => (Some(checked_module), symbols, vec![]), }, }; - (opt_checked_module.map(Arc::new), Arc::new(symbols), Arc::new(diagnostics)) + (opt_checked_module.map(Rc::new), Rc::new(symbols), Rc::new(diagnostics)) } -fn anf_module(db: &dyn Compiler, uri: Uri) -> Option> { - db.checked_module(uri).0.map(|checked_module| Arc::new(checked_module.to_anf())) +fn anf_module(db: &dyn Compiler, uri: Uri) -> Option> { + db.checked_module(uri).0.map(|checked_module| Rc::new(checked_module.to_anf())) } #[salsa::database(CompilerStorage)] @@ -74,19 +74,19 @@ impl CompilerDB { Self { storage: salsa::Storage::default() } } - pub fn set_input(&mut self, uri: Uri, input: Arc) { + pub fn set_input(&mut self, uri: Uri, input: Rc) { (self as &mut dyn Compiler).set_input(uri, input); } - pub fn checked_module(&self, uri: Uri) -> Option> { + pub fn checked_module(&self, uri: Uri) -> Option> { (self as &dyn Compiler).checked_module(uri).0 } - pub fn symbols(&self, uri: Uri) -> Arc> { + pub fn symbols(&self, uri: Uri) -> Rc> { (self as &dyn Compiler).checked_module(uri).1 } - pub fn anf_module(&self, uri: Uri) -> Option> { + pub fn anf_module(&self, uri: Uri) -> Option> { (self as &dyn Compiler).anf_module(uri) } diff --git a/compiler/src/tests/anf.rs b/compiler/src/tests/anf.rs index 5cf0b58..05da845 100644 --- a/compiler/src/tests/anf.rs +++ b/compiler/src/tests/anf.rs @@ -1,10 +1,10 @@ use crate::build::*; -use std::sync::Arc; +use std::rc::Rc; fn anf_output(input: &str) -> String { let db = &mut CompilerDB::new(); let uri = Uri::new("foo.homer"); - db.set_input(uri, Arc::new(input.to_owned())); + db.set_input(uri, Rc::new(input.to_owned())); assert!(db.with_diagnostics(uri, |diagnostics| diagnostics.next().is_none())); format!("{:#?}", db.anf_module(uri).unwrap()) } diff --git a/compiler/src/tests/build.rs b/compiler/src/tests/build.rs index 31f5a4d..3d8ce43 100644 --- a/compiler/src/tests/build.rs +++ b/compiler/src/tests/build.rs @@ -1,11 +1,11 @@ use crate::build::*; -use std::sync::Arc; +use std::rc::Rc; fn build_output(input: &str) -> String { use std::fmt::Write; let db = &mut CompilerDB::new(); let uri = Uri::new("foo.homer"); - db.set_input(uri, Arc::new(input.to_owned())); + db.set_input(uri, Rc::new(input.to_owned())); let mut output = String::new(); match db.anf_module(uri) { diff --git a/compiler/src/tests/cek.rs b/compiler/src/tests/cek.rs index fe938b9..b534945 100644 --- a/compiler/src/tests/cek.rs +++ b/compiler/src/tests/cek.rs @@ -1,5 +1,5 @@ use crate::*; -use std::sync::Arc; +use std::rc::Rc; fn with_cek_result(main: &str, input: &str, f: F) -> R where @@ -7,7 +7,7 @@ where { let db = &mut build::CompilerDB::new(); let uri = build::Uri::new("test.doh"); - db.set_input(uri, Arc::new(input.to_string())); + db.set_input(uri, Rc::new(input.to_string())); assert_eq!(0, db.with_diagnostics(uri, |diagnostics| diagnostics.count())); let module = db.anf_module(uri).expect("module could not be compiled");