mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-20 07:17:50 +03:00
remove HostExposedAlias
This commit is contained in:
parent
e6e1a13670
commit
5d3c7a9363
@ -847,29 +847,17 @@ fn can_annotation_help(
|
||||
let alias = scope.lookup_alias(symbol).unwrap();
|
||||
local_aliases.insert(symbol, alias.clone());
|
||||
|
||||
if vars.is_empty() && env.home == symbol.module_id() {
|
||||
let actual_var = var_store.fresh();
|
||||
introduced_variables.insert_host_exposed_alias(symbol, actual_var);
|
||||
Type::HostExposedAlias {
|
||||
name: symbol,
|
||||
type_arguments: vars,
|
||||
lambda_set_variables: alias.lambda_set_variables.clone(),
|
||||
actual: Box::new(alias.typ.clone()),
|
||||
actual_var,
|
||||
}
|
||||
} else {
|
||||
Type::Alias {
|
||||
symbol,
|
||||
type_arguments: vars.into_iter().map(OptAbleType::unbound).collect(),
|
||||
lambda_set_variables: alias.lambda_set_variables.clone(),
|
||||
infer_ext_in_output_types: alias
|
||||
.infer_ext_in_output_variables
|
||||
.iter()
|
||||
.map(|v| Type::Variable(*v))
|
||||
.collect(),
|
||||
actual: Box::new(alias.typ.clone()),
|
||||
kind: alias.kind,
|
||||
}
|
||||
Type::Alias {
|
||||
symbol,
|
||||
type_arguments: vars.into_iter().map(OptAbleType::unbound).collect(),
|
||||
lambda_set_variables: alias.lambda_set_variables.clone(),
|
||||
infer_ext_in_output_types: alias
|
||||
.infer_ext_in_output_variables
|
||||
.iter()
|
||||
.map(|v| Type::Variable(*v))
|
||||
.collect(),
|
||||
actual: Box::new(alias.typ.clone()),
|
||||
kind: alias.kind,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,8 +142,7 @@ impl RegisterVariable {
|
||||
TypeTag::EmptyTagUnion => Direct(Variable::EMPTY_TAG_UNION),
|
||||
TypeTag::DelayedAlias { shared }
|
||||
| TypeTag::StructuralAlias { shared, .. }
|
||||
| TypeTag::OpaqueAlias { shared, .. }
|
||||
| TypeTag::HostExposedAlias { shared, .. } => {
|
||||
| TypeTag::OpaqueAlias { shared, .. } => {
|
||||
let AliasShared { symbol, .. } = types[shared];
|
||||
if let Some(reserved) = Variable::get_reserved(symbol) {
|
||||
let direct_var = if rank.is_generalized() {
|
||||
@ -752,92 +751,6 @@ pub(crate) fn type_to_var_help(
|
||||
|
||||
env.register_with_known_var(destination, rank, content)
|
||||
}
|
||||
HostExposedAlias {
|
||||
shared,
|
||||
actual_type: alias_type,
|
||||
actual_variable: actual_var,
|
||||
} => {
|
||||
let AliasShared {
|
||||
symbol,
|
||||
type_argument_abilities: _,
|
||||
type_argument_regions: _,
|
||||
lambda_set_variables,
|
||||
infer_ext_in_output_variables: _, // TODO
|
||||
} = types[shared];
|
||||
|
||||
let type_arguments = types.get_type_arguments(typ_index);
|
||||
|
||||
let alias_variables = {
|
||||
let length = type_arguments.len() + lambda_set_variables.len();
|
||||
let new_variables = VariableSubsSlice::reserve_into_subs(env.subs, length);
|
||||
|
||||
for (target_index, arg_type) in
|
||||
(new_variables.indices()).zip(type_arguments.into_iter())
|
||||
{
|
||||
let copy_var = helper!(arg_type);
|
||||
env.subs.variables[target_index] = copy_var;
|
||||
}
|
||||
let it = (new_variables.indices().skip(type_arguments.len()))
|
||||
.zip(lambda_set_variables.into_iter());
|
||||
for (target_index, ls) in it {
|
||||
// We MUST do this now, otherwise when linking the ambient function during
|
||||
// instantiation of the real var, there will be nothing to link against.
|
||||
let copy_var = type_to_var_help(
|
||||
env,
|
||||
rank,
|
||||
problems,
|
||||
abilities_store,
|
||||
obligation_cache,
|
||||
arena,
|
||||
aliases,
|
||||
types,
|
||||
ls,
|
||||
true,
|
||||
);
|
||||
env.subs.variables[target_index] = copy_var;
|
||||
}
|
||||
|
||||
AliasVariables {
|
||||
variables_start: new_variables.start,
|
||||
type_variables_len: type_arguments.len() as _,
|
||||
lambda_set_variables_len: lambda_set_variables.len() as _,
|
||||
all_variables_len: length as _,
|
||||
}
|
||||
};
|
||||
|
||||
// cannot use helper! here because this variable may be involved in unification below
|
||||
let alias_variable = type_to_var_help(
|
||||
env,
|
||||
rank,
|
||||
problems,
|
||||
abilities_store,
|
||||
obligation_cache,
|
||||
arena,
|
||||
aliases,
|
||||
types,
|
||||
alias_type,
|
||||
false,
|
||||
);
|
||||
// TODO(opaques): I think host-exposed aliases should always be structural
|
||||
// (when does it make sense to give a host an opaque type?)
|
||||
let content = Content::Alias(
|
||||
symbol,
|
||||
alias_variables,
|
||||
alias_variable,
|
||||
AliasKind::Structural,
|
||||
);
|
||||
let result = env.register_with_known_var(destination, rank, content);
|
||||
|
||||
// We only want to unify the actual_var with the alias once
|
||||
// if it's already redirected (and therefore, redundant)
|
||||
// don't do it again
|
||||
if !env.subs.redundant(actual_var) {
|
||||
let descriptor = env.subs.get(result);
|
||||
env.subs.union(result, actual_var, descriptor);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
Error => {
|
||||
let content = Content::Error;
|
||||
|
||||
|
@ -398,11 +398,6 @@ pub enum TypeTag {
|
||||
shared: Index<AliasShared>,
|
||||
actual: Index<TypeTag>,
|
||||
},
|
||||
HostExposedAlias {
|
||||
shared: Index<AliasShared>,
|
||||
actual_type: Index<TypeTag>,
|
||||
actual_variable: Variable,
|
||||
},
|
||||
|
||||
Apply {
|
||||
symbol: Symbol,
|
||||
@ -998,41 +993,6 @@ impl Types {
|
||||
self.set_type_tag(index, tag, type_arguments_slice)
|
||||
}
|
||||
|
||||
Type::HostExposedAlias {
|
||||
name,
|
||||
type_arguments,
|
||||
lambda_set_variables,
|
||||
actual_var,
|
||||
actual,
|
||||
} => {
|
||||
let type_arguments_slice = self.from_old_type_slice(type_arguments.iter());
|
||||
|
||||
let lambda_set_slice = {
|
||||
let slice = self.reserve_type_tags(lambda_set_variables.len());
|
||||
|
||||
for (index, argument) in slice.into_iter().zip(lambda_set_variables) {
|
||||
self.from_old_type_at(index, &argument.0);
|
||||
}
|
||||
|
||||
Slice::new(slice.start() as _, slice.len() as _)
|
||||
};
|
||||
|
||||
let alias_shared = AliasShared {
|
||||
symbol: *name,
|
||||
type_argument_abilities: Slice::default(),
|
||||
type_argument_regions: Slice::default(),
|
||||
lambda_set_variables: lambda_set_slice,
|
||||
infer_ext_in_output_variables: Slice::default(),
|
||||
};
|
||||
|
||||
let tag = TypeTag::HostExposedAlias {
|
||||
shared: Index::push_new(&mut self.aliases, alias_shared),
|
||||
actual_type: self.from_old_type(actual),
|
||||
actual_variable: *actual_var,
|
||||
};
|
||||
|
||||
self.set_type_tag(index, tag, type_arguments_slice)
|
||||
}
|
||||
Type::Variable(var) => {
|
||||
self.set_type_tag(index, TypeTag::Variable(*var), Slice::default())
|
||||
}
|
||||
@ -1217,27 +1177,6 @@ impl Types {
|
||||
new_type_arguments,
|
||||
)
|
||||
}
|
||||
HostExposedAlias {
|
||||
shared,
|
||||
actual_type,
|
||||
actual_variable,
|
||||
} => {
|
||||
let type_arguments = self.get_type_arguments(typ);
|
||||
|
||||
let new_type_arguments = defer_slice!(type_arguments);
|
||||
let new_shared = do_shared!(shared);
|
||||
let new_actual_type = defer!(actual_type);
|
||||
let new_actual_variable = subst!(actual_variable);
|
||||
|
||||
(
|
||||
HostExposedAlias {
|
||||
shared: new_shared,
|
||||
actual_type: new_actual_type,
|
||||
actual_variable: new_actual_variable,
|
||||
},
|
||||
new_type_arguments,
|
||||
)
|
||||
}
|
||||
Apply {
|
||||
symbol,
|
||||
type_argument_regions,
|
||||
@ -1432,12 +1371,7 @@ mod debug_types {
|
||||
maybe_paren!(Free, p, alias(types, f, tag, shared))
|
||||
}
|
||||
TypeTag::StructuralAlias { shared, actual }
|
||||
| TypeTag::OpaqueAlias { shared, actual }
|
||||
| TypeTag::HostExposedAlias {
|
||||
shared,
|
||||
actual_type: actual,
|
||||
actual_variable: _,
|
||||
} => maybe_paren!(
|
||||
| TypeTag::OpaqueAlias { shared, actual } => maybe_paren!(
|
||||
Free,
|
||||
p,
|
||||
alias(types, f, tag, shared)
|
||||
@ -1743,13 +1677,6 @@ pub enum Type {
|
||||
actual: Box<Type>,
|
||||
kind: AliasKind,
|
||||
},
|
||||
HostExposedAlias {
|
||||
name: Symbol,
|
||||
type_arguments: Vec<Type>,
|
||||
lambda_set_variables: Vec<LambdaSet>,
|
||||
actual_var: Variable,
|
||||
actual: Box<Type>,
|
||||
},
|
||||
RecursiveTagUnion(Variable, Vec<(TagName, Vec<Type>)>, TypeExtension),
|
||||
/// Applying a type to some arguments (e.g. Dict.Dict String Int)
|
||||
Apply(Symbol, Vec<Loc<Type>>, Region),
|
||||
@ -1836,19 +1763,6 @@ impl Clone for Type {
|
||||
actual: actual.clone(),
|
||||
kind: *kind,
|
||||
},
|
||||
Self::HostExposedAlias {
|
||||
name,
|
||||
type_arguments,
|
||||
lambda_set_variables,
|
||||
actual_var,
|
||||
actual,
|
||||
} => Self::HostExposedAlias {
|
||||
name: *name,
|
||||
type_arguments: type_arguments.clone(),
|
||||
lambda_set_variables: lambda_set_variables.clone(),
|
||||
actual_var: *actual_var,
|
||||
actual: actual.clone(),
|
||||
},
|
||||
Self::RecursiveTagUnion(arg0, arg1, arg2) => {
|
||||
Self::RecursiveTagUnion(*arg0, arg1.clone(), arg2.clone())
|
||||
}
|
||||
@ -2054,22 +1968,6 @@ impl fmt::Debug for Type {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Type::HostExposedAlias {
|
||||
name,
|
||||
type_arguments: arguments,
|
||||
..
|
||||
} => {
|
||||
write!(f, "HostExposedAlias {name:?}")?;
|
||||
|
||||
for arg in arguments {
|
||||
write!(f, " {arg:?}")?;
|
||||
}
|
||||
|
||||
// Sometimes it's useful to see the expansion of the alias
|
||||
// write!(f, "[ but actually {:?} ]", _actual)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Type::Record(fields, ext) => {
|
||||
write!(f, "{{")?;
|
||||
|
||||
@ -2384,22 +2282,6 @@ impl Type {
|
||||
|
||||
stack.push(actual);
|
||||
}
|
||||
HostExposedAlias {
|
||||
type_arguments,
|
||||
lambda_set_variables,
|
||||
actual: actual_type,
|
||||
..
|
||||
} => {
|
||||
for value in type_arguments.iter_mut() {
|
||||
stack.push(value);
|
||||
}
|
||||
|
||||
for lambda_set in lambda_set_variables.iter_mut() {
|
||||
stack.push(lambda_set.as_inner_mut());
|
||||
}
|
||||
|
||||
stack.push(actual_type);
|
||||
}
|
||||
Apply(_, args, _) => {
|
||||
stack.extend(args.iter_mut().map(|t| &mut t.value));
|
||||
}
|
||||
@ -2522,22 +2404,6 @@ impl Type {
|
||||
|
||||
stack.push(actual);
|
||||
}
|
||||
HostExposedAlias {
|
||||
type_arguments,
|
||||
lambda_set_variables,
|
||||
actual: actual_type,
|
||||
..
|
||||
} => {
|
||||
for value in type_arguments.iter_mut() {
|
||||
stack.push(value);
|
||||
}
|
||||
|
||||
for lambda_set in lambda_set_variables.iter_mut() {
|
||||
stack.push(lambda_set.as_inner_mut());
|
||||
}
|
||||
|
||||
stack.push(actual_type);
|
||||
}
|
||||
Apply(_, args, _) => {
|
||||
stack.extend(args.iter_mut().map(|t| &mut t.value));
|
||||
}
|
||||
@ -2640,10 +2506,6 @@ impl Type {
|
||||
}
|
||||
alias_actual.substitute_alias(rep_symbol, rep_args, actual)
|
||||
}
|
||||
HostExposedAlias {
|
||||
actual: actual_type,
|
||||
..
|
||||
} => actual_type.substitute_alias(rep_symbol, rep_args, actual),
|
||||
Apply(symbol, args, region) if *symbol == rep_symbol => {
|
||||
if args.len() == rep_args.len()
|
||||
&& args
|
||||
@ -2727,9 +2589,6 @@ impl Type {
|
||||
actual: actual_type,
|
||||
..
|
||||
} => alias_symbol == &rep_symbol || actual_type.contains_symbol(rep_symbol),
|
||||
HostExposedAlias { name, actual, .. } => {
|
||||
name == &rep_symbol || actual.contains_symbol(rep_symbol)
|
||||
}
|
||||
Apply(symbol, _, _) if *symbol == rep_symbol => true,
|
||||
Apply(_, args, _) => args.iter().any(|arg| arg.value.contains_symbol(rep_symbol)),
|
||||
RangedNumber(_) => false,
|
||||
@ -2793,7 +2652,6 @@ impl Type {
|
||||
actual: actual_type,
|
||||
..
|
||||
} => actual_type.contains_variable(rep_variable),
|
||||
HostExposedAlias { actual, .. } => actual.contains_variable(rep_variable),
|
||||
Apply(_, args, _) => args
|
||||
.iter()
|
||||
.any(|arg| arg.value.contains_variable(rep_variable)),
|
||||
@ -2996,22 +2854,6 @@ fn instantiate_aliases<'a, F>(
|
||||
.iter_mut()
|
||||
.for_each(|t| instantiate_aliases(&mut t.value.typ, region, aliases, ctx));
|
||||
}
|
||||
HostExposedAlias {
|
||||
type_arguments: type_args,
|
||||
lambda_set_variables,
|
||||
actual: actual_type,
|
||||
..
|
||||
} => {
|
||||
for arg in type_args {
|
||||
instantiate_aliases(arg, region, aliases, ctx);
|
||||
}
|
||||
|
||||
for arg in lambda_set_variables {
|
||||
arg.instantiate_aliases(region, aliases, ctx);
|
||||
}
|
||||
|
||||
instantiate_aliases(&mut *actual_type, region, aliases, ctx);
|
||||
}
|
||||
Alias {
|
||||
type_arguments: type_args,
|
||||
lambda_set_variables,
|
||||
@ -3170,12 +3012,6 @@ fn symbols_help(initial: &Type) -> Vec<Symbol> {
|
||||
output.push(*alias_symbol);
|
||||
stack.push(actual_type);
|
||||
}
|
||||
HostExposedAlias { name, actual, .. } => {
|
||||
// because the type parameters are inlined in the actual type, we don't need to look
|
||||
// at the type parameters here
|
||||
output.push(*name);
|
||||
stack.push(actual);
|
||||
}
|
||||
Apply(symbol, args, _) => {
|
||||
output.push(*symbol);
|
||||
stack.extend(args.iter().map(|t| &t.value));
|
||||
@ -3301,16 +3137,6 @@ fn variables_help(tipe: &Type, accum: &mut ImSet<Variable>) {
|
||||
}
|
||||
variables_help(actual, accum);
|
||||
}
|
||||
HostExposedAlias {
|
||||
type_arguments: arguments,
|
||||
actual,
|
||||
..
|
||||
} => {
|
||||
for arg in arguments {
|
||||
variables_help(arg, accum);
|
||||
}
|
||||
variables_help(actual, accum);
|
||||
}
|
||||
RangedNumber(_) => {}
|
||||
Apply(_, args, _) => {
|
||||
for x in args {
|
||||
@ -3453,16 +3279,6 @@ fn variables_help_detailed(tipe: &Type, accum: &mut VariableDetail) {
|
||||
}
|
||||
variables_help_detailed(actual, accum);
|
||||
}
|
||||
HostExposedAlias {
|
||||
type_arguments: arguments,
|
||||
actual,
|
||||
..
|
||||
} => {
|
||||
for arg in arguments {
|
||||
variables_help_detailed(arg, accum);
|
||||
}
|
||||
variables_help_detailed(actual, accum);
|
||||
}
|
||||
RangedNumber(_) => {}
|
||||
Apply(_, args, _) => {
|
||||
for x in args {
|
||||
@ -4653,20 +4469,6 @@ fn instantiate_lambda_sets_as_unspecialized(
|
||||
stack.push(actual);
|
||||
stack.extend(type_arguments.iter_mut().rev().map(|t| &mut t.typ));
|
||||
}
|
||||
Type::HostExposedAlias {
|
||||
name: _,
|
||||
type_arguments,
|
||||
lambda_set_variables,
|
||||
actual_var: _,
|
||||
actual,
|
||||
} => {
|
||||
for lambda_set in lambda_set_variables.iter_mut() {
|
||||
debug_assert!(matches!(lambda_set.0, Type::Variable(_)));
|
||||
lambda_set.0 = new_uls();
|
||||
}
|
||||
stack.push(actual);
|
||||
stack.extend(type_arguments.iter_mut().rev());
|
||||
}
|
||||
Type::Apply(_sym, args, _region) => {
|
||||
stack.extend(args.iter_mut().rev().map(|t| &mut t.value));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user