2020-01-12 22:59:16 -05:00
|
|
|
// Abstract semantic graph (ASG) intermediate representation (IR)
|
|
|
|
//
|
2023-01-17 23:09:25 -05:00
|
|
|
// Copyright (C) 2014-2023 Ryan Specialty, LLC.
|
2020-03-06 11:05:18 -05:00
|
|
|
//
|
|
|
|
// This file is part of TAME.
|
2020-01-12 22:59:16 -05:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
//! Abstract semantic graph.
|
|
|
|
//!
|
|
|
|
//! The [abstract semantic graph][asg] (ASG) is an IR representing the
|
|
|
|
//! relationship between objects using a directed [graph][].
|
|
|
|
//! An _object_ is an identifier or expression.
|
|
|
|
//!
|
|
|
|
//! Since TAME is a declarative language,
|
|
|
|
//! the ASG does not represent control flow;
|
|
|
|
//! instead, it represents the relationship between objects and their
|
|
|
|
//! dependencies.
|
|
|
|
//! Control flow is determined solely by the [linker][crate::ld] based on
|
|
|
|
//! these dependencies.
|
|
|
|
//!
|
|
|
|
//! See [`crate::global`] for available index sizes depending on context.
|
|
|
|
//! For example,
|
|
|
|
//! a linker may choose to use [`crate::global::ProgIdentSize`];
|
|
|
|
//!
|
|
|
|
//!
|
2023-03-10 14:11:55 -05:00
|
|
|
//! Graph Ontology
|
|
|
|
//! ==============
|
2023-01-23 11:40:10 -05:00
|
|
|
//! Each node (vertex) in the graph represents an [`Object`],
|
2020-01-12 22:59:16 -05:00
|
|
|
//! such as an identifier or an expression.
|
2023-01-23 11:40:10 -05:00
|
|
|
//! For information on how [`Object`]s are stored and represented on the
|
|
|
|
//! graph,
|
|
|
|
//! and for information on relationships between objects,
|
|
|
|
//! see the [`graph::object`] module.
|
2020-01-12 22:59:16 -05:00
|
|
|
//!
|
2023-03-10 14:11:55 -05:00
|
|
|
//! A visualization of the graph ontology is provided here:
|
|
|
|
//!
|
|
|
|
//! ![Visualization of ASG ontology](./ontviz.svg)
|
|
|
|
//!
|
2020-01-12 22:59:16 -05:00
|
|
|
//! Graphs may contain cycles for recursive functions—that is,
|
|
|
|
//! TAME's ASG is _not_ a DAG.
|
|
|
|
//! Mutually recursive functions are therefore represented as
|
|
|
|
//! [strongly connected components][scc].
|
|
|
|
//!
|
|
|
|
//! [asg]: https://en.wikipedia.org/wiki/Abstract_semantic_graph
|
|
|
|
//! [graph]: https://en.wikipedia.org/wiki/Graph_(discrete_mathematics)
|
|
|
|
//! [scc]: https://en.wikipedia.org/wiki/Strongly_connected_component
|
|
|
|
|
2022-05-11 16:38:59 -04:00
|
|
|
mod error;
|
2020-01-12 22:59:16 -05:00
|
|
|
mod graph;
|
|
|
|
|
tamer: Refactor asg_builder into obj::xmlo::lower and asg::air
This finally uses `parse` all the way up to aggregation into the ASG, as can
be seen by the mess in `poc`. This will be further simplified---I just need
to get this committed so that I can mentally get it off my plate. I've been
separating this commit into smaller commits, but there's a point where it's
just not worth the effort anymore. I don't like making large changes such
as this one.
There is still work to do here. First, it's worth re-mentioning that
`poc` means "proof-of-concept", and represents things that still need a
proper home/abstraction.
Secondly, `poc` is retrieving the context of two parsers---`LowerContext`
and `Asg`. The latter is desirable, since it's the final aggregation point,
but the former needs to be eliminated; in particular, packages need to be
worked into the ASG so that `found` can be removed.
Recursively loading `xmlo` files still happens in `poc`, but the compiler
will need this as well. Once packages are on the ASG, along with their
state, that responsibility can be generalized as well.
That will then simplify lowering even further, to the point where hopefully
everything has the same shape (once final aggregation has an abstraction),
after which we can then create a final abstraction to concisely stitch
everything together. Right now, Rust isn't able to infer `S` for
`Lower<S, LS>`, which is unfortunate, but we'll be able to help it along
with a more explicit abstraction.
DEV-11864
2022-05-27 13:51:29 -04:00
|
|
|
pub mod air;
|
|
|
|
|
2022-05-11 16:38:59 -04:00
|
|
|
pub use error::AsgError;
|
2023-01-17 22:58:41 -05:00
|
|
|
pub use graph::{
|
|
|
|
object::{
|
|
|
|
expr::{Expr, ExprDim, ExprOp},
|
|
|
|
ident::{
|
|
|
|
FragmentText, Ident, IdentKind, Source, TransitionError,
|
|
|
|
TransitionResult, UnresolvedError,
|
|
|
|
},
|
|
|
|
Object, ObjectIndex, ObjectKind,
|
2023-01-17 22:48:19 -05:00
|
|
|
},
|
2023-02-22 23:16:53 -05:00
|
|
|
visit,
|
|
|
|
xmli::AsgTreeToXirf,
|
|
|
|
Asg, AsgResult, IndexType,
|
2020-03-16 11:49:41 -04:00
|
|
|
};
|
2020-01-12 22:59:16 -05:00
|
|
|
|
|
|
|
/// Default concrete ASG implementation.
|
2022-05-12 15:44:32 -04:00
|
|
|
pub type DefaultAsg = graph::Asg;
|