Skip to main content

detect_cycles

Function detect_cycles 

Source
pub fn detect_cycles(modules: &[Module]) -> Vec<ImportCycle>
Expand description

Detect circular imports among a slice of parsed modules.

Returns one ImportCycle per distinct cycle found. The same cycle is never reported more than once regardless of which node the DFS enters it from. An empty Vec means no cycles were detected.

ยงExample

use synta_codegen::{parse, import_graph::detect_cycles};

let a = parse("ModA DEFINITIONS ::= BEGIN IMPORTS Foo FROM ModB; END").unwrap();
let b = parse("ModB DEFINITIONS ::= BEGIN IMPORTS Bar FROM ModA; END").unwrap();

let cycles = detect_cycles(&[a, b]);
assert_eq!(cycles.len(), 1);