mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
Merge branch 'delay-instantiating-aliases-fix-limitations' into builtins-in-roc
This commit is contained in:
commit
35e5a36ea4
6 changed files with 256 additions and 92 deletions
|
@ -343,12 +343,8 @@ fn can_annotation_help(
|
|||
return error;
|
||||
}
|
||||
|
||||
// For now, aliases of function types cannot be delayed.
|
||||
// This is a limitation of the current implementation,
|
||||
// and this totally should be possible in the future.
|
||||
let is_import = !symbol.is_builtin() && (env.home != symbol.module_id());
|
||||
let is_structural = alias.kind == AliasKind::Structural;
|
||||
if !is_import && is_structural && alias.lambda_set_variables.is_empty() {
|
||||
if is_structural {
|
||||
let mut type_var_to_arg = Vec::new();
|
||||
|
||||
for (loc_var, arg_ann) in alias.type_variables.iter().zip(args) {
|
||||
|
@ -357,10 +353,21 @@ fn can_annotation_help(
|
|||
type_var_to_arg.push((name, arg_ann));
|
||||
}
|
||||
|
||||
let mut lambda_set_variables =
|
||||
Vec::with_capacity(alias.lambda_set_variables.len());
|
||||
|
||||
for _ in 0..alias.lambda_set_variables.len() {
|
||||
let lvar = var_store.fresh();
|
||||
|
||||
introduced_variables.insert_lambda_set(lvar);
|
||||
|
||||
lambda_set_variables.push(LambdaSet(Type::Variable(lvar)));
|
||||
}
|
||||
|
||||
Type::DelayedAlias(AliasCommon {
|
||||
symbol,
|
||||
type_arguments: type_var_to_arg,
|
||||
lambda_set_variables: alias.lambda_set_variables.clone(),
|
||||
lambda_set_variables,
|
||||
})
|
||||
} else {
|
||||
let (type_arguments, lambda_set_variables, actual) =
|
||||
|
|
|
@ -22,6 +22,7 @@ use roc_problem::can::{CycleEntry, Problem, RuntimeError};
|
|||
use roc_region::all::{Loc, Region};
|
||||
use roc_types::subs::{VarStore, Variable};
|
||||
use roc_types::types::AliasKind;
|
||||
use roc_types::types::LambdaSet;
|
||||
use roc_types::types::{Alias, Type};
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Debug;
|
||||
|
@ -1703,12 +1704,21 @@ fn correct_mutual_recursive_type_alias<'a>(
|
|||
let alias = pending_aliases.get_mut(&rec).unwrap();
|
||||
// Don't try to instantiate the alias itself in its definition.
|
||||
let original_alias_def = to_instantiate.remove(&rec).unwrap();
|
||||
|
||||
let mut new_lambda_sets = ImSet::default();
|
||||
alias.typ.instantiate_aliases(
|
||||
alias.region,
|
||||
&to_instantiate,
|
||||
var_store,
|
||||
&mut ImSet::default(),
|
||||
&mut new_lambda_sets,
|
||||
);
|
||||
|
||||
for lambda_set_var in new_lambda_sets {
|
||||
alias
|
||||
.lambda_set_variables
|
||||
.push(LambdaSet(Type::Variable(lambda_set_var)));
|
||||
}
|
||||
|
||||
to_instantiate.insert(rec, original_alias_def);
|
||||
|
||||
// Now mark the alias recursive, if it needs to be.
|
||||
|
|
|
@ -548,7 +548,7 @@ pub fn canonicalize_module_defs<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
Ok(ModuleOutput {
|
||||
let output = ModuleOutput {
|
||||
scope,
|
||||
aliases,
|
||||
rigid_variables,
|
||||
|
@ -559,7 +559,9 @@ pub fn canonicalize_module_defs<'a>(
|
|||
problems: env.problems,
|
||||
lookups,
|
||||
ident_ids: env.ident_ids,
|
||||
})
|
||||
};
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
(Err(runtime_error), _) => Err(runtime_error),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue