Skip to content

Commit

Permalink
bag should be String indexed for some reason
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Nov 30, 2024
1 parent 8549e1c commit 94f9f6d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 32 deletions.
28 changes: 14 additions & 14 deletions fastn-resolved/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ pub type Map<T> = std::collections::BTreeMap<String, T>;

#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub enum Definition {
// SymbolAlias {
// symbol: String,
// alias: String,
// line_number: usize,
// },
// ModuleAlias {
// module: String,
// alias: String,
// line_number: usize,
// },
SymbolAlias {
symbol: String,
alias: String,
line_number: usize,
},
ModuleAlias {
module: String,
alias: String,
line_number: usize,
},
Record(fastn_resolved::Record),
OrType(fastn_resolved::OrType),
OrTypeWithVariant {
Expand Down Expand Up @@ -74,8 +74,8 @@ impl Definition {
fastn_resolved::Definition::WebComponent(w) => w.name.to_string(),
fastn_resolved::Definition::Export { to, .. } => to.to_string(),
// TODO: check if the following two are valid
// Definition::SymbolAlias { alias, .. } => alias.to_string(),
// Definition::ModuleAlias { alias, .. } => alias.to_string(),
Definition::SymbolAlias { alias, .. } => alias.to_string(),
Definition::ModuleAlias { alias, .. } => alias.to_string(),
}
}

Expand All @@ -89,8 +89,8 @@ impl Definition {
Definition::OrTypeWithVariant { variant, .. } => variant.line_number(),
Definition::WebComponent(w) => w.line_number,
Definition::Export { line_number, .. } => *line_number,
// Definition::SymbolAlias { line_number, .. } => *line_number,
// Definition::ModuleAlias { line_number, .. } => *line_number,
Definition::SymbolAlias { line_number, .. } => *line_number,
Definition::ModuleAlias { line_number, .. } => *line_number,
}
}

