From a90354ad0c767404db3cb076808f875f8706eace Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Fri, 6 Dec 2024 13:36:09 +0530 Subject: [PATCH] remoed the fastn_compiler::Symbols trait --- v0.5/Cargo.lock | 445 +--------------------------- v0.5/Cargo.toml | 1 - v0.5/fastn-compiler/Cargo.toml | 1 - v0.5/fastn-compiler/src/compiler.rs | 74 ++--- v0.5/fastn-compiler/src/lib.rs | 2 - v0.5/fastn-compiler/src/symbols.rs | 19 -- v0.5/fastn/Cargo.toml | 5 +- v0.5/fastn/src/commands/render.rs | 25 +- v0.5/fastn/src/commands/serve.rs | 1 - v0.5/fastn/src/symbols.rs | 4 +- 10 files changed, 61 insertions(+), 516 deletions(-) delete mode 100644 v0.5/fastn-compiler/src/symbols.rs diff --git a/v0.5/Cargo.lock b/v0.5/Cargo.lock index e3adb6f48..38ddb2721 100644 --- a/v0.5/Cargo.lock +++ b/v0.5/Cargo.lock @@ -32,23 +32,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03918c3dbd7701a85c6b9887732e2921175f26c350b4563841d0958c21d57e6d" -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - -[[package]] -name = "async-trait" -version = "0.1.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.90", -] - [[package]] name = "backtrace" version = "0.3.74" @@ -64,83 +47,18 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - [[package]] name = "bytes" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" -[[package]] -name = "cc" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" -dependencies = [ - "shlex", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "copy_dir" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "543d1dd138ef086e2ff05e3a48cf9da045da2033d16f8538fd76b86cd49b2ca3" -dependencies = [ - "walkdir", -] - -[[package]] -name = "cpufeatures" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - [[package]] name = "either" version = "1.13.0" @@ -157,10 +75,7 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" name = "fastn" version = "0.1.0" dependencies = [ - "async-trait", - "fastn-compiler", "fastn-core", - "fastn-runtime", "fastn-unresolved", "http-body-util", "hyper", @@ -183,7 +98,6 @@ dependencies = [ name = "fastn-compiler" version = "0.1.0" dependencies = [ - "async-trait", "fastn-builtins", "fastn-resolved", "fastn-section", @@ -200,20 +114,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "fastn-js" -version = "0.1.0" -dependencies = [ - "fastn-resolved", - "indoc", - "itertools", - "prettify-js", - "pretty", - "quick-js", - "rquickjs", - "thiserror", -] - [[package]] name = "fastn-resolved" version = "0.1.1" @@ -222,21 +122,6 @@ dependencies = [ "serde", ] -[[package]] -name = "fastn-runtime" -version = "0.1.0" -dependencies = [ - "fastn-builtins", - "fastn-js", - "fastn-resolved", - "indexmap", - "indoc", - "itertools", - "once_cell", - "serde", - "sha2", -] - [[package]] name = "fastn-section" version = "0.1.0" @@ -312,16 +197,6 @@ dependencies = [ "pin-utils", ] -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "gimli" version = "0.31.1" @@ -423,12 +298,6 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - [[package]] name = "indexmap" version = "2.7.0" @@ -440,12 +309,6 @@ dependencies = [ "serde", ] -[[package]] -name = "indoc" -version = "2.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" - [[package]] name = "itertools" version = "0.13.0" @@ -467,22 +330,6 @@ version = "0.2.167" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" -[[package]] -name = "libquickjs-sys" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f0b24e9bd171b75ae0295bd428fb8fe58410fb23156e5f34a4657a70c3cee96" -dependencies = [ - "cc", - "copy_dir", -] - -[[package]] -name = "log" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" - [[package]] name = "memchr" version = "2.7.4" @@ -506,7 +353,7 @@ checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" dependencies = [ "libc", "wasi", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -518,12 +365,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "once_cell" -version = "1.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" - [[package]] name = "pin-project-lite" version = "0.2.15" @@ -536,63 +377,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "prettify-js" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7ff18ec712649921186715eeee7d880c3c5fb41c86a5a3524057da346e27771" -dependencies = [ - "log", - "ress", - "serde", - "serde_json", -] - -[[package]] -name = "pretty" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b55c4d17d994b637e2f4daf6e5dc5d660d209d5642377d675d7a1c3ab69fa579" -dependencies = [ - "arrayvec", - "typed-arena", - "unicode-width", -] - -[[package]] -name = "proc-macro-crate" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" -dependencies = [ - "once_cell", - "toml_edit", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.92" @@ -602,16 +386,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "quick-js" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19cb4cefcb00f4ab9b332664d06005a74f582ac16aa959c6ad5912957bd83e5f" -dependencies = [ - "libquickjs-sys", - "once_cell", -] - [[package]] name = "quote" version = "1.0.37" @@ -650,69 +424,6 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" -[[package]] -name = "relative-path" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2" - -[[package]] -name = "ress" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fb1cedc0fd02351568b53be91c4ba2f94beb31ff730bd7df1e54e9b19169b9b" -dependencies = [ - "log", - "unicode-xid", -] - -[[package]] -name = "rquickjs" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cbd33e0b668aea0ab238b9164523aca929096f9f40834700d71d91dd4888882" -dependencies = [ - "rquickjs-core", - "rquickjs-macro", -] - -[[package]] -name = "rquickjs-core" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9129d69b7b8f7ee8ad1da5b12c7f4a8a8acd45f2e6dd9cb2ee1bc5a1f2fa3d" -dependencies = [ - "relative-path", - "rquickjs-sys", -] - -[[package]] -name = "rquickjs-macro" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d2ecaf7c9eda262e02a91e9541989a9dd18984d17d0d97f99f33b464318057" -dependencies = [ - "convert_case", - "fnv", - "ident_case", - "indexmap", - "proc-macro-crate", - "proc-macro-error", - "proc-macro2", - "quote", - "rquickjs-core", - "syn 2.0.90", -] - -[[package]] -name = "rquickjs-sys" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf6f2288d8e7fbb5130f62cf720451641e99d55f6fde9db86aa2914ecb553fd2" -dependencies = [ - "cc", -] - [[package]] name = "rustc-demangle" version = "0.1.24" @@ -725,15 +436,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - [[package]] name = "serde" version = "1.0.215" @@ -751,7 +453,7 @@ checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -766,23 +468,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - [[package]] name = "smallvec" version = "1.13.2" @@ -796,7 +481,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -809,16 +494,6 @@ dependencies = [ "serde", ] -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.90" @@ -830,26 +505,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.90", -] - [[package]] name = "tokio" version = "1.41.1" @@ -862,7 +517,7 @@ dependencies = [ "pin-project-lite", "socket2", "tokio-macros", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -873,93 +528,21 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", -] - -[[package]] -name = "toml_datetime" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" - -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap", - "toml_datetime", - "winnow", + "syn", ] -[[package]] -name = "typed-arena" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - [[package]] name = "unicode-ident" version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" -[[package]] -name = "unicode-segmentation" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" - -[[package]] -name = "unicode-width" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" - -[[package]] -name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "walkdir" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" -dependencies = [ - "same-file", - "winapi-util", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "winapi-util" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "windows-sys" version = "0.52.0" @@ -969,15 +552,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-targets" version = "0.52.6" @@ -1041,12 +615,3 @@ name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "winnow" -version = "0.5.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" -dependencies = [ - "memchr", -] diff --git a/v0.5/Cargo.toml b/v0.5/Cargo.toml index 05bb93100..6fe7302cd 100644 --- a/v0.5/Cargo.toml +++ b/v0.5/Cargo.toml @@ -38,7 +38,6 @@ homepage = "https://fastn.com" # using the latest dependency, and what is the plan to move to the latest version. arcstr = "1" -async-trait = "0.1" fastn-compiler = { path = "fastn-compiler", default-features = false } fastn-core = { path = "fastn-core" } fastn-section = { path = "fastn-section" } diff --git a/v0.5/fastn-compiler/Cargo.toml b/v0.5/fastn-compiler/Cargo.toml index 50697df80..9a34f1deb 100644 --- a/v0.5/fastn-compiler/Cargo.toml +++ b/v0.5/fastn-compiler/Cargo.toml @@ -12,7 +12,6 @@ homepage.workspace = true owned-tdoc = ["fastn-resolved/owned-tdoc"] [dependencies] -async-trait.workspace = true fastn-section.workspace = true fastn-resolved.workspace = true fastn-builtins.workspace = true diff --git a/v0.5/fastn-compiler/src/compiler.rs b/v0.5/fastn-compiler/src/compiler.rs index e8873007d..adeb4d09c 100644 --- a/v0.5/fastn-compiler/src/compiler.rs +++ b/v0.5/fastn-compiler/src/compiler.rs @@ -1,12 +1,19 @@ const ITERATION_THRESHOLD: usize = 100; + +pub enum CompilerState { + StuckOnSymbols( + Box, + std::collections::HashSet, + ), + Done(Result), +} + // foo.ftd // -- import: foo as f (f => foo) // // -- import: bar (bar => Module, x => Symbol) (bar => bar, x => bar.y) // exposing: y as x -// -pub(crate) struct Compiler { - symbols: Box, +pub struct Compiler { pub(crate) definitions_used: std::collections::HashSet, pub(crate) arena: fastn_unresolved::Arena, pub(crate) definitions: std::collections::HashMap, @@ -14,14 +21,14 @@ pub(crate) struct Compiler { /// if module exists, if in dict bool tells if it exists. pub(crate) modules: std::collections::HashMap, /// checkout resolve_document for why this is an Option - content: Option>, + pub(crate) content: Option>, pub(crate) document: fastn_unresolved::Document, - global_aliases: fastn_unresolved::AliasesSimple, + #[expect(unused)] + pub(crate) global_aliases: fastn_unresolved::AliasesSimple, } impl Compiler { fn new( - symbols: Box, source: &str, package: &str, module: Option<&str>, @@ -39,7 +46,6 @@ impl Compiler { Self { arena, - symbols, definitions: std::collections::HashMap::new(), modules: std::collections::HashMap::new(), content, @@ -51,28 +57,29 @@ impl Compiler { async fn fetch_unresolved_symbols( &mut self, - symbols_to_fetch: &std::collections::HashSet, + _symbols_to_fetch: &std::collections::HashSet, ) { - self.definitions_used - .extend(symbols_to_fetch.iter().cloned()); - let definitions = self - .symbols - .lookup(&mut self.arena, &self.global_aliases, symbols_to_fetch) - .await; - for definition in definitions { - // the following is only okay if our symbol store only returns unresolved definitions, - // some other store might return resolved definitions, and we need to handle that. - self.definitions.insert( - definition - .unresolved() - .unwrap() - .symbol - .clone() - .unwrap() - .string(&self.arena), - definition, - ); - } + todo!() + // self.definitions_used + // .extend(symbols_to_fetch.iter().cloned()); + // let definitions = self + // .symbols + // .lookup(&mut self.arena, &self.global_aliases, symbols_to_fetch) + // .await; + // for definition in definitions { + // // the following is only okay if our symbol store only returns unresolved definitions, + // // some other store might return resolved definitions, and we need to handle that. + // self.definitions.insert( + // definition + // .unresolved() + // .unwrap() + // .symbol + // .clone() + // .unwrap() + // .string(&self.arena), + // definition, + // ); + // } } /// try to resolve as many symbols as possible, and return the ones that we made any progress on. @@ -170,7 +177,7 @@ impl Compiler { stuck_on_symbols } - async fn compile(mut self) -> Result { + async fn compile(mut self) -> CompilerState { // we only make 10 attempts to resolve the document: we need a warning if we are not able to // resolve the document in 10 attempts. let mut unresolvable = std::collections::HashSet::new(); @@ -222,14 +229,14 @@ impl Compiler { } // there were no errors, etc. - Ok(fastn_resolved::CompiledDocument { + CompilerState::Done(Ok(fastn_resolved::CompiledDocument { content: fastn_compiler::utils::resolved_content(self.content.unwrap()), definitions: fastn_compiler::utils::used_definitions( self.definitions, self.definitions_used, self.arena, ), - }) + })) } } @@ -243,13 +250,12 @@ impl Compiler { /// earlier we had strict mode here, but to simplify things, now we let the caller convert non-empty /// warnings from OK part as error, and discard the generated JS. pub async fn compile( - symbols: Box, source: &str, package: &str, module: Option<&str>, global_aliases: fastn_unresolved::AliasesSimple, -) -> Result { - Compiler::new(symbols, source, package, module, global_aliases) +) -> CompilerState { + Compiler::new(source, package, module, global_aliases) .compile() .await } diff --git a/v0.5/fastn-compiler/src/lib.rs b/v0.5/fastn-compiler/src/lib.rs index e1936981a..85a8a9e5a 100644 --- a/v0.5/fastn-compiler/src/lib.rs +++ b/v0.5/fastn-compiler/src/lib.rs @@ -5,14 +5,12 @@ extern crate self as fastn_compiler; mod compiler; -mod symbols; mod tdoc; mod utils; pub use tdoc::CompiledDocument; pub use compiler::compile; pub use fastn_section::Result; -pub use symbols::SymbolStore; #[derive(Debug)] pub struct Error { diff --git a/v0.5/fastn-compiler/src/symbols.rs b/v0.5/fastn-compiler/src/symbols.rs deleted file mode 100644 index b13994c46..000000000 --- a/v0.5/fastn-compiler/src/symbols.rs +++ /dev/null @@ -1,19 +0,0 @@ -#[async_trait::async_trait] -pub trait SymbolStore: Send { - /// it is okay / acceptable to return more symbols than asked. - /// - /// this is because if we are fetching symbols by parsing a ftd file, it makes sense to store - /// all the symbols found in that file in one go. - /// instead of parsing the file multiple times, or storing the symbols on the type implementing - /// this trait. - /// - /// or maybe the system can predict that if you asked for one symbol, you are going to ask - /// for some related symbols soon. - // TODO: should we make it async? - async fn lookup( - &mut self, - arena: &mut fastn_unresolved::Arena, - global_aliases: &fastn_unresolved::AliasesSimple, - symbols: &std::collections::HashSet, - ) -> Vec; -} diff --git a/v0.5/fastn/Cargo.toml b/v0.5/fastn/Cargo.toml index 669d4be5e..f034c5c04 100644 --- a/v0.5/fastn/Cargo.toml +++ b/v0.5/fastn/Cargo.toml @@ -9,10 +9,9 @@ repository.workspace = true homepage.workspace = true [dependencies] -async-trait.workspace = true fastn-core.workspace = true -fastn-compiler.workspace = true -fastn-runtime.workspace = true +#fastn-compiler.workspace = true +#fastn-runtime.workspace = true fastn-unresolved.workspace = true hyper.workspace = true http-body-util.workspace = true diff --git a/v0.5/fastn/src/commands/render.rs b/v0.5/fastn/src/commands/render.rs index b2aadadb8..f2d7f45a6 100644 --- a/v0.5/fastn/src/commands/render.rs +++ b/v0.5/fastn/src/commands/render.rs @@ -4,7 +4,6 @@ impl fastn::commands::Render { match route { fastn_core::Route::Document(path, data) => { let html = fastn::commands::render::render_document( - Box::new(fastn::Symbols {}), config.auto_imports.clone(), path.as_str(), data, @@ -19,19 +18,19 @@ impl fastn::commands::Render { } pub async fn render_document( - symbols: Box, - global_aliases: fastn_unresolved::AliasesSimple, - path: &str, + _global_aliases: fastn_unresolved::AliasesSimple, + _path: &str, _data: serde_json::Value, _strict: bool, ) -> String { - let source = std::fs::File::open(path) - .and_then(std::io::read_to_string) - .unwrap(); - let o = fastn_compiler::compile(symbols, &source, "main", None, global_aliases) - .await - .unwrap(); - - let h = fastn_runtime::HtmlData::from_cd(o); - h.to_test_html() + todo!() + // let source = std::fs::File::open(path) + // .and_then(std::io::read_to_string) + // .unwrap(); + // let o = fastn_compiler::compile(&source, "main", None, global_aliases) + // .await + // .unwrap(); + // + // let h = fastn_runtime::HtmlData::from_cd(o); + // h.to_test_html() } diff --git a/v0.5/fastn/src/commands/serve.rs b/v0.5/fastn/src/commands/serve.rs index c625db23c..72723c5b4 100644 --- a/v0.5/fastn/src/commands/serve.rs +++ b/v0.5/fastn/src/commands/serve.rs @@ -49,7 +49,6 @@ async fn render( Ok(hyper::Response::new(http_body_util::Full::new( hyper::body::Bytes::from( fastn::commands::render::render_document( - Box::new(fastn::Symbols {}), global_aliases, "index.ftd", serde_json::Value::Null, diff --git a/v0.5/fastn/src/symbols.rs b/v0.5/fastn/src/symbols.rs index 30cc5fe86..008a648f4 100644 --- a/v0.5/fastn/src/symbols.rs +++ b/v0.5/fastn/src/symbols.rs @@ -34,8 +34,8 @@ impl Symbols { } } -#[async_trait::async_trait] -impl fastn_compiler::SymbolStore for Symbols { +impl Symbols { + #[expect(unused)] async fn lookup( &mut self, arena: &mut fastn_unresolved::Arena,