feat: sort modules and detect cycles

This commit is contained in:
rvcas
2022-10-13 15:29:08 -04:00
committed by Lucas
parent 15c774b7d0
commit ed2ef4fa9b
7 changed files with 264 additions and 39 deletions

View File

@@ -37,6 +37,31 @@ pub struct Module<Info, Definitions> {
pub kind: ModuleKind,
}
impl UntypedModule {
pub fn dependencies(&self) -> Vec<(String, Span)> {
self.definitions()
.flat_map(|def| {
if let Definition::Use {
location, module, ..
} = def
{
Some((module.join("/"), *location))
} else {
None
}
})
.collect()
}
pub fn definitions(&self) -> impl Iterator<Item = &UntypedDefinition> {
self.definitions.iter()
}
pub fn into_definitions(self) -> impl Iterator<Item = UntypedDefinition> {
self.definitions.into_iter()
}
}
pub type TypedDefinition = Definition<Arc<Type>, TypedExpr, String, String>;
pub type UntypedDefinition = Definition<(), UntypedExpr, (), ()>;
@@ -500,7 +525,7 @@ pub struct Span {
impl From<Span> for miette::SourceSpan {
fn from(span: Span) -> Self {
Self::new(span.start.into(), span.end.into())
Self::new(span.start.into(), (span.end - span.start).into())
}
}