Modify ownership to fix layout copying

This commit is contained in:
Brendan Hansknecht 2021-12-07 14:39:51 -08:00
parent 54861ef5fa
commit 931b373d80
3 changed files with 19 additions and 19 deletions

View file

@ -243,14 +243,14 @@ pub struct Backend64Bit<
buf: Vec<'a, u8>,
relocs: Vec<'a, Relocation>,
proc_name: Option<String>,
is_self_recursive: Option<SelfRecursive>,
is_self_recursive: Option<&'a SelfRecursive>,
last_seen_map: MutMap<Symbol, *const Stmt<'a>>,
layout_map: MutMap<Symbol, Layout<'a>>,
free_map: MutMap<*const Stmt<'a>, Vec<'a, Symbol>>,
symbol_storage_map: MutMap<Symbol, SymbolStorage<GeneralReg, FloatReg>>,
literal_map: MutMap<Symbol, (Literal<'a>, Layout<'a>)>,
literal_map: MutMap<Symbol, (&'a Literal<'a>, &'a Layout<'a>)>,
join_map: MutMap<JoinPointId, u64>,
// This should probably be smarter than a vec.
@ -313,7 +313,7 @@ impl<
self.env
}
fn reset(&mut self, name: String, is_self_recursive: SelfRecursive) {
fn reset(&mut self, name: String, is_self_recursive: &'a SelfRecursive) {
self.proc_name = Some(name);
self.is_self_recursive = Some(is_self_recursive);
self.stack_size = 0;
@ -337,7 +337,7 @@ impl<
.extend_from_slice(CC::FLOAT_DEFAULT_FREE_REGS);
}
fn literal_map(&mut self) -> &mut MutMap<Symbol, (Literal<'a>, Layout<'a>)> {
fn literal_map(&mut self) -> &mut MutMap<Symbol, (&'a Literal<'a>, &'a Layout<'a>)> {
&mut self.literal_map
}

View file

@ -65,7 +65,7 @@ where
/// reset resets any registers or other values that may be occupied at the end of a procedure.
/// It also passes basic procedure information to the builder for setup of the next function.
fn reset(&mut self, name: String, is_self_recursive: SelfRecursive);
fn reset(&mut self, name: String, is_self_recursive: &'a SelfRecursive);
/// finalize does any setup and cleanup that should happen around the procedure.
/// finalize does setup because things like stack size and jump locations are not know until the function is written.
@ -81,11 +81,11 @@ where
fn build_wrapped_jmp(&mut self) -> (&'a [u8], u64);
/// build_proc creates a procedure and outputs it to the wrapped object writer.
fn build_proc(&mut self, proc: Proc<'a>) -> (&'a [u8], &[Relocation]) {
fn build_proc(&mut self, proc: &'a Proc<'a>) -> (&'a [u8], &[Relocation]) {
let proc_name = LayoutIds::default()
.get(proc.name, &proc.ret_layout)
.to_symbol_string(proc.name, &self.env().interns);
self.reset(proc_name, proc.is_self_recursive);
self.reset(proc_name, &proc.is_self_recursive);
self.load_args(proc.args, &proc.ret_layout);
for (layout, sym) in proc.args {
self.set_layout_map(*sym, layout);
@ -97,7 +97,7 @@ where
}
/// build_stmt builds a statement and outputs at the end of the buffer.
fn build_stmt(&mut self, stmt: &Stmt<'a>, ret_layout: &Layout<'a>) {
fn build_stmt(&mut self, stmt: &'a Stmt<'a>, ret_layout: &Layout<'a>) {
match stmt {
Stmt::Let(sym, expr, layout, following) => {
self.build_expr(sym, expr, layout);
@ -192,11 +192,11 @@ where
/// build_expr builds the expressions for the specified symbol.
/// The builder must keep track of the symbol because it may be referred to later.
fn build_expr(&mut self, sym: &Symbol, expr: &Expr<'a>, layout: &Layout<'a>) {
fn build_expr(&mut self, sym: &Symbol, expr: &'a Expr<'a>, layout: &'a Layout<'a>) {
match expr {
Expr::Literal(lit) => {
if self.env().lazy_literals {
self.literal_map().insert(*sym, (*lit, *layout));
self.literal_map().insert(*sym, (lit, layout));
} else {
self.load_literal(sym, layout, lit);
}
@ -547,7 +547,7 @@ where
);
/// literal_map gets the map from symbol to literal and layout, used for lazy loading and literal folding.
fn literal_map(&mut self) -> &mut MutMap<Symbol, (Literal<'a>, Layout<'a>)>;
fn literal_map(&mut self) -> &mut MutMap<Symbol, (&'a Literal<'a>, &'a Layout<'a>)>;
fn load_literal_symbols(&mut self, syms: &[Symbol]) {
if self.env().lazy_literals {

View file

@ -38,7 +38,7 @@ pub fn build_module<'a>(
> = Backend::new(env);
build_object(
env,
procedures,
&procedures,
backend,
Object::new(BinaryFormat::Elf, Architecture::X86_64, Endianness::Little),
)
@ -56,7 +56,7 @@ pub fn build_module<'a>(
> = Backend::new(env);
build_object(
env,
procedures,
&procedures,
backend,
Object::new(
BinaryFormat::MachO,
@ -78,7 +78,7 @@ pub fn build_module<'a>(
> = Backend::new(env);
build_object(
env,
procedures,
&procedures,
backend,
Object::new(BinaryFormat::Elf, Architecture::Aarch64, Endianness::Little),
)
@ -96,7 +96,7 @@ pub fn build_module<'a>(
> = Backend::new(env);
build_object(
env,
procedures,
&procedures,
backend,
Object::new(
BinaryFormat::MachO,
@ -164,7 +164,7 @@ fn generate_wrapper<'a, B: Backend<'a>>(
fn build_object<'a, B: Backend<'a>>(
env: &'a Env,
procedures: MutMap<(symbol::Symbol, ProcLayout<'a>), Proc<'a>>,
procedures: &'a MutMap<(symbol::Symbol, ProcLayout<'a>), Proc<'a>>,
mut backend: B,
mut output: Object,
) -> Object {
@ -212,8 +212,8 @@ fn build_object<'a, B: Backend<'a>>(
let mut procs = Vec::with_capacity_in(procedures.len(), env.arena);
for ((sym, layout), proc) in procedures {
let base_name = layout_ids
.get_toplevel(sym, &layout)
.to_symbol_string(sym, &env.interns);
.get_toplevel(*sym, &layout)
.to_symbol_string(*sym, &env.interns);
let fn_name = if env.exposed_to_host.contains(&sym) {
format!("roc_{}_exposed", base_name)
@ -251,7 +251,7 @@ fn build_object<'a, B: Backend<'a>>(
let mut relocations = bumpalo::vec![in env.arena];
for (fn_name, section_id, proc_id, proc) in procs {
let mut local_data_index = 0;
let (proc_data, relocs) = backend.build_proc(proc);
let (proc_data, relocs) = backend.build_proc(&proc);
let proc_offset = output.add_symbol_data(proc_id, section_id, proc_data, 16);
for reloc in relocs {
let elfreloc = match reloc {