Skip to content

Commit

Permalink
Make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
hurryabit committed Dec 22, 2023
1 parent 352d442 commit 603b153
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 30 deletions.
6 changes: 3 additions & 3 deletions compiler/benches/run-cek.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/ast/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
};
Expand Down
7 changes: 4 additions & 3 deletions compiler/src/bin/homer-ide.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -288,6 +288,7 @@ impl Server {
}
}

#[allow(clippy::type_complexity)]
fn dispatch_request<R: Request>(
&self,
request: lsp_server::Request,
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/bin/homer-run.rs
Original file line number Diff line number Diff line change
@@ -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<bool> {
Expand All @@ -10,8 +10,8 @@ fn run() -> std::io::Result<bool> {
};
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| {
Expand Down
28 changes: 14 additions & 14 deletions compiler/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -24,24 +24,24 @@ impl fmt::Debug for Uri {
}
}

type CheckedModuleOutcome = (Option<Arc<Module>>, Arc<Vec<SymbolInfo>>, Arc<Vec<Diagnostic>>);
type CheckedModuleOutcome = (Option<Rc<Module>>, Rc<Vec<SymbolInfo>>, Rc<Vec<Diagnostic>>);

#[salsa::query_group(CompilerStorage)]
trait Compiler: salsa::Database {
#[salsa::input]
fn input(&self, uri: Uri) -> Arc<String>;
fn input(&self, uri: Uri) -> Rc<String>;

fn parsed_module(&self, uri: Uri) -> (Option<Arc<Module>>, Arc<Vec<Diagnostic>>);
fn parsed_module(&self, uri: Uri) -> (Option<Rc<Module>>, Rc<Vec<Diagnostic>>);

fn checked_module(&self, uri: Uri) -> CheckedModuleOutcome;

fn anf_module(&self, uri: Uri) -> Option<Arc<anf::Module>>;
fn anf_module(&self, uri: Uri) -> Option<Rc<anf::Module>>;
}

fn parsed_module(db: &dyn Compiler, uri: Uri) -> (Option<Arc<Module>>, Arc<Vec<Diagnostic>>) {
fn parsed_module(db: &dyn Compiler, uri: Uri) -> (Option<Rc<Module>>, Rc<Vec<Diagnostic>>) {
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 {
Expand All @@ -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<Arc<anf::Module>> {
db.checked_module(uri).0.map(|checked_module| Arc::new(checked_module.to_anf()))
fn anf_module(db: &dyn Compiler, uri: Uri) -> Option<Rc<anf::Module>> {
db.checked_module(uri).0.map(|checked_module| Rc::new(checked_module.to_anf()))
}

#[salsa::database(CompilerStorage)]
Expand All @@ -74,19 +74,19 @@ impl CompilerDB {
Self { storage: salsa::Storage::default() }
}

pub fn set_input(&mut self, uri: Uri, input: Arc<String>) {
pub fn set_input(&mut self, uri: Uri, input: Rc<String>) {
(self as &mut dyn Compiler).set_input(uri, input);
}

pub fn checked_module(&self, uri: Uri) -> Option<Arc<Module>> {
pub fn checked_module(&self, uri: Uri) -> Option<Rc<Module>> {
(self as &dyn Compiler).checked_module(uri).0
}

pub fn symbols(&self, uri: Uri) -> Arc<Vec<SymbolInfo>> {
pub fn symbols(&self, uri: Uri) -> Rc<Vec<SymbolInfo>> {
(self as &dyn Compiler).checked_module(uri).1
}

pub fn anf_module(&self, uri: Uri) -> Option<Arc<anf::Module>> {
pub fn anf_module(&self, uri: Uri) -> Option<Rc<anf::Module>> {
(self as &dyn Compiler).anf_module(uri)
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/tests/anf.rs
Original file line number Diff line number Diff line change
@@ -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())
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/tests/build.rs
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/tests/cek.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::*;
use std::sync::Arc;
use std::rc::Rc;

fn with_cek_result<R, F>(main: &str, input: &str, f: F) -> R
where
F: FnOnce(&cek::MachineResult) -> R,
{
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");
Expand Down

0 comments on commit 603b153

Please sign in to comment.