mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Even more dead code
This commit is contained in:
parent
51fd7711e7
commit
5d70a8dbe1
1 changed files with 20 additions and 59 deletions
|
@ -1899,18 +1899,9 @@ impl Subs {
|
|||
/// reference chain r -> t1 -> t2 -> r, [occurs] will return `Err(r, [t2, t1, r])`.
|
||||
///
|
||||
/// This ignores [Content::RecursionVar]s that occur recursively, because those are
|
||||
/// already priced in and expected to occur. Use [Subs::occurs_including_recursion_vars] if you
|
||||
/// need to check for recursion var occurrence.
|
||||
/// already priced in and expected to occur.
|
||||
pub fn occurs(&self, var: Variable) -> Result<(), (Variable, Vec<Variable>)> {
|
||||
occurs(self, &[], var, false)
|
||||
}
|
||||
|
||||
/// Like [Subs::occurs], but also errors when recursion vars occur.
|
||||
pub fn occurs_including_recursion_vars(
|
||||
&self,
|
||||
var: Variable,
|
||||
) -> Result<(), (Variable, Vec<Variable>)> {
|
||||
occurs(self, &[], var, true)
|
||||
occurs(self, &[], var)
|
||||
}
|
||||
|
||||
pub fn mark_tag_union_recursive(
|
||||
|
@ -3066,7 +3057,6 @@ fn occurs(
|
|||
subs: &Subs,
|
||||
seen: &[Variable],
|
||||
input_var: Variable,
|
||||
include_recursion_var: bool,
|
||||
) -> Result<(), (Variable, Vec<Variable>)> {
|
||||
use self::Content::*;
|
||||
use self::FlatType::*;
|
||||
|
@ -3090,88 +3080,62 @@ fn occurs(
|
|||
new_seen.push(root_var);
|
||||
|
||||
match flat_type {
|
||||
Apply(_, args) => short_circuit(
|
||||
subs,
|
||||
root_var,
|
||||
&new_seen,
|
||||
subs.get_subs_slice(*args).iter(),
|
||||
include_recursion_var,
|
||||
),
|
||||
Apply(_, args) => {
|
||||
short_circuit(subs, root_var, &new_seen, subs.get_subs_slice(*args).iter())
|
||||
}
|
||||
Func(arg_vars, closure_var, ret_var) => {
|
||||
let it = once(ret_var)
|
||||
.chain(once(closure_var))
|
||||
.chain(subs.get_subs_slice(*arg_vars).iter());
|
||||
short_circuit(subs, root_var, &new_seen, it, include_recursion_var)
|
||||
short_circuit(subs, root_var, &new_seen, it)
|
||||
}
|
||||
Record(vars_by_field, ext_var) => {
|
||||
let slice =
|
||||
SubsSlice::new(vars_by_field.variables_start, vars_by_field.length);
|
||||
let it = once(ext_var).chain(subs.get_subs_slice(slice).iter());
|
||||
short_circuit(subs, root_var, &new_seen, it, include_recursion_var)
|
||||
short_circuit(subs, root_var, &new_seen, it)
|
||||
}
|
||||
TagUnion(tags, ext_var) => {
|
||||
occurs_union(subs, root_var, &new_seen, include_recursion_var, tags)?;
|
||||
occurs_union(subs, root_var, &new_seen, tags)?;
|
||||
|
||||
short_circuit_help(
|
||||
subs,
|
||||
root_var,
|
||||
&new_seen,
|
||||
*ext_var,
|
||||
include_recursion_var,
|
||||
)
|
||||
short_circuit_help(subs, root_var, &new_seen, *ext_var)
|
||||
}
|
||||
FunctionOrTagUnion(_, _, ext_var) => {
|
||||
let it = once(ext_var);
|
||||
short_circuit(subs, root_var, &new_seen, it, include_recursion_var)
|
||||
short_circuit(subs, root_var, &new_seen, it)
|
||||
}
|
||||
RecursiveTagUnion(rec_var, tags, ext_var) => {
|
||||
if include_recursion_var {
|
||||
new_seen.push(subs.get_root_key_without_compacting(*rec_var));
|
||||
}
|
||||
occurs_union(subs, root_var, &new_seen, include_recursion_var, tags)?;
|
||||
RecursiveTagUnion(_, tags, ext_var) => {
|
||||
occurs_union(subs, root_var, &new_seen, tags)?;
|
||||
|
||||
short_circuit_help(
|
||||
subs,
|
||||
root_var,
|
||||
&new_seen,
|
||||
*ext_var,
|
||||
include_recursion_var,
|
||||
)
|
||||
short_circuit_help(subs, root_var, &new_seen, *ext_var)
|
||||
}
|
||||
EmptyRecord | EmptyTagUnion | Erroneous(_) => Ok(()),
|
||||
}
|
||||
}
|
||||
Alias(_, args, real_var, _) => {
|
||||
Alias(_, args, _, _) => {
|
||||
let mut new_seen = seen.to_owned();
|
||||
new_seen.push(root_var);
|
||||
|
||||
for var_index in args.into_iter() {
|
||||
let var = subs[var_index];
|
||||
short_circuit_help(subs, root_var, &new_seen, var, include_recursion_var)?;
|
||||
short_circuit_help(subs, root_var, &new_seen, var)?;
|
||||
}
|
||||
short_circuit_help(subs, root_var, &new_seen, *real_var, include_recursion_var)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
LambdaSet(self::LambdaSet {
|
||||
solved,
|
||||
recursion_var,
|
||||
recursion_var: _,
|
||||
unspecialized: _,
|
||||
ambient_function: _,
|
||||
}) => {
|
||||
let mut new_seen = seen.to_owned();
|
||||
new_seen.push(root_var);
|
||||
|
||||
if include_recursion_var {
|
||||
if let Some(v) = recursion_var.into_variable() {
|
||||
new_seen.push(subs.get_root_key_without_compacting(v));
|
||||
}
|
||||
}
|
||||
|
||||
// unspecialized lambda vars excluded because they are not explicitly part of the
|
||||
// type (they only matter after being resolved).
|
||||
|
||||
occurs_union(subs, root_var, &new_seen, include_recursion_var, solved)
|
||||
occurs_union(subs, root_var, &new_seen, solved)
|
||||
}
|
||||
RangedNumber(_range_vars) => Ok(()),
|
||||
}
|
||||
|
@ -3183,14 +3147,13 @@ fn occurs_union<L: Label>(
|
|||
subs: &Subs,
|
||||
root_var: Variable,
|
||||
seen: &[Variable],
|
||||
include_recursion_var: bool,
|
||||
tags: &UnionLabels<L>,
|
||||
) -> Result<(), (Variable, Vec<Variable>)> {
|
||||
for slice_index in tags.variables() {
|
||||
let slice = subs[slice_index];
|
||||
for var_index in slice {
|
||||
let var = subs[var_index];
|
||||
short_circuit_help(subs, root_var, seen, var, include_recursion_var)?;
|
||||
short_circuit_help(subs, root_var, seen, var)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -3202,13 +3165,12 @@ fn short_circuit<'a, T>(
|
|||
root_key: Variable,
|
||||
seen: &[Variable],
|
||||
iter: T,
|
||||
include_recursion_var: bool,
|
||||
) -> Result<(), (Variable, Vec<Variable>)>
|
||||
where
|
||||
T: Iterator<Item = &'a Variable>,
|
||||
{
|
||||
for var in iter {
|
||||
short_circuit_help(subs, root_key, seen, *var, include_recursion_var)?;
|
||||
short_circuit_help(subs, root_key, seen, *var)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -3220,9 +3182,8 @@ fn short_circuit_help(
|
|||
root_key: Variable,
|
||||
seen: &[Variable],
|
||||
var: Variable,
|
||||
include_recursion_var: bool,
|
||||
) -> Result<(), (Variable, Vec<Variable>)> {
|
||||
if let Err((v, mut vec)) = occurs(subs, seen, var, include_recursion_var) {
|
||||
if let Err((v, mut vec)) = occurs(subs, seen, var) {
|
||||
vec.push(root_key);
|
||||
return Err((v, vec));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue