diff --git a/fastn-resolved/src/lib.rs b/fastn-resolved/src/lib.rs index ce523b882..ed2b69142 100644 --- a/fastn-resolved/src/lib.rs +++ b/fastn-resolved/src/lib.rs @@ -87,6 +87,7 @@ impl Definition { } } +#[derive(Debug)] pub struct CompiledDocument { pub content: Vec, pub definitions: indexmap::IndexMap, diff --git a/v0.5/fastn-compiler/src/compiler.rs b/v0.5/fastn-compiler/src/compiler.rs index 78d3e764a..2791ded55 100644 --- a/v0.5/fastn-compiler/src/compiler.rs +++ b/v0.5/fastn-compiler/src/compiler.rs @@ -142,26 +142,24 @@ impl Compiler { let mut stuck_on_symbols = std::collections::HashSet::new(); let content = self.content.replace(vec![]).unwrap(); + dbg!(&content); let mut new_content = vec![]; - for ci in content { - match ci { - fastn_unresolved::UR::UnResolved(mut c) => { - let mut needed = Default::default(); - c.resolve( - &self.definitions, - &self.modules, - &mut self.arena, - &mut needed, - ); - stuck_on_symbols.extend(needed.stuck_on); - self.document - .merge(needed.errors, needed.warnings, needed.comments); - } - v => new_content.push(v), + for mut ci in content { + if let fastn_unresolved::UR::UnResolved(ref mut c) = ci { + let mut needed = Default::default(); + c.resolve( + &self.definitions, + &self.modules, + &mut self.arena, + &mut needed, + ); + stuck_on_symbols.extend(needed.stuck_on); + self.document + .merge(needed.errors, needed.warnings, needed.comments); } + new_content.push(ci); } - self.content = Some(new_content); stuck_on_symbols @@ -176,10 +174,13 @@ impl Compiler { while iterations < ITERATION_THRESHOLD { // resolve_document can internally run in parallel. // TODO: pass unresolvable to self.resolve_document() and make sure they don't come back + dbg!(&self.content); let unresolved_symbols = self.resolve_document(); if unresolved_symbols.is_empty() { + dbg!(&self.content); break; } + dbg!(&self.content); // ever_used.extend(&unresolved_symbols); self.fetch_unresolved_symbols(&unresolved_symbols).await; // this itself has to happen in a loop. we need a warning if we are not able to resolve all @@ -219,14 +220,14 @@ impl Compiler { } // there were no errors, etc. - Ok(fastn_resolved::CompiledDocument { - content: fastn_compiler::utils::resolved_content(self.document.content), + Ok(dbg!(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, ), - }) + })) } } diff --git a/v0.5/fastn-compiler/src/utils.rs b/v0.5/fastn-compiler/src/utils.rs index 866d7f831..40c90ef7c 100644 --- a/v0.5/fastn-compiler/src/utils.rs +++ b/v0.5/fastn-compiler/src/utils.rs @@ -1,6 +1,7 @@ pub(crate) fn resolved_content( content: Vec, ) -> Vec { + dbg!(&content); // self.content should be all UR::R now // every symbol in self.symbol_used in the bag must be UR::R now content.into_iter().map(|ur| ur.into_resolved()).collect() diff --git a/v0.5/fastn-unresolved/src/lib.rs b/v0.5/fastn-unresolved/src/lib.rs index ad672a924..01b343ae8 100644 --- a/v0.5/fastn-unresolved/src/lib.rs +++ b/v0.5/fastn-unresolved/src/lib.rs @@ -152,7 +152,7 @@ pub enum InnerDefinition { } #[derive(Debug, Clone, PartialEq)] -pub enum UR { +pub enum UR { Resolved(R), UnResolved(U), NotFound, diff --git a/v0.5/fastn-unresolved/src/utils.rs b/v0.5/fastn-unresolved/src/utils.rs index b873d69de..07ee6d823 100644 --- a/v0.5/fastn-unresolved/src/utils.rs +++ b/v0.5/fastn-unresolved/src/utils.rs @@ -109,13 +109,13 @@ pub(crate) fn assert_no_extra_headers( !found } -impl From for fastn_unresolved::UR { +impl From for fastn_unresolved::UR { fn from(u: U) -> fastn_unresolved::UR { fastn_unresolved::UR::UnResolved(u) } } -impl fastn_unresolved::UR { +impl fastn_unresolved::UR { pub fn unresolved(&self) -> Option<&U> { match self { fastn_unresolved::UR::UnResolved(u) => Some(u), @@ -133,7 +133,7 @@ impl fastn_unresolved::UR { pub fn into_resolved(self) -> V { match self { fastn_unresolved::UR::Resolved(v) => v, - _ => panic!(), + _ => panic!("{self:?}"), } } }