tamer: asg::graph::Asg.graph: Finally encapsulate

With the previous commit using a visitor implemented within the `asg`
module, we can now finally encapsulate the graph.  This is a wonderfully
liberating, long-awaited change, since I have been fighting with the lack of
encapsulation for some time; it has made certain changes challenging and has
made the system more difficult to reason about.  It also made it impossible
to assert that invariants were _actually_ properly enforced, if things could
just peer into and modify the graph directly, out from underneath the API
that provides those assurances.

This also removes our dependency on Petgraph outside of the `asg`
module.  There are no plans to migrate away from it currently; we'll see how
the graph continues to evolve over time and what redundancies are introduced
with our data structures.  It may render petgraph unnecessary.

Interestingly, because my DFS implementation is so similar to Petgraph's,
the emitted ordering is _identical_ between this commit and the previous.

DEV-13162
main
Mike Gerwitz 2023-04-28 15:28:21 -04:00
parent 78c1a9136e
commit 77ada079e1
2 changed files with 2 additions and 5 deletions

View File

@ -87,9 +87,8 @@ type Ix = global::ProgSymSize;
/// For more information,
/// see the [module-level documentation][self].
pub struct Asg {
// TODO: private; see `ld::xmle::lower`.
/// Directed graph on which objects are stored.
pub graph: DiGraph<Node, AsgEdge, Ix>,
graph: DiGraph<Node, AsgEdge, Ix>,
/// Edge cache of [`SymbolId`][crate::sym::SymbolId] to
/// [`ObjectIndex`]es.

View File

@ -36,9 +36,7 @@ pub type SortResult<T> = Result<T, SortError>;
/// Lower ASG into [`XmleSections`] by ordering relocatable text fragments.
///
/// This performs the equivalent of a topological sort,
/// although function cycles are permitted.
/// The actual operation performed is a post-order depth-first traversal.
/// The topological sort is performed by [`topo_sort`].
pub fn sort<'a, S: XmleSections<'a>>(asg: &'a Asg, mut dest: S) -> SortResult<S>
where
S: XmleSections<'a>,