tamer: asg::graph: {ctx=>rel}_span: Emphasize span use
When this span was originally introduced for an edge, I wasn't sure whether it may have use cases beyond just references. At this point, I'd rather be explicit; it can evolve over time if need be. There is nothing yet that prevents a span from being added to a tree edge, though. DEV-13163main
parent
62884b2e68
commit
c0ba827d90
|
@ -209,13 +209,13 @@ impl Asg {
|
|||
&mut self,
|
||||
from_oi: OA,
|
||||
to_oi: ObjectIndex<OB>,
|
||||
ctx_span: Option<Span>,
|
||||
ref_span: Option<Span>,
|
||||
) -> Result<(), AsgError> {
|
||||
from_oi.pre_add_edge(self, to_oi, ctx_span, |asg| {
|
||||
from_oi.pre_add_edge(self, to_oi, ref_span, |asg| {
|
||||
asg.graph.add_edge(
|
||||
from_oi.widen().into(),
|
||||
to_oi.into(),
|
||||
(from_oi.src_rel_ty(), OB::rel_ty(), ctx_span),
|
||||
(from_oi.src_rel_ty(), OB::rel_ty(), ref_span),
|
||||
);
|
||||
})
|
||||
}
|
||||
|
@ -333,14 +333,14 @@ impl Asg {
|
|||
oi: ObjectIndex<Object>,
|
||||
) -> impl Iterator<Item = DynObjectRel> + 'a {
|
||||
self.graph.edges(oi.into()).map(move |edge| {
|
||||
let (src_ty, target_ty, ctx_span) = edge.weight();
|
||||
let (src_ty, target_ty, ref_span) = edge.weight();
|
||||
|
||||
DynObjectRel::new(
|
||||
*src_ty,
|
||||
*target_ty,
|
||||
oi,
|
||||
ObjectIndex::<Object>::new(edge.target(), oi),
|
||||
*ctx_span,
|
||||
*ref_span,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
@ -542,7 +542,7 @@ impl<OA: ObjectRelatable, OB: ObjectRelatable> AsgRelMut<OB> for OA {
|
|||
pub struct ProposedRel<OA: ObjectKind, OB: ObjectKind> {
|
||||
from_oi: ObjectIndex<OA>,
|
||||
to_oi: ObjectIndex<OB>,
|
||||
ctx_span: Option<Span>,
|
||||
ref_span: Option<Span>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -198,7 +198,7 @@ macro_rules! object_rel {
|
|||
// on its own;
|
||||
// an edge only needs supplemental span information if there is
|
||||
// another context in which that object is referenced.
|
||||
(@is_cross_edge dyn $rel:ident) => { $rel.ctx_span().is_some() };
|
||||
(@is_cross_edge dyn $rel:ident) => { $rel.ref_span().is_some() };
|
||||
|
||||
// Similar to above but providing _static_ information to the type
|
||||
// system.
|
||||
|
@ -234,9 +234,9 @@ impl<S, T> DynObjectRel<S, T> {
|
|||
to_ty: ObjectRelTy,
|
||||
src: S,
|
||||
target: T,
|
||||
ctx_span: Option<Span>,
|
||||
ref_span: Option<Span>,
|
||||
) -> Self {
|
||||
Self((from_ty, to_ty), (src, target), ctx_span)
|
||||
Self((from_ty, to_ty), (src, target), ref_span)
|
||||
}
|
||||
|
||||
/// The type of the source edge.
|
||||
|
@ -270,12 +270,16 @@ impl<S, T> DynObjectRel<S, T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// A [`Span`] associated with the _relationship_ between the source and
|
||||
/// target objects,
|
||||
/// if any.
|
||||
pub fn ctx_span(&self) -> Option<Span> {
|
||||
/// A [`Span`] representing the reference location of a relationship.
|
||||
///
|
||||
/// This value indicates that the edge represents a cross edge.
|
||||
/// In this case,
|
||||
/// a separate span is needed to provide information about the source
|
||||
/// location of the reference,
|
||||
/// rather than the object that has been referenced.
|
||||
pub fn ref_span(&self) -> Option<Span> {
|
||||
match self {
|
||||
Self(_, _, ctx_span) => *ctx_span,
|
||||
Self(_, _, ref_span) => *ref_span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -486,7 +490,7 @@ impl<S, T, U, V> Map<(S, T), (U, V)> for DynObjectRel<S, T> {
|
|||
|
||||
fn map(self, f: impl FnOnce((S, T)) -> (U, V)) -> Self::Target {
|
||||
match self {
|
||||
Self(tys, x, ctx_span) => DynObjectRel(tys, f(x), ctx_span),
|
||||
Self(tys, x, ref_span) => DynObjectRel(tys, f(x), ref_span),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -863,7 +867,7 @@ pub trait ObjectIndexRelTo<OB: ObjectRelatable>: Sized + Clone + Copy {
|
|||
&self,
|
||||
asg: &mut Asg,
|
||||
to_oi: ObjectIndex<OB>,
|
||||
ctx_span: Option<Span>,
|
||||
ref_span: Option<Span>,
|
||||
commit: impl FnOnce(&mut Asg),
|
||||
) -> Result<(), AsgError>;
|
||||
|
||||
|
@ -947,7 +951,7 @@ where
|
|||
&self,
|
||||
asg: &mut Asg,
|
||||
to_oi: ObjectIndex<OB>,
|
||||
ctx_span: Option<Span>,
|
||||
ref_span: Option<Span>,
|
||||
commit: impl FnOnce(&mut Asg),
|
||||
) -> Result<(), AsgError> {
|
||||
O::pre_add_edge(
|
||||
|
@ -955,7 +959,7 @@ where
|
|||
ProposedRel {
|
||||
from_oi: self.widen().must_narrow_into::<O>(),
|
||||
to_oi,
|
||||
ctx_span,
|
||||
ref_span,
|
||||
},
|
||||
commit,
|
||||
)
|
||||
|
@ -977,7 +981,7 @@ impl<OB: ObjectRelatable> ObjectIndexRelTo<OB> for ObjectIndexTo<OB> {
|
|||
&self,
|
||||
asg: &mut Asg,
|
||||
to_oi: ObjectIndex<OB>,
|
||||
ctx_span: Option<Span>,
|
||||
ref_span: Option<Span>,
|
||||
commit: impl FnOnce(&mut Asg),
|
||||
) -> Result<(), AsgError> {
|
||||
macro_rules! pre_add_edge {
|
||||
|
@ -987,7 +991,7 @@ impl<OB: ObjectRelatable> ObjectIndexRelTo<OB> for ObjectIndexTo<OB> {
|
|||
ProposedRel {
|
||||
from_oi: self.widen().must_narrow_into::<$ty>(),
|
||||
to_oi,
|
||||
ctx_span,
|
||||
ref_span,
|
||||
},
|
||||
commit,
|
||||
)
|
||||
|
@ -1023,11 +1027,11 @@ impl<OB: ObjectRelatable> ObjectIndexRelTo<OB> for ObjectIndexToTree<OB> {
|
|||
&self,
|
||||
asg: &mut Asg,
|
||||
to_oi: ObjectIndex<OB>,
|
||||
ctx_span: Option<Span>,
|
||||
ref_span: Option<Span>,
|
||||
commit: impl FnOnce(&mut Asg),
|
||||
) -> Result<(), AsgError> {
|
||||
match self {
|
||||
Self(oito) => oito.pre_add_edge(asg, to_oi, ctx_span, commit),
|
||||
Self(oito) => oito.pre_add_edge(asg, to_oi, ref_span, commit),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -266,7 +266,7 @@ object_rel! {
|
|||
) -> Result<(), AsgError> {
|
||||
let tpl_name = rel.from_oi.name(asg);
|
||||
|
||||
match (rel.ctx_span, rel.to_oi.definition(asg)) {
|
||||
match (rel.ref_span, rel.to_oi.definition(asg)) {
|
||||
// Missing definition results in shape uncertainty that
|
||||
// will have to be resolved when (if) a definition
|
||||
// becomes available.
|
||||
|
|
|
@ -313,10 +313,10 @@ impl Token for TreeWalkRel {
|
|||
/// while concrete spans are stored on the objects that those
|
||||
/// relationships reference.
|
||||
/// This will return a potentially-useful span only if the inner
|
||||
/// [`DynObjectRel::ctx_span`] does.
|
||||
/// [`DynObjectRel::ref_span`] does.
|
||||
fn span(&self) -> Span {
|
||||
match self {
|
||||
Self(dyn_rel, _) => dyn_rel.ctx_span().unwrap_or(UNKNOWN_SPAN),
|
||||
Self(dyn_rel, _) => dyn_rel.ref_span().unwrap_or(UNKNOWN_SPAN),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue