use bitvec in the input for sccs

This commit is contained in:
Folkert 2022-05-07 00:33:27 +02:00
parent 13fc0f9a1e
commit 8a209334cc
No known key found for this signature in database
GPG Key ID: 1F17F6FFD112B97C
3 changed files with 16 additions and 31 deletions

View File

@ -192,17 +192,12 @@ fn sort_type_defs_before_introduction(
}
// find the strongly connected components and their relations
let nodes: Vec<_> = (0..capacity as u32).collect();
let mut output = Vec::with_capacity(capacity);
for group in matrix.strongly_connected_components(&nodes).groups() {
for index in group.iter_ones() {
output.push(symbols[index])
}
}
output
matrix
.strongly_connected_components_all()
.groups()
.flat_map(|group| group.iter_ones())
.map(|index| symbols[index])
.collect()
}
#[inline(always)]
@ -790,14 +785,10 @@ pub(crate) fn sort_can_defs(
};
}
let nodes: Vec<_> = (0..defs.len() as u32).collect();
// We first perform SCC based on any reference, both variable usage and calls
// considering both value definitions and function bodies. This will spot any
// recursive relations between any 2 definitions.
let sccs = def_ordering
.references
.strongly_connected_components(&nodes);
let sccs = def_ordering.references.strongly_connected_components_all();
let mut declarations = Vec::new();
@ -838,10 +829,9 @@ pub(crate) fn sort_can_defs(
// boom = \{} -> boom {}
//
// In general we cannot spot faulty recursion (halting problem) so this is our best attempt
let nodes: Vec<_> = group.iter_ones().map(|v| v as u32).collect();
let direct_sccs = def_ordering
.direct_references
.strongly_connected_components(&nodes);
.strongly_connected_components_subset(group);
let declaration = if direct_sccs.groups().count() == 1 {
// all defs are part of the same direct cycle, that is invalid!
@ -1571,8 +1561,7 @@ fn correct_mutual_recursive_type_alias<'a>(
let mut solved_aliases = bitvec::vec::BitVec::<usize>::repeat(false, capacity);
let group: Vec<_> = (0u32..capacity as u32).collect();
let sccs = matrix.strongly_connected_components(&group);
let sccs = matrix.strongly_connected_components_all();
// scratchpad to store aliases that are modified in the current iteration.
// Only used when there is are more than one alias in a group. See below why

View File

@ -129,18 +129,14 @@ impl ReferenceMatrix {
TopologicalSort::Groups { groups }
}
/// Get the strongly-connected components of the set of input nodes.
pub fn strongly_connected_components(&self, nodes: &[u32]) -> Sccs {
let mut bitvec = BitVec::repeat(false, self.length);
for value in nodes {
bitvec.set(*value as usize, true);
}
self.strongly_connected_components_help(&bitvec)
/// Get the strongly-connected components all nodes in the matrix
pub fn strongly_connected_components_all(&self) -> Sccs {
let bitvec = BitVec::repeat(true, self.length);
self.strongly_connected_components_subset(&bitvec)
}
fn strongly_connected_components_help(&self, nodes: &BitSlice) -> Sccs {
/// Get the strongly-connected components of a set of input nodes.
pub fn strongly_connected_components_subset(&self, nodes: &BitSlice) -> Sccs {
let mut params = Params::new(self.length, nodes);
'outer: loop {

View File

@ -1159,7 +1159,7 @@ pub fn load<'a>(
) -> Result<LoadResult<'a>, LoadingProblem<'a>> {
// When compiling to wasm, we cannot spawn extra threads
// so we have a single-threaded implementation
if true || threading == Threading::Single || cfg!(target_family = "wasm") {
if threading == Threading::Single || cfg!(target_family = "wasm") {
load_single_threaded(
arena,
load_start,