Skip to content

Commit

Permalink
cleanup ModuleGraph::topological_sort_from_root
Browse files Browse the repository at this point in the history
  • Loading branch information
plafer committed Jul 25, 2024
1 parent a784b00 commit 98ae7bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
26 changes: 16 additions & 10 deletions assembly/src/assembler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,22 @@ impl Assembler {
is_entrypoint: bool,
mast_forest_builder: &mut MastForestBuilder,
) -> Result<Arc<Procedure>, Report> {
let mut worklist = self.module_graph.topological_sort_from_root(root).map_err(|cycle| {
let iter = cycle.into_node_ids();
let mut nodes = Vec::with_capacity(iter.len());
for node in iter {
let module = self.module_graph[node.module].path();
let proc = self.module_graph.get_procedure_unsafe(node);
nodes.push(format!("{}::{}", module, proc.name()));
}
AssemblyError::Cycle { nodes }
})?;
let mut worklist: Vec<GlobalProcedureIndex> = self
.module_graph
.topological_sort_from_root(root)
.map_err(|cycle| {
let iter = cycle.into_node_ids();
let mut nodes = Vec::with_capacity(iter.len());
for node in iter {
let module = self.module_graph[node.module].path();
let proc = self.module_graph.get_procedure_unsafe(node);
nodes.push(format!("{}::{}", module, proc.name()));
}
AssemblyError::Cycle { nodes }
})?
.into_iter()
.filter(|&gid| self.module_graph.get_procedure_unsafe(gid).is_ast())
.collect();

assert!(!worklist.is_empty());

Expand Down
8 changes: 1 addition & 7 deletions assembly/src/assembler/module_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,7 @@ impl ModuleGraph {
&self,
caller: GlobalProcedureIndex,
) -> Result<Vec<GlobalProcedureIndex>, CycleError> {
Ok(self
.callgraph
.toposort_caller(caller)?
.into_iter()
// TODOP: do this outside the function
.filter(|&gid| self.get_procedure_unsafe(gid).is_ast())
.collect())
Ok(self.callgraph.toposort_caller(caller)?)
}

/// Fetch a [Module] by [ModuleIndex]
Expand Down

0 comments on commit 98ae7bc

Please sign in to comment.