Skip to content

Commit

Permalink
Interpreter: avoid allocating nullary constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
osa1 committed Sep 20, 2024
1 parent ec27ef0 commit 43dcc93
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,6 @@ struct ValCon {
fields: Fields,
}

#[derive(Debug, Clone)]
struct Fun {
/// Index of the function in `top_level_funs_by_idx` (if top-level function), or
/// `associated_funs_by_idx` (if associated function).
idx: u64,

kind: FunKind,
}

#[derive(Debug, Clone)]
enum FunKind {
Builtin(BuiltinFun),
Source(ast::FunDecl),
}

#[derive(Debug, Clone)]
enum Fields {
Unnamed(u32),
Expand All @@ -236,6 +221,21 @@ impl Fields {
}
}

#[derive(Debug, Clone)]
struct Fun {
/// Index of the function in `top_level_funs_by_idx` (if top-level function), or
/// `associated_funs_by_idx` (if associated function).
idx: u64,

kind: FunKind,
}

#[derive(Debug, Clone)]
enum FunKind {
Builtin(BuiltinFun),
Source(ast::FunDecl),
}

const INITIAL_HEAP_SIZE_WORDS: usize = (1024 * 1024 * 1024) / 8; // 1 GiB

#[derive(Debug)]
Expand Down Expand Up @@ -1181,13 +1181,9 @@ fn constr_select(pgm: &Pgm, heap: &mut Heap, ty_id: &Id, constr_id: &Id) -> u64
.find(|(_constr_idx, constr)| constr.name.as_ref().unwrap() == constr_id)
.unwrap();
let tag = ty_con.type_tag + (constr_idx as u64);
if constr.fields.is_empty() {
let addr = heap.allocate(1);
heap[addr] = tag;
addr
} else {
heap.allocate_constr(tag)
}
let con = &pgm.cons_by_tag[tag as usize];
debug_assert!(!constr.fields.is_empty() || con.alloc.is_some());
con.alloc.unwrap_or_else(|| heap.allocate_constr(tag))
}

fn assign<W: Write>(
Expand Down

0 comments on commit 43dcc93

Please sign in to comment.