LightAndLight / ipso

A functional scripting language.

Home Page:https://ipso.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reduce allocations involved in temporary types?

LightAndLight opened this issue · comments

The instruction count / heap usage of my usual benchmark (./scripts/{callgrind,dhat} examples/todolist.ipso < ipso-cli/benches/todolist_1_input.txt) crept up a little bit in #263.

I suspect it's from the extra types I create during checking. Examples:

  • unification::unify(
    env.as_unification_env(),
    &mut state.kind_inference_state,
    &mut state.type_solutions,
    pos,
    expected,
    &Type::mk_app(&Type::mk_record_ctor(env.common_kinds), &entire_row),
    )
    .map_err(|error| Error::unification_error(env.source, pos, error))?;
  • unification::unify(
    env.as_unification_env(),
    &mut state.kind_inference_state,
    &mut state.type_solutions,
    pos,
    expected,
    &Type::mk_variant(
    env.common_kinds,
    vec![(ctor.clone(), arg_ty.clone())],
    Some(rest_row.clone()),
    ),
    )
    .map_err(|error| Error::unification_error(env.source, pos, error))?;
  • let fun = check(
    env,
    state,
    fun,
    &Type::mk_arrow(env.common_kinds, &in_ty, &out_ty),
    )?;
  • unification::unify(
    env.as_unification_env(),
    &mut state.kind_inference_state,
    &mut state.type_solutions,
    position,
    expected,
    &in_tys.iter().rev().fold(out_ty.clone(), |acc, el| {
    Type::arrow(env.common_kinds, el.clone(), acc)
    }),
    )
    .map_err(|error| Error::unification_error(env.source, position, error))?;
  • unification::unify(
    env.as_unification_env(),
    &mut state.kind_inference_state,
    &mut state.type_solutions,
    expr.pos,
    expected,
    &Type::app(Type::mk_array(env.common_kinds), item_type.clone()),
    )
    .map_err(|error| Error::unification_error(env.source, expr.pos, error))?;

and more.

These temporary types involve heap allocations, because they're recursive.

Is this a big deal and is there a cheap way to do it?