Merge remote-tracking branch 'origin/trunk' into builtins-in-roc

This commit is contained in:
Folkert 2022-04-10 19:08:11 +02:00
commit 6ef443d1b0
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
34 changed files with 1491 additions and 262 deletions

View file

@ -13,7 +13,7 @@ use roc_exhaustive::{Ctor, Guard, RenderAs, TagId};
use roc_module::ident::{ForeignSymbol, Lowercase, TagName};
use roc_module::low_level::LowLevel;
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
use roc_problem::can::RuntimeError;
use roc_problem::can::{RuntimeError, ShadowKind};
use roc_region::all::{Loc, Region};
use roc_std::RocDec;
use roc_target::TargetInfo;
@ -2037,6 +2037,7 @@ fn pattern_to_when<'a>(
let error = roc_problem::can::RuntimeError::Shadowing {
original_region: *region,
shadow: loc_ident.clone(),
kind: ShadowKind::Variable,
};
(*new_symbol, Loc::at_zero(RuntimeError(error)))
}
@ -2088,6 +2089,13 @@ fn pattern_to_when<'a>(
// They should have been replaced with `UnsupportedPattern` during canonicalization
unreachable!("refutable pattern {:?} where irrefutable pattern is expected. This should never happen!", pattern.value)
}
AbilityMemberSpecialization { .. } => {
unreachable!(
"Ability member specialization {:?} should never appear in a when!",
pattern.value
)
}
}
}
@ -3053,7 +3061,7 @@ fn specialize_naked_symbol<'a>(
let opt_fn_var = Some(variable);
// if this is a function symbol, ensure that it's properly specialized!
reuse_function_symbol(
specialize_symbol(
env,
procs,
layout_cache,
@ -3432,7 +3440,6 @@ pub fn with_hole<'a>(
ZeroArgumentTag {
variant_var,
name: tag_name,
arguments: args,
ext_var,
closure_name,
} => {
@ -3466,7 +3473,7 @@ pub fn with_hole<'a>(
tag_name,
procs,
layout_cache,
args,
std::vec::Vec::new(),
arena,
)
}
@ -3558,7 +3565,7 @@ pub fn with_hole<'a>(
// this symbol is already defined; nothing to do
}
Field::Function(symbol, variable) => {
stmt = reuse_function_symbol(
stmt = specialize_symbol(
env,
procs,
layout_cache,
@ -4114,7 +4121,7 @@ pub fn with_hole<'a>(
Stmt::Let(*symbol, access_expr, *field_layout, arena.alloc(stmt));
if record_needs_specialization {
stmt = reuse_function_symbol(
stmt = specialize_symbol(
env,
procs,
layout_cache,
@ -4804,8 +4811,7 @@ fn construct_closure_data<'a>(
// symbols to be inlined when specializing the closure body elsewhere.
for &&(symbol, var) in symbols {
if procs.partial_exprs.contains(symbol) {
result =
reuse_function_symbol(env, procs, layout_cache, Some(var), symbol, result, symbol);
result = specialize_symbol(env, procs, layout_cache, Some(var), symbol, result, symbol);
}
}
@ -6318,6 +6324,20 @@ fn store_pattern_help<'a>(
match can_pat {
Identifier(symbol) => {
if let Some((_, var)) = procs.partial_exprs.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);
}
Underscore => {
@ -6781,9 +6801,8 @@ fn let_empty_struct<'a>(assigned: Symbol, hole: &'a Stmt<'a>) -> Stmt<'a> {
Stmt::Let(assigned, Expr::Struct(&[]), Layout::UNIT, hole)
}
/// If the symbol is a function, make sure it is properly specialized
// TODO: rename this now that we handle polymorphic non-function expressions too
fn reuse_function_symbol<'a>(
/// If the symbol is a function or polymorphic value, make sure it is properly specialized
fn specialize_symbol<'a>(
env: &mut Env<'a, '_>,
procs: &mut Procs<'a>,
layout_cache: &mut LayoutCache<'a>,
@ -6992,7 +7011,7 @@ fn assign_to_symbol<'a>(
match can_reuse_symbol(env, procs, &loc_arg.value) {
Imported(original) | LocalFunction(original) | UnspecializedExpr(original) => {
// for functions we must make sure they are specialized correctly
reuse_function_symbol(
specialize_symbol(
env,
procs,
layout_cache,
@ -7808,6 +7827,7 @@ fn from_can_pattern_help<'a>(
match can_pattern {
Underscore => Ok(Pattern::Underscore),
Identifier(symbol) => Ok(Pattern::Identifier(*symbol)),
AbilityMemberSpecialization { ident, .. } => Ok(Pattern::Identifier(*ident)),
IntLiteral(_, precision_var, _, int, _bound) => {
match num_argument_to_int_or_float(env.subs, env.target_info, *precision_var, false) {
IntOrFloat::Int(precision) => {
@ -7851,6 +7871,7 @@ fn from_can_pattern_help<'a>(
Shadowed(region, ident, _new_symbol) => Err(RuntimeError::Shadowing {
original_region: *region,
shadow: ident.clone(),
kind: ShadowKind::Variable,
}),
UnsupportedPattern(region) => Err(RuntimeError::UnsupportedPattern(*region)),
MalformedPattern(_problem, region) => {