mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
wasm: fix dead code elimination in the case where there are live imports
This commit is contained in:
parent
8d484e8c9e
commit
21a3ed4258
1 changed files with 13 additions and 6 deletions
|
@ -70,12 +70,17 @@ pub fn parse_preloads_call_graph<'a>(
|
||||||
defined_fn_signatures: &[u32],
|
defined_fn_signatures: &[u32],
|
||||||
indirect_callees: &[u32],
|
indirect_callees: &[u32],
|
||||||
) -> PreloadsCallGraph<'a> {
|
) -> PreloadsCallGraph<'a> {
|
||||||
let mut call_graph =
|
let mut call_graph = PreloadsCallGraph::new(
|
||||||
PreloadsCallGraph::new(arena, imported_fn_signatures.len(), defined_fn_signatures.len());
|
arena,
|
||||||
|
imported_fn_signatures.len(),
|
||||||
|
defined_fn_signatures.len(),
|
||||||
|
);
|
||||||
|
|
||||||
// Function type signatures, used for indirect calls
|
// Function type signatures, used for indirect calls
|
||||||
let mut signatures =
|
let mut signatures = Vec::with_capacity_in(
|
||||||
Vec::with_capacity_in(imported_fn_signatures.len() + defined_fn_signatures.len(), arena);
|
imported_fn_signatures.len() + defined_fn_signatures.len(),
|
||||||
|
arena,
|
||||||
|
);
|
||||||
signatures.extend_from_slice(imported_fn_signatures);
|
signatures.extend_from_slice(imported_fn_signatures);
|
||||||
signatures.extend_from_slice(defined_fn_signatures);
|
signatures.extend_from_slice(defined_fn_signatures);
|
||||||
|
|
||||||
|
@ -211,11 +216,13 @@ pub fn copy_preloads_shrinking_dead_fns<'a, T: SerialBuffer>(
|
||||||
live_preload_indices.sort_unstable();
|
live_preload_indices.sort_unstable();
|
||||||
live_preload_indices.dedup();
|
live_preload_indices.dedup();
|
||||||
|
|
||||||
let mut live_iter = live_preload_indices.iter();
|
let mut live_iter = live_preload_indices
|
||||||
|
.into_iter()
|
||||||
|
.filter(|f| (*f as usize) >= preload_idx_start);
|
||||||
let mut next_live_idx = live_iter.next();
|
let mut next_live_idx = live_iter.next();
|
||||||
for i in preload_idx_start..call_graph.num_preloads {
|
for i in preload_idx_start..call_graph.num_preloads {
|
||||||
match next_live_idx {
|
match next_live_idx {
|
||||||
Some(live) if *live as usize == i => {
|
Some(live) if live as usize == i => {
|
||||||
next_live_idx = live_iter.next();
|
next_live_idx = live_iter.next();
|
||||||
let live_body_start = call_graph.code_offsets[i] as usize;
|
let live_body_start = call_graph.code_offsets[i] as usize;
|
||||||
let live_body_end = call_graph.code_offsets[i + 1] as usize;
|
let live_body_end = call_graph.code_offsets[i + 1] as usize;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue