2023-03-07 13:35:01 -05:00
|
|
|
|
// ASG IR expression parsing
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2014-2023 Ryan Specialty, LLC.
|
|
|
|
|
//
|
|
|
|
|
// This file is part of TAME.
|
|
|
|
|
//
|
|
|
|
|
// 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/>.
|
|
|
|
|
|
|
|
|
|
//! AIR expression parser.
|
|
|
|
|
//!
|
|
|
|
|
//! See the [parent module](super) for more information.
|
|
|
|
|
|
|
|
|
|
use super::{
|
|
|
|
|
super::{
|
2023-03-07 16:28:32 -05:00
|
|
|
|
graph::object::{Expr, Object},
|
2023-03-07 13:35:01 -05:00
|
|
|
|
Asg, AsgError, ObjectIndex,
|
|
|
|
|
},
|
|
|
|
|
ir::AirBindableExpr,
|
tamer: asg::air: AirAggregateCtx: New AirAggregate::Context
Future changes to `AirAggregate` are going to require additional context (a
stack, specifically), but the `Context` is currently utilized
by `Asg`. This introduces a layer of abstraction that will allow us to add
the stack.
Alongside these changes, `ParseState` has been augmented with a `PubContext`
type that is utilized on public APIs, both maintaining BC with existing code
and keeping these implementation details encapsulated.
This does make a bit of a mess of the internal implementation, though, with
`asg_mut()` sprinkled about, so maybe the next commit can clean that up a
bit. EDIT: After adding `AsMut` to a bunch of asg::graph::object::*
methods, I decided against it, because it messes with the inferred
ownership, requiring explicit borrows via `as_mut()` where they were not
required before. I think the existing code is easier to reason about than
what would otherwise result from having `mut asg: impl AsMut<Asg>`
everwhere.
DEV-13708
2023-03-27 11:47:11 -04:00
|
|
|
|
AirAggregateCtx,
|
2023-03-07 13:35:01 -05:00
|
|
|
|
};
|
|
|
|
|
use crate::{
|
2023-03-28 11:34:05 -04:00
|
|
|
|
asg::{
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
graph::object::{ObjectIndexRelTo, ObjectIndexTo},
|
2023-03-28 11:34:05 -04:00
|
|
|
|
Ident, ObjectKind,
|
|
|
|
|
},
|
2023-03-07 13:35:01 -05:00
|
|
|
|
f::Functor,
|
|
|
|
|
parse::prelude::*,
|
|
|
|
|
};
|
2023-03-08 11:18:51 -05:00
|
|
|
|
|
|
|
|
|
#[cfg(doc)]
|
|
|
|
|
use StackEdge::{Dangling, Reachable};
|
|
|
|
|
|
|
|
|
|
/// Parse and aggregate [`Reachable`] [`Expr`]s into the graph,
|
|
|
|
|
/// with expression roots bound to their associated [`Ident`]s.
|
|
|
|
|
///
|
|
|
|
|
/// See [`ReachableOnly`] for more information.
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
pub type AirExprAggregateReachable = AirExprAggregate<ReachableOnly>;
|
2023-03-08 11:18:51 -05:00
|
|
|
|
|
|
|
|
|
/// Parse and aggregate both [`Reachable`] and [`Dangling`] [`Expr`]s into
|
|
|
|
|
/// the graph.
|
|
|
|
|
///
|
|
|
|
|
/// See [`StoreDangling`] for more information.
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
pub type AirExprAggregateStoreDangling = AirExprAggregate<StoreDangling>;
|
2023-03-07 13:35:01 -05:00
|
|
|
|
|
|
|
|
|
/// Parse an AIR expression with binding support.
|
|
|
|
|
///
|
|
|
|
|
/// Expressions are composable,
|
|
|
|
|
/// so this parser need only care about whether it has any active
|
|
|
|
|
/// expression being parsed.
|
|
|
|
|
///
|
|
|
|
|
/// This parser has no dead states---it
|
|
|
|
|
/// handles each of its tokens and performs error recovery on invalid
|
|
|
|
|
/// state transitions.
|
2023-03-07 16:28:32 -05:00
|
|
|
|
#[derive(Debug, PartialEq)]
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
pub enum AirExprAggregate<S: RootStrategy> {
|
2023-03-07 13:35:01 -05:00
|
|
|
|
/// Ready for an expression;
|
|
|
|
|
/// expression stack is empty.
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
Ready(S, ExprStack<Dormant>),
|
2023-03-07 13:35:01 -05:00
|
|
|
|
|
|
|
|
|
/// Building an expression.
|
2023-03-08 11:18:51 -05:00
|
|
|
|
BuildingExpr(S, ExprStack<Active>, ObjectIndex<Expr>),
|
2023-03-07 13:35:01 -05:00
|
|
|
|
}
|
2023-03-07 16:28:32 -05:00
|
|
|
|
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
impl<S: RootStrategy> Display for AirExprAggregate<S> {
|
2023-03-07 13:35:01 -05:00
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
|
match self {
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
Self::Ready(_, es) => {
|
2023-03-08 11:18:51 -05:00
|
|
|
|
write!(f, "ready for expression with {es}")
|
|
|
|
|
}
|
2023-03-07 13:35:01 -05:00
|
|
|
|
Self::BuildingExpr(_, es, _) => {
|
|
|
|
|
write!(f, "building expression with {es}")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
impl<S: RootStrategy> ParseState for AirExprAggregate<S> {
|
2023-03-07 13:35:01 -05:00
|
|
|
|
type Token = AirBindableExpr;
|
|
|
|
|
type Object = ();
|
|
|
|
|
type Error = AsgError;
|
tamer: asg::air: AirAggregateCtx: New AirAggregate::Context
Future changes to `AirAggregate` are going to require additional context (a
stack, specifically), but the `Context` is currently utilized
by `Asg`. This introduces a layer of abstraction that will allow us to add
the stack.
Alongside these changes, `ParseState` has been augmented with a `PubContext`
type that is utilized on public APIs, both maintaining BC with existing code
and keeping these implementation details encapsulated.
This does make a bit of a mess of the internal implementation, though, with
`asg_mut()` sprinkled about, so maybe the next commit can clean that up a
bit. EDIT: After adding `AsMut` to a bunch of asg::graph::object::*
methods, I decided against it, because it messes with the inferred
ownership, requiring explicit borrows via `as_mut()` where they were not
required before. I think the existing code is easier to reason about than
what would otherwise result from having `mut asg: impl AsMut<Asg>`
everwhere.
DEV-13708
2023-03-27 11:47:11 -04:00
|
|
|
|
type Context = AirAggregateCtx;
|
2023-03-07 13:35:01 -05:00
|
|
|
|
|
|
|
|
|
fn parse_token(
|
|
|
|
|
self,
|
|
|
|
|
tok: Self::Token,
|
tamer: asg::air: AirAggregateCtx: New AirAggregate::Context
Future changes to `AirAggregate` are going to require additional context (a
stack, specifically), but the `Context` is currently utilized
by `Asg`. This introduces a layer of abstraction that will allow us to add
the stack.
Alongside these changes, `ParseState` has been augmented with a `PubContext`
type that is utilized on public APIs, both maintaining BC with existing code
and keeping these implementation details encapsulated.
This does make a bit of a mess of the internal implementation, though, with
`asg_mut()` sprinkled about, so maybe the next commit can clean that up a
bit. EDIT: After adding `AsMut` to a bunch of asg::graph::object::*
methods, I decided against it, because it messes with the inferred
ownership, requiring explicit borrows via `as_mut()` where they were not
required before. I think the existing code is easier to reason about than
what would otherwise result from having `mut asg: impl AsMut<Asg>`
everwhere.
DEV-13708
2023-03-27 11:47:11 -04:00
|
|
|
|
ctx: &mut Self::Context,
|
2023-03-07 13:35:01 -05:00
|
|
|
|
) -> crate::parse::TransitionResult<Self::Super> {
|
|
|
|
|
use super::ir::{AirBind::*, AirExpr::*};
|
|
|
|
|
use AirBindableExpr::*;
|
|
|
|
|
use AirExprAggregate::*;
|
|
|
|
|
|
|
|
|
|
match (self, tok) {
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
(Ready(root, es), AirExpr(ExprStart(op, span))) => {
|
2023-03-29 09:46:17 -04:00
|
|
|
|
let oi = ctx.asg_mut().create(Expr::new(op, span));
|
2023-03-08 11:18:51 -05:00
|
|
|
|
Transition(BuildingExpr(root, es.activate(), oi)).incomplete()
|
2023-03-07 13:35:01 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-15 10:59:22 -04:00
|
|
|
|
(BuildingExpr(root, es, poi), AirExpr(ExprStart(op, span))) => {
|
2023-03-29 09:46:17 -04:00
|
|
|
|
let oi = poi.create_subexpr(ctx.asg_mut(), Expr::new(op, span));
|
2023-03-08 11:18:51 -05:00
|
|
|
|
Transition(BuildingExpr(root, es.push(poi), oi)).incomplete()
|
2023-03-07 13:35:01 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-15 10:59:22 -04:00
|
|
|
|
(BuildingExpr(root, es, oi), AirExpr(ExprEnd(end))) => {
|
2023-03-29 09:46:17 -04:00
|
|
|
|
let _ = oi.map_obj(ctx.asg_mut(), |expr| {
|
2023-03-07 13:35:01 -05:00
|
|
|
|
expr.map(|span| span.merge(end).unwrap_or(span))
|
|
|
|
|
});
|
|
|
|
|
|
2023-03-08 12:06:31 -05:00
|
|
|
|
let dangling = es.is_dangling();
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
let oi_root = ctx.dangling_expr_oi();
|
2023-03-08 12:06:31 -05:00
|
|
|
|
|
|
|
|
|
match (es.pop(), dangling) {
|
|
|
|
|
((es, Some(poi)), _) => {
|
2023-03-08 11:18:51 -05:00
|
|
|
|
Transition(BuildingExpr(root, es, poi)).incomplete()
|
2023-03-07 13:35:01 -05:00
|
|
|
|
}
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
((es, None), true) => root
|
|
|
|
|
.hold_dangling(ctx.asg_mut(), oi_root, oi)
|
|
|
|
|
.transition(Ready(root, es.done())),
|
|
|
|
|
((es, None), false) => {
|
|
|
|
|
Transition(Ready(root, es.done())).incomplete()
|
2023-03-07 13:35:01 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-08 11:18:51 -05:00
|
|
|
|
(BuildingExpr(root, es, oi), AirBind(BindIdent(id))) => {
|
2023-03-29 09:46:17 -04:00
|
|
|
|
let oi_root = ctx.rooting_oi().expect("TODO");
|
|
|
|
|
let oi_ident = root.defines(ctx.asg_mut(), oi_root, id);
|
2023-03-07 13:35:01 -05:00
|
|
|
|
|
|
|
|
|
// It is important that we do not mark this expression as
|
|
|
|
|
// reachable unless we successfully bind the identifier.
|
2023-03-29 09:46:17 -04:00
|
|
|
|
match oi_ident.bind_definition(ctx.asg_mut(), id, oi) {
|
2023-03-07 13:35:01 -05:00
|
|
|
|
Ok(_) => Transition(BuildingExpr(
|
2023-03-08 11:18:51 -05:00
|
|
|
|
root,
|
2023-03-07 14:30:56 -05:00
|
|
|
|
es.reachable_by(oi_ident),
|
2023-03-07 13:35:01 -05:00
|
|
|
|
oi,
|
|
|
|
|
))
|
|
|
|
|
.incomplete(),
|
2023-03-08 11:18:51 -05:00
|
|
|
|
Err(e) => Transition(BuildingExpr(root, es, oi)).err(e),
|
2023-03-07 13:35:01 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-08 11:18:51 -05:00
|
|
|
|
(BuildingExpr(root, es, oi), AirBind(RefIdent(ident))) => {
|
2023-03-29 09:46:17 -04:00
|
|
|
|
Transition(BuildingExpr(
|
|
|
|
|
root,
|
|
|
|
|
es,
|
|
|
|
|
oi.ref_expr(ctx.asg_mut(), ident),
|
|
|
|
|
))
|
|
|
|
|
.incomplete()
|
2023-03-07 13:35:01 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-15 10:59:22 -04:00
|
|
|
|
(st @ Ready(..), AirExpr(ExprEnd(span))) => {
|
2023-03-07 13:35:01 -05:00
|
|
|
|
Transition(st).err(AsgError::UnbalancedExpr(span))
|
|
|
|
|
}
|
2023-03-08 13:21:31 -05:00
|
|
|
|
|
|
|
|
|
// The binding may refer to a parent context.
|
|
|
|
|
(st @ Ready(..), tok @ AirBind(..)) => Transition(st).dead(tok),
|
2023-03-07 13:35:01 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn is_accepting(&self, _: &Self::Context) -> bool {
|
|
|
|
|
matches!(self, Self::Ready(..))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
impl<S: RootStrategy> AirExprAggregate<S> {
|
|
|
|
|
pub(super) fn new() -> Self {
|
|
|
|
|
Self::Ready(S::new(), ExprStack::default())
|
2023-03-07 13:35:01 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Stack of held expressions,
|
|
|
|
|
/// with the root expression at the bottom of the stack.
|
|
|
|
|
///
|
|
|
|
|
/// Expression [`ObjectIndex`]es are pushed onto this stack when
|
|
|
|
|
/// parsing a subexpression,
|
|
|
|
|
/// and are popped when the subexpression terminates.
|
|
|
|
|
/// The active expression is _not_ stored on this stack to avoid unnecessary
|
|
|
|
|
/// indirection.
|
|
|
|
|
///
|
|
|
|
|
/// Despite the immutable interface,
|
|
|
|
|
/// this does modify the inner [`Vec`] in-place;
|
|
|
|
|
/// it does not reallocate unless its capacity has been reached.
|
|
|
|
|
///
|
|
|
|
|
/// Unlike other parts of the system,
|
|
|
|
|
/// this is heap-allocated,
|
|
|
|
|
/// but should be very cache-friendly.
|
|
|
|
|
/// This reason for heap allocation is that this is explicitly
|
|
|
|
|
/// _unbounded_—systems like code generators ought to be able to output
|
|
|
|
|
/// expressions in a tacit style without worrying about arbitrary limits.
|
|
|
|
|
/// It is worth noting that the other parts of the system using
|
|
|
|
|
/// stack-allocated data structures is less about performance and more
|
|
|
|
|
/// about the simplicity afforded by keeping allocators out of the picture.
|
|
|
|
|
/// We'll address performance issues if they appear during profiling.
|
|
|
|
|
///
|
|
|
|
|
/// Another benefit of using [`Vec`] here is that Rust is able to properly
|
|
|
|
|
/// optimize away `memcpy`s for it,
|
|
|
|
|
/// rather than having to utilize the parser's mutable context.
|
|
|
|
|
/// Further,
|
|
|
|
|
/// the ASG is heap-allocated,
|
|
|
|
|
/// so we're not avoiding the heap anyway.
|
|
|
|
|
///
|
|
|
|
|
/// The interface is modeled after [Haskell's `Stack`][haskell-stack],
|
|
|
|
|
/// with a slight variation for [`Self::pop`] so that we can avoid
|
|
|
|
|
/// reallocation after a stack is used up,
|
|
|
|
|
/// which is frequent.
|
|
|
|
|
///
|
|
|
|
|
/// [haskell-stack]: https://hackage.haskell.org/package/Stack/docs/Data-Stack.html
|
|
|
|
|
///
|
|
|
|
|
/// The stack states [`Dormant`] and [`Active`] selectively provide
|
|
|
|
|
/// different APIs to enforce certain invariants,
|
|
|
|
|
/// as an alternative to re-allocating an inner [`Vec`] each time a new
|
|
|
|
|
/// root expression is encountered.
|
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
|
|
|
|
pub struct ExprStack<S>(Vec<ObjectIndex<Expr>>, S);
|
|
|
|
|
|
|
|
|
|
/// Expression stack is not in use and must be empty;
|
|
|
|
|
/// no ongoing expression parsing.
|
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
|
|
|
|
pub struct Dormant;
|
|
|
|
|
/// Expression stack is in use as part of an expression parse.
|
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
|
|
|
|
pub struct Active(StackEdge);
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
|
|
|
|
pub enum StackEdge {
|
|
|
|
|
/// Root expression is yet not reachable from any other object.
|
|
|
|
|
///
|
|
|
|
|
/// Dangling expressions are expected to transition into
|
|
|
|
|
/// [`Self::Reachable`] after being bound to an identifier.
|
|
|
|
|
/// Closing a dangling expression will result in a
|
|
|
|
|
/// [`AsgError::DanglingExpr`].
|
|
|
|
|
///
|
|
|
|
|
/// Binding a sub-expression does not bind the root of the stack,
|
|
|
|
|
/// since sub-expressions cannot reference their parent;
|
|
|
|
|
/// a stack is dangling until its root expression has been bound to
|
|
|
|
|
/// an identifier.
|
|
|
|
|
Dangling,
|
|
|
|
|
|
|
|
|
|
/// Root expression is reachable from another object.
|
|
|
|
|
///
|
2023-03-07 14:30:56 -05:00
|
|
|
|
/// The associated [`ObjectIndex`] serves as _evidence_ of this
|
|
|
|
|
/// assertion.
|
|
|
|
|
Reachable(ObjectIndex<Object>),
|
2023-03-07 13:35:01 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for StackEdge {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
|
match self {
|
|
|
|
|
Self::Dangling => write!(f, "dangling"),
|
2023-03-07 14:30:56 -05:00
|
|
|
|
Self::Reachable(oi) => {
|
|
|
|
|
write!(f, "reachable (by {oi})")
|
2023-03-07 13:35:01 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ExprStack<Dormant> {
|
|
|
|
|
/// Mark the stack as active,
|
|
|
|
|
/// exposing its stack API for use.
|
|
|
|
|
///
|
|
|
|
|
/// [`ExprStack::done`] will return the stack to a dormant state.
|
|
|
|
|
fn activate(self) -> ExprStack<Active> {
|
|
|
|
|
let Self(stack, _) = self;
|
|
|
|
|
ExprStack(stack, Active(StackEdge::Dangling))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ExprStack<Active> {
|
|
|
|
|
fn push(self, item: ObjectIndex<Expr>) -> Self {
|
|
|
|
|
let Self(mut stack, s) = self;
|
|
|
|
|
stack.push(item);
|
|
|
|
|
Self(stack, s)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Attempt to remove an item from the stack,
|
|
|
|
|
/// returning a new stack and the item,
|
|
|
|
|
/// if any.
|
|
|
|
|
///
|
|
|
|
|
/// This returns a new [`Self`] even if it is empty so that it can be
|
|
|
|
|
/// reused without having to reallocate.
|
|
|
|
|
fn pop(self) -> (Self, Option<ObjectIndex<Expr>>) {
|
|
|
|
|
let Self(mut stack, s) = self;
|
|
|
|
|
let oi = stack.pop();
|
|
|
|
|
|
|
|
|
|
(Self(stack, s), oi)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Whether the stack is dangling.
|
|
|
|
|
fn is_dangling(&self) -> bool {
|
|
|
|
|
matches!(self, Self(_, Active(StackEdge::Dangling)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Mark stack as reachable if processing the root expression.
|
|
|
|
|
///
|
|
|
|
|
/// `ident` is admitted as evidence of reachability,
|
|
|
|
|
/// both for debugging and for making it more difficult to
|
|
|
|
|
/// misuse this API.
|
|
|
|
|
/// If the stack is already reachable,
|
|
|
|
|
/// the previous identifier takes precedence.
|
|
|
|
|
///
|
|
|
|
|
/// If not parsing the root expression
|
|
|
|
|
/// (if the stack is non-empty),
|
|
|
|
|
/// this returns `self` unchanged.
|
2023-03-07 14:30:56 -05:00
|
|
|
|
fn reachable_by<O: ObjectKind>(self, oi: ObjectIndex<O>) -> Self {
|
2023-03-07 13:35:01 -05:00
|
|
|
|
match self {
|
|
|
|
|
Self(stack, Active(StackEdge::Dangling)) if stack.is_empty() => {
|
2023-03-07 14:30:56 -05:00
|
|
|
|
Self(stack, Active(StackEdge::Reachable(oi.widen())))
|
2023-03-07 13:35:01 -05:00
|
|
|
|
}
|
|
|
|
|
_ => self,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Mark the stack as dormant,
|
|
|
|
|
/// hiding its stack API and ensuring that its state is properly reset
|
|
|
|
|
/// for the next root expression.
|
|
|
|
|
///
|
|
|
|
|
/// [`ExprStack::activate`] will re-activate the stack for use.
|
|
|
|
|
fn done(self) -> ExprStack<Dormant> {
|
|
|
|
|
let Self(stack, _) = self;
|
|
|
|
|
|
|
|
|
|
// TODO: error if non-empty stack (unclosed expr)
|
|
|
|
|
if !stack.is_empty() {
|
|
|
|
|
todo!("ExprStack::done(): error on non-empty stack")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExprStack(stack, Dormant)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for ExprStack<Dormant> {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
// TODO: 16 is a generous guess that is very unlikely to be exceeded
|
|
|
|
|
// in practice at the time of writing,
|
|
|
|
|
// even with template expansion,
|
|
|
|
|
// but let's develop an informed heuristic.
|
|
|
|
|
// Note that this is very unlikely to make a difference;
|
|
|
|
|
// I just don't like using numbers without data to back them up.
|
|
|
|
|
Self(Vec::with_capacity(16), Dormant)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for ExprStack<Dormant> {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
|
let Self(stack, _) = self;
|
|
|
|
|
write!(f, "dormant expression stack of size {}", stack.capacity())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for ExprStack<Active> {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
|
let Self(stack, Active(edge_st)) = self;
|
|
|
|
|
write!(
|
|
|
|
|
f,
|
|
|
|
|
"active {edge_st} expression stack of length {} and size {}",
|
|
|
|
|
stack.len(),
|
|
|
|
|
stack.capacity()
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-08 11:18:51 -05:00
|
|
|
|
pub use root::*;
|
|
|
|
|
mod root {
|
|
|
|
|
use super::*;
|
|
|
|
|
use std::fmt::Debug;
|
|
|
|
|
|
|
|
|
|
/// The rooting strategy to employ after an [`Expr`] construction.
|
|
|
|
|
///
|
|
|
|
|
/// The method [`Self::defines`] roots an identifier,
|
|
|
|
|
/// stating that the object associated with [`Self`] is responsible
|
|
|
|
|
/// for the definition associated with this identifier.
|
|
|
|
|
/// An identified expression will be rooted in [`Self`] even if it is a
|
|
|
|
|
/// sub-expression.
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
pub trait RootStrategy: Debug + PartialEq {
|
2023-03-08 11:18:51 -05:00
|
|
|
|
/// Declare `oi` as the root of all accepted [`Expr`]s produced by
|
|
|
|
|
/// the parser.
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
fn new() -> Self;
|
2023-03-08 11:18:51 -05:00
|
|
|
|
|
|
|
|
|
/// Look up the provided identifier `id` on the [`Asg`] and indicate
|
|
|
|
|
/// that its definition is associated with [`Self`]'s root.
|
|
|
|
|
///
|
|
|
|
|
/// This is invoked for _all_ identifiers,
|
|
|
|
|
/// including sub-expressions.
|
2023-03-28 16:14:09 -04:00
|
|
|
|
fn defines(
|
|
|
|
|
&self,
|
|
|
|
|
asg: &mut Asg,
|
|
|
|
|
oi_root: ObjectIndexTo<Ident>,
|
|
|
|
|
id: SPair,
|
|
|
|
|
) -> ObjectIndex<Ident>;
|
2023-03-08 12:06:31 -05:00
|
|
|
|
|
|
|
|
|
/// Hold or reject a [`Dangling`] root [`Expr`].
|
|
|
|
|
///
|
|
|
|
|
/// A [`Dangling`] expression is not reachable by any other object,
|
|
|
|
|
/// so this strategy must decide whether to root it in [`Self`] or
|
|
|
|
|
/// reject it.
|
|
|
|
|
fn hold_dangling(
|
|
|
|
|
&self,
|
|
|
|
|
asg: &mut Asg,
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
oi_root: Option<ObjectIndexTo<Expr>>,
|
2023-03-08 12:06:31 -05:00
|
|
|
|
oi_expr: ObjectIndex<Expr>,
|
|
|
|
|
) -> Result<(), AsgError>;
|
2023-03-08 11:18:51 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Accept and root only [`Reachable`] root expressions.
|
|
|
|
|
///
|
|
|
|
|
/// Note that a root expresion is still [`Dangling`]
|
|
|
|
|
/// (and therefore not [`Reachable`])
|
|
|
|
|
/// even if one of its sub-expressions has been bound to an
|
|
|
|
|
/// identifier.
|
|
|
|
|
/// In that case,
|
|
|
|
|
/// the sub-expression will be rooted in [`Self`],
|
|
|
|
|
/// but the [`Dangling`] root expression will still be rejected.
|
|
|
|
|
///
|
2023-03-22 12:19:40 -04:00
|
|
|
|
/// This expects identifiers to be rooted in the global environment,
|
|
|
|
|
/// which is the package representing the active compilation unit.
|
|
|
|
|
/// This may be relaxed once identifier caching is generalized;
|
|
|
|
|
/// at the time of writing it is too coupled to the graph root.
|
|
|
|
|
///
|
2023-03-08 11:18:51 -05:00
|
|
|
|
/// See [`RootStrategy`] for more information.
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
pub struct ReachableOnly;
|
|
|
|
|
|
|
|
|
|
impl RootStrategy for ReachableOnly {
|
|
|
|
|
fn new() -> Self {
|
|
|
|
|
Self
|
2023-03-08 11:18:51 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-28 16:14:09 -04:00
|
|
|
|
fn defines(
|
|
|
|
|
&self,
|
|
|
|
|
asg: &mut Asg,
|
|
|
|
|
oi_root: ObjectIndexTo<Ident>,
|
|
|
|
|
id: SPair,
|
|
|
|
|
) -> ObjectIndex<Ident> {
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
asg.lookup_global_or_missing(id)
|
|
|
|
|
.add_edge_from(asg, oi_root, None)
|
2023-03-08 11:18:51 -05:00
|
|
|
|
}
|
2023-03-08 12:06:31 -05:00
|
|
|
|
|
|
|
|
|
fn hold_dangling(
|
|
|
|
|
&self,
|
|
|
|
|
asg: &mut Asg,
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
_oi_root: Option<ObjectIndexTo<Expr>>,
|
2023-03-08 12:06:31 -05:00
|
|
|
|
oi_expr: ObjectIndex<Expr>,
|
|
|
|
|
) -> Result<(), AsgError> {
|
|
|
|
|
Err(AsgError::DanglingExpr(oi_expr.resolve(asg).span()))
|
|
|
|
|
}
|
2023-03-08 11:18:51 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Accept both [`Reachable`] and [`Dangling`] expressions.
|
|
|
|
|
///
|
|
|
|
|
/// A [`Dangling`] expression will have the [`Expr`] rooted instead of
|
|
|
|
|
/// an [`Ident`].
|
|
|
|
|
///
|
|
|
|
|
/// Sub-expressions can be thought of as utilizing this strategy with an
|
|
|
|
|
/// implicit parent [`ObjectIndex<Expr>`](ObjectIndex).
|
|
|
|
|
///
|
2023-03-22 12:19:40 -04:00
|
|
|
|
/// Unlike [`ReachableOnly`],
|
|
|
|
|
/// this does _not_ cache identifiers in the global environment.
|
|
|
|
|
/// See there for more information.
|
|
|
|
|
///
|
2023-03-08 11:18:51 -05:00
|
|
|
|
/// See [`RootStrategy`] for more information.
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
pub struct StoreDangling;
|
|
|
|
|
|
|
|
|
|
impl RootStrategy for StoreDangling {
|
|
|
|
|
fn new() -> Self {
|
|
|
|
|
Self
|
2023-03-08 11:18:51 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-28 16:14:09 -04:00
|
|
|
|
fn defines(
|
|
|
|
|
&self,
|
|
|
|
|
asg: &mut Asg,
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
oi_root: ObjectIndexTo<Ident>,
|
2023-03-28 16:14:09 -04:00
|
|
|
|
name: SPair,
|
|
|
|
|
) -> ObjectIndex<Ident> {
|
2023-03-22 12:19:40 -04:00
|
|
|
|
// This cannot simply call [`ReachableOnly`]'s `defines` because
|
|
|
|
|
// we cannot cache in the global environment.
|
|
|
|
|
// This can be realized once caching is generalized;
|
|
|
|
|
// see the commit that introduced this comment.
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
oi_root.declare_local(asg, name)
|
2023-03-08 11:18:51 -05:00
|
|
|
|
}
|
2023-03-08 12:06:31 -05:00
|
|
|
|
|
|
|
|
|
fn hold_dangling(
|
|
|
|
|
&self,
|
2023-03-08 23:44:40 -05:00
|
|
|
|
asg: &mut Asg,
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
oi_root: Option<ObjectIndexTo<Expr>>,
|
2023-03-08 23:44:40 -05:00
|
|
|
|
oi_expr: ObjectIndex<Expr>,
|
2023-03-08 12:06:31 -05:00
|
|
|
|
) -> Result<(), AsgError> {
|
tamer: asg::air: Eliminate parent context from AirExprAggregate
This does the same thing to `AirExprAggregate` that was previously done for
`AirAggregate`, taking all parent context from the stack.
This results in a fairly significant simplification of the code, which is
nice, and it makes the `RootStrategy` obviously obsolete in the dangling
case, which will result in more refactoring to simplify it even more.
I regret not taking this route to begin with, but not only was I hoping I
wouldn't need to, but I was still deriving the graph structure and wasn't
sure how this would eventually turn out. These commits serve as a proof of
necessity. Or, at least, concrete rationale.
It's worth noting that this also introduces `From` implementations for
`AirAggregate` and the child parsers, and then uses _that_ to push context
from the `AirTplAggregate` parser. This means that we're just about ready
for it to serve as a superstate. But there is still a specialization of
`AirExprAggregate` in that `From` impl, which must be removed.
DEV-13708
2023-03-29 11:19:59 -04:00
|
|
|
|
oi_root.expect("TODO").add_edge_to(asg, oi_expr, None);
|
2023-03-08 23:44:40 -05:00
|
|
|
|
Ok(())
|
2023-03-08 12:06:31 -05:00
|
|
|
|
}
|
2023-03-08 11:18:51 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-07 13:35:01 -05:00
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub mod test;
|