Expand Down
25 changes: 17 additions & 8 deletions v0.5/fastn-compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ pub(crate) struct Compiler {
symbols: Box<dyn fastn_compiler::SymbolStore>,
pub(crate) definitions_used: std::collections::HashSet<fastn_unresolved::Symbol>,
pub(crate) arena: fastn_unresolved::Arena,
pub(crate) definitions:
std::collections::HashMap<fastn_unresolved::Symbol, fastn_unresolved::URD>,
pub(crate) definitions: std::collections::HashMap<String, fastn_unresolved::URD>,
/// checkout resolve_document for why this is an Option
content: Option<Vec<fastn_unresolved::URCI>>,
pub(crate) document: fastn_unresolved::Document,
Expand Down Expand Up @@ -50,7 +49,13 @@ impl Compiler {
// 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(),
definition
.unresolved()
.unwrap()
.symbol
.clone()
.unwrap()
.string(&self.arena),
definition,
);
}
Expand Down Expand Up @@ -80,7 +85,7 @@ impl Compiler {
// `foo` in the `bag`.
// to make sure this happens better, we have to ensure that the definition.resolve()
// tries to resolve the signature first, and then the body.
let mut definition = self.definitions.remove(&symbol);
let mut definition = self.definitions.remove(symbol.str(&self.arena));
match definition.as_mut() {
Some(fastn_unresolved::UR::UnResolved(definition)) => {
let mut o = Default::default();
Expand All @@ -96,13 +101,17 @@ impl Compiler {
if let Some(fastn_unresolved::UR::UnResolved(definition)) = definition {
match definition.resolved() {
Ok(resolved) => {
self.definitions
.insert(symbol, fastn_unresolved::UR::Resolved(resolved));
self.definitions.insert(
symbol.string(&self.arena),
fastn_unresolved::UR::Resolved(resolved),
);
}
Err(s) => {
r.need_more_symbols.insert(symbol.clone());
self.definitions
.insert(symbol, fastn_unresolved::UR::UnResolved(s));
self.definitions.insert(
symbol.string(&self.arena),
fastn_unresolved::UR::UnResolved(s),
);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions v0.5/fastn-compiler/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ pub(crate) fn resolved_content(
}

pub(crate) fn used_definitions(
definitions: std::collections::HashMap<fastn_unresolved::Symbol, fastn_unresolved::URD>,
definitions: std::collections::HashMap<String, fastn_unresolved::URD>,
definitions_used: std::collections::HashSet<fastn_unresolved::Symbol>,
arena: fastn_unresolved::Arena,
) -> indexmap::IndexMap<String, fastn_resolved::Definition> {
// go through self.symbols_used and get the resolved definitions
let def_map = indexmap::IndexMap::new();
for definition in definitions_used.iter() {
if let Some(_definition) = definitions.get(definition) {
if let Some(_definition) = definitions.get(definition.str(&arena)) {
// definitions.insert(symbol.clone(), definition);
todo!()
} else if let Some(_definition) = fastn_builtins::builtins().get(definition.str(&arena)) {
Expand Down
6 changes: 3 additions & 3 deletions v0.5/fastn-unresolved/src/resolver/component_invocation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
impl fastn_unresolved::ComponentInvocation {
pub fn resolve(
&mut self,
definitions: &std::collections::HashMap<fastn_unresolved::Symbol, fastn_unresolved::URD>,
definitions: &std::collections::HashMap<String, fastn_unresolved::URD>,
arena: &mut fastn_unresolved::Arena,
output: &mut fastn_unresolved::resolver::Output,
) {
Expand Down Expand Up @@ -33,13 +33,13 @@ impl fastn_unresolved::ComponentInvocation {
}

pub fn get_component<'a>(
definitions: &'a std::collections::HashMap<fastn_unresolved::Symbol, fastn_unresolved::URD>,
definitions: &'a std::collections::HashMap<String, fastn_unresolved::URD>,
arena: &fastn_unresolved::Arena,
symbol: &fastn_unresolved::Symbol,
) -> Option<&'a fastn_resolved::ComponentDefinition> {
println!("looking for: {}", symbol.str(arena));
if let Some(fastn_unresolved::UR::Resolved(fastn_resolved::Definition::Component(v))) =
definitions.get(symbol)
definitions.get(symbol.str(arena))
{
println!("found in definitions");
return Some(v);
Expand Down
2 changes: 1 addition & 1 deletion v0.5/fastn-unresolved/src/resolver/definition.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
impl fastn_unresolved::Definition {
pub fn resolve(
&mut self,
_definitions: &std::collections::HashMap<fastn_unresolved::Symbol, fastn_unresolved::URD>,
_definitions: &std::collections::HashMap<String, fastn_unresolved::URD>,
_arena: &mut fastn_unresolved::Arena,
_output: &mut fastn_unresolved::resolver::Output,
) {
Expand Down
6 changes: 2 additions & 4 deletions v0.5/fastn-unresolved/src/resolver/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn resolve(
current_module: &fastn_unresolved::Module,
// parent: Option<fastn_unresolved::Symbol>,
name: &mut fastn_unresolved::URIS,
definitions: &std::collections::HashMap<fastn_unresolved::Symbol, fastn_unresolved::URD>,
definitions: &std::collections::HashMap<String, fastn_unresolved::URD>,
arena: &mut fastn_unresolved::Arena,
_output: &mut fastn_unresolved::resolver::Output,
_locals: &[Vec<fastn_unresolved::UR<fastn_unresolved::Argument, fastn_resolved::Argument>>],
Expand All @@ -34,9 +34,7 @@ pub fn resolve(
// module from the module alias.
// we combine the target module with the name, "x" to get the target symbol.

match definitions.get(&current_module.symbol(module.str(), arena)) {
// ideally we should resolve everything, but we will actually never resolve
// aliases, and always do the resolution when needed?
match definitions.get(&current_module.symbol(module.str(), arena).string(arena)) {
Some(fastn_unresolved::UR::UnResolved(fastn_unresolved::Definition {
inner: fastn_unresolved::InnerDefinition::ModuleAlias(target),
..
Expand Down
4 changes: 4 additions & 0 deletions v0.5/fastn-unresolved/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ impl fastn_unresolved::Symbol {
arena.interner.resolve(self.interned).unwrap()
}

pub fn string(&self, arena: &fastn_unresolved::Arena) -> String {
self.str(arena).to_string()
}

pub fn package<'a>(&self, arena: &'a fastn_unresolved::Arena) -> &'a str {
&self.str(arena)[..self.package_len as usize]
}
Expand Down

0 comments on commit 94f9f6d

Please sign in to comment.