mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Wasm: Use Vec instead of MutSet for called preloads
This commit is contained in:
parent
f4650654ca
commit
6bdc27a49e
3 changed files with 12 additions and 12 deletions
|
@ -2,7 +2,7 @@ use bumpalo::{self, collections::Vec};
|
||||||
|
|
||||||
use code_builder::Align;
|
use code_builder::Align;
|
||||||
use roc_builtins::bitcode::{self, IntWidth};
|
use roc_builtins::bitcode::{self, IntWidth};
|
||||||
use roc_collections::all::{MutMap, MutSet};
|
use roc_collections::all::MutMap;
|
||||||
use roc_module::ident::Ident;
|
use roc_module::ident::Ident;
|
||||||
use roc_module::low_level::{LowLevel, LowLevelWrapperType};
|
use roc_module::low_level::{LowLevel, LowLevelWrapperType};
|
||||||
use roc_module::symbol::{Interns, Symbol};
|
use roc_module::symbol::{Interns, Symbol};
|
||||||
|
@ -42,7 +42,7 @@ pub struct WasmBackend<'a> {
|
||||||
layout_ids: LayoutIds<'a>,
|
layout_ids: LayoutIds<'a>,
|
||||||
next_constant_addr: u32,
|
next_constant_addr: u32,
|
||||||
fn_index_offset: u32,
|
fn_index_offset: u32,
|
||||||
called_preload_fns: MutSet<u32>,
|
called_preload_fns: Vec<'a, u32>,
|
||||||
proc_symbols: Vec<'a, (Symbol, u32)>,
|
proc_symbols: Vec<'a, (Symbol, u32)>,
|
||||||
helper_proc_gen: CodeGenHelp<'a>,
|
helper_proc_gen: CodeGenHelp<'a>,
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ impl<'a> WasmBackend<'a> {
|
||||||
layout_ids,
|
layout_ids,
|
||||||
next_constant_addr: CONST_SEGMENT_BASE_ADDR,
|
next_constant_addr: CONST_SEGMENT_BASE_ADDR,
|
||||||
fn_index_offset,
|
fn_index_offset,
|
||||||
called_preload_fns: MutSet::default(),
|
called_preload_fns: Vec::with_capacity_in(2, env.arena),
|
||||||
proc_symbols,
|
proc_symbols,
|
||||||
helper_proc_gen,
|
helper_proc_gen,
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ impl<'a> WasmBackend<'a> {
|
||||||
self.module.linking.symbol_table.push(linker_symbol);
|
self.module.linking.symbol_table.push(linker_symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finalize(self) -> (WasmModule<'a>, MutSet<u32>) {
|
pub fn finalize(self) -> (WasmModule<'a>, Vec<'a, u32>) {
|
||||||
(self.module, self.called_preload_fns)
|
(self.module, self.called_preload_fns)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1474,7 +1474,7 @@ impl<'a> WasmBackend<'a> {
|
||||||
let num_wasm_args = param_types.len();
|
let num_wasm_args = param_types.len();
|
||||||
let has_return_val = ret_type.is_some();
|
let has_return_val = ret_type.is_some();
|
||||||
let fn_index = self.module.names.functions[name.as_bytes()];
|
let fn_index = self.module.names.functions[name.as_bytes()];
|
||||||
self.called_preload_fns.insert(fn_index);
|
self.called_preload_fns.push(fn_index);
|
||||||
let linker_symbol_index = u32::MAX;
|
let linker_symbol_index = u32::MAX;
|
||||||
|
|
||||||
self.code_builder
|
self.code_builder
|
||||||
|
|
|
@ -57,7 +57,7 @@ pub fn build_module_without_test_wrapper<'a>(
|
||||||
interns: &'a mut Interns,
|
interns: &'a mut Interns,
|
||||||
preload_bytes: &[u8],
|
preload_bytes: &[u8],
|
||||||
procedures: MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
procedures: MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||||
) -> (WasmModule<'a>, MutSet<u32>, u32) {
|
) -> (WasmModule<'a>, Vec<'a, u32>, u32) {
|
||||||
let mut layout_ids = LayoutIds::default();
|
let mut layout_ids = LayoutIds::default();
|
||||||
let mut procs = Vec::with_capacity_in(procedures.len(), env.arena);
|
let mut procs = Vec::with_capacity_in(procedures.len(), env.arena);
|
||||||
let mut proc_symbols = Vec::with_capacity_in(procedures.len() * 2, env.arena);
|
let mut proc_symbols = Vec::with_capacity_in(procedures.len() * 2, env.arena);
|
||||||
|
|
|
@ -16,10 +16,10 @@ Or, more specifically, "dead function replacement"
|
||||||
and checking which function index they refer to. Store this in a `PreloadsCallGraph`
|
and checking which function index they refer to. Store this in a `PreloadsCallGraph`
|
||||||
- While compiling Roc code:
|
- While compiling Roc code:
|
||||||
- Run the backend as usual, adding more data into various sections of the Wasm module
|
- Run the backend as usual, adding more data into various sections of the Wasm module
|
||||||
- Whenever a call to a builtin or platform function is made, record its index in a Set.
|
- Whenever a call to a builtin or platform function is made, record its index.
|
||||||
These are the "live" preloaded functions that we are not allowed to eliminate.
|
These are the "live" preloaded functions that we are not allowed to eliminate.
|
||||||
- Call graph analysis:
|
- Call graph analysis:
|
||||||
- Starting with the set of live preloaded functions, trace their call graphs using the info we
|
- Starting with the live preloaded functions, trace their call graphs using the info we
|
||||||
collected earlier in `PreloadsCallGraph`. Mark all function indices in the call graph as "live".
|
collected earlier in `PreloadsCallGraph`. Mark all function indices in the call graph as "live".
|
||||||
- Dead function replacement:
|
- Dead function replacement:
|
||||||
- We actually don't want to just *delete* dead functions, because that would change the indices
|
- We actually don't want to just *delete* dead functions, because that would change the indices
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue