@@ -469,6 +469,64 @@ fn entry_island_needs_fetch() {
469469 assert ! ( provides. contains( EntityPath :: Properties ) ) ;
470470}
471471
472+ /// DataFlow edge dedup: an Interpreter island accesses two paths that both originate
473+ /// from Postgres (`Properties` and `EntityUuid`). Both resolve to the same Postgres
474+ /// dominator, but only one `DataFlow` edge should exist between them.
475+ #[ test]
476+ fn data_flow_edge_dedup ( ) {
477+ let heap = Heap :: new ( ) ;
478+ let interner = Interner :: new ( & heap) ;
479+ let env = Environment :: new ( & heap) ;
480+
481+ let body = body ! ( interner, env; [ graph:: read:: filter] @0 /2 -> ? {
482+ decl env: ( ) , vertex: [ Opaque sym:: path:: Entity ; ?] , val1: ?, val2: ?;
483+ @proj props = vertex. properties: ?,
484+ meta = vertex. metadata: ?,
485+ rec = meta. record_id: ?,
486+ eid = rec. entity_id: ?,
487+ uuid = eid. entity_uuid: ?;
488+
489+ bb0( ) {
490+ val1 = load props;
491+ goto bb1( ) ;
492+ } ,
493+ bb1( ) {
494+ val1 = load props;
495+ val2 = load uuid;
496+ return val1;
497+ }
498+ } ) ;
499+
500+ let graph = build_graph ( & body, & [ TargetId :: Postgres , TargetId :: Interpreter ] ) ;
501+ assert_eq ! ( graph. node_count( ) , 2 ) ;
502+
503+ let postgres = find_island ( & graph, TargetId :: Postgres ) ;
504+ let interpreter = find_island ( & graph, TargetId :: Interpreter ) ;
505+
506+ // Postgres provides both paths to the Interpreter island.
507+ let provides = graph[ postgres] . provides ( ) ;
508+ let provides = provides. as_entity ( ) . expect ( "entity vertex" ) ;
509+ assert ! ( provides. contains( EntityPath :: Properties ) ) ;
510+ assert ! ( provides. contains( EntityPath :: EntityUuid ) ) ;
511+ assert_eq ! ( provides. len( ) , 2 ) ;
512+
513+ // Exactly two edges: one ControlFlow and one DataFlow, both Postgres -> Interpreter.
514+ // Without dedup, the two paths would produce two DataFlow edges to the same consumer.
515+ assert_eq ! ( graph. edge_count( ) , 2 ) ;
516+ assert ! ( has_edge(
517+ & graph,
518+ postgres,
519+ interpreter,
520+ IslandEdge :: ControlFlow
521+ ) ) ;
522+ assert ! ( has_edge(
523+ & graph,
524+ postgres,
525+ interpreter,
526+ IslandEdge :: DataFlow
527+ ) ) ;
528+ }
529+
472530/// Control flow edge dedup: two blocks in the same island both have a successor in
473531/// another island, but only one `ControlFlow` edge should be created.
474532#[ test]
0 commit comments