tamer: ld::xmle::lower: Sort only rooted Idents

This is one of many changes that have been lingering that I need to start to
break apart in an attempt to commit the confusing and disappointing
conclusion to this package loading madness.

More information to come.

DEV-13162
main
Mike Gerwitz 2023-05-09 15:20:39 -04:00
parent 5f275fb801
commit ebdae9ac38
2 changed files with 21 additions and 7 deletions

View File

@ -70,9 +70,11 @@
//! 2. A cycle representing allowed recursion performs a cut since the
//! path taken thus far already represents a valid ordering.
use super::super::{Asg, ObjectIndex};
use crate::{
asg::{graph::object::DynObjectRel, Object, ObjectIndexResolvedSpan},
asg::{
graph::object::DynObjectRel, Asg, Object, ObjectIndex,
ObjectIndexResolvedSpan, ObjectKind,
},
diagnose::{Annotate, AnnotatedSpan, Diagnostic},
};
use fixedbitset::FixedBitSet;
@ -81,11 +83,17 @@ use std::{error::Error, fmt::Display, iter::once};
#[cfg(doc)]
use crate::{asg::graph::object::ObjectRel, span::Span};
pub fn topo_sort(
/// Topological sort with cutting of ontologically permitted cycles.
///
/// This is a TAMER-specific topological sort that is aware of the graph's
/// ontology and will automatically sort an acyclic subgraph produced by
/// cutting permitted cycles.
/// See the [module-level documentation](self) for more information.
pub fn topo_sort<O: ObjectKind>(
asg: &Asg,
init: impl Iterator<Item = ObjectIndex<Object>>,
init: impl Iterator<Item = ObjectIndex<O>>,
) -> TopoPostOrderDfs {
TopoPostOrderDfs::new(asg, init)
TopoPostOrderDfs::new(asg, init.map(ObjectIndex::widen))
}
/// Topological sort implemented as a post-order depth-first search (DFS).

View File

@ -23,7 +23,7 @@
use super::section::{SectionsError, XmleSections};
use crate::{
asg::{visit::topo_sort, Asg, AsgError, Object},
asg::{visit::topo_sort, Asg, AsgError, Ident, Object},
diagnose::{Annotate, Diagnostic},
diagnostic_unreachable,
span::UNKNOWN_SPAN,
@ -39,7 +39,13 @@ pub fn sort<'a, S: XmleSections<'a>>(asg: &'a Asg, mut dest: S) -> SortResult<S>
where
S: XmleSections<'a>,
{
let roots = [asg.root(UNKNOWN_SPAN).widen()].into_iter();
// All rooted identifiers will be linked.
// This is important,
// otherwise the sort will traverse into packages
// (which are also rooted)
// and we'll wind up linking everything rather than just the things
// we need.
let roots = asg.root(UNKNOWN_SPAN).edges_filtered::<Ident>(asg);
for result in topo_sort(asg, roots) {
let oi = result.map_err(AsgError::UnsupportedCycle)?;