Merge remote-tracking branch 'origin/main' into remove-nat

This commit is contained in:
Richard Feldman 2024-01-29 06:48:20 -05:00
commit 3e27e18566
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
73 changed files with 732 additions and 514 deletions

View file

@ -257,8 +257,6 @@ fn get_tags_vars_and_variant<'a>(
(vars_of_tag, union_variant)
}
const FAKE_EXPR: &Loc<Expr> = &Loc::at_zero(Expr::Crash);
fn expr_of_tag<'a, M: ReplAppMemory>(
env: &mut Env<'a, '_>,
mem: &'a M,
@ -288,6 +286,7 @@ fn expr_of_tag<'a, M: ReplAppMemory>(
cmp_fields(&env.layout_cache.interner, i1, *lay1, i2, *lay2)
});
const FAKE_EXPR: &Loc<Expr> = &Loc::at_zero(Expr::Crash);
let mut output: Vec<&Loc<Expr>> =
Vec::from_iter_in(std::iter::repeat(FAKE_EXPR).take(layouts.len()), env.arena);
let mut field_addr = data_addr;
@ -351,11 +350,6 @@ fn tag_id_from_recursive_ptr<'a, M: ReplAppMemory>(
}
}
const OPAQUE_FUNCTION: Expr = Expr::Var {
module_name: "",
ident: "<function>",
};
fn jit_to_ast_help<'a, A: ReplApp<'a>>(
env: &mut Env<'a, '_>,
app: &mut A,
@ -422,7 +416,10 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>(
Expr::Str(StrLiteral::PlainLine(arena_str))
};
app.call_function_returns_roc_str(env.target_info, main_fn_name, body)
match app.call_function_returns_roc_str(env.target_info, main_fn_name, body) {
Some(string) => string,
None => Expr::REPL_RUNTIME_CRASH,
}
}
LayoutRepr::Builtin(Builtin::List(elem_layout)) => app.call_function_returns_roc_list(
main_fn_name,
@ -468,7 +465,7 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>(
}
Content::Structure(FlatType::Func(_, _, _)) => {
// a function with a struct as the closure environment
OPAQUE_FUNCTION
Expr::REPL_OPAQUE_FUNCTION
}
other => {
unreachable!(
@ -478,16 +475,21 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>(
}
};
app.call_function_dynamic_size(
let opt_struct = app.call_function_dynamic_size(
main_fn_name,
result_stack_size as usize,
struct_addr_to_ast,
)
);
match opt_struct {
Some(struct_) => struct_,
None => Expr::REPL_RUNTIME_CRASH,
}
}
LayoutRepr::Union(UnionLayout::NonRecursive(_)) => {
let size = env.layout_cache.interner.stack_size(layout);
app.call_function_dynamic_size(
let opt_union = app.call_function_dynamic_size(
main_fn_name,
size as usize,
|mem: &'a A::Memory, addr: usize| {
@ -500,7 +502,12 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>(
env.subs.get_root_key_without_compacting(raw_var),
)
},
)
);
match opt_union {
Some(union_) => union_,
None => Expr::REPL_RUNTIME_CRASH,
}
}
LayoutRepr::Union(UnionLayout::Recursive(_))
| LayoutRepr::Union(UnionLayout::NonNullableUnwrapped(_))
@ -508,7 +515,7 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>(
| LayoutRepr::Union(UnionLayout::NullableWrapped { .. }) => {
let size = env.layout_cache.interner.stack_size(layout);
app.call_function_dynamic_size(
let opt_union = app.call_function_dynamic_size(
main_fn_name,
size as usize,
|mem: &'a A::Memory, addr: usize| {
@ -521,7 +528,12 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>(
env.subs.get_root_key_without_compacting(raw_var),
)
},
)
);
match opt_union {
Some(union_) => union_,
None => Expr::REPL_RUNTIME_CRASH,
}
}
LayoutRepr::RecursivePointer(_) => {
unreachable!("RecursivePointers can only be inside structures")
@ -530,7 +542,7 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>(
unreachable!("Ptr will never be visible to users")
}
LayoutRepr::LambdaSet(_) | LayoutRepr::FunctionPointer(_) | LayoutRepr::Erased(_) => {
OPAQUE_FUNCTION
Expr::REPL_OPAQUE_FUNCTION
}
};
@ -570,7 +582,7 @@ fn addr_to_ast<'a, M: ReplAppMemory>(
let expr = match (raw_content, layout) {
(Content::Structure(FlatType::Func(_, _, _)), _) | (_, LayoutRepr::LambdaSet(_) | LayoutRepr::FunctionPointer(_) | LayoutRepr::Erased(_)) => {
OPAQUE_FUNCTION
Expr::REPL_OPAQUE_FUNCTION
}
(_, LayoutRepr::Builtin(Builtin::Bool)) => {
// TODO: bits are not as expected here.