Skip to content

Commit

Permalink
Remove some duplocation of the Compiler interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hurryabit committed Dec 23, 2023
1 parent d7765f2 commit f11bfb6
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 20 deletions.
1 change: 1 addition & 0 deletions compiler/benches/run-cek.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use build::Compiler;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use homer_compiler::*;
use std::sync::Arc;
Expand Down
7 changes: 4 additions & 3 deletions compiler/src/bin/homer-ide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use tower_lsp::{Client, LanguageServer, LspService, Server};

use homer_compiler::{build, cek, checker, location, syntax};

use build::Compiler;
use checker::SymbolInfo;

// #[derive(Debug)]
Expand Down Expand Up @@ -136,7 +137,7 @@ impl LanguageServer for Backend {
let lsp_uri = params.text_document.uri;
log::info!("code_lens {lsp_uri}");
let uri = build::Uri::new(lsp_uri.as_str());
let lenses = if let Some(module) = db.checked_module(uri) {
let lenses = if let Some(module) = db.checked_module(uri).0 {
let mut lenses = Vec::new();
for decl in module.func_decls() {
if decl.expr_params.is_empty() {
Expand Down Expand Up @@ -202,7 +203,7 @@ impl Backend {
self.client.publish_diagnostics(lsp_uri, diagnostics, None).await;

if print_module {
if let Some(module) = db.checked_module(uri) {
if let Some(module) = db.checked_module(uri).0 {
log::debug!("{module:?}");
}
}
Expand All @@ -214,7 +215,7 @@ impl Backend {
) -> Option<SymbolInfo> {
let db = self.db.lock().await;
let uri = build::Uri::new(position_params.text_document.uri.as_str());
let symbols = db.symbols(uri);
let symbols = db.checked_module(uri).1;

let loc = location::SourceLocation::from_lsp(position_params.position);
// FIXME(MH): We should do a binary search here.
Expand Down
1 change: 1 addition & 0 deletions compiler/src/bin/homer-run.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use build::Compiler;
use homer_compiler::{build, cek, syntax};
use std::sync::Arc;

Expand Down
18 changes: 1 addition & 17 deletions compiler/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl fmt::Debug for Uri {
type CheckedModuleOutcome = (Option<Arc<Module>>, Arc<Vec<SymbolInfo>>, Arc<Vec<Diagnostic>>);

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

Expand Down Expand Up @@ -74,22 +74,6 @@ impl CompilerDB {
Self { storage: salsa::Storage::default() }
}

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

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

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

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

pub fn with_diagnostics<R, F>(&self, uri: Uri, f: F) -> R
where
F: FnOnce(&mut dyn Iterator<Item = &Diagnostic>) -> R,
Expand Down
1 change: 1 addition & 0 deletions compiler/src/tests/anf.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::build::Compiler;
use crate::build::*;
use std::sync::Arc;

Expand Down
1 change: 1 addition & 0 deletions compiler/src/tests/cek.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::*;
use build::Compiler;
use std::sync::Arc;

fn with_cek_result<R, F>(main: &str, input: &str, f: F) -> R
Expand Down

0 comments on commit f11bfb6

Please sign in to comment.