mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-13 00:40:22 +00:00
wip
This commit is contained in:
parent
fdc363b65f
commit
4769e32d44
5 changed files with 17 additions and 57 deletions
|
@ -7,8 +7,6 @@ extern crate proc_macro2;
|
|||
#[macro_use]
|
||||
extern crate quote;
|
||||
|
||||
mod hygiene;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
macro_rules! parse_quote {
|
||||
|
@ -42,6 +40,7 @@ mod accumulator;
|
|||
mod db;
|
||||
mod db_lifetime;
|
||||
mod debug;
|
||||
mod hygiene;
|
||||
mod input;
|
||||
mod interned;
|
||||
mod options;
|
||||
|
@ -50,6 +49,7 @@ mod tracked;
|
|||
mod tracked_fn;
|
||||
mod tracked_struct;
|
||||
mod update;
|
||||
mod xform;
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn accumulator(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
|
|
|
@ -2,7 +2,7 @@ use proc_macro2::{Span, TokenStream};
|
|||
use quote::ToTokens;
|
||||
use syn::{spanned::Spanned, ItemFn};
|
||||
|
||||
use crate::{db_lifetime, hygiene::Hygiene, options::Options};
|
||||
use crate::{db_lifetime, hygiene::Hygiene, options::Options, xform::ChangeLt};
|
||||
|
||||
// Source:
|
||||
//
|
||||
|
@ -65,7 +65,7 @@ impl Macro {
|
|||
let db_lt = db_lifetime::db_lifetime(&item.sig.generics);
|
||||
let input_ids = self.input_ids(&item);
|
||||
let input_tys = self.input_tys(&item)?;
|
||||
let output_ty = self.output_ty(&item)?;
|
||||
let output_ty = self.output_ty(&db_lt, &item)?;
|
||||
let (cycle_recovery_fn, cycle_recovery_strategy) = self.cycle_recovery();
|
||||
|
||||
let mut inner_fn = item.clone();
|
||||
|
@ -293,10 +293,14 @@ impl Macro {
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn output_ty<'item>(&self, item: &'item ItemFn) -> syn::Result<syn::Type> {
|
||||
fn output_ty<'item>(
|
||||
&self,
|
||||
db_lt: &syn::Lifetime,
|
||||
item: &'item ItemFn,
|
||||
) -> syn::Result<syn::Type> {
|
||||
match &item.sig.output {
|
||||
syn::ReturnType::Default => Ok(parse_quote!(())),
|
||||
syn::ReturnType::Type(_, ty) => Ok(syn::Type::clone(ty)),
|
||||
syn::ReturnType::Type(_, ty) => Ok(ChangeLt::elided_to(&db_lt).in_type(&ty)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,27 +6,12 @@ pub(crate) struct ChangeLt<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ChangeLt<'a> {
|
||||
pub fn elided_to_static() -> Self {
|
||||
ChangeLt {
|
||||
from: Some("_"),
|
||||
to: "static".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn elided_to(db_lt: &syn::Lifetime) -> Self {
|
||||
ChangeLt {
|
||||
from: Some("_"),
|
||||
to: db_lt.ident.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_elided() -> Self {
|
||||
ChangeLt {
|
||||
from: None,
|
||||
to: "_".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn in_type(mut self, ty: &syn::Type) -> syn::Type {
|
||||
let mut ty = ty.clone();
|
||||
self.visit_type_mut(&mut ty);
|
||||
|
|
|
@ -1,30 +1,5 @@
|
|||
use ir::{Diagnostics, SourceProgram};
|
||||
|
||||
// ANCHOR: jar_struct
|
||||
#[salsa::jar(db = Db)]
|
||||
pub struct Jar(
|
||||
crate::compile::compile,
|
||||
crate::ir::SourceProgram,
|
||||
crate::ir::Program<'_>,
|
||||
crate::ir::VariableId<'_>,
|
||||
crate::ir::FunctionId<'_>,
|
||||
crate::ir::Function<'_>,
|
||||
crate::ir::Diagnostics,
|
||||
crate::ir::Span<'_>,
|
||||
crate::parser::parse_statements,
|
||||
crate::type_check::type_check_program,
|
||||
crate::type_check::type_check_function,
|
||||
crate::type_check::find_function,
|
||||
);
|
||||
// ANCHOR_END: jar_struct
|
||||
|
||||
// ANCHOR: jar_db
|
||||
pub trait Db: salsa::DbWithJar<Jar> {}
|
||||
// ANCHOR_END: jar_db
|
||||
|
||||
// ANCHOR: jar_db_impl
|
||||
impl<DB> Db for DB where DB: ?Sized + salsa::DbWithJar<Jar> {}
|
||||
// ANCHOR_END: jar_db_impl
|
||||
use salsa::Database as Db;
|
||||
|
||||
mod compile;
|
||||
mod db;
|
||||
|
|
|
@ -8,7 +8,6 @@ use notify_debouncer_mini::{
|
|||
notify::{RecommendedWatcher, RecursiveMode},
|
||||
DebounceEventResult, Debouncer,
|
||||
};
|
||||
use salsa::DebugWithDb;
|
||||
|
||||
// ANCHOR: main
|
||||
fn main() -> Result<()> {
|
||||
|
@ -61,9 +60,6 @@ fn main() -> Result<()> {
|
|||
}
|
||||
// ANCHOR_END: main
|
||||
|
||||
#[salsa::jar(db = Db)]
|
||||
struct Jar(Diagnostic, File, ParsedFile<'_>, compile, parse, sum);
|
||||
|
||||
// ANCHOR: db
|
||||
#[salsa::input]
|
||||
struct File {
|
||||
|
@ -72,11 +68,12 @@ struct File {
|
|||
contents: String,
|
||||
}
|
||||
|
||||
trait Db: salsa::DbWithJar<Jar> {
|
||||
#[salsa::db]
|
||||
trait Db: salsa::Database {
|
||||
fn input(&self, path: PathBuf) -> Result<File>;
|
||||
}
|
||||
|
||||
#[salsa::db(Jar)]
|
||||
#[salsa::db]
|
||||
struct Database {
|
||||
storage: salsa::Storage<Self>,
|
||||
logs: Mutex<Vec<String>>,
|
||||
|
@ -96,6 +93,7 @@ impl Database {
|
|||
}
|
||||
}
|
||||
|
||||
#[salsa::db]
|
||||
impl Db for Database {
|
||||
fn input(&self, path: PathBuf) -> Result<File> {
|
||||
let path = path
|
||||
|
@ -123,14 +121,12 @@ impl Db for Database {
|
|||
}
|
||||
// ANCHOR_END: db
|
||||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Database {
|
||||
fn salsa_event(&self, event: salsa::Event) {
|
||||
// don't log boring events
|
||||
if let salsa::EventKind::WillExecute { .. } = event.kind {
|
||||
self.logs
|
||||
.lock()
|
||||
.unwrap()
|
||||
.push(format!("{:?}", event.debug(self)));
|
||||
self.logs.lock().unwrap().push(format!("{:?}", event));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue