Skip to main content

check_wf2

Function check_wf2 

Source
pub fn check_wf2(tenv: &TyEnv) -> Result<(), Diagnostics>
Expand description

Check WF2: the channel dependency graph is acyclic.

§Errors

One diagnostic per cycle, naming its PDs and channels, at its first channel.

§Examples

use fic::ast::RawAst;
use fic::foreign::ForeignModules;
use fic::parser::parse_system;
use fic::wfcheck::check_wf2;

// The check reads the typed tree; the system's declarations type it,
// whatever the programs do.
let wf2 = |src: &str| {
    let system = parse_system(src).unwrap();
    // One program per protection domain, by position; empty `.fi`s here.
    let programs = system.protection_domains.iter()
        .map(|_| fic::parser::parse_program("").unwrap())
        .collect();
    let rawast = RawAst { system, programs };
    let (env, tenv) = fic::frontend::data_layer(&rawast).unwrap();
    let (rast, _) = fic::rast::build(&rawast, env, &mut ForeignModules::new()).unwrap();
    let (tast, _) = fic::tast::build(rast, tenv).unwrap();
    check_wf2(&tast.tenv)
};
assert!(wf2("ProtectionDomain A(10); ProtectionDomain B(20); Chan ab = A --> B;").is_ok());
assert!(wf2("ProtectionDomain A(10); ProtectionDomain B(20); Chan ab = A <-> B;").is_err());