Skip to content

Commit

Permalink
Resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpita-Jaiswal committed Dec 1, 2024
2 parents 78c0986 + 905cdae commit e0af425
Show file tree
Hide file tree
Showing 30 changed files with 219 additions and 182 deletions.
6 changes: 1 addition & 5 deletions fastn-core/src/commands/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,7 @@ fn section(input: &mut String) -> Option<Section> {
if !trimmed_line.is_empty() {
trimmed_line = format!(
"{}{}",
" ".repeat(if current_leading_spaces_count > leading_spaces_count {
current_leading_spaces_count - leading_spaces_count
} else {
0
}),
" ".repeat(current_leading_spaces_count.saturating_sub(leading_spaces_count)),
trimmed_line.trim()
);
}
Expand Down
4 changes: 2 additions & 2 deletions fastn-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ impl Config {
generated_style.push('\n');
entry = package.next();
}
return match generated_style.trim().is_empty() {
match generated_style.trim().is_empty() {
false => format!("<style>{}</style>", generated_style),
_ => "".to_string(),
};
}
}

pub(crate) async fn download_fonts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ fn extract_type_data(
}

fn extract_raw_data(property_value: Option<fastn_resolved::PropertyValue>) -> Option<ValueType> {
return match property_value.as_ref() {
match property_value.as_ref() {
Some(fastn_resolved::PropertyValue::Value { value, .. }) => match value {
fastn_resolved::Value::String { text } => Some(ValueType {
value: text.to_string(),
Expand Down Expand Up @@ -295,7 +295,7 @@ fn extract_raw_data(property_value: Option<fastn_resolved::PropertyValue>) -> Op
Some(fastn_resolved::PropertyValue::Clone { .. }) => None,
Some(fastn_resolved::PropertyValue::FunctionCall { .. }) => None,
None => None,
};
}
}

#[derive(Debug, Default, Serialize, Deserialize)]
Expand Down
4 changes: 2 additions & 2 deletions fastn-core/src/package/redirects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ pub fn find_redirect<'a>(redirects: &'a ftd::Map<String>, path: &str) -> Option<
.trim_end_matches(".ftd")
);

return if redirects.contains_key(original) {
if redirects.contains_key(original) {
redirects.get(original)
} else if redirects.contains_key(fixed.as_str()) {
redirects.get(fixed.as_str())
} else {
None
};
}
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion fastn-core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub struct Timer<'a> {
msg: &'a str,
}

impl<'a> Timer<'a> {
impl Timer<'_> {
pub fn it<T>(&self, a: T) -> T {
use colored::Colorize;

Expand Down
29 changes: 15 additions & 14 deletions fastn-resolved/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,10 @@ 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,
/// every module is a "thing" and can be referred to etc., so we need to keep track of them
Module {
package: String,
module: Option<String>,
},
Record(fastn_resolved::Record),
OrType(fastn_resolved::OrType),
Expand Down Expand Up @@ -73,9 +68,14 @@ impl Definition {
fastn_resolved::Definition::Function(f) => f.name.to_string(),
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::Module {
package,
module: None,
} => package.clone(),
Definition::Module {
package,
module: Some(module),
} => format!("{}/{}", package, module),
}
}

Expand All @@ -89,8 +89,9 @@ 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,
// module is not defined on any given line, unless it is defined using the future
// module proposal, till now we return 0
Definition::Module { .. } => 0,
}
}

Expand Down
1 change: 1 addition & 0 deletions fastn-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ homepage.workspace = true

[features]
owned-tdoc = ["fastn-resolved/owned-tdoc"]
default = ["owned-tdoc"]

[dependencies]
fastn-js.workspace = true
Expand Down
1 change: 1 addition & 0 deletions fastn.com/d/v0.5/index.ftd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- ftd.text: v0.5
5 changes: 2 additions & 3 deletions ftd/src/interpreter/tdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,8 @@ impl<'a> TDoc<'a> {
false,
),
ftd::interpreter::Thing::Function(f) => (f.return_kind, false),
ftd::interpreter::Thing::Export { .. }
| ftd::interpreter::Thing::SymbolAlias { .. }
| ftd::interpreter::Thing::ModuleAlias { .. } => unreachable!(),
ftd::interpreter::Thing::Export { .. } => unreachable!(),
ftd::interpreter::Thing::Module { .. } => todo!(),
};

