mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
use Cell, remove threading of identids
This commit is contained in:
parent
47840a4e65
commit
3291cc680e
5 changed files with 48 additions and 58 deletions
|
@ -7,7 +7,7 @@ use roc_builtins::bitcode::{self, FloatWidth, IntWidth};
|
|||
use roc_collections::all::{MutMap, MutSet};
|
||||
use roc_module::ident::{ModuleName, TagName};
|
||||
use roc_module::low_level::LowLevel;
|
||||
use roc_module::symbol::{IdentIds, Interns, ModuleId, Symbol};
|
||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
||||
use roc_mono::gen_refcount::RefcountProcGenerator;
|
||||
use roc_mono::ir::{
|
||||
BranchInfo, CallType, Expr, JoinPointId, ListLiteralElement, Literal, Param, Proc, ProcLayout,
|
||||
|
@ -111,11 +111,7 @@ 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,
|
||||
ident_ids: &mut IdentIds,
|
||||
proc: Proc<'a>,
|
||||
) -> (&'a [u8], &[Relocation]) {
|
||||
fn build_proc(&mut self, proc: Proc<'a>) -> (&'a [u8], &[Relocation]) {
|
||||
let layout_id = LayoutIds::default().get(proc.name, &proc.ret_layout);
|
||||
let proc_name = self.env().symbol_to_string(proc.name, layout_id);
|
||||
self.reset(proc_name, proc.is_self_recursive);
|
||||
|
@ -125,18 +121,18 @@ where
|
|||
}
|
||||
self.scan_ast(&proc.body);
|
||||
self.create_free_map();
|
||||
self.build_stmt(ident_ids, &proc.body, &proc.ret_layout);
|
||||
self.build_stmt(&proc.body, &proc.ret_layout);
|
||||
self.finalize()
|
||||
}
|
||||
|
||||
/// build_stmt builds a statement and outputs at the end of the buffer.
|
||||
fn build_stmt(&mut self, ident_ids: &mut IdentIds, stmt: &Stmt<'a>, ret_layout: &Layout<'a>) {
|
||||
fn build_stmt(&mut self, stmt: &Stmt<'a>, ret_layout: &Layout<'a>) {
|
||||
match stmt {
|
||||
Stmt::Let(sym, expr, layout, following) => {
|
||||
self.build_expr(sym, expr, layout);
|
||||
self.set_layout_map(*sym, layout);
|
||||
self.free_symbols(stmt);
|
||||
self.build_stmt(ident_ids, following, ret_layout);
|
||||
self.build_stmt(following, ret_layout);
|
||||
}
|
||||
Stmt::Ret(sym) => {
|
||||
self.load_literal_symbols(&[*sym]);
|
||||
|
@ -145,21 +141,31 @@ where
|
|||
}
|
||||
Stmt::Refcounting(modify, following) => {
|
||||
let sym = modify.get_symbol();
|
||||
let layout = self.layout_map().get(&sym).unwrap().clone();
|
||||
let layout = *self.layout_map().get(&sym).unwrap();
|
||||
|
||||
// Expand the Refcounting statement into more detailed IR with a function call
|
||||
// If this layout requires a new RC proc, we get enough info to create a linker symbol
|
||||
// for it. Here we don't create linker symbols at this time, but in Wasm backend, we do.
|
||||
let (rc_stmt, new_proc_info) = self
|
||||
.refcount_proc_gen_mut()
|
||||
.expand_refcount_stmt(ident_ids, layout, modify, *following);
|
||||
let (rc_stmt, new_proc_info) = {
|
||||
let module_id = self.env().module_id;
|
||||
let mut interns = self.env().interns.take();
|
||||
let ident_ids = interns.all_ident_ids.get_mut(&module_id).unwrap();
|
||||
|
||||
let expanded = self
|
||||
.refcount_proc_gen_mut()
|
||||
.expand_refcount_stmt(ident_ids, layout, modify, *following);
|
||||
|
||||
self.env().interns.set(interns);
|
||||
|
||||
expanded
|
||||
};
|
||||
|
||||
if let Some((rc_proc_symbol, rc_proc_layout)) = new_proc_info {
|
||||
self.refcount_proc_symbols_mut()
|
||||
.push((rc_proc_symbol, rc_proc_layout));
|
||||
}
|
||||
|
||||
self.build_stmt(ident_ids, &rc_stmt, ret_layout)
|
||||
self.build_stmt(&rc_stmt, ret_layout)
|
||||
}
|
||||
Stmt::Switch {
|
||||
cond_symbol,
|
||||
|
@ -170,7 +176,6 @@ where
|
|||
} => {
|
||||
self.load_literal_symbols(&[*cond_symbol]);
|
||||
self.build_switch(
|
||||
ident_ids,
|
||||
cond_symbol,
|
||||
cond_layout,
|
||||
branches,
|
||||
|
@ -188,7 +193,7 @@ where
|
|||
for param in parameters.iter() {
|
||||
self.set_layout_map(param.symbol, ¶m.layout);
|
||||
}
|
||||
self.build_join(ident_ids, id, parameters, body, remainder, ret_layout);
|
||||
self.build_join(id, parameters, body, remainder, ret_layout);
|
||||
self.free_symbols(stmt);
|
||||
}
|
||||
Stmt::Jump(id, args) => {
|
||||
|
@ -212,7 +217,6 @@ where
|
|||
// build_switch generates a instructions for a switch statement.
|
||||
fn build_switch(
|
||||
&mut self,
|
||||
ident_ids: &mut IdentIds,
|
||||
cond_symbol: &Symbol,
|
||||
cond_layout: &Layout<'a>,
|
||||
branches: &'a [(u64, BranchInfo<'a>, Stmt<'a>)],
|
||||
|
@ -223,7 +227,6 @@ where
|
|||
// build_join generates a instructions for a join statement.
|
||||
fn build_join(
|
||||
&mut self,
|
||||
ident_ids: &mut IdentIds,
|
||||
id: &JoinPointId,
|
||||
parameters: &'a [Param<'a>],
|
||||
body: &'a Stmt<'a>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue