mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
Little bit of cleanup
This commit is contained in:
parent
261df36c50
commit
c070bfed8b
2 changed files with 25 additions and 390 deletions
|
@ -404,6 +404,8 @@ fn deep_copy_type_vars<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug_assert!(result.contains(&(var, cloned_var)));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
|
|
@ -2583,7 +2583,7 @@ fn specialize_external<'a>(
|
||||||
let proc_args: Vec<_> = proc_args
|
let proc_args: Vec<_> = proc_args
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(layout, symbol)| {
|
.map(|&(layout, symbol)| {
|
||||||
let (symbol) = procs
|
let symbol = procs
|
||||||
.needed_symbol_specializations
|
.needed_symbol_specializations
|
||||||
.get(&(symbol, layout))
|
.get(&(symbol, layout))
|
||||||
.map(|(_, specialized_symbol)| *specialized_symbol)
|
.map(|(_, specialized_symbol)| *specialized_symbol)
|
||||||
|
@ -3259,135 +3259,15 @@ pub fn with_hole<'a>(
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let rest = build_rest(env, procs, layout_cache);
|
let rest = build_rest(env, procs, layout_cache);
|
||||||
// with_hole(
|
with_hole(
|
||||||
// env,
|
env,
|
||||||
// def.loc_expr.value,
|
def.loc_expr.value,
|
||||||
// def.expr_var,
|
def.expr_var,
|
||||||
// procs,
|
procs,
|
||||||
// layout_cache,
|
layout_cache,
|
||||||
// symbol,
|
symbol,
|
||||||
// env.arena.alloc(rest),
|
env.arena.alloc(rest),
|
||||||
// )
|
)
|
||||||
|
|
||||||
let needs_def_specializations = procs
|
|
||||||
.needed_symbol_specializations
|
|
||||||
.keys()
|
|
||||||
.find(|(s, _)| *s == symbol)
|
|
||||||
.is_some();
|
|
||||||
|
|
||||||
if !needs_def_specializations {
|
|
||||||
return with_hole(
|
|
||||||
env,
|
|
||||||
def.loc_expr.value,
|
|
||||||
def.expr_var,
|
|
||||||
procs,
|
|
||||||
layout_cache,
|
|
||||||
symbol,
|
|
||||||
env.arena.alloc(rest),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We do need specializations
|
|
||||||
|
|
||||||
let mut stmt = rest;
|
|
||||||
let mut needed_specializations = procs
|
|
||||||
.needed_symbol_specializations
|
|
||||||
.drain_filter(|(s, _), _| *s == symbol)
|
|
||||||
.collect::<std::vec::Vec<_>>();
|
|
||||||
|
|
||||||
if needed_specializations.len() == 1 {
|
|
||||||
let ((_, _wanted_layout), (var, specialized_symbol)) =
|
|
||||||
needed_specializations.pop().unwrap();
|
|
||||||
|
|
||||||
// Unify the expr_var with the requested specialization once.
|
|
||||||
let _res = roc_unify::unify::unify(env.subs, var, def.expr_var, Mode::EQ);
|
|
||||||
|
|
||||||
return with_hole(
|
|
||||||
env,
|
|
||||||
def.loc_expr.value,
|
|
||||||
def.expr_var,
|
|
||||||
procs,
|
|
||||||
layout_cache,
|
|
||||||
specialized_symbol,
|
|
||||||
env.arena.alloc(stmt),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// Need to eat the cost and create a specialized version of the body for each specialization.
|
|
||||||
for ((_, wanted_layout), (var, specialized_symbol)) in
|
|
||||||
needed_specializations
|
|
||||||
{
|
|
||||||
macro_rules! p {
|
|
||||||
($v:expr) => {{
|
|
||||||
let content = env.subs.get_content_without_compacting($v);
|
|
||||||
let c = roc_types::subs::SubsFmtContent(content, env.subs);
|
|
||||||
c
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
// let res =
|
|
||||||
// roc_unify::unify::unify(env.subs, var, def.expr_var, Mode::EQ);
|
|
||||||
// let content = env.subs.get_content_without_compacting(def.expr_var);
|
|
||||||
// let c = roc_types::subs::SubsFmtContent(content, env.subs);
|
|
||||||
// let content2 = env.subs.get_content_without_compacting(var);
|
|
||||||
// let c2 = roc_types::subs::SubsFmtContent(content2, env.subs);
|
|
||||||
// let layout = layout_cache
|
|
||||||
// .from_var(env.arena, def.expr_var, env.subs)
|
|
||||||
// .unwrap();
|
|
||||||
// dbg!(
|
|
||||||
// specialized_symbol,
|
|
||||||
// c,
|
|
||||||
// c2,
|
|
||||||
// layout,
|
|
||||||
// wanted_layout,
|
|
||||||
// var,
|
|
||||||
// def.expr_var,
|
|
||||||
// );
|
|
||||||
|
|
||||||
use crate::copy::deep_copy_type_vars_into_expr;
|
|
||||||
|
|
||||||
let (new_def_expr_var, specialized_expr) =
|
|
||||||
deep_copy_type_vars_into_expr(
|
|
||||||
env.arena,
|
|
||||||
env.subs,
|
|
||||||
def.expr_var,
|
|
||||||
&def.loc_expr.value
|
|
||||||
).expect("expr marked as having specializations, but it has no type variables!");
|
|
||||||
|
|
||||||
// dbg!(&def.loc_expr.value, &specialized_expr);
|
|
||||||
|
|
||||||
// dbg!(
|
|
||||||
// def.expr_var,
|
|
||||||
// p!(def.expr_var),
|
|
||||||
// var,
|
|
||||||
// p!(var),
|
|
||||||
// new_def_expr_var,
|
|
||||||
// p!(new_def_expr_var)
|
|
||||||
// );
|
|
||||||
|
|
||||||
let _res =
|
|
||||||
roc_unify::unify::unify(env.subs, var, new_def_expr_var, Mode::EQ);
|
|
||||||
|
|
||||||
// dbg!(
|
|
||||||
// def.expr_var,
|
|
||||||
// p!(def.expr_var),
|
|
||||||
// var,
|
|
||||||
// p!(var),
|
|
||||||
// new_def_expr_var,
|
|
||||||
// p!(new_def_expr_var)
|
|
||||||
// );
|
|
||||||
|
|
||||||
stmt = with_hole(
|
|
||||||
env,
|
|
||||||
specialized_expr,
|
|
||||||
new_def_expr_var,
|
|
||||||
procs,
|
|
||||||
layout_cache,
|
|
||||||
specialized_symbol,
|
|
||||||
env.arena.alloc(stmt),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stmt;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// this may be a destructure pattern
|
// this may be a destructure pattern
|
||||||
|
@ -3533,7 +3413,7 @@ pub fn with_hole<'a>(
|
||||||
// TODO(POLYEXPR): can this just be `possible_reuse_symbol_or_spec`?
|
// TODO(POLYEXPR): can this just be `possible_reuse_symbol_or_spec`?
|
||||||
match can_reuse_symbol(env, procs, &loc_arg_expr.value) {
|
match can_reuse_symbol(env, procs, &loc_arg_expr.value) {
|
||||||
// Opaques decay to their argument.
|
// Opaques decay to their argument.
|
||||||
ReuseSymbol::Value(real_name) => {
|
ReuseSymbol::Value(_real_name) => {
|
||||||
let real_name = possible_reuse_symbol_or_spec(
|
let real_name = possible_reuse_symbol_or_spec(
|
||||||
env,
|
env,
|
||||||
procs,
|
procs,
|
||||||
|
@ -4027,16 +3907,9 @@ pub fn with_hole<'a>(
|
||||||
);
|
);
|
||||||
|
|
||||||
match raw_layout {
|
match raw_layout {
|
||||||
RawFunctionLayout::Function(_, lambda_set, _) => construct_closure_data(
|
RawFunctionLayout::Function(_, lambda_set, _) => {
|
||||||
env,
|
construct_closure_data(env, lambda_set, name, &[], assigned, hole)
|
||||||
procs,
|
}
|
||||||
layout_cache,
|
|
||||||
lambda_set,
|
|
||||||
name,
|
|
||||||
&[],
|
|
||||||
assigned,
|
|
||||||
hole,
|
|
||||||
),
|
|
||||||
RawFunctionLayout::ZeroArgumentThunk(_) => unreachable!(),
|
RawFunctionLayout::ZeroArgumentThunk(_) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4257,8 +4130,6 @@ pub fn with_hole<'a>(
|
||||||
|
|
||||||
construct_closure_data(
|
construct_closure_data(
|
||||||
env,
|
env,
|
||||||
procs,
|
|
||||||
layout_cache,
|
|
||||||
lambda_set,
|
lambda_set,
|
||||||
name,
|
name,
|
||||||
symbols.iter().copied(),
|
symbols.iter().copied(),
|
||||||
|
@ -4413,53 +4284,7 @@ pub fn with_hole<'a>(
|
||||||
assigned,
|
assigned,
|
||||||
hole,
|
hole,
|
||||||
);
|
);
|
||||||
} // TODO(POLYEXPR)
|
}
|
||||||
// PolymorphicExpr::Expr(lambda_expr, lambda_expr_var) => {
|
|
||||||
// match full_layout {
|
|
||||||
// RawFunctionLayout::Function(
|
|
||||||
// arg_layouts,
|
|
||||||
// lambda_set,
|
|
||||||
// ret_layout,
|
|
||||||
// ) => {
|
|
||||||
// let closure_data_symbol = env.unique_symbol();
|
|
||||||
|
|
||||||
// result = match_on_lambda_set(
|
|
||||||
// env,
|
|
||||||
// lambda_set,
|
|
||||||
// closure_data_symbol,
|
|
||||||
// arg_symbols,
|
|
||||||
// arg_layouts,
|
|
||||||
// ret_layout,
|
|
||||||
// assigned,
|
|
||||||
// hole,
|
|
||||||
// );
|
|
||||||
|
|
||||||
// let snapshot = env.subs.snapshot();
|
|
||||||
// let cache_snapshot = layout_cache.snapshot();
|
|
||||||
// let _unified = roc_unify::unify::unify(
|
|
||||||
// env.subs,
|
|
||||||
// fn_var,
|
|
||||||
// *lambda_expr_var,
|
|
||||||
// roc_unify::unify::Mode::EQ,
|
|
||||||
// );
|
|
||||||
|
|
||||||
// result = with_hole(
|
|
||||||
// env,
|
|
||||||
// lambda_expr.clone(),
|
|
||||||
// fn_var,
|
|
||||||
// procs,
|
|
||||||
// layout_cache,
|
|
||||||
// closure_data_symbol,
|
|
||||||
// env.arena.alloc(result),
|
|
||||||
// );
|
|
||||||
// env.subs.rollback_to(snapshot);
|
|
||||||
// layout_cache.rollback_to(cache_snapshot);
|
|
||||||
// }
|
|
||||||
// RawFunctionLayout::ZeroArgumentThunk(_) => {
|
|
||||||
// unreachable!("calling a non-closure layout")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NotASymbol => {
|
NotASymbol => {
|
||||||
|
@ -4836,10 +4661,6 @@ fn get_specialization<'a>(
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn construct_closure_data<'a, I>(
|
fn construct_closure_data<'a, I>(
|
||||||
env: &mut Env<'a, '_>,
|
env: &mut Env<'a, '_>,
|
||||||
// TODO(POLYEXPR): remove?
|
|
||||||
_procs: &mut Procs<'a>,
|
|
||||||
// TODO(POLYEXPR): remove?
|
|
||||||
_layout_cache: &mut LayoutCache<'a>,
|
|
||||||
lambda_set: LambdaSet<'a>,
|
lambda_set: LambdaSet<'a>,
|
||||||
name: Symbol,
|
name: Symbol,
|
||||||
symbols: I,
|
symbols: I,
|
||||||
|
@ -4863,11 +4684,7 @@ where
|
||||||
// captured variables are in symbol-alphabetic order, but now we want
|
// captured variables are in symbol-alphabetic order, but now we want
|
||||||
// them ordered by their alignment requirements
|
// them ordered by their alignment requirements
|
||||||
let mut combined = Vec::with_capacity_in(symbols.len(), env.arena);
|
let mut combined = Vec::with_capacity_in(symbols.len(), env.arena);
|
||||||
for ((symbol, variable), layout) in symbols.zip(field_layouts.iter()) {
|
for ((symbol, _variable), layout) in symbols.zip(field_layouts.iter()) {
|
||||||
// if procs.partial_exprs.contains(*symbol) {
|
|
||||||
// polymorphic_arguments.push((*symbol, *variable));
|
|
||||||
// }
|
|
||||||
|
|
||||||
combined.push((*symbol, layout))
|
combined.push((*symbol, layout))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4898,11 +4715,7 @@ where
|
||||||
// captured variables are in symbol-alphabetic order, but now we want
|
// captured variables are in symbol-alphabetic order, but now we want
|
||||||
// them ordered by their alignment requirements
|
// them ordered by their alignment requirements
|
||||||
let mut combined = Vec::with_capacity_in(symbols.len(), env.arena);
|
let mut combined = Vec::with_capacity_in(symbols.len(), env.arena);
|
||||||
for ((symbol, variable), layout) in symbols.zip(field_layouts.iter()) {
|
for ((symbol, _variable), layout) in symbols.zip(field_layouts.iter()) {
|
||||||
// if procs.partial_exprs.contains(*symbol) {
|
|
||||||
// polymorphic_arguments.push((*symbol, *variable));
|
|
||||||
// }
|
|
||||||
|
|
||||||
combined.push((*symbol, layout))
|
combined.push((*symbol, layout))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4950,20 +4763,6 @@ where
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Some of the captured symbols may be references to polymorphic expressions,
|
|
||||||
// which have not been specialized yet. We need to perform those
|
|
||||||
// specializations now so that there are real symbols to capture.
|
|
||||||
//
|
|
||||||
// TODO: this is not quite right. What we should actually be doing is removing references to
|
|
||||||
// polymorphic expressions from the captured symbols, and allowing the specializations of those
|
|
||||||
// symbols to be inlined when specializing the closure body elsewhere.
|
|
||||||
// TODO(POLYEXPR)
|
|
||||||
// for &&(symbol, var) in symbols {
|
|
||||||
// if procs.ability_member_aliases.contains(symbol) {
|
|
||||||
// result = specialize_symbol(env, procs, layout_cache, Some(var), symbol, result, symbol);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5265,16 +5064,9 @@ fn tag_union_to_function<'a>(
|
||||||
);
|
);
|
||||||
|
|
||||||
match raw_layout {
|
match raw_layout {
|
||||||
RawFunctionLayout::Function(_, lambda_set, _) => construct_closure_data(
|
RawFunctionLayout::Function(_, lambda_set, _) => {
|
||||||
env,
|
construct_closure_data(env, lambda_set, proc_symbol, &[], assigned, hole)
|
||||||
procs,
|
}
|
||||||
layout_cache,
|
|
||||||
lambda_set,
|
|
||||||
proc_symbol,
|
|
||||||
&[],
|
|
||||||
assigned,
|
|
||||||
hole,
|
|
||||||
),
|
|
||||||
RawFunctionLayout::ZeroArgumentThunk(_) => unreachable!(),
|
RawFunctionLayout::ZeroArgumentThunk(_) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5729,28 +5521,6 @@ pub fn from_can<'a>(
|
||||||
|
|
||||||
return from_can(env, variable, new_outer, procs, layout_cache);
|
return from_can(env, variable, new_outer, procs, layout_cache);
|
||||||
}
|
}
|
||||||
// TODO(POLYEXPR)
|
|
||||||
// ref body if expr_is_polymorphic(env, body, def.expr_var) => {
|
|
||||||
// // This is a pattern like
|
|
||||||
// //
|
|
||||||
// // n = 1
|
|
||||||
// // asU8 n
|
|
||||||
// //
|
|
||||||
// // At the definition site `n = 1` we only know `1` to have the type `[Int *]`,
|
|
||||||
// // which won't be refined until the call `asU8 n`. Add it as a partial expression
|
|
||||||
// // that will be specialized at each concrete usage site.
|
|
||||||
// procs.ability_member_aliases.insert(
|
|
||||||
// *symbol,
|
|
||||||
// PolymorphicExpr::Expr(def.loc_expr.value, def.expr_var),
|
|
||||||
// );
|
|
||||||
|
|
||||||
// let result = from_can(env, variable, cont.value, procs, layout_cache);
|
|
||||||
|
|
||||||
// // We won't see this symbol again.
|
|
||||||
// procs.ability_member_aliases.remove(*symbol);
|
|
||||||
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
_ => {
|
_ => {
|
||||||
let rest = from_can(env, variable, cont.value, procs, layout_cache);
|
let rest = from_can(env, variable, cont.value, procs, layout_cache);
|
||||||
|
|
||||||
|
@ -5799,35 +5569,9 @@ pub fn from_can<'a>(
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Need to eat the cost and create a specialized version of the body for each specialization.
|
// Need to eat the cost and create a specialized version of the body for each specialization.
|
||||||
for ((_, wanted_layout), (var, specialized_symbol)) in
|
for ((_original_symbol, _wanted_layout), (var, specialized_symbol)) in
|
||||||
needed_specializations
|
needed_specializations
|
||||||
{
|
{
|
||||||
macro_rules! p {
|
|
||||||
($v:expr) => {{
|
|
||||||
let content = env.subs.get_content_without_compacting($v);
|
|
||||||
let c = roc_types::subs::SubsFmtContent(content, env.subs);
|
|
||||||
c
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
// let res =
|
|
||||||
// roc_unify::unify::unify(env.subs, var, def.expr_var, Mode::EQ);
|
|
||||||
// let content = env.subs.get_content_without_compacting(def.expr_var);
|
|
||||||
// let c = roc_types::subs::SubsFmtContent(content, env.subs);
|
|
||||||
// let content2 = env.subs.get_content_without_compacting(var);
|
|
||||||
// let c2 = roc_types::subs::SubsFmtContent(content2, env.subs);
|
|
||||||
// let layout = layout_cache
|
|
||||||
// .from_var(env.arena, def.expr_var, env.subs)
|
|
||||||
// .unwrap();
|
|
||||||
// dbg!(
|
|
||||||
// specialized_symbol,
|
|
||||||
// c,
|
|
||||||
// c2,
|
|
||||||
// layout,
|
|
||||||
// wanted_layout,
|
|
||||||
// var,
|
|
||||||
// def.expr_var,
|
|
||||||
// );
|
|
||||||
|
|
||||||
use crate::copy::deep_copy_type_vars_into_expr;
|
use crate::copy::deep_copy_type_vars_into_expr;
|
||||||
|
|
||||||
let (new_def_expr_var, specialized_expr) =
|
let (new_def_expr_var, specialized_expr) =
|
||||||
|
@ -5838,17 +5582,6 @@ pub fn from_can<'a>(
|
||||||
&def.loc_expr.value
|
&def.loc_expr.value
|
||||||
).expect("expr marked as having specializations, but it has no type variables!");
|
).expect("expr marked as having specializations, but it has no type variables!");
|
||||||
|
|
||||||
// dbg!(&def.loc_expr.value, &specialized_expr);
|
|
||||||
|
|
||||||
// dbg!(
|
|
||||||
// def.expr_var,
|
|
||||||
// p!(def.expr_var),
|
|
||||||
// var,
|
|
||||||
// p!(var),
|
|
||||||
// new_def_expr_var,
|
|
||||||
// p!(new_def_expr_var)
|
|
||||||
// );
|
|
||||||
|
|
||||||
let _res = roc_unify::unify::unify(
|
let _res = roc_unify::unify::unify(
|
||||||
env.subs,
|
env.subs,
|
||||||
var,
|
var,
|
||||||
|
@ -5856,15 +5589,6 @@ pub fn from_can<'a>(
|
||||||
Mode::EQ,
|
Mode::EQ,
|
||||||
);
|
);
|
||||||
|
|
||||||
// dbg!(
|
|
||||||
// def.expr_var,
|
|
||||||
// p!(def.expr_var),
|
|
||||||
// var,
|
|
||||||
// p!(var),
|
|
||||||
// new_def_expr_var,
|
|
||||||
// p!(new_def_expr_var)
|
|
||||||
// );
|
|
||||||
|
|
||||||
stmt = with_hole(
|
stmt = with_hole(
|
||||||
env,
|
env,
|
||||||
specialized_expr,
|
specialized_expr,
|
||||||
|
@ -6519,23 +6243,6 @@ fn store_pattern_help<'a>(
|
||||||
|
|
||||||
match can_pat {
|
match can_pat {
|
||||||
Identifier(symbol) => {
|
Identifier(symbol) => {
|
||||||
// TODO(POLYEXPR)
|
|
||||||
// if let Some(&PolymorphicExpr::Expr(_, var)) =
|
|
||||||
// procs.ability_member_aliases.get(outer_symbol)
|
|
||||||
// {
|
|
||||||
// // It might be the case that symbol we're storing hasn't been reified to a value
|
|
||||||
// // yet, if it's polymorphic. Do that now.
|
|
||||||
// stmt = specialize_symbol(
|
|
||||||
// env,
|
|
||||||
// procs,
|
|
||||||
// layout_cache,
|
|
||||||
// Some(var),
|
|
||||||
// *symbol,
|
|
||||||
// stmt,
|
|
||||||
// outer_symbol,
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
substitute_in_exprs(env.arena, &mut stmt, *symbol, outer_symbol);
|
substitute_in_exprs(env.arena, &mut stmt, *symbol, outer_symbol);
|
||||||
}
|
}
|
||||||
Underscore => {
|
Underscore => {
|
||||||
|
@ -6962,13 +6669,6 @@ fn possible_reuse_symbol_or_spec<'a>(
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
// if format!("{:?}", *specialized_symbol).contains("IdentId(19)") {
|
|
||||||
// panic!();
|
|
||||||
// }
|
|
||||||
dbg!(symbol, *specialized_symbol, wanted_layout);
|
|
||||||
// if true {
|
|
||||||
// panic!()
|
|
||||||
// }
|
|
||||||
*specialized_symbol
|
*specialized_symbol
|
||||||
}
|
}
|
||||||
_ => env.unique_symbol(),
|
_ => env.unique_symbol(),
|
||||||
|
@ -7032,8 +6732,6 @@ where
|
||||||
} else {
|
} else {
|
||||||
// This should be a fully specialized value. Replace the alias with the original symbol.
|
// This should be a fully specialized value. Replace the alias with the original symbol.
|
||||||
let mut result = build_rest(env, procs, layout_cache);
|
let mut result = build_rest(env, procs, layout_cache);
|
||||||
// dbg!(&result);
|
|
||||||
dbg!(&procs.needed_symbol_specializations);
|
|
||||||
|
|
||||||
// We need to lift all specializations of "left" to be specializations of "right".
|
// We need to lift all specializations of "left" to be specializations of "right".
|
||||||
let to_update = procs
|
let to_update = procs
|
||||||
|
@ -7042,8 +6740,6 @@ where
|
||||||
.collect::<std::vec::Vec<_>>();
|
.collect::<std::vec::Vec<_>>();
|
||||||
let mut scratchpad_update_specializations = std::vec::Vec::new();
|
let mut scratchpad_update_specializations = std::vec::Vec::new();
|
||||||
|
|
||||||
dbg!(left, right, &to_update);
|
|
||||||
|
|
||||||
let left_had_specialization_symbols = !to_update.is_empty();
|
let left_had_specialization_symbols = !to_update.is_empty();
|
||||||
|
|
||||||
for ((_, layout), (specialized_var, specialized_sym)) in to_update.into_iter() {
|
for ((_, layout), (specialized_var, specialized_sym)) in to_update.into_iter() {
|
||||||
|
@ -7055,18 +6751,15 @@ where
|
||||||
scratchpad_update_specializations.push((old_specialized_sym, specialized_sym));
|
scratchpad_update_specializations.push((old_specialized_sym, specialized_sym));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbg!(&procs.needed_symbol_specializations);
|
|
||||||
|
|
||||||
if left_had_specialization_symbols {
|
if left_had_specialization_symbols {
|
||||||
// If the symbol is specialized, only the specializations need to be updated.
|
// If the symbol is specialized, only the specializations need to be updated.
|
||||||
for (old_specialized_sym, specialized_sym) in
|
for (old_specialized_sym, specialized_sym) in
|
||||||
scratchpad_update_specializations.into_iter()
|
scratchpad_update_specializations.into_iter()
|
||||||
{
|
{
|
||||||
dbg!((old_specialized_sym, "->", specialized_sym));
|
|
||||||
substitute_in_exprs(env.arena, &mut result, old_specialized_sym, specialized_sym);
|
substitute_in_exprs(env.arena, &mut result, old_specialized_sym, specialized_sym);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dbg!((left, "=>", right));
|
|
||||||
substitute_in_exprs(env.arena, &mut result, left, right);
|
substitute_in_exprs(env.arena, &mut result, left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7108,37 +6801,6 @@ fn specialize_symbol<'a>(
|
||||||
result: Stmt<'a>,
|
result: Stmt<'a>,
|
||||||
original: Symbol,
|
original: Symbol,
|
||||||
) -> Stmt<'a> {
|
) -> Stmt<'a> {
|
||||||
// TODO(POLYEXPR)
|
|
||||||
// if let Some(PolymorphicExpr::Expr(expr, expr_var)) = procs.ability_member_aliases.get(original)
|
|
||||||
// {
|
|
||||||
// // Specialize the expression type now, based off the `arg_var` we've been given.
|
|
||||||
// // TODO: cache the specialized result
|
|
||||||
// let snapshot = env.subs.snapshot();
|
|
||||||
// let cache_snapshot = layout_cache.snapshot();
|
|
||||||
// let _unified = roc_unify::unify::unify(
|
|
||||||
// env.subs,
|
|
||||||
// arg_var.unwrap(),
|
|
||||||
// *expr_var,
|
|
||||||
// roc_unify::unify::Mode::EQ,
|
|
||||||
// );
|
|
||||||
|
|
||||||
// let result = with_hole(
|
|
||||||
// env,
|
|
||||||
// expr.clone(),
|
|
||||||
// *expr_var,
|
|
||||||
// procs,
|
|
||||||
// layout_cache,
|
|
||||||
// symbol,
|
|
||||||
// env.arena.alloc(result),
|
|
||||||
// );
|
|
||||||
|
|
||||||
// // Restore the prior state so as not to interfere with future specializations.
|
|
||||||
// env.subs.rollback_to(snapshot);
|
|
||||||
// layout_cache.rollback_to(cache_snapshot);
|
|
||||||
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
|
|
||||||
match procs.get_partial_proc(original) {
|
match procs.get_partial_proc(original) {
|
||||||
None => {
|
None => {
|
||||||
match arg_var {
|
match arg_var {
|
||||||
|
@ -7238,8 +6900,6 @@ fn specialize_symbol<'a>(
|
||||||
|
|
||||||
construct_closure_data(
|
construct_closure_data(
|
||||||
env,
|
env,
|
||||||
procs,
|
|
||||||
layout_cache,
|
|
||||||
lambda_set,
|
lambda_set,
|
||||||
original,
|
original,
|
||||||
symbols.iter().copied(),
|
symbols.iter().copied(),
|
||||||
|
@ -7276,8 +6936,6 @@ fn specialize_symbol<'a>(
|
||||||
// unification may still cause it to have an extra argument
|
// unification may still cause it to have an extra argument
|
||||||
construct_closure_data(
|
construct_closure_data(
|
||||||
env,
|
env,
|
||||||
procs,
|
|
||||||
layout_cache,
|
|
||||||
lambda_set,
|
lambda_set,
|
||||||
original,
|
original,
|
||||||
&[],
|
&[],
|
||||||
|
@ -7321,19 +6979,7 @@ fn assign_to_symbol<'a>(
|
||||||
original,
|
original,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Value(_symbol) => {
|
Value(_symbol) => result,
|
||||||
//let wanted_layout = layout_cache.from_var(env.arena, arg_var, env.subs).unwrap();
|
|
||||||
//let (_, specialized_symbol) = procs
|
|
||||||
// .needed_symbol_specializations
|
|
||||||
// .entry((symbol, wanted_layout))
|
|
||||||
// .or_insert_with(|| (arg_var, env.unique_symbol()));
|
|
||||||
|
|
||||||
//dbg!(symbol, wanted_layout);
|
|
||||||
|
|
||||||
//let mut result = result;
|
|
||||||
//substitute_in_exprs(env.arena, &mut result, symbol, *specialized_symbol);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
NotASymbol => with_hole(
|
NotASymbol => with_hole(
|
||||||
env,
|
env,
|
||||||
loc_arg.value,
|
loc_arg.value,
|
||||||
|
@ -7650,16 +7296,7 @@ fn call_by_name_help<'a>(
|
||||||
// imported symbols cannot capture anything
|
// imported symbols cannot capture anything
|
||||||
let captured = &[];
|
let captured = &[];
|
||||||
|
|
||||||
construct_closure_data(
|
construct_closure_data(env, lambda_set, proc_name, captured, assigned, hole)
|
||||||
env,
|
|
||||||
procs,
|
|
||||||
layout_cache,
|
|
||||||
lambda_set,
|
|
||||||
proc_name,
|
|
||||||
captured,
|
|
||||||
assigned,
|
|
||||||
hole,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
debug_assert_eq!(
|
debug_assert_eq!(
|
||||||
argument_layouts.len(),
|
argument_layouts.len(),
|
||||||
|
@ -7752,8 +7389,6 @@ fn call_by_name_help<'a>(
|
||||||
|
|
||||||
construct_closure_data(
|
construct_closure_data(
|
||||||
env,
|
env,
|
||||||
procs,
|
|
||||||
layout_cache,
|
|
||||||
lambda_set,
|
lambda_set,
|
||||||
proc_name,
|
proc_name,
|
||||||
captured.iter(),
|
captured.iter(),
|
||||||
|
@ -8042,8 +7677,6 @@ fn call_specialized_proc<'a>(
|
||||||
|
|
||||||
let result = construct_closure_data(
|
let result = construct_closure_data(
|
||||||
env,
|
env,
|
||||||
procs,
|
|
||||||
layout_cache,
|
|
||||||
lambda_set,
|
lambda_set,
|
||||||
proc_name,
|
proc_name,
|
||||||
symbols.iter().copied(),
|
symbols.iter().copied(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue