remove Boxed

This commit is contained in:
Folkert 2021-07-14 15:33:50 +02:00
parent 56d4ac190e
commit 0171fd0959
10 changed files with 41 additions and 67 deletions

View file

@ -972,7 +972,6 @@ fn layout_spec(builder: &mut FuncDefBuilder, layout: &Layout) -> Result<TypeId>
} => worst_case_type(builder),
},
RecursivePointer => worst_case_type(builder),
Boxed(_) => worst_case_type(builder),
Closure(_, lambda_set, _) => layout_spec(builder, &lambda_set.runtime_representation()),
}
}

View file

@ -154,6 +154,7 @@ struct VarInfo {
reference: bool, // true if the variable may be a reference (aka pointer) at runtime
persistent: bool, // true if the variable is statically known to be marked a Persistent at runtime
consume: bool, // true if the variable RC must be "consumed"
reset: bool, // true if the variable is the result of a Reset operation
}
type VarMap = MutMap<Symbol, VarInfo>;
@ -254,6 +255,7 @@ impl<'a> Context<'a> {
reference: false, // assume function symbols are global constants
persistent: true, // assume function symbols are global constants
consume: false, // no need to consume this variable
reset: false, // reset symbols cannot be passed as function arguments
},
);
}
@ -310,7 +312,12 @@ impl<'a> Context<'a> {
return stmt;
}
let modify = ModifyRc::Dec(symbol);
let modify = if info.reset {
ModifyRc::DecRef(symbol)
} else {
ModifyRc::Dec(symbol)
};
self.arena.alloc(Stmt::Refcounting(modify, stmt))
}
@ -812,7 +819,7 @@ impl<'a> Context<'a> {
// must this value be consumed?
let consume = consume_call(&self.vars, call);
self.update_var_info_help(symbol, layout, persistent, consume)
self.update_var_info_help(symbol, layout, persistent, consume, false)
}
fn update_var_info(&self, symbol: Symbol, layout: &Layout<'a>, expr: &Expr<'a>) -> Self {
@ -823,7 +830,9 @@ impl<'a> Context<'a> {
// must this value be consumed?
let consume = consume_expr(&self.vars, expr);
self.update_var_info_help(symbol, layout, persistent, consume)
let reset = matches!(expr, Expr::Reset(_));
self.update_var_info_help(symbol, layout, persistent, consume, reset)
}
fn update_var_info_help(
@ -832,6 +841,7 @@ impl<'a> Context<'a> {
layout: &Layout<'a>,
persistent: bool,
consume: bool,
reset: bool,
) -> Self {
// should we perform incs and decs on this value?
let reference = layout.contains_refcounted();
@ -840,6 +850,7 @@ impl<'a> Context<'a> {
reference,
persistent,
consume,
reset,
};
let mut ctx = self.clone();
@ -857,6 +868,7 @@ impl<'a> Context<'a> {
reference: p.layout.contains_refcounted(),
consume: !p.borrow,
persistent: false,
reset: false,
};
ctx.vars.insert(p.symbol, info);
}

View file

@ -44,8 +44,6 @@ pub enum Layout<'a> {
Union(UnionLayout<'a>),
RecursivePointer,
Boxed(&'a Layout<'a>),
/// A function. The types of its arguments, then the type of its return value.
Closure(&'a [Layout<'a>], LambdaSet<'a>, &'a Layout<'a>),
}
@ -599,7 +597,6 @@ impl<'a> Layout<'a> {
// We cannot memcpy pointers, because then we would have the same pointer in multiple places!
false
}
Boxed(_) => false,
}
}
@ -651,7 +648,6 @@ impl<'a> Layout<'a> {
}
Closure(_, lambda_set, _) => lambda_set.stack_size(pointer_size),
RecursivePointer => pointer_size,
Boxed(_) => pointer_size,
}
}
@ -682,7 +678,6 @@ impl<'a> Layout<'a> {
}
Layout::Builtin(builtin) => builtin.alignment_bytes(pointer_size),
Layout::RecursivePointer => pointer_size,
Layout::Boxed(_) => pointer_size,
Layout::Closure(_, captured, _) => {
pointer_size.max(captured.alignment_bytes(pointer_size))
}
@ -704,7 +699,6 @@ impl<'a> Layout<'a> {
}
RecursivePointer => true,
Boxed(_) => true,
Builtin(List(_)) | Builtin(Str) => true,
@ -738,11 +732,6 @@ impl<'a> Layout<'a> {
}
RecursivePointer => true,
Boxed(_) => {
// technically we should look at layout of the box's content
// but refcount insertion needs this to return true
true
}
Closure(_, closure_layout, _) => closure_layout.contains_refcounted(),
}
}
@ -767,7 +756,6 @@ impl<'a> Layout<'a> {
}
Union(union_layout) => union_layout.to_doc(alloc, parens),
RecursivePointer => alloc.text("*self"),
Boxed(_) => alloc.text("unbox"),
Closure(args, closure_layout, result) => {
let args_doc = args.iter().map(|x| x.to_doc(alloc, Parens::InFunction));

View file

@ -212,7 +212,7 @@ fn try_function_s<'a, 'i>(
if std::ptr::eq(stmt, new_stmt) || stmt == new_stmt {
stmt
} else {
insert_reset(env, w, x, new_stmt)
insert_reset(env, w, x, c.layout, new_stmt)
}
}
@ -220,6 +220,7 @@ fn insert_reset<'a>(
env: &mut Env<'a, '_>,
w: Symbol,
x: Symbol,
union_layout: UnionLayout<'a>,
mut stmt: &'a Stmt<'a>,
) -> &'a Stmt<'a> {
use crate::ir::Expr::*;
@ -246,11 +247,11 @@ fn insert_reset<'a>(
let reset_expr = Expr::Reset(x);
const I64: Layout<'static> = Layout::Builtin(crate::layout::Builtin::Int64);
// const I64: Layout<'static> = Layout::Builtin(crate::layout::Builtin::Int64);
stmt = env
.arena
.alloc(Stmt::Let(w, reset_expr, Layout::Boxed(&I64), stmt));
let layout = Layout::Union(union_layout);
stmt = env.arena.alloc(Stmt::Let(w, reset_expr, layout, stmt));
for (symbol, expr, expr_layout) in stack.into_iter().rev() {
stmt = env