mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
construct reference matrix
This commit is contained in:
parent
c5b7ff98fd
commit
df9b5bd0f5
1 changed files with 36 additions and 1 deletions
|
@ -1,8 +1,9 @@
|
|||
use crate::ir::{Expr, HigherOrderLowLevel, JoinPointId, Param, Proc, ProcLayout, Stmt};
|
||||
use crate::layout::Layout;
|
||||
use bumpalo::collections::Vec;
|
||||
use bumpalo::collections::{CollectIn, Vec};
|
||||
use bumpalo::Bump;
|
||||
use roc_collections::all::{default_hasher, MutMap, MutSet};
|
||||
use roc_collections::ReferenceMatrix;
|
||||
use roc_module::low_level::LowLevel;
|
||||
use roc_module::symbol::Symbol;
|
||||
|
||||
|
@ -47,6 +48,38 @@ pub fn infer_borrow<'a>(
|
|||
// topological sort on these components, finally run the fix-point borrow analysis on each
|
||||
// component (in top-sorted order, from primitives (std-lib) to main)
|
||||
|
||||
let mut matrix = ReferenceMatrix::new(procs.len());
|
||||
let keys: Vec<_> = procs.keys().collect_in(arena);
|
||||
{
|
||||
for (row, proc) in procs.values().enumerate() {
|
||||
let mut call_info = CallInfo {
|
||||
keys: Vec::new_in(arena),
|
||||
};
|
||||
call_info_stmt(arena, &proc.body, &mut call_info);
|
||||
|
||||
for key in call_info.keys.iter() {
|
||||
// the same symbol can be in `keys` multiple times (with different layouts)
|
||||
for (col, (k, _)) in keys.iter().enumerate() {
|
||||
if k == key {
|
||||
matrix.set_row_col(row, col, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let nodes: Vec<_> = (0..procs.len() as u32).collect_in(arena);
|
||||
|
||||
for group in matrix
|
||||
.strongly_connected_components(nodes.as_slice())
|
||||
.groups()
|
||||
{
|
||||
println!("== new group ====");
|
||||
for index in group.iter_ones() {
|
||||
println!("{:?}", keys[index].0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let successor_map = &make_successor_mapping(arena, procs);
|
||||
let successors = move |key: &Symbol| {
|
||||
let slice = match successor_map.get(key) {
|
||||
|
@ -135,6 +168,7 @@ pub fn infer_borrow<'a>(
|
|||
}
|
||||
|
||||
for group in groups.into_iter().rev() {
|
||||
println!("\n -- new group ----------------");
|
||||
// This is a fixed-point analysis
|
||||
//
|
||||
// all functions initiall own all their parameters
|
||||
|
@ -144,6 +178,7 @@ pub fn infer_borrow<'a>(
|
|||
// when the signatures no longer change, the analysis stops and returns the signatures
|
||||
loop {
|
||||
for (proc, param_offset) in group.iter() {
|
||||
println!("{:?}", proc.name);
|
||||
env.collect_proc(&mut param_map, proc, *param_offset);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue