@@ -1303,14 +1303,20 @@ impl StackGraph {
13031303 let edges = & mut self . outgoing_edges [ source] ;
13041304 if let Err ( index) = edges. binary_search_by_key ( & sink, |o| o. sink ) {
13051305 edges. insert ( index, OutgoingEdge { sink, precedence } ) ;
1306+ self . incoming_edges [ sink] += Degree :: One ;
13061307 }
13071308 }
13081309
13091310 /// Removes an edge from the stack graph.
1310- pub fn remove_edge ( & mut self , source : Handle < Node > , sink : Handle < Node > ) {
1311+ pub fn set_edge_precedence (
1312+ & mut self ,
1313+ source : Handle < Node > ,
1314+ sink : Handle < Node > ,
1315+ precedence : i32 ,
1316+ ) {
13111317 let edges = & mut self . outgoing_edges [ source] ;
13121318 if let Ok ( index) = edges. binary_search_by_key ( & sink, |o| o. sink ) {
1313- edges. remove ( index) ;
1319+ edges[ index] . precedence = precedence ;
13141320 }
13151321 }
13161322
@@ -1325,6 +1331,11 @@ impl StackGraph {
13251331 None => Either :: Left ( std:: iter:: empty ( ) ) ,
13261332 }
13271333 }
1334+
1335+ /// Returns the number of edges that end at a particular sink node.
1336+ pub fn incoming_edge_degree ( & self , sink : Handle < Node > ) -> Degree {
1337+ self . incoming_edges [ sink]
1338+ }
13281339}
13291340
13301341//-------------------------------------------------------------------------------------------------
@@ -1430,6 +1441,36 @@ impl StackGraph {
14301441//-------------------------------------------------------------------------------------------------
14311442// Stack graphs
14321443
1444+ #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
1445+ #[ repr( u8 ) ]
1446+ pub enum Degree {
1447+ Zero ,
1448+ One ,
1449+ Multiple ,
1450+ }
1451+
1452+ impl Default for Degree {
1453+ fn default ( ) -> Self {
1454+ Self :: Zero
1455+ }
1456+ }
1457+
1458+ impl std:: ops:: Add for Degree {
1459+ type Output = Self ;
1460+ fn add ( self , rhs : Self ) -> Self :: Output {
1461+ match ( self , rhs) {
1462+ ( Self :: Zero , result) | ( result, Self :: Zero ) => result,
1463+ _ => Self :: Multiple ,
1464+ }
1465+ }
1466+ }
1467+
1468+ impl std:: ops:: AddAssign for Degree {
1469+ fn add_assign ( & mut self , rhs : Self ) {
1470+ * self = * self + rhs;
1471+ }
1472+ }
1473+
14331474/// Contains all of the nodes and edges that make up a stack graph.
14341475pub struct StackGraph {
14351476 interned_strings : InternedStringArena ,
@@ -1442,9 +1483,10 @@ pub struct StackGraph {
14421483 pub ( crate ) nodes : Arena < Node > ,
14431484 pub ( crate ) source_info : SupplementalArena < Node , SourceInfo > ,
14441485 node_id_handles : NodeIDHandles ,
1445- outgoing_edges : SupplementalArena < Node , SmallVec < [ OutgoingEdge ; 8 ] > > ,
1486+ outgoing_edges : SupplementalArena < Node , SmallVec < [ OutgoingEdge ; 4 ] > > ,
1487+ incoming_edges : SupplementalArena < Node , Degree > ,
14461488 pub ( crate ) node_debug_info : SupplementalArena < Node , DebugInfo > ,
1447- pub ( crate ) edge_debug_info : SupplementalArena < Node , SmallVec < [ ( Handle < Node > , DebugInfo ) ; 8 ] > > ,
1489+ pub ( crate ) edge_debug_info : SupplementalArena < Node , SmallVec < [ ( Handle < Node > , DebugInfo ) ; 4 ] > > ,
14481490}
14491491
14501492impl StackGraph {
@@ -1625,6 +1667,7 @@ impl Default for StackGraph {
16251667 source_info : SupplementalArena :: new ( ) ,
16261668 node_id_handles : NodeIDHandles :: new ( ) ,
16271669 outgoing_edges : SupplementalArena :: new ( ) ,
1670+ incoming_edges : SupplementalArena :: new ( ) ,
16281671 node_debug_info : SupplementalArena :: new ( ) ,
16291672 edge_debug_info : SupplementalArena :: new ( ) ,
16301673 }
0 commit comments