tamer: asg::graph: Root->Ident {tree=>cross} edge

tameld isn't yet adding edges to Idents from their associated Pkg (see
previous commit), but this formalizes how the ontology will interpret such a
relationship.  The idea is that Idents are always owned by Pkgs, but they
may be optionally explicitly rooted, which will be used by a particular type
of DFS walk that is about to be written, which can ignore Root->Pkg and
focus instead on cross edges to Idents.

Though it's not lost on me that now that I'll be introducing a DFS for the
linker, the terms "cross" and "tree" edge now become ambiguous; I used to
call them "ontological X edge", but I had fallen out of that habit; perhaps
I need to reintroduce that rigor.

DEV-13162
main
Mike Gerwitz 2023-04-24 09:44:02 -04:00
parent 48d9bca3b7
commit 42aa5bd407
2 changed files with 17 additions and 7 deletions

View File

@ -22,8 +22,8 @@
//! ![Visualization of ASG ontology](../ontviz.svg)
use self::object::{
DynObjectRel, NameableMissingObject, ObjectIndexRelTo,
ObjectIndexTreeRelTo, ObjectRelFrom, ObjectRelTy, ObjectRelatable, Root,
DynObjectRel, NameableMissingObject, ObjectIndexRelTo, ObjectRelFrom,
ObjectRelTy, ObjectRelatable, Root,
};
use super::{AsgError, Object, ObjectIndex, ObjectKind};
@ -199,7 +199,7 @@ impl Asg {
/// Debug builds contain an assertion that will panic in this instance.
pub(super) fn index<
O: ObjectRelatable,
OS: ObjectIndexTreeRelTo<O>,
OS: ObjectIndexRelTo<O>,
S: Into<SymbolId>,
>(
&mut self,
@ -219,7 +219,7 @@ impl Asg {
use crate::fmt::{DisplayWrapper, TtQuote};
crate::debug_diagnostic_panic!(
vec![
imm_env.into().note("at this scope boundary"),
imm_env.widen().note("at this scope boundary"),
prev_oi.note("previously indexed identifier was here"),
oi.internal_error(
"this identifier has already been indexed at the above scope boundary"
@ -259,7 +259,7 @@ impl Asg {
/// See [`Self::index`] for more information.
pub(super) fn lookup_or_missing<O: ObjectRelatable>(
&mut self,
imm_env: impl ObjectIndexTreeRelTo<O>,
imm_env: impl ObjectIndexRelTo<O>,
name: SPair,
) -> ObjectIndex<O>
where
@ -493,7 +493,7 @@ impl Asg {
/// compilation unit,
/// which is a package.
#[inline]
pub fn lookup<O: ObjectRelatable, OS: ObjectIndexTreeRelTo<O>>(
pub fn lookup<O: ObjectRelatable, OS: ObjectIndexRelTo<O>>(
&self,
imm_env: OS,
id: SPair,

View File

@ -45,8 +45,18 @@ impl Display for Root {
object_rel! {
/// The root of the graph by definition has no cross edges.
Root -> {
// Packages are always rooted since they are the toplevel
// collection.
tree Pkg,
tree Ident,
// Identifiers may optionally be explicitly rooted in contexts where
// the system cares only about particular identifiers and their
// dependencies,
// with `Pkg`s being only incidental.
// For example,
// `tameld` only links objects that are reachable from identifiers
// in the return map.
cross Ident,
}
}