From 4168c579fd29d8b91da34568fa3a907bc7857db3 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 25 Jul 2023 11:15:41 -0400 Subject: [PATCH] tamer: asg::graph::Asg{Object=>Rel}Mut: Trait-level target type This allows for a declarative matching on edge targets using the trait system, rather than having to convert the type to a runtime value to match on (which doesn't make a whole lot of sense). See a commit to follow shortly (with Tpl) for an example use case. DEV-13163 --- tamer/src/asg/graph.rs | 6 +++--- tamer/src/asg/graph/object.rs | 6 +++--- tamer/src/asg/graph/object/doc.rs | 2 +- tamer/src/asg/graph/object/expr.rs | 2 +- tamer/src/asg/graph/object/ident.rs | 2 +- tamer/src/asg/graph/object/meta.rs | 2 +- tamer/src/asg/graph/object/pkg.rs | 2 +- tamer/src/asg/graph/object/rel.rs | 9 +++++---- tamer/src/asg/graph/object/root.rs | 2 +- tamer/src/asg/graph/object/tpl.rs | 2 +- 10 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tamer/src/asg/graph.rs b/tamer/src/asg/graph.rs index 8a3ae72b..4daa1732 100644 --- a/tamer/src/asg/graph.rs +++ b/tamer/src/asg/graph.rs @@ -393,7 +393,7 @@ fn diagnostic_node_missing_desc( ] } -/// Mutation of an [`Object`] or its edges on the [`Asg`]. +/// Mutation of an [`Object`]'s relationships (edges) on the [`Asg`]. /// /// This trait is intended to delegate certain responsibilities to /// [`ObjectKind`]s so that they may enforce their own invariants with @@ -403,7 +403,7 @@ fn diagnostic_node_missing_desc( /// trait, /// but the current module structure together with Rust's visibility /// with sibling modules doesn't seem to make that possible. -pub trait AsgObjectMut: ObjectKind { +pub trait AsgRelMut: ObjectKind { /// Allow an object to handle or reject the creation of an edge from it /// to another object. /// @@ -434,7 +434,7 @@ pub trait AsgObjectMut: ObjectKind { /// Unlike the type of [`Asg::add_edge`], /// the source [`ObjectIndex`] has been narrowed to the appropriate /// type for you. - fn pre_add_edge( + fn pre_add_edge( asg: &mut Asg, _from_oi: ObjectIndex, _to_oi: ObjectIndex, diff --git a/tamer/src/asg/graph/object.rs b/tamer/src/asg/graph/object.rs index 3c7347ff..74199a18 100644 --- a/tamer/src/asg/graph/object.rs +++ b/tamer/src/asg/graph/object.rs @@ -114,8 +114,8 @@ //! follow an edge to an unexpected [`ObjectKind`]. //! //! In addition to these static guarantees, -//! [`AsgObjectMut`](super::AsgObjectMut) is utilized by [`Asg`] to -//! consult an object before an edge is added _from_ it, +//! [`AsgRelMut`](super::AsgRelMut) is utilized by [`Asg`] to consult an +//! object before an edge is added _from_ it, //! allowing objects to assert ownership over their edges and cache //! information about them as the graph is being built. @@ -162,7 +162,7 @@ pub use tpl::Tpl; /// Often-needed exports for [`ObjectKind`]s. pub mod prelude { pub use super::{ - super::{super::error::AsgError, Asg, AsgObjectMut}, + super::{super::error::AsgError, Asg, AsgRelMut}, Object, ObjectIndex, ObjectIndexRelTo, ObjectKind, ObjectRel, ObjectRelFrom, ObjectRelTo, ObjectRelTy, ObjectRelatable, ObjectTreeRelTo, diff --git a/tamer/src/asg/graph/object/doc.rs b/tamer/src/asg/graph/object/doc.rs index 6ce6af69..d125009a 100644 --- a/tamer/src/asg/graph/object/doc.rs +++ b/tamer/src/asg/graph/object/doc.rs @@ -92,4 +92,4 @@ object_rel! { } } -impl AsgObjectMut for Doc {} +impl AsgRelMut for Doc {} diff --git a/tamer/src/asg/graph/object/expr.rs b/tamer/src/asg/graph/object/expr.rs index 8b5a290b..d131f7cb 100644 --- a/tamer/src/asg/graph/object/expr.rs +++ b/tamer/src/asg/graph/object/expr.rs @@ -269,4 +269,4 @@ impl ObjectIndex { } } -impl AsgObjectMut for Expr {} +impl AsgRelMut for Expr {} diff --git a/tamer/src/asg/graph/object/ident.rs b/tamer/src/asg/graph/object/ident.rs index 500035ed..3e9a3193 100644 --- a/tamer/src/asg/graph/object/ident.rs +++ b/tamer/src/asg/graph/object/ident.rs @@ -1406,7 +1406,7 @@ impl ObjectIndex { } } -impl AsgObjectMut for Ident {} +impl AsgRelMut for Ident {} #[cfg(test)] mod test; diff --git a/tamer/src/asg/graph/object/meta.rs b/tamer/src/asg/graph/object/meta.rs index fbc935e8..6a6a9d1b 100644 --- a/tamer/src/asg/graph/object/meta.rs +++ b/tamer/src/asg/graph/object/meta.rs @@ -307,4 +307,4 @@ impl ObjectIndex { } } -impl AsgObjectMut for Meta {} +impl AsgRelMut for Meta {} diff --git a/tamer/src/asg/graph/object/pkg.rs b/tamer/src/asg/graph/object/pkg.rs index 62a8b384..1773c995 100644 --- a/tamer/src/asg/graph/object/pkg.rs +++ b/tamer/src/asg/graph/object/pkg.rs @@ -148,4 +148,4 @@ impl ObjectIndex { } } -impl AsgObjectMut for Pkg {} +impl AsgRelMut for Pkg {} diff --git a/tamer/src/asg/graph/object/rel.rs b/tamer/src/asg/graph/object/rel.rs index 3404cfd9..d2419824 100644 --- a/tamer/src/asg/graph/object/rel.rs +++ b/tamer/src/asg/graph/object/rel.rs @@ -27,7 +27,7 @@ use super::{ }; use crate::{ asg::{ - graph::{object::Tpl, AsgObjectMut}, + graph::{object::Tpl, AsgRelMut}, Asg, AsgError, }, f::Functor, @@ -504,7 +504,8 @@ impl Display for DynObjectRel { /// statically analyzed by the type system to ensure that they only /// construct graphs that adhere to this schema. pub trait ObjectRelTo = - ObjectRelatable where ::Rel: From>; + ObjectRelatable + AsgRelMut + where ::Rel: From>; /// Reverse of [`ObjectRelTo`]. /// @@ -532,7 +533,7 @@ pub trait ObjectTreeRelTo: /// This is used to derive [`ObjectRelTo``], /// which can be used as a trait bound to assert a valid relationship /// between two [`Object`]s. -pub trait ObjectRelatable: ObjectKind + AsgObjectMut { +pub trait ObjectRelatable: ObjectKind { /// Sum type representing a subset of [`Object`] variants that are valid /// targets for edges from [`Self`]. /// @@ -840,7 +841,7 @@ pub trait ObjectIndexRelTo: Sized + Clone + Copy { /// without sacrificing edge ownership. /// /// For more information, - /// see [`AsgObjectMut::pre_add_edge`]. + /// see [`AsgRelMut::pre_add_edge`]. /// /// _This should only be called by [`Asg`]_; /// `commit` is expected to be a continuation that adds the edge to diff --git a/tamer/src/asg/graph/object/root.rs b/tamer/src/asg/graph/object/root.rs index d9a8fdf5..6cfd536c 100644 --- a/tamer/src/asg/graph/object/root.rs +++ b/tamer/src/asg/graph/object/root.rs @@ -71,4 +71,4 @@ impl ObjectIndex { } } -impl AsgObjectMut for Root {} +impl AsgRelMut for Root {} diff --git a/tamer/src/asg/graph/object/tpl.rs b/tamer/src/asg/graph/object/tpl.rs index 29ba83bc..75c8adfa 100644 --- a/tamer/src/asg/graph/object/tpl.rs +++ b/tamer/src/asg/graph/object/tpl.rs @@ -132,4 +132,4 @@ impl ObjectIndex { } } -impl AsgObjectMut for Tpl {} +impl AsgRelMut for Tpl {}