From cb7ae3c4eecfc2a07db23545c81de8bca0ed52b3 Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Wed, 4 Dec 2024 23:31:02 +0530 Subject: [PATCH] finally fastn-core depends on v0.5/fastn-compiler --- Cargo.lock | 51 +++++++++++++++++++++++++ Cargo.toml | 2 + fastn-ds/Cargo.toml | 2 + fastn-ds/src/lib.rs | 1 + fastn-ds/src/symbols.rs | 67 +++++++++++++++++++++++++++++++++ v0.5/fastn-compiler/Cargo.toml | 2 + v0.5/fastn-compiler/src/tdoc.rs | 36 ++++++++++++++++++ 7 files changed, 161 insertions(+) create mode 100644 fastn-ds/src/symbols.rs diff --git a/Cargo.lock b/Cargo.lock index 188a96d380..7f233ae610 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -354,6 +354,12 @@ dependencies = [ "derive_arbitrary", ] +[[package]] +name = "arcstr" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03918c3dbd7701a85c6b9887732e2921175f26c350b4563841d0958c21d57e6d" + [[package]] name = "arrayvec" version = "0.5.2" @@ -1409,6 +1415,18 @@ dependencies = [ "regex", ] +[[package]] +name = "fastn-compiler" +version = "0.1.0" +dependencies = [ + "async-trait", + "fastn-builtins", + "fastn-resolved", + "fastn-section", + "fastn-unresolved", + "indexmap", +] + [[package]] name = "fastn-core" version = "0.1.0" @@ -1477,6 +1495,8 @@ dependencies = [ "deadpool", "deadpool-postgres", "dirs", + "fastn-compiler", + "fastn-unresolved", "fastn-utils", "ft-sys-shared", "futures-util", @@ -1583,6 +1603,27 @@ dependencies = [ "sha2", ] +[[package]] +name = "fastn-section" +version = "0.1.0" +dependencies = [ + "arcstr", + "serde", + "serde_json", +] + +[[package]] +name = "fastn-unresolved" +version = "0.1.0" +dependencies = [ + "arcstr", + "fastn-builtins", + "fastn-resolved", + "fastn-section", + "id-arena", + "string-interner", +] + [[package]] name = "fastn-update" version = "0.1.0" @@ -3653,6 +3694,16 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "string-interner" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a3275464d7a9f2d4cac57c89c2ef96a8524dba2864c8d6f82e3980baf136f9b" +dependencies = [ + "hashbrown 0.15.2", + "serde", +] + [[package]] name = "stringprep" version = "0.1.5" diff --git a/Cargo.toml b/Cargo.toml index e72ff09e68..3d232f4b77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -92,6 +92,8 @@ fastn-core.path = "fastn-core" fastn-issues.path = "fastn-issues" fastn-package.path = "fastn-package" fastn-utils.path = "fastn-utils" +fastn-compiler = { path = "v0.5/fastn-compiler", features = ["owned-tdoc"] } +fastn-unresolved.path = "v0.5/fastn-unresolved" fastn-runtime.path = "fastn-runtime" fbt-lib.path = "fbt_lib" fastn-expr.path = "fastn-expr" diff --git a/fastn-ds/Cargo.toml b/fastn-ds/Cargo.toml index f5a388adc3..ff8ee3df6f 100644 --- a/fastn-ds/Cargo.toml +++ b/fastn-ds/Cargo.toml @@ -10,6 +10,8 @@ homepage.workspace = true [dependencies] fastn-utils.workspace = true +fastn-compiler.workspace = true +fastn-unresolved.workspace = true tokio.workspace = true thiserror.workspace = true actix-web.workspace = true diff --git a/fastn-ds/src/lib.rs b/fastn-ds/src/lib.rs index 2f41473cbd..25d1e0a2e4 100644 --- a/fastn-ds/src/lib.rs +++ b/fastn-ds/src/lib.rs @@ -10,6 +10,7 @@ mod user_data; mod utils; pub mod wasm; pub use user_data::UserDataError; +mod symbols; pub use create_pool::create_pool; diff --git a/fastn-ds/src/symbols.rs b/fastn-ds/src/symbols.rs new file mode 100644 index 0000000000..11db00bd3e --- /dev/null +++ b/fastn-ds/src/symbols.rs @@ -0,0 +1,67 @@ +impl fastn_ds::DocumentStore { + // fn find_all_definitions_in_a_module( + // &mut self, + // arena: &mut fastn_unresolved::Arena, + // global_aliases: &fastn_unresolved::AliasesSimple, + // (file, module): (String, fastn_unresolved::Module), + // ) -> Vec { + // // we need to fetch the symbol from the store + // let source = match std::fs::File::open(file.as_str()).and_then(std::io::read_to_string) { + // Ok(v) => v, + // Err(e) => { + // println!("failed to read file {}.ftd: {e:?}", file); + // return vec![]; + // } + // }; + // + // let d = fastn_unresolved::parse(module.clone(), &source, arena, global_aliases); + // + // d.definitions + // .into_iter() + // .map(|d| match d { + // fastn_unresolved::UR::UnResolved(mut v) => { + // v.symbol = Some(module.symbol(v.name.unresolved().unwrap().str(), arena)); + // fastn_unresolved::UR::UnResolved(v) + // } + // _ => { + // unreachable!("fastn_unresolved::parse() only returns unresolved definitions") + // } + // }) + // .collect::>() + // } +} + +#[async_trait::async_trait] +impl fastn_compiler::SymbolStore for fastn_ds::DocumentStore { + async fn lookup( + &mut self, + _arena: &mut fastn_unresolved::Arena, + _global_aliases: &fastn_unresolved::AliasesSimple, + _symbols: &std::collections::HashSet, + ) -> Vec { + todo!() + // let unique_modules = symbols + // .iter() + // .map(|s| file_for_symbol(s, arena)) + // .collect::>(); + // + // unique_modules + // .into_iter() + // .flat_map(|m| self.find_all_definitions_in_a_module(arena, global_aliases, m)) + // .collect() + } +} + +// fn file_for_symbol( +// symbol: &fastn_unresolved::Symbol, +// arena: &mut fastn_unresolved::Arena, +// ) -> (String, fastn_unresolved::Module) { +// ( +// // this code is nonsense right now +// match symbol.module(arena) { +// Some(module) => format!("{}/{}.ftd", symbol.package(arena), module), +// None => format!("{}/index.ftd", symbol.package(arena)), +// }, +// symbol.parent(arena), +// ) +// } diff --git a/v0.5/fastn-compiler/Cargo.toml b/v0.5/fastn-compiler/Cargo.toml index de4a31d2b1..566b0f738c 100644 --- a/v0.5/fastn-compiler/Cargo.toml +++ b/v0.5/fastn-compiler/Cargo.toml @@ -8,6 +8,8 @@ license.workspace = true repository.workspace = true homepage.workspace = true +[features] +owned-tdoc = [] [dependencies] async-trait.workspace = true diff --git a/v0.5/fastn-compiler/src/tdoc.rs b/v0.5/fastn-compiler/src/tdoc.rs index 3309bf3009..7aec614902 100644 --- a/v0.5/fastn-compiler/src/tdoc.rs +++ b/v0.5/fastn-compiler/src/tdoc.rs @@ -18,6 +18,7 @@ impl CompiledDocument { } impl fastn_resolved::tdoc::TDoc for CompiledDocument { + #[cfg(not(feature = "owned-tdoc"))] fn get_opt_function(&self, name: &str) -> Option<&fastn_resolved::Function> { match self.get(name) { Some(fastn_resolved::Definition::Function(f)) => Some(f), @@ -25,6 +26,15 @@ impl fastn_resolved::tdoc::TDoc for CompiledDocument { } } + #[cfg(feature = "owned-tdoc")] + fn get_opt_function(&self, name: &str) -> Option { + match self.get(name) { + Some(fastn_resolved::Definition::Function(f)) => Some(f.clone()), + _ => None, + } + } + + #[cfg(not(feature = "owned-tdoc"))] fn get_opt_record(&self, name: &str) -> Option<&fastn_resolved::Record> { match self.get(name) { Some(fastn_resolved::Definition::Record(f)) => Some(f), @@ -32,10 +42,19 @@ impl fastn_resolved::tdoc::TDoc for CompiledDocument { } } + #[cfg(feature = "owned-tdoc")] + fn get_opt_record(&self, name: &str) -> Option { + match self.get(name) { + Some(fastn_resolved::Definition::Record(f)) => Some(f.clone()), + _ => None, + } + } + fn name(&self) -> &str { self.name.as_str() } + #[cfg(not(feature = "owned-tdoc"))] fn get_opt_component(&self, name: &str) -> Option<&fastn_resolved::ComponentDefinition> { match self.get(name) { Some(fastn_resolved::Definition::Component(f)) => Some(f), @@ -43,6 +62,15 @@ impl fastn_resolved::tdoc::TDoc for CompiledDocument { } } + #[cfg(feature = "owned-tdoc")] + fn get_opt_component(&self, name: &str) -> Option { + match self.get(name) { + Some(fastn_resolved::Definition::Component(f)) => Some(f.clone()), + _ => None, + } + } + + #[cfg(not(feature = "owned-tdoc"))] fn get_opt_web_component(&self, name: &str) -> Option<&fastn_resolved::WebComponentDefinition> { match self.get(name) { Some(fastn_resolved::Definition::WebComponent(f)) => Some(f), @@ -50,6 +78,14 @@ impl fastn_resolved::tdoc::TDoc for CompiledDocument { } } + #[cfg(feature = "owned-tdoc")] + fn get_opt_web_component(&self, name: &str) -> Option { + match self.get(name) { + Some(fastn_resolved::Definition::WebComponent(f)) => Some(f.clone()), + _ => None, + } + } + fn definitions(&self) -> &indexmap::IndexMap { &self.definitions }