mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
take lambda name into account when generating function id in dev backend
This commit is contained in:
parent
728f982aa5
commit
b048cb38a6
3 changed files with 33 additions and 29 deletions
|
@ -13,7 +13,7 @@ use roc_mono::ir::{
|
||||||
SelfRecursive, Stmt,
|
SelfRecursive, Stmt,
|
||||||
};
|
};
|
||||||
use roc_mono::layout::{
|
use roc_mono::layout::{
|
||||||
Builtin, InLayout, Layout, LayoutIds, LayoutInterner, LayoutRepr, STLayoutInterner,
|
Builtin, InLayout, LambdaName, Layout, LayoutIds, LayoutInterner, LayoutRepr, STLayoutInterner,
|
||||||
TagIdIntType, UnionLayout,
|
TagIdIntType, UnionLayout,
|
||||||
};
|
};
|
||||||
use roc_mono::low_level::HigherOrder;
|
use roc_mono::low_level::HigherOrder;
|
||||||
|
@ -1590,8 +1590,8 @@ impl<
|
||||||
HelperOp::Eq,
|
HelperOp::Eq,
|
||||||
);
|
);
|
||||||
|
|
||||||
let fn_name = self.function_symbol_to_string(
|
let fn_name = self.lambda_name_to_string(
|
||||||
eq_symbol,
|
LambdaName::no_niche(eq_symbol),
|
||||||
[*arg_layout, *arg_layout].into_iter(),
|
[*arg_layout, *arg_layout].into_iter(),
|
||||||
None,
|
None,
|
||||||
Layout::U8,
|
Layout::U8,
|
||||||
|
@ -1975,8 +1975,8 @@ impl<
|
||||||
self.load_layout_stack_size(old_element_layout, old_element_width);
|
self.load_layout_stack_size(old_element_layout, old_element_width);
|
||||||
self.load_layout_stack_size(new_element_layout, new_element_width);
|
self.load_layout_stack_size(new_element_layout, new_element_width);
|
||||||
|
|
||||||
let caller_string = self.function_symbol_to_string(
|
let caller_string = self.lambda_name_to_string(
|
||||||
caller_proc.proc_symbol,
|
LambdaName::no_niche(caller_proc.proc_symbol),
|
||||||
std::iter::empty(),
|
std::iter::empty(),
|
||||||
None,
|
None,
|
||||||
Layout::UNIT,
|
Layout::UNIT,
|
||||||
|
|
|
@ -20,7 +20,7 @@ use roc_mono::ir::{
|
||||||
Literal, Param, Proc, ProcLayout, SelfRecursive, Stmt,
|
Literal, Param, Proc, ProcLayout, SelfRecursive, Stmt,
|
||||||
};
|
};
|
||||||
use roc_mono::layout::{
|
use roc_mono::layout::{
|
||||||
Builtin, InLayout, Layout, LayoutIds, LayoutInterner, LayoutRepr, STLayoutInterner,
|
Builtin, InLayout, LambdaName, Layout, LayoutIds, LayoutInterner, LayoutRepr, STLayoutInterner,
|
||||||
TagIdIntType, UnionLayout,
|
TagIdIntType, UnionLayout,
|
||||||
};
|
};
|
||||||
use roc_mono::list_element_layout;
|
use roc_mono::list_element_layout;
|
||||||
|
@ -317,9 +317,9 @@ trait Backend<'a> {
|
||||||
&mut Vec<'a, CallerProc<'a>>,
|
&mut Vec<'a, CallerProc<'a>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn function_symbol_to_string<'b, I>(
|
fn lambda_name_to_string<'b, I>(
|
||||||
&self,
|
&self,
|
||||||
symbol: Symbol,
|
name: LambdaName,
|
||||||
arguments: I,
|
arguments: I,
|
||||||
_lambda_set: Option<InLayout>,
|
_lambda_set: Option<InLayout>,
|
||||||
result: InLayout,
|
result: InLayout,
|
||||||
|
@ -330,6 +330,8 @@ trait Backend<'a> {
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::hash::{BuildHasher, Hash, Hasher};
|
use std::hash::{BuildHasher, Hash, Hasher};
|
||||||
|
|
||||||
|
let symbol = name.name();
|
||||||
|
|
||||||
let mut buf = String::with_capacity(1024);
|
let mut buf = String::with_capacity(1024);
|
||||||
|
|
||||||
for a in arguments {
|
for a in arguments {
|
||||||
|
@ -337,7 +339,9 @@ trait Backend<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// lambda set should not matter; it should already be added as an argument
|
// lambda set should not matter; it should already be added as an argument
|
||||||
// lambda_set.hash(&mut state);
|
// but the niche of the lambda name may be the only thing differentiating two different
|
||||||
|
// implementations of a function with the same symbol
|
||||||
|
write!(buf, "{:?}", name.niche().dbg_deep(self.interner())).expect("capacity");
|
||||||
|
|
||||||
write!(buf, "{:?}", self.interner().dbg_deep(result)).expect("capacity");
|
write!(buf, "{:?}", self.interner().dbg_deep(result)).expect("capacity");
|
||||||
|
|
||||||
|
@ -394,8 +398,8 @@ trait Backend<'a> {
|
||||||
let element_increment = self.debug_symbol("element_increment");
|
let element_increment = self.debug_symbol("element_increment");
|
||||||
let element_increment_symbol = self.build_indirect_inc(layout);
|
let element_increment_symbol = self.build_indirect_inc(layout);
|
||||||
|
|
||||||
let element_increment_string = self.function_symbol_to_string(
|
let element_increment_string = self.lambda_name_to_string(
|
||||||
element_increment_symbol,
|
LambdaName::no_niche(element_increment_symbol),
|
||||||
[box_layout].into_iter(),
|
[box_layout].into_iter(),
|
||||||
None,
|
None,
|
||||||
Layout::UNIT,
|
Layout::UNIT,
|
||||||
|
@ -414,8 +418,8 @@ trait Backend<'a> {
|
||||||
let element_decrement = self.debug_symbol("element_decrement");
|
let element_decrement = self.debug_symbol("element_decrement");
|
||||||
let element_decrement_symbol = self.build_indirect_dec(layout);
|
let element_decrement_symbol = self.build_indirect_dec(layout);
|
||||||
|
|
||||||
let element_decrement_string = self.function_symbol_to_string(
|
let element_decrement_string = self.lambda_name_to_string(
|
||||||
element_decrement_symbol,
|
LambdaName::no_niche(element_decrement_symbol),
|
||||||
[box_layout].into_iter(),
|
[box_layout].into_iter(),
|
||||||
None,
|
None,
|
||||||
Layout::UNIT,
|
Layout::UNIT,
|
||||||
|
@ -457,8 +461,8 @@ trait Backend<'a> {
|
||||||
proc: Proc<'a>,
|
proc: Proc<'a>,
|
||||||
layout_ids: &mut LayoutIds<'a>,
|
layout_ids: &mut LayoutIds<'a>,
|
||||||
) -> (Vec<u8>, Vec<Relocation>, Vec<'a, (Symbol, String)>) {
|
) -> (Vec<u8>, Vec<Relocation>, Vec<'a, (Symbol, String)>) {
|
||||||
let proc_name = self.function_symbol_to_string(
|
let proc_name = self.lambda_name_to_string(
|
||||||
proc.name.name(),
|
proc.name,
|
||||||
proc.args.iter().map(|t| t.0),
|
proc.args.iter().map(|t| t.0),
|
||||||
proc.closure_data_layout,
|
proc.closure_data_layout,
|
||||||
proc.ret_layout,
|
proc.ret_layout,
|
||||||
|
@ -695,8 +699,8 @@ trait Backend<'a> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let fn_name = self.function_symbol_to_string(
|
let fn_name = self.lambda_name_to_string(
|
||||||
func_sym.name(),
|
*func_sym,
|
||||||
arg_layouts.iter().copied(),
|
arg_layouts.iter().copied(),
|
||||||
None,
|
None,
|
||||||
*ret_layout,
|
*ret_layout,
|
||||||
|
@ -1825,12 +1829,12 @@ trait Backend<'a> {
|
||||||
fn build_builtin(
|
fn build_builtin(
|
||||||
&mut self,
|
&mut self,
|
||||||
sym: &Symbol,
|
sym: &Symbol,
|
||||||
func_sym: Symbol,
|
func_name: Symbol,
|
||||||
args: &'a [Symbol],
|
args: &'a [Symbol],
|
||||||
arg_layouts: &[InLayout<'a>],
|
arg_layouts: &[InLayout<'a>],
|
||||||
ret_layout: &InLayout<'a>,
|
ret_layout: &InLayout<'a>,
|
||||||
) {
|
) {
|
||||||
match func_sym {
|
match func_name {
|
||||||
Symbol::NUM_IS_ZERO => {
|
Symbol::NUM_IS_ZERO => {
|
||||||
debug_assert_eq!(
|
debug_assert_eq!(
|
||||||
1,
|
1,
|
||||||
|
@ -1853,8 +1857,8 @@ trait Backend<'a> {
|
||||||
}
|
}
|
||||||
Symbol::LIST_GET | Symbol::LIST_SET | Symbol::LIST_REPLACE | Symbol::LIST_APPEND => {
|
Symbol::LIST_GET | Symbol::LIST_SET | Symbol::LIST_REPLACE | Symbol::LIST_APPEND => {
|
||||||
// TODO: This is probably simple enough to be worth inlining.
|
// TODO: This is probably simple enough to be worth inlining.
|
||||||
let fn_name = self.function_symbol_to_string(
|
let fn_name = self.lambda_name_to_string(
|
||||||
func_sym,
|
LambdaName::no_niche(func_name),
|
||||||
arg_layouts.iter().copied(),
|
arg_layouts.iter().copied(),
|
||||||
None,
|
None,
|
||||||
*ret_layout,
|
*ret_layout,
|
||||||
|
@ -1885,8 +1889,8 @@ trait Backend<'a> {
|
||||||
}
|
}
|
||||||
Symbol::STR_IS_VALID_SCALAR => {
|
Symbol::STR_IS_VALID_SCALAR => {
|
||||||
// just call the function
|
// just call the function
|
||||||
let fn_name = self.function_symbol_to_string(
|
let fn_name = self.lambda_name_to_string(
|
||||||
func_sym,
|
LambdaName::no_niche(func_name),
|
||||||
arg_layouts.iter().copied(),
|
arg_layouts.iter().copied(),
|
||||||
None,
|
None,
|
||||||
*ret_layout,
|
*ret_layout,
|
||||||
|
@ -1897,8 +1901,8 @@ trait Backend<'a> {
|
||||||
}
|
}
|
||||||
_other => {
|
_other => {
|
||||||
// just call the function
|
// just call the function
|
||||||
let fn_name = self.function_symbol_to_string(
|
let fn_name = self.lambda_name_to_string(
|
||||||
func_sym,
|
LambdaName::no_niche(func_name),
|
||||||
arg_layouts.iter().copied(),
|
arg_layouts.iter().copied(),
|
||||||
None,
|
None,
|
||||||
*ret_layout,
|
*ret_layout,
|
||||||
|
|
|
@ -343,8 +343,8 @@ fn build_object<'a, B: Backend<'a>>(
|
||||||
for ((sym, layout), proc) in helper_symbols_and_layouts.into_iter().zip(helper_procs) {
|
for ((sym, layout), proc) in helper_symbols_and_layouts.into_iter().zip(helper_procs) {
|
||||||
debug_assert_eq!(sym, proc.name.name());
|
debug_assert_eq!(sym, proc.name.name());
|
||||||
|
|
||||||
let fn_name = backend.function_symbol_to_string(
|
let fn_name = backend.lambda_name_to_string(
|
||||||
sym,
|
LambdaName::no_niche(sym),
|
||||||
layout.arguments.iter().copied(),
|
layout.arguments.iter().copied(),
|
||||||
None,
|
None,
|
||||||
layout.result,
|
layout.result,
|
||||||
|
@ -559,8 +559,8 @@ fn build_proc_symbol<'a, B: Backend<'a>>(
|
||||||
Exposed::Exposed => layout_ids
|
Exposed::Exposed => layout_ids
|
||||||
.get_toplevel(sym, &layout)
|
.get_toplevel(sym, &layout)
|
||||||
.to_exposed_symbol_string(sym, backend.interns()),
|
.to_exposed_symbol_string(sym, backend.interns()),
|
||||||
Exposed::NotExposed => backend.function_symbol_to_string(
|
Exposed::NotExposed => backend.lambda_name_to_string(
|
||||||
sym,
|
proc.name,
|
||||||
layout.arguments.iter().copied(),
|
layout.arguments.iter().copied(),
|
||||||
None,
|
None,
|
||||||
layout.result,
|
layout.result,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue