Skip to content

Commit

Permalink
resolver is buggy yet
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Dec 3, 2024
1 parent 4881dab commit 1e7f139
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions fastn-resolved/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl Definition {
}
}

#[derive(Debug)]
pub struct CompiledDocument {
pub content: Vec<fastn_resolved::ComponentInvocation>,
pub definitions: indexmap::IndexMap<String, fastn_resolved::Definition>,
Expand Down
39 changes: 20 additions & 19 deletions v0.5/fastn-compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
),
})
}))
}
}

Expand Down
1 change: 1 addition & 0 deletions v0.5/fastn-compiler/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub(crate) fn resolved_content(
content: Vec<fastn_unresolved::URCI>,
) -> Vec<fastn_resolved::ComponentInvocation> {
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()
Expand Down
2 changes: 1 addition & 1 deletion v0.5/fastn-unresolved/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub enum InnerDefinition {
}

#[derive(Debug, Clone, PartialEq)]
pub enum UR<U, R> {
pub enum UR<U: std::fmt::Debug, R: std::fmt::Debug> {
Resolved(R),
UnResolved(U),
NotFound,
Expand Down
6 changes: 3 additions & 3 deletions v0.5/fastn-unresolved/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ pub(crate) fn assert_no_extra_headers(
!found
}

impl<U, R> From<U> for fastn_unresolved::UR<U, R> {
impl<U: std::fmt::Debug, R: std::fmt::Debug> From<U> for fastn_unresolved::UR<U, R> {
fn from(u: U) -> fastn_unresolved::UR<U, R> {
fastn_unresolved::UR::UnResolved(u)
}
}

impl<U, V> fastn_unresolved::UR<U, V> {
impl<U: std::fmt::Debug, V: std::fmt::Debug> fastn_unresolved::UR<U, V> {
pub fn unresolved(&self) -> Option<&U> {
match self {
fastn_unresolved::UR::UnResolved(u) => Some(u),
Expand All @@ -133,7 +133,7 @@ impl<U, V> fastn_unresolved::UR<U, V> {
pub fn into_resolved(self) -> V {
match self {
fastn_unresolved::UR::Resolved(v) => v,
_ => panic!(),
_ => panic!("{self:?}"),
}
}
}
Expand Down

0 comments on commit 1e7f139

Please sign in to comment.