mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
use snapshots to remove clone on Subs
This commit is contained in:
parent
3dbaac210a
commit
c9644e4ee7
1 changed files with 6 additions and 15 deletions
|
@ -977,21 +977,12 @@ fn specialize_proc_body<'a>(
|
||||||
loc_args: &[(Variable, Located<roc_can::expr::Expr>)],
|
loc_args: &[(Variable, Located<roc_can::expr::Expr>)],
|
||||||
partial_proc: &PartialProc<'a>,
|
partial_proc: &PartialProc<'a>,
|
||||||
) -> Option<Proc<'a>> {
|
) -> Option<Proc<'a>> {
|
||||||
let mut subs: Subs = env.subs.clone();
|
// unify the called function with the specialized signature, then specialize the function body
|
||||||
roc_unify::unify::unify(&mut subs, partial_proc.annotation, fn_var);
|
let snapshot = env.subs.snapshot();
|
||||||
|
roc_unify::unify::unify(env.subs, partial_proc.annotation, fn_var);
|
||||||
// Swap in copied subs, specialize the body, put old subs back
|
let specialized_body = from_can(env, partial_proc.body.clone(), procs, None);
|
||||||
let specialized_body = {
|
// reset subs, so we don't get type errors when specializing for a different signature
|
||||||
let mut env = Env {
|
env.subs.rollback_to(snapshot);
|
||||||
subs: env.arena.alloc(subs),
|
|
||||||
arena: env.arena,
|
|
||||||
home: env.home,
|
|
||||||
ident_ids: &mut env.ident_ids,
|
|
||||||
pointer_size: env.pointer_size,
|
|
||||||
};
|
|
||||||
|
|
||||||
from_can(&mut env, partial_proc.body.clone(), procs, None)
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut proc_args = Vec::with_capacity_in(loc_args.len(), &env.arena);
|
let mut proc_args = Vec::with_capacity_in(loc_args.len(), &env.arena);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue