mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Add linker data for strings, and deduplicate them
For references to addresses of constant strings, we make an entry in reloc.CODE and configure the relocation type to say it points at a memory address. (At least I think this is right, I can't test it yet!) The same info can also be used for de-duplication. It turns out we don't need reloc.DATA. I had misunderstood it. The use case for that would be constant nested data structures, where constant data would contain pointers to other constant data. I don't think we're doing this in Roc at all, but not sure.
This commit is contained in:
parent
2f0296a5fa
commit
38d9fc5bbd
5 changed files with 113 additions and 65 deletions
|
@ -9,7 +9,6 @@ use bumpalo::{self, collections::Vec, Bump};
|
|||
use roc_collections::all::{MutMap, MutSet};
|
||||
use roc_module::symbol::{Interns, Symbol};
|
||||
use roc_mono::ir::{Proc, ProcLayout};
|
||||
use roc_mono::layout::LayoutIds;
|
||||
|
||||
use crate::backend::WasmBackend;
|
||||
use crate::wasm_module::{
|
||||
|
@ -46,11 +45,11 @@ pub fn build_module_help<'a>(
|
|||
let proc_symbols = Vec::from_iter_in(procedures.keys().map(|(sym, _)| *sym), env.arena);
|
||||
let mut backend = WasmBackend::new(env, proc_symbols);
|
||||
|
||||
let mut layout_ids = LayoutIds::default();
|
||||
let mut symbol_table_entries = Vec::with_capacity_in(procedures.len(), env.arena);
|
||||
|
||||
for (i, ((sym, layout), proc)) in procedures.into_iter().enumerate() {
|
||||
let proc_name = layout_ids
|
||||
let proc_name = backend
|
||||
.layout_ids
|
||||
.get(proc.name, &proc.ret_layout)
|
||||
.to_symbol_string(proc.name, &env.interns);
|
||||
symbol_table_entries.push(SymInfo::for_function(i as u32, proc_name));
|
||||
|
@ -58,7 +57,8 @@ pub fn build_module_help<'a>(
|
|||
backend.build_proc(proc, sym)?;
|
||||
|
||||
if env.exposed_to_host.contains(&sym) {
|
||||
let fn_name = layout_ids
|
||||
let fn_name = backend
|
||||
.layout_ids
|
||||
.get_toplevel(sym, &layout)
|
||||
.to_symbol_string(sym, &env.interns);
|
||||
|
||||
|
@ -70,6 +70,13 @@ pub fn build_module_help<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
let mut data_symbols_and_indices = Vec::from_iter_in(backend.strings.values(), env.arena);
|
||||
data_symbols_and_indices.sort_by_key(|(idx, _)| *idx);
|
||||
let data_syminfos = data_symbols_and_indices
|
||||
.iter()
|
||||
.map(|(_, data_symbol)| SymInfo::for_data(data_symbol.clone()));
|
||||
symbol_table_entries.extend(data_syminfos);
|
||||
|
||||
let symbol_table = LinkingSubSection::SymbolTable(symbol_table_entries);
|
||||
backend.module.linking.subsections.push(symbol_table);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue