-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tested] verify consistency in linked blocks
- Loading branch information
Showing
8 changed files
with
286 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use folidity_semantics::GlobalSymbol; | ||
use petgraph::{ | ||
algo::tarjan_scc, | ||
Graph, | ||
Undirected, | ||
}; | ||
use std::collections::HashSet; | ||
|
||
use crate::{ | ||
ast::Constraint, | ||
SymbolicExecutor, | ||
}; | ||
|
||
type LinkGraph = Graph<usize, usize, Undirected, usize>; | ||
|
||
// pub struct LinkBlock<'ctx> { | ||
|
||
// } | ||
|
||
fn find_link_components(executor: &SymbolicExecutor) -> Vec<Vec<usize>> { | ||
let mut edges: HashSet<(usize, usize)> = HashSet::new(); | ||
|
||
for (sym, d) in &executor.declarations { | ||
if d.links.is_empty() { | ||
continue; | ||
} | ||
let origin = executor | ||
.declarations | ||
.get_index_of(sym) | ||
.expect("should exist"); | ||
|
||
for l in &d.links { | ||
edges.insert((origin, *l)); | ||
} | ||
} | ||
|
||
// collect into a graph. | ||
let graph: LinkGraph = LinkGraph::from_edges(&edges); | ||
// since the graph is undirected, tarjan algo will just return sets of connected nodes. | ||
let components = tarjan_scc(&graph) | ||
.iter() | ||
.map(|vec| vec.iter().map(|x| x.index()).collect()) | ||
.collect(); | ||
|
||
components | ||
} | ||
|
||
pub fn build_constraint_blocks<'ctx>( | ||
executor: &mut SymbolicExecutor<'ctx>, | ||
) -> Vec<Vec<(Constraint<'ctx>, GlobalSymbol)>> { | ||
let components = find_link_components(executor); | ||
let mut blocks = vec![]; | ||
for decls in &components { | ||
let mut constraints: Vec<(Constraint, GlobalSymbol)> = vec![]; | ||
for i in decls { | ||
let (sym, decl) = executor.declarations.get_index(*i).expect("should exist"); | ||
|
||
for (_, c) in decl.constraints.clone() { | ||
constraints.push((c, sym.clone())); | ||
} | ||
} | ||
blocks.push(constraints); | ||
} | ||
blocks | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.