tamer: asg::air::expr: Remove RootStrategy::hold_dangling
Whether or not dangling expressions are permitted is now based solely off of the stack context, which is also much more intuitive. `RootStrategy` now only does one thing, and the existing comments describe why it exists despite that one thing seeming very similar. `RootStrategy` further alludes to how `ExprStack` could also be eliminated, should it be worth doing so. It is a tad redundant now with the new stack. DEV-13708main
parent
525adb8a6c
commit
26ddb2ae9d
|
@ -123,9 +123,10 @@ impl<S: RootStrategy> ParseState for AirExprAggregate<S> {
|
||||||
((es, Some(poi)), _) => {
|
((es, Some(poi)), _) => {
|
||||||
Transition(BuildingExpr(root, es, poi)).incomplete()
|
Transition(BuildingExpr(root, es, poi)).incomplete()
|
||||||
}
|
}
|
||||||
((es, None), true) => root
|
((es, None), true) => {
|
||||||
.hold_dangling(ctx.asg_mut(), oi_root, oi)
|
Self::hold_dangling(ctx.asg_mut(), oi_root, oi)
|
||||||
.transition(Ready(root, es.done())),
|
.transition(Ready(root, es.done()))
|
||||||
|
}
|
||||||
((es, None), false) => {
|
((es, None), false) => {
|
||||||
Transition(Ready(root, es.done())).incomplete()
|
Transition(Ready(root, es.done())).incomplete()
|
||||||
}
|
}
|
||||||
|
@ -176,6 +177,22 @@ impl<S: RootStrategy> AirExprAggregate<S> {
|
||||||
pub(super) fn new() -> Self {
|
pub(super) fn new() -> Self {
|
||||||
Self::Ready(S::new(), ExprStack::default())
|
Self::Ready(S::new(), ExprStack::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Hold or reject a [`Dangling`] root [`Expr`].
|
||||||
|
///
|
||||||
|
/// A [`Dangling`] expression is not reachable by any other object.
|
||||||
|
/// If there is no context able to handle such an expression,
|
||||||
|
/// then an [`AsgError::DanglingExpr`] will be returned.
|
||||||
|
fn hold_dangling(
|
||||||
|
asg: &mut Asg,
|
||||||
|
oi_root: Option<ObjectIndexTo<Expr>>,
|
||||||
|
oi_expr: ObjectIndex<Expr>,
|
||||||
|
) -> Result<(), AsgError> {
|
||||||
|
oi_root
|
||||||
|
.ok_or(AsgError::DanglingExpr(oi_expr.resolve(asg).span()))?
|
||||||
|
.add_edge_to(asg, oi_expr, None);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stack of held expressions,
|
/// Stack of held expressions,
|
||||||
|
@ -396,18 +413,6 @@ mod root {
|
||||||
oi_root: ObjectIndexTo<Ident>,
|
oi_root: ObjectIndexTo<Ident>,
|
||||||
id: SPair,
|
id: SPair,
|
||||||
) -> ObjectIndex<Ident>;
|
) -> ObjectIndex<Ident>;
|
||||||
|
|
||||||
/// 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,
|
|
||||||
oi_root: Option<ObjectIndexTo<Expr>>,
|
|
||||||
oi_expr: ObjectIndex<Expr>,
|
|
||||||
) -> Result<(), AsgError>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accept and root only [`Reachable`] root expressions.
|
/// Accept and root only [`Reachable`] root expressions.
|
||||||
|
@ -443,15 +448,6 @@ mod root {
|
||||||
asg.lookup_global_or_missing(id)
|
asg.lookup_global_or_missing(id)
|
||||||
.add_edge_from(asg, oi_root, None)
|
.add_edge_from(asg, oi_root, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hold_dangling(
|
|
||||||
&self,
|
|
||||||
asg: &mut Asg,
|
|
||||||
_oi_root: Option<ObjectIndexTo<Expr>>,
|
|
||||||
oi_expr: ObjectIndex<Expr>,
|
|
||||||
) -> Result<(), AsgError> {
|
|
||||||
Err(AsgError::DanglingExpr(oi_expr.resolve(asg).span()))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accept both [`Reachable`] and [`Dangling`] expressions.
|
/// Accept both [`Reachable`] and [`Dangling`] expressions.
|
||||||
|
@ -487,16 +483,6 @@ mod root {
|
||||||
// see the commit that introduced this comment.
|
// see the commit that introduced this comment.
|
||||||
oi_root.declare_local(asg, name)
|
oi_root.declare_local(asg, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hold_dangling(
|
|
||||||
&self,
|
|
||||||
asg: &mut Asg,
|
|
||||||
oi_root: Option<ObjectIndexTo<Expr>>,
|
|
||||||
oi_expr: ObjectIndex<Expr>,
|
|
||||||
) -> Result<(), AsgError> {
|
|
||||||
oi_root.expect("TODO").add_edge_to(asg, oi_expr, None);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue