tamer: asg::object: Move into graph module

The ASG delegates certain operations to Objects so that they may enforce
their own invariants and ontology.  It is therefore important that only
objects have access to certain methods on `Asg`, otherwise those invariants
could be circumvented.

It should be noted that the nesting of this module is such that AIR should
_not_ have privileged access to the ASG---it too must utilize objects to
ensure those invariants are enforced in a single place.

DEV-13597
main
Mike Gerwitz 2023-01-17 22:58:41 -05:00
parent cdfe9083f8
commit 1be0f2fe70
7 changed files with 24 additions and 20 deletions

View File

@ -20,9 +20,10 @@
//! These are tested as if they are another API directly atop of the ASG,
//! since that is how they are used.
use super::super::graph::object::{ObjectKind, ObjectRelTo};
use super::super::Ident;
use super::*;
use crate::{
asg::{object::ObjectRelTo, Ident, ObjectKind},
parse::{ParseError, Parsed},
span::dummy::*,
};

View File

@ -20,7 +20,6 @@
//! Abstract semantic graph.
use super::{
object::{ObjectContainer, ObjectRelTo},
AsgError, FragmentText, Ident, IdentKind, Object, ObjectIndex, ObjectKind,
Source, TransitionResult,
};
@ -39,6 +38,10 @@ use petgraph::{
};
use std::{fmt::Debug, result::Result};
pub mod object;
use object::{ObjectContainer, ObjectRelTo};
/// Datatype representing node and edge indexes.
pub trait IndexType = petgraph::graph::IndexType;
@ -57,7 +60,7 @@ pub type Node = ObjectContainer;
/// Index size for Graph nodes and edges.
type Ix = global::ProgSymSize;
/// An abstract semantic graph (ASG) of [objects][super::object].
/// An abstract semantic graph (ASG) of [objects](object).
///
/// This implementation is currently based on [`petgraph`].
///
@ -384,7 +387,7 @@ impl Asg {
///
/// For more information on how the ASG's ontology is enforced statically,
/// see [`ObjectRelTo`].
pub(super) fn add_edge<OA: ObjectKind, OB: ObjectKind>(
fn add_edge<OA: ObjectKind, OB: ObjectKind>(
&mut self,
from_oi: ObjectIndex<OA>,
to_oi: ObjectIndex<OB>,
@ -416,7 +419,7 @@ impl Asg {
/// [`ObjectIndex`].
/// This method will attempt to narrow to that object type,
/// panicing if there is a mismatch;
/// see the [`object` module documentation](super::object) for more
/// see the [`object` module documentation](object) for more
/// information and rationale on this behavior.
///
/// Panics
@ -470,11 +473,7 @@ impl Asg {
/// it may prefer to filter unwanted objects rather than panicing
/// if they do not match a given [`ObjectKind`],
/// depending on its ontology.
///
/// You should prefer methods on [`ObjectIndex`] instead,
/// with this method expected to be used only in those
/// implementations.
pub(super) fn edges<'a, O: ObjectKind + 'a>(
fn edges<'a, O: ObjectKind + 'a>(
&'a self,
oi: ObjectIndex<O>,
) -> impl Iterator<Item = ObjectIndex<Object>> + 'a {

View File

@ -61,7 +61,7 @@
//! [`ObjectIndex`] is associated with a span derived from the point of its
//! creation to handle this diagnostic situation automatically.
use super::{Asg, Expr, Ident};
use super::Asg;
use crate::{
diagnose::{panic::DiagnosticPanic, Annotate, AnnotatedSpan},
diagnostic_panic,
@ -74,6 +74,9 @@ use std::{convert::Infallible, fmt::Display, marker::PhantomData};
pub mod expr;
pub mod ident;
use expr::Expr;
use ident::Ident;
/// An object on the ASG.
///
/// See the [module-level documentation](super) for more information.

View File

@ -17,7 +17,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//! Identifiers (a type of [object][super::object]).
//! Identifiers (a type of [object](super)).
use super::{
super::{Asg, AsgError, ObjectIndex, ObjectKind},

View File

@ -65,19 +65,20 @@
mod error;
mod graph;
mod object;
pub mod air;
pub use error::AsgError;
pub use graph::{Asg, AsgResult, IndexType};
pub use object::{
expr::{Expr, ExprDim, ExprOp},
ident::{
FragmentText, Ident, IdentKind, Source, TransitionError,
TransitionResult, UnresolvedError,
pub use graph::{
object::{
expr::{Expr, ExprDim, ExprOp},
ident::{
FragmentText, Ident, IdentKind, Source, TransitionError,
TransitionResult, UnresolvedError,
},
Object, ObjectIndex, ObjectKind,
},
Object, ObjectIndex, ObjectKind,
Asg, AsgResult, IndexType,
};
/// Default concrete ASG implementation.