mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-12 23:50:20 +03:00
cleanup
This commit is contained in:
parent
68524ef07e
commit
958d44a21c
@ -34,7 +34,7 @@ use roc_std::RocDec;
|
|||||||
use roc_target::TargetInfo;
|
use roc_target::TargetInfo;
|
||||||
use roc_types::subs::{
|
use roc_types::subs::{
|
||||||
instantiate_rigids, storage_copy_var_to, Content, ExhaustiveMark, FlatType, RedundantMark,
|
instantiate_rigids, storage_copy_var_to, Content, ExhaustiveMark, FlatType, RedundantMark,
|
||||||
StorageSubs, Subs, Variable, VariableSubsSlice,
|
StorageSubs, Subs, Variable, VariableSubsSlice,
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder};
|
use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder};
|
||||||
@ -1186,7 +1186,6 @@ impl<'a> Procs<'a> {
|
|||||||
name,
|
name,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
annotation,
|
annotation,
|
||||||
&[],
|
|
||||||
partial_proc_id,
|
partial_proc_id,
|
||||||
) {
|
) {
|
||||||
Ok((proc, layout)) => {
|
Ok((proc, layout)) => {
|
||||||
@ -1279,7 +1278,6 @@ impl<'a> Procs<'a> {
|
|||||||
proc_name,
|
proc_name,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
fn_var,
|
fn_var,
|
||||||
Default::default(),
|
|
||||||
partial_proc_id,
|
partial_proc_id,
|
||||||
) {
|
) {
|
||||||
Ok((proc, raw_layout)) => {
|
Ok((proc, raw_layout)) => {
|
||||||
@ -2920,7 +2918,7 @@ fn specialize_suspended<'a>(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match specialize_variable(env, procs, name, layout_cache, var, &[], partial_proc) {
|
match specialize_variable(env, procs, name, layout_cache, var, partial_proc) {
|
||||||
Ok((proc, raw_layout)) => {
|
Ok((proc, raw_layout)) => {
|
||||||
let proc_layout = ProcLayout::from_raw_named(env.arena, name, raw_layout);
|
let proc_layout = ProcLayout::from_raw_named(env.arena, name, raw_layout);
|
||||||
procs
|
procs
|
||||||
@ -3066,15 +3064,8 @@ fn specialize_external_help<'a>(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let specialization_result = specialize_variable(
|
let specialization_result =
|
||||||
env,
|
specialize_variable(env, procs, name, layout_cache, variable, partial_proc_id);
|
||||||
procs,
|
|
||||||
name,
|
|
||||||
layout_cache,
|
|
||||||
variable,
|
|
||||||
host_exposed_aliases,
|
|
||||||
partial_proc_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
match specialization_result {
|
match specialization_result {
|
||||||
Ok((mut proc, layout)) => {
|
Ok((mut proc, layout)) => {
|
||||||
@ -3133,7 +3124,7 @@ fn specialize_external_help<'a>(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let (key, (_name, top_level, proc)) = generate_host_exposed_function(
|
let (key, (top_level, proc)) = generate_host_exposed_function(
|
||||||
env,
|
env,
|
||||||
procs,
|
procs,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
@ -3164,14 +3155,13 @@ fn specialize_external_help<'a>(
|
|||||||
let symbol = env.unique_symbol();
|
let symbol = env.unique_symbol();
|
||||||
let lambda_name = LambdaName::no_niche(symbol);
|
let lambda_name = LambdaName::no_niche(symbol);
|
||||||
|
|
||||||
let (_lambda_name, (proc_name, proc_layout, proc)) =
|
let (proc_name, (proc_layout, proc)) = generate_host_exposed_function(
|
||||||
generate_host_exposed_function(
|
env,
|
||||||
env,
|
procs,
|
||||||
procs,
|
layout_cache,
|
||||||
layout_cache,
|
lambda_name,
|
||||||
lambda_name,
|
raw_function_layout,
|
||||||
raw_function_layout,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
procs
|
procs
|
||||||
.specialized
|
.specialized
|
||||||
@ -3329,9 +3319,8 @@ fn generate_host_exposed_function<'a>(
|
|||||||
layout_cache: &mut LayoutCache<'a>,
|
layout_cache: &mut LayoutCache<'a>,
|
||||||
lambda_name: LambdaName<'a>,
|
lambda_name: LambdaName<'a>,
|
||||||
layout: RawFunctionLayout<'a>,
|
layout: RawFunctionLayout<'a>,
|
||||||
) -> (Symbol, (Symbol, ProcLayout<'a>, Proc<'a>)) {
|
) -> (Symbol, (ProcLayout<'a>, Proc<'a>)) {
|
||||||
let symbol = lambda_name.name();
|
let function_name = lambda_name.name();
|
||||||
let function_name = symbol;
|
|
||||||
|
|
||||||
match layout {
|
match layout {
|
||||||
RawFunctionLayout::Function(_, lambda_set, _) => {
|
RawFunctionLayout::Function(_, lambda_set, _) => {
|
||||||
@ -3343,12 +3332,12 @@ fn generate_host_exposed_function<'a>(
|
|||||||
lambda_set,
|
lambda_set,
|
||||||
);
|
);
|
||||||
|
|
||||||
(symbol, (function_name, top_level, proc))
|
(function_name, (top_level, proc))
|
||||||
}
|
}
|
||||||
RawFunctionLayout::ZeroArgumentThunk(result) => {
|
RawFunctionLayout::ZeroArgumentThunk(result) => {
|
||||||
let assigned = env.unique_symbol();
|
let assigned = env.unique_symbol();
|
||||||
let hole = env.arena.alloc(Stmt::Ret(assigned));
|
let hole = env.arena.alloc(Stmt::Ret(assigned));
|
||||||
let forced = force_thunk(env, symbol, result, assigned, hole);
|
let forced = force_thunk(env, function_name, result, assigned, hole);
|
||||||
|
|
||||||
let lambda_name = LambdaName::no_niche(function_name);
|
let lambda_name = LambdaName::no_niche(function_name);
|
||||||
let proc = Proc {
|
let proc = Proc {
|
||||||
@ -3364,7 +3353,7 @@ fn generate_host_exposed_function<'a>(
|
|||||||
|
|
||||||
let top_level = ProcLayout::from_raw_named(env.arena, lambda_name, layout);
|
let top_level = ProcLayout::from_raw_named(env.arena, lambda_name, layout);
|
||||||
|
|
||||||
(symbol, (function_name, top_level, proc))
|
(function_name, (top_level, proc))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3447,7 +3436,6 @@ fn specialize_proc_help<'a>(
|
|||||||
lambda_name: LambdaName<'a>,
|
lambda_name: LambdaName<'a>,
|
||||||
layout_cache: &mut LayoutCache<'a>,
|
layout_cache: &mut LayoutCache<'a>,
|
||||||
fn_var: Variable,
|
fn_var: Variable,
|
||||||
host_exposed_variables: &[(Symbol, Variable)],
|
|
||||||
partial_proc_id: PartialProcId,
|
partial_proc_id: PartialProcId,
|
||||||
) -> Result<Proc<'a>, LayoutProblem> {
|
) -> Result<Proc<'a>, LayoutProblem> {
|
||||||
let partial_proc = procs.partial_procs.get_id(partial_proc_id);
|
let partial_proc = procs.partial_procs.get_id(partial_proc_id);
|
||||||
@ -3488,44 +3476,8 @@ fn specialize_proc_help<'a>(
|
|||||||
let body = partial_proc.body.clone();
|
let body = partial_proc.body.clone();
|
||||||
let body_var = partial_proc.body_var;
|
let body_var = partial_proc.body_var;
|
||||||
|
|
||||||
// determine the layout of aliases/rigids exposed to the host
|
// host-exposed functions are tagged on later
|
||||||
let host_exposed_layouts = if true || host_exposed_variables.is_empty() {
|
let host_exposed_layouts = HostExposedLayouts::NotHostExposed;
|
||||||
HostExposedLayouts::NotHostExposed
|
|
||||||
} else {
|
|
||||||
let mut aliases = BumpMap::new_in(env.arena);
|
|
||||||
|
|
||||||
for (alias_name, variable) in host_exposed_variables {
|
|
||||||
let raw_function_layout = layout_cache
|
|
||||||
.raw_from_var(env.arena, *variable, env.subs)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (_lambda_name, (proc_name, proc_layout, proc)) = generate_host_exposed_function(
|
|
||||||
env,
|
|
||||||
procs,
|
|
||||||
layout_cache,
|
|
||||||
lambda_name,
|
|
||||||
raw_function_layout,
|
|
||||||
);
|
|
||||||
|
|
||||||
procs
|
|
||||||
.specialized
|
|
||||||
.insert_specialized(proc_name, proc_layout, proc);
|
|
||||||
|
|
||||||
let hels = HostExposedLambdaSet {
|
|
||||||
id: LambdaSetId::default(),
|
|
||||||
symbol: proc_name,
|
|
||||||
proc_layout,
|
|
||||||
raw_function_layout,
|
|
||||||
};
|
|
||||||
|
|
||||||
aliases.insert(*alias_name, hels);
|
|
||||||
}
|
|
||||||
|
|
||||||
HostExposedLayouts::HostExposed {
|
|
||||||
rigids: BumpMap::new_in(env.arena),
|
|
||||||
aliases: Default::default(),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut specialized_body = from_can(env, body_var, body, procs, layout_cache);
|
let mut specialized_body = from_can(env, body_var, body, procs, layout_cache);
|
||||||
|
|
||||||
@ -3972,7 +3924,6 @@ fn specialize_variable<'a>(
|
|||||||
proc_name: LambdaName<'a>,
|
proc_name: LambdaName<'a>,
|
||||||
layout_cache: &mut LayoutCache<'a>,
|
layout_cache: &mut LayoutCache<'a>,
|
||||||
fn_var: Variable,
|
fn_var: Variable,
|
||||||
host_exposed_variables: &[(Symbol, Variable)],
|
|
||||||
partial_proc_id: PartialProcId,
|
partial_proc_id: PartialProcId,
|
||||||
) -> Result<SpecializeSuccess<'a>, SpecializeFailure<'a>> {
|
) -> Result<SpecializeSuccess<'a>, SpecializeFailure<'a>> {
|
||||||
let snapshot = snapshot_typestate(env.subs, procs, layout_cache);
|
let snapshot = snapshot_typestate(env.subs, procs, layout_cache);
|
||||||
@ -4002,15 +3953,8 @@ fn specialize_variable<'a>(
|
|||||||
procs.push_active_specialization(proc_name.name());
|
procs.push_active_specialization(proc_name.name());
|
||||||
roc_tracing::debug!(?proc_name, ?fn_var, fn_content = ?roc_types::subs::SubsFmtContent(env.subs.get_content_without_compacting(fn_var), env.subs), "specialization start");
|
roc_tracing::debug!(?proc_name, ?fn_var, fn_content = ?roc_types::subs::SubsFmtContent(env.subs.get_content_without_compacting(fn_var), env.subs), "specialization start");
|
||||||
|
|
||||||
let specialized = specialize_proc_help(
|
let specialized =
|
||||||
env,
|
specialize_proc_help(env, procs, proc_name, layout_cache, fn_var, partial_proc_id);
|
||||||
procs,
|
|
||||||
proc_name,
|
|
||||||
layout_cache,
|
|
||||||
fn_var,
|
|
||||||
host_exposed_variables,
|
|
||||||
partial_proc_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
roc_tracing::debug!(
|
roc_tracing::debug!(
|
||||||
?proc_name,
|
?proc_name,
|
||||||
@ -9181,7 +9125,6 @@ fn call_by_name_help<'a>(
|
|||||||
proc_name,
|
proc_name,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
fn_var,
|
fn_var,
|
||||||
&[],
|
|
||||||
partial_proc,
|
partial_proc,
|
||||||
) {
|
) {
|
||||||
Ok((proc, layout)) => {
|
Ok((proc, layout)) => {
|
||||||
@ -9329,7 +9272,6 @@ fn call_by_name_module_thunk<'a>(
|
|||||||
LambdaName::no_niche(proc_name),
|
LambdaName::no_niche(proc_name),
|
||||||
layout_cache,
|
layout_cache,
|
||||||
fn_var,
|
fn_var,
|
||||||
&[],
|
|
||||||
partial_proc,
|
partial_proc,
|
||||||
) {
|
) {
|
||||||
Ok((proc, raw_layout)) => {
|
Ok((proc, raw_layout)) => {
|
||||||
@ -11402,7 +11344,7 @@ where
|
|||||||
},
|
},
|
||||||
Layout::LambdaSet(lambda_set) => {
|
Layout::LambdaSet(lambda_set) => {
|
||||||
let raw_function_layout =
|
let raw_function_layout =
|
||||||
RawFunctionLayout::Function(*lambda_set.args, lambda_set, lambda_set.ret);
|
RawFunctionLayout::Function(lambda_set.args, lambda_set, lambda_set.ret);
|
||||||
|
|
||||||
let key = (lambda_set_id, raw_function_layout);
|
let key = (lambda_set_id, raw_function_layout);
|
||||||
answer.extern_names.push(key);
|
answer.extern_names.push(key);
|
||||||
@ -11503,15 +11445,14 @@ fn unique_glue_symbol(
|
|||||||
|
|
||||||
*next_unique_id = unique_id + 1;
|
*next_unique_id = unique_id + 1;
|
||||||
|
|
||||||
|
// then name of the platform `main.roc` is the empty string
|
||||||
|
let module_name = "";
|
||||||
|
|
||||||
// Turn unique_id into a Symbol without doing a heap allocation.
|
// Turn unique_id into a Symbol without doing a heap allocation.
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
let mut string = bumpalo::collections::String::with_capacity_in(32, arena);
|
let mut string = bumpalo::collections::String::with_capacity_in(32, arena);
|
||||||
let _result = write!(
|
|
||||||
&mut string,
|
let _result = write!(&mut string, "roc__getter_{}_{}", module_name, unique_id);
|
||||||
"roc__getter_{}_{}",
|
|
||||||
"", // then name of the platform `main.roc` is the empty string
|
|
||||||
unique_id
|
|
||||||
);
|
|
||||||
debug_assert_eq!(_result, Ok(())); // This should never fail, but doesn't hurt to debug-check!
|
debug_assert_eq!(_result, Ok(())); // This should never fail, but doesn't hurt to debug-check!
|
||||||
|
|
||||||
let ident_id = ident_ids.get_or_insert(string.into_bump_str());
|
let ident_id = ident_ids.get_or_insert(string.into_bump_str());
|
||||||
|
Loading…
Reference in New Issue
Block a user