mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
fix problem with specializing rigids
This commit is contained in:
parent
6aaba98d31
commit
f07fe1879b
5 changed files with 28 additions and 9 deletions
|
@ -530,6 +530,24 @@ mod gen_primitives {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
|
fn top_level_constant() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
app LinkedListLen0 provides [ main ] imports []
|
||||||
|
|
||||||
|
pi = 3.1415
|
||||||
|
|
||||||
|
main =
|
||||||
|
pi + pi
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
3.1415 + 3.1415,
|
||||||
|
f64
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
fn linked_list_len_0() {
|
fn linked_list_len_0() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
indoc!(
|
indoc!(
|
||||||
|
@ -538,8 +556,8 @@ mod gen_primitives {
|
||||||
|
|
||||||
LinkedList a : [ Nil, Cons a (LinkedList a) ]
|
LinkedList a : [ Nil, Cons a (LinkedList a) ]
|
||||||
|
|
||||||
nil : LinkedList Int
|
nil : {} -> LinkedList Int
|
||||||
nil = Nil
|
nil = \_ -> Nil
|
||||||
|
|
||||||
length : LinkedList a -> Int
|
length : LinkedList a -> Int
|
||||||
length = \list ->
|
length = \list ->
|
||||||
|
@ -549,7 +567,7 @@ mod gen_primitives {
|
||||||
|
|
||||||
|
|
||||||
main =
|
main =
|
||||||
length nil
|
length (nil {})
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -282,7 +282,7 @@ macro_rules! assert_evals_to {
|
||||||
// parsing the source, so that there's no chance their passing
|
// parsing the source, so that there's no chance their passing
|
||||||
// or failing depends on leftover state from the previous one.
|
// or failing depends on leftover state from the previous one.
|
||||||
{
|
{
|
||||||
//assert_llvm_evals_to!($src, $expected, $ty, $transform, $leak);
|
assert_llvm_evals_to!($src, $expected, $ty, $transform, $leak);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
assert_opt_evals_to!($src, $expected, $ty, $transform, $leak);
|
assert_opt_evals_to!($src, $expected, $ty, $transform, $leak);
|
||||||
|
|
|
@ -1365,10 +1365,12 @@ fn specialize_external<'a>(
|
||||||
|
|
||||||
// unify the called function with the specialized signature, then specialize the function body
|
// unify the called function with the specialized signature, then specialize the function body
|
||||||
let snapshot = env.subs.snapshot();
|
let snapshot = env.subs.snapshot();
|
||||||
|
let cache_snapshot = layout_cache.snapshot();
|
||||||
|
|
||||||
let unified = roc_unify::unify::unify(env.subs, annotation, fn_var);
|
let unified = roc_unify::unify::unify(env.subs, annotation, fn_var);
|
||||||
|
|
||||||
debug_assert!(matches!(unified, roc_unify::unify::Unified::Success(_)));
|
let is_valid = matches!(unified, roc_unify::unify::Unified::Success(_));
|
||||||
|
debug_assert!(is_valid);
|
||||||
|
|
||||||
let specialized_body = from_can(env, body, procs, layout_cache);
|
let specialized_body = from_can(env, body, procs, layout_cache);
|
||||||
|
|
||||||
|
@ -1376,6 +1378,7 @@ fn specialize_external<'a>(
|
||||||
build_specialized_proc_from_var(env, layout_cache, pattern_symbols, fn_var)?;
|
build_specialized_proc_from_var(env, layout_cache, pattern_symbols, fn_var)?;
|
||||||
|
|
||||||
// reset subs, so we don't get type errors when specializing for a different signature
|
// reset subs, so we don't get type errors when specializing for a different signature
|
||||||
|
layout_cache.rollback_to(cache_snapshot);
|
||||||
env.subs.rollback_to(snapshot);
|
env.subs.rollback_to(snapshot);
|
||||||
|
|
||||||
// TODO WRONG
|
// TODO WRONG
|
||||||
|
|
|
@ -1227,8 +1227,6 @@ fn instantiate_rigids_help(
|
||||||
|
|
||||||
if let Some(copy) = desc.copy.into_variable() {
|
if let Some(copy) = desc.copy.into_variable() {
|
||||||
return copy;
|
return copy;
|
||||||
} else if desc.rank != Rank::NONE {
|
|
||||||
return var;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let make_descriptor = |content| Descriptor {
|
let make_descriptor = |content| Descriptor {
|
||||||
|
|
|
@ -681,7 +681,7 @@ fn unify_shared_tags(
|
||||||
|
|
||||||
merge(subs, ctx, Structure(flat_type))
|
merge(subs, ctx, Structure(flat_type))
|
||||||
} else {
|
} else {
|
||||||
mismatch!()
|
mismatch!("Problem with Tag Union")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -911,7 +911,7 @@ fn unify_rigid(subs: &mut Subs, ctx: &Context, name: &Lowercase, other: &Content
|
||||||
RigidVar(_) | Structure(_) | Alias(_, _, _) => {
|
RigidVar(_) | Structure(_) | Alias(_, _, _) => {
|
||||||
// Type mismatch! Rigid can only unify with flex, even if the
|
// Type mismatch! Rigid can only unify with flex, even if the
|
||||||
// rigid names are the same.
|
// rigid names are the same.
|
||||||
mismatch!()
|
mismatch!("Rigid with {:?}", &other)
|
||||||
}
|
}
|
||||||
Error => {
|
Error => {
|
||||||
// Error propagates.
|
// Error propagates.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue