Skip to content

Commit

Permalink
feat: Use salsa for incremental compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Oct 1, 2019
1 parent 039825a commit 7bc8253
Show file tree
Hide file tree
Showing 42 changed files with 1,234 additions and 750 deletions.
119 changes: 116 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ itertools = "0.8"
futures = "0.1.11"
codespan = "0.3"
codespan-reporting = "0.3"
salsa = { version = "0.13", path = "../salsa" }

serde = { version = "1.0.0", optional = true }
serde_state = { version = "0.4", optional = true }
Expand Down
17 changes: 16 additions & 1 deletion base/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use codespan_reporting::{Diagnostic, Label};
use crate::pos::{BytePos, Span, Spanned};

/// An error type which can represent multiple errors.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct Errors<T> {
errors: Vec<T>,
}
Expand Down Expand Up @@ -159,6 +159,8 @@ pub struct InFile<E> {
error: Errors<Spanned<E, BytePos>>,
}

impl<E> Eq for InFile<E> where E: Eq {}

impl<E> PartialEq for InFile<E>
where
E: PartialEq,
Expand All @@ -168,6 +170,19 @@ where
}
}

impl<E> std::hash::Hash for InFile<E>
where
E: std::hash::Hash,
{
#[inline(always)]
fn hash<H>(&self, state: &mut H)
where
H: std::hash::Hasher,
{
self.error.hash(state)
}
}

impl<E: fmt::Display> InFile<E> {
/// Creates a new `InFile` error which states that the error occurred in `file` using the file
/// contents in `source` to provide a context to the span.
Expand Down
15 changes: 15 additions & 0 deletions base/src/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ pub struct Spanned<T, Pos> {
pub value: T,
}

impl<T, Pos> std::hash::Hash for Spanned<T, Pos>
where
T: std::hash::Hash,
Pos: std::hash::Hash + Copy,
{
fn hash<H>(&self, state: &mut H)
where
H: std::hash::Hasher,
{
self.span.start().hash(state);
self.span.end().hash(state);
self.value.hash(state);
}
}

impl<T, Pos> Spanned<T, Pos> {
pub fn map<U, F>(self, mut f: F) -> Spanned<U, Pos>
where
Expand Down
Loading

0 comments on commit 7bc8253

Please sign in to comment.