mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-08-04 11:00:05 +00:00
Remove dev dependency derive-new
This was only used for 4 structs in the `calc` example and the expanded code isn't that large.
This commit is contained in:
parent
e23dedac5e
commit
d2f2c6bc0b
3 changed files with 36 additions and 7 deletions
|
@ -32,7 +32,6 @@ salsa_unstable = []
|
|||
|
||||
[dev-dependencies]
|
||||
annotate-snippets = "0.11.5"
|
||||
derive-new = "0.6.0"
|
||||
codspeed-criterion-compat = { version = "2.6.0", default-features = false }
|
||||
expect-test = "1.5.0"
|
||||
eyre = "0.6.8"
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#![allow(clippy::needless_borrow)]
|
||||
|
||||
use derive_new::new;
|
||||
use ordered_float::OrderedFloat;
|
||||
|
||||
// ANCHOR: input
|
||||
|
@ -35,13 +34,19 @@ pub struct Program<'db> {
|
|||
// ANCHOR_END: program
|
||||
|
||||
// ANCHOR: statements_and_expressions
|
||||
#[derive(Eq, PartialEq, Debug, Hash, new, salsa::Update)]
|
||||
#[derive(Eq, PartialEq, Debug, Hash, salsa::Update)]
|
||||
pub struct Statement<'db> {
|
||||
pub span: Span<'db>,
|
||||
|
||||
pub data: StatementData<'db>,
|
||||
}
|
||||
|
||||
impl<'db> Statement<'db> {
|
||||
pub fn new(span: Span<'db>, data: StatementData<'db>) -> Self {
|
||||
Statement { span, data }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Hash, salsa::Update)]
|
||||
pub enum StatementData<'db> {
|
||||
/// Defines `fn <name>(<args>) = <body>`
|
||||
|
@ -50,13 +55,19 @@ pub enum StatementData<'db> {
|
|||
Print(Expression<'db>),
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Hash, new, salsa::Update)]
|
||||
#[derive(Eq, PartialEq, Debug, Hash, salsa::Update)]
|
||||
pub struct Expression<'db> {
|
||||
pub span: Span<'db>,
|
||||
|
||||
pub data: ExpressionData<'db>,
|
||||
}
|
||||
|
||||
impl<'db> Expression<'db> {
|
||||
pub fn new(span: Span<'db>, data: ExpressionData<'db>) -> Self {
|
||||
Expression { span, data }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Hash, salsa::Update)]
|
||||
pub enum ExpressionData<'db> {
|
||||
Op(Box<Expression<'db>>, Op, Box<Expression<'db>>),
|
||||
|
@ -102,7 +113,6 @@ pub struct Span<'db> {
|
|||
// ANCHOR: diagnostic
|
||||
#[salsa::accumulator]
|
||||
#[allow(dead_code)] // Debug impl uses them
|
||||
#[derive(new)]
|
||||
pub struct Diagnostic {
|
||||
pub start: usize,
|
||||
pub end: usize,
|
||||
|
@ -111,6 +121,14 @@ pub struct Diagnostic {
|
|||
// ANCHOR_END: diagnostic
|
||||
|
||||
impl Diagnostic {
|
||||
pub fn new(start: usize, end: usize, message: String) -> Self {
|
||||
Diagnostic {
|
||||
start,
|
||||
end,
|
||||
message,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn render(&self, db: &dyn crate::Db, src: SourceProgram) -> String {
|
||||
use annotate_snippets::*;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use crate::ir::{
|
||||
Diagnostic, Expression, Function, FunctionId, Program, Span, StatementData, VariableId,
|
||||
};
|
||||
use derive_new::new;
|
||||
#[cfg(test)]
|
||||
use expect_test::expect;
|
||||
use salsa::Accumulator;
|
||||
|
@ -44,13 +43,26 @@ pub fn find_function<'db>(
|
|||
.next()
|
||||
}
|
||||
|
||||
#[derive(new)]
|
||||
struct CheckExpression<'input, 'db> {
|
||||
db: &'db dyn crate::Db,
|
||||
program: Program<'db>,
|
||||
names_in_scope: &'input [VariableId<'db>],
|
||||
}
|
||||
|
||||
impl<'input, 'db> CheckExpression<'input, 'db> {
|
||||
pub fn new(
|
||||
db: &'db dyn crate::Db,
|
||||
program: Program<'db>,
|
||||
names_in_scope: &'input [VariableId<'db>],
|
||||
) -> Self {
|
||||
CheckExpression {
|
||||
db,
|
||||
program,
|
||||
names_in_scope,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> CheckExpression<'_, 'db> {
|
||||
fn check(&self, expression: &Expression<'db>) {
|
||||
match &expression.data {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue