mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 00:09:33 +03:00
generate rc proc names when building the procedure to fix borrowing issue
This commit is contained in:
parent
845a5ca731
commit
c7e7186be0
@ -104,7 +104,11 @@ trait Backend<'a> {
|
||||
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>) -> (Vec<u8>, Vec<Relocation>) {
|
||||
/// Returns the procedure bytes, its relocations, and the names of the refcounting functions it references.
|
||||
fn build_proc(
|
||||
&mut self,
|
||||
proc: Proc<'a>,
|
||||
) -> (Vec<u8>, Vec<Relocation>, Vec<'a, (Symbol, String)>) {
|
||||
let layout_id = LayoutIds::default().get(proc.name, &proc.ret_layout);
|
||||
let proc_name = self.symbol_to_string(proc.name, layout_id);
|
||||
self.reset(proc_name, proc.is_self_recursive);
|
||||
@ -115,7 +119,13 @@ trait Backend<'a> {
|
||||
self.scan_ast(&proc.body);
|
||||
self.create_free_map();
|
||||
self.build_stmt(&proc.body, &proc.ret_layout);
|
||||
self.finalize()
|
||||
let mut rc_proc_names = bumpalo::vec![in self.env().arena];
|
||||
rc_proc_names.reserve(self.refcount_proc_symbols().len());
|
||||
for (sym, _) in self.refcount_proc_symbols() {
|
||||
rc_proc_names.push((*sym, self.symbol_to_string(*sym, layout_id)));
|
||||
}
|
||||
let (bytes, relocs) = self.finalize();
|
||||
(bytes, relocs, rc_proc_names)
|
||||
}
|
||||
|
||||
/// build_stmt builds a statement and outputs at the end of the buffer.
|
||||
|
@ -231,7 +231,6 @@ fn build_object<'a, B: Backend<'a>>(
|
||||
&mut output,
|
||||
&mut backend,
|
||||
&mut relocations,
|
||||
&mut layout_ids,
|
||||
data_section,
|
||||
fn_name,
|
||||
section_id,
|
||||
@ -276,7 +275,6 @@ fn build_object<'a, B: Backend<'a>>(
|
||||
&mut output,
|
||||
&mut backend,
|
||||
&mut relocations,
|
||||
&mut layout_ids,
|
||||
data_section,
|
||||
fn_name,
|
||||
section_id,
|
||||
@ -344,7 +342,6 @@ fn build_proc<'a, B: Backend<'a>>(
|
||||
output: &mut Object,
|
||||
backend: &mut B,
|
||||
relocations: &mut Vec<'a, (SectionId, object::write::Relocation)>,
|
||||
layout_ids: &mut LayoutIds<'a>,
|
||||
data_section: SectionId,
|
||||
fn_name: String,
|
||||
section_id: SectionId,
|
||||
@ -352,13 +349,9 @@ fn build_proc<'a, B: Backend<'a>>(
|
||||
proc: Proc<'a>,
|
||||
) {
|
||||
let mut local_data_index = 0;
|
||||
let (proc_data, relocs) = backend.build_proc(proc);
|
||||
let (proc_data, relocs, rc_proc_names) = backend.build_proc(proc);
|
||||
let proc_offset = output.add_symbol_data(proc_id, section_id, &proc_data, 16);
|
||||
// TODO: figure out the borrowing here and fix this hack.
|
||||
let relocs2 = relocs.to_vec();
|
||||
std::mem::drop(proc_data);
|
||||
std::mem::drop(relocs);
|
||||
for reloc in relocs2.iter() {
|
||||
for reloc in relocs.iter() {
|
||||
let elfreloc = match reloc {
|
||||
Relocation::LocalData { offset, data } => {
|
||||
let data_symbol = write::Symbol {
|
||||
@ -416,10 +409,8 @@ fn build_proc<'a, B: Backend<'a>>(
|
||||
}
|
||||
// If the symbol is an undefined reference counting procedure, we need to add it here.
|
||||
if output.symbol_id(name.as_bytes()) == None {
|
||||
for (sym, layout) in backend.refcount_proc_symbols().iter() {
|
||||
let layout_id = layout_ids.get_toplevel(*sym, layout);
|
||||
let rc_name = backend.symbol_to_string(*sym, layout_id);
|
||||
if name == &rc_name {
|
||||
for (sym, rc_name) in rc_proc_names.iter() {
|
||||
if name == rc_name {
|
||||
let section_id = output.add_section(
|
||||
output.segment_name(StandardSegment::Text).to_vec(),
|
||||
format!(".text.{:x}", sym.as_u64()).as_bytes().to_vec(),
|
||||
|
Loading…
Reference in New Issue
Block a user