(
Expand Down
23 changes: 6 additions & 17 deletions v0.5/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions v0.5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,13 @@ arcstr = "1"
async-trait = "0.1"
fastn-compiler = { path = "fastn-compiler" }
fastn-core = { path = "fastn-core" }
fastn-jdebug = { version = "0.1.0", path = "fastn-jdebug" }
fastn-section = { path = "fastn-section" }
fastn-static = { path = "fastn-static" }
fastn-resolved = { path = "../fastn-resolved" }
fastn-runtime = { path = "../fastn-runtime" }
fastn-resolved = { path = "../fastn-resolved", default-features = false }
fastn-runtime = { path = "../fastn-runtime", default-features = false }
fastn-builtins = { path = "../fastn-builtins" }
fastn-js = { path = "../fastn-js" }
fastn-unresolved = { path = "fastn-unresolved" }
fastn-update = { path = "fastn-update" }
id-arena = "2"
indexmap = "2"
insta = { version = "1", features = ["yaml", "glob"] }
itertools = "0.13"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
string-interner = "0.18"
Expand Down
43 changes: 26 additions & 17 deletions v0.5/fastn-compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@ 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,
auto_import_scope: fastn_unresolved::SFId,
auto_imports: fastn_unresolved::AliasesID,
}

impl Compiler {
fn new(
symbols: Box<dyn fastn_compiler::SymbolStore>,
source: &str,
package: &str,
module: &str,
auto_import_scope: fastn_unresolved::SFId,
module: Option<&str>,
auto_imports: fastn_unresolved::AliasesID,
mut arena: fastn_unresolved::Arena,
) -> Self {
let mut document = fastn_unresolved::parse(
fastn_unresolved::Module::new(package, module, &mut arena),
source,
&mut arena,
auto_import_scope,
auto_imports,
);
let content = Some(document.content);
document.content = vec![];
Expand All @@ -36,8 +35,8 @@ impl Compiler {
definitions: std::collections::HashMap::new(),
content,
document,
auto_imports,
definitions_used: Default::default(),
auto_import_scope,
}
}

Expand All @@ -49,13 +48,19 @@ impl Compiler {
.extend(symbols_to_fetch.iter().cloned());
let definitions = self
.symbols
.lookup(&mut self.arena, symbols_to_fetch, self.auto_import_scope)
.lookup(&mut self.arena, symbols_to_fetch, self.auto_imports)
.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(),
definition
.unresolved()
.unwrap()
.symbol
.clone()
.unwrap()
.string(&self.arena),
definition,
);
}
Expand Down Expand Up @@ -85,7 +90,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 @@ -101,13 +106,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 Expand Up @@ -220,11 +229,11 @@ pub async fn compile(
symbols: Box<dyn fastn_compiler::SymbolStore>,
source: &str,
package: &str,
module: &str,
auto_import_scope: fastn_unresolved::SFId,
module: Option<&str>,
auto_imports: fastn_unresolved::AliasesID,
arena: fastn_unresolved::Arena,
) -> Result<fastn_resolved::CompiledDocument, fastn_compiler::Error> {
Compiler::new(symbols, source, package, module, auto_import_scope, arena)
Compiler::new(symbols, source, package, module, auto_imports, arena)
.compile()
.await
}
Expand Down
2 changes: 1 addition & 1 deletion v0.5/fastn-compiler/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ pub trait SymbolStore {
&mut self,
arena: &mut fastn_unresolved::Arena,
symbols: &std::collections::HashSet<fastn_unresolved::Symbol>,
auto_imports: fastn_unresolved::SFId,
auto_imports: fastn_unresolved::AliasesID,
) -> Vec<fastn_unresolved::URD>;
}
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
2 changes: 1 addition & 1 deletion v0.5/fastn-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod read;
#[allow(dead_code)]
pub struct Config {
sitemap: Sitemap,
pub auto_import_scope: fastn_unresolved::SFId,
pub auto_imports: fastn_unresolved::AliasesID,
redirects: Vec<Redirect>,
dynamic_routes: Vec<DynamicRoute>,
}
Expand Down
6 changes: 3 additions & 3 deletions v0.5/fastn-core/src/config/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ impl fastn_core::Config {
) -> Result<Self, ReadError> {
Ok(fastn_core::Config {
sitemap: fastn_core::Sitemap {},
auto_import_scope: desugar_auto_imports(arena, &[]),
auto_imports: desugar_auto_imports(arena, &[]),
redirects: vec![],
dynamic_routes: vec![],
})
Expand All @@ -20,6 +20,6 @@ pub enum ReadError {
fn desugar_auto_imports(
arena: &mut fastn_unresolved::Arena,
_auto_imports: &[fastn_core::config::AutoImport],
) -> fastn_unresolved::SFId {
arena.new_scope("auto-imports")
) -> fastn_unresolved::AliasesID {
arena.new_aliases()
}
Loading

0 comments on commit e0af425

Please sign in to comment.