Merge pull request #4881 from roc-lang/rename-rank-none

Rename rank none to rank generalized
This commit is contained in:
Folkert de Vries 2023-01-12 00:25:24 +01:00 committed by GitHub
commit 386983a657
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 21 deletions

View File

@ -628,7 +628,7 @@ fn solve<'a>(
let failing: Vec<_> = rigid_vars let failing: Vec<_> = rigid_vars
.iter() .iter()
.filter(|&var| { .filter(|&var| {
!subs.redundant(*var) && subs.get_rank(*var) != Rank::NONE !subs.redundant(*var) && subs.get_rank(*var) != Rank::GENERALIZED
}) })
.collect(); .collect();
@ -772,7 +772,7 @@ pub fn insert_type_into_subs<'a>(
subs: &mut Subs, subs: &mut Subs,
typ: &Type2, typ: &Type2,
) -> Variable { ) -> Variable {
let rank = Rank::NONE; let rank = Rank::GENERALIZED;
let mut pools = Pools::default(); let mut pools = Pools::default();
let mut cached = MutMap::default(); let mut cached = MutMap::default();
@ -1235,7 +1235,7 @@ fn generalize(
if desc_rank < young_rank { if desc_rank < young_rank {
pools.get_mut(desc_rank).push(var); pools.get_mut(desc_rank).push(var);
} else { } else {
subs.set_rank(var, Rank::NONE); subs.set_rank(var, Rank::GENERALIZED);
} }
} }
} }
@ -1494,7 +1494,7 @@ fn introduce(subs: &mut Subs, rank: Rank, pools: &mut Pools, vars: &[Variable])
/// Function that converts rigids variables to flex variables /// Function that converts rigids variables to flex variables
/// this is used during the monomorphization process /// this is used during the monomorphization process
pub fn instantiate_rigids(subs: &mut Subs, var: Variable) { pub fn instantiate_rigids(subs: &mut Subs, var: Variable) {
let rank = Rank::NONE; let rank = Rank::GENERALIZED;
let mut pools = Pools::default(); let mut pools = Pools::default();
instantiate_rigids_help(subs, rank, &mut pools, var); instantiate_rigids_help(subs, rank, &mut pools, var);
@ -1677,7 +1677,7 @@ fn deep_copy_var_help(
if let Some(copy) = desc.copy.into_variable() { if let Some(copy) = desc.copy.into_variable() {
return copy; return copy;
} else if desc.rank != Rank::NONE { } else if desc.rank != Rank::GENERALIZED {
return var; return var;
} }

View File

@ -847,7 +847,9 @@ fn solve(
// or that it just never came up in elm. // or that it just never came up in elm.
let mut it = rigid_vars let mut it = rigid_vars
.iter() .iter()
.filter(|&var| !subs.redundant(*var) && subs.get_rank(*var) != Rank::NONE) .filter(|&var| {
!subs.redundant(*var) && subs.get_rank(*var) != Rank::GENERALIZED
})
.peekable(); .peekable();
if it.peek().is_some() { if it.peek().is_some() {
@ -2338,7 +2340,7 @@ impl RegisterVariable {
| TypeTag::HostExposedAlias { shared, .. } => { | TypeTag::HostExposedAlias { shared, .. } => {
let AliasShared { symbol, .. } = types[shared]; let AliasShared { symbol, .. } = types[shared];
if let Some(reserved) = Variable::get_reserved(symbol) { if let Some(reserved) = Variable::get_reserved(symbol) {
let direct_var = if rank.is_none() { let direct_var = if rank.is_generalized() {
// reserved variables are stored with rank NONE // reserved variables are stored with rank NONE
reserved reserved
} else { } else {
@ -3545,7 +3547,7 @@ fn generalize(
if desc_rank < young_rank { if desc_rank < young_rank {
pools.get_mut(desc_rank).push(var); pools.get_mut(desc_rank).push(var);
} else { } else {
subs.set_rank(var, Rank::NONE); subs.set_rank(var, Rank::GENERALIZED);
} }
} }
@ -3759,7 +3761,7 @@ fn adjust_rank_content(
// we'll wind up with [Z, S a]{}, but it will be at rank 0, and "a" will get // we'll wind up with [Z, S a]{}, but it will be at rank 0, and "a" will get
// over-generalized. Really, the empty tag union should be introduced at // over-generalized. Really, the empty tag union should be introduced at
// whatever current group rank we're at, and so that's how we encode it here. // whatever current group rank we're at, and so that's how we encode it here.
if *ext_var == Variable::EMPTY_TAG_UNION && rank.is_none() { if *ext_var == Variable::EMPTY_TAG_UNION && rank.is_generalized() {
rank = group_rank; rank = group_rank;
} }
@ -3959,7 +3961,7 @@ fn has_trivial_copy(subs: &Subs, root_var: Variable) -> Option<Variable> {
if let Some(copy) = existing_copy.into_variable() { if let Some(copy) = existing_copy.into_variable() {
Some(copy) Some(copy)
} else if subs.get_rank_unchecked(root_var) != Rank::NONE { } else if subs.get_rank_unchecked(root_var) != Rank::GENERALIZED {
Some(root_var) Some(root_var)
} else { } else {
None None

View File

@ -427,7 +427,7 @@ fn name_all_type_vars(variable: Variable, subs: &mut Subs, debug_print: DebugPri
fn is_weakened_unbound(subs: &Subs, var: Variable) -> bool { fn is_weakened_unbound(subs: &Subs, var: Variable) -> bool {
use Content::*; use Content::*;
let desc = subs.get_without_compacting(var); let desc = subs.get_without_compacting(var);
!desc.rank.is_none() !desc.rank.is_generalized()
&& !matches!( && !matches!(
desc.content, desc.content,
FlexVar(_) | RigidVar(_) | FlexAbleVar(..) | RigidAbleVar(..) FlexVar(_) | RigidVar(_) | FlexAbleVar(..) | RigidAbleVar(..)

View File

@ -2183,11 +2183,12 @@ const fn unnamed_flex_var() -> Content {
pub struct Rank(u32); pub struct Rank(u32);
impl Rank { impl Rank {
pub const NONE: Rank = Rank(0); /// Reserved rank for variables that are generalized
pub const GENERALIZED: Rank = Rank(0);
/// The generalized rank /// The generalized rank
pub fn is_none(&self) -> bool { pub fn is_generalized(&self) -> bool {
*self == Self::NONE *self == Self::GENERALIZED
} }
pub const fn toplevel() -> Self { pub const fn toplevel() -> Self {
@ -2270,7 +2271,7 @@ impl From<Content> for Descriptor {
fn from(content: Content) -> Descriptor { fn from(content: Content) -> Descriptor {
Descriptor { Descriptor {
content, content,
rank: Rank::NONE, rank: Rank::GENERALIZED,
mark: Mark::NONE, mark: Mark::NONE,
copy: OptVariable::NONE, copy: OptVariable::NONE,
} }
@ -4562,7 +4563,7 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) ->
if let Some(&copy) = env.copy_table.get(&var) { if let Some(&copy) = env.copy_table.get(&var) {
debug_assert!(env.target.contains(copy)); debug_assert!(env.target.contains(copy));
return copy; return copy;
} else if desc.rank != Rank::NONE { } else if desc.rank != Rank::GENERALIZED {
// DO NOTHING, Fall through // DO NOTHING, Fall through
// //
// The original deep_copy_var can do // The original deep_copy_var can do
@ -5007,7 +5008,7 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl
if let Some(&copy) = env.copy_table.get(&var) { if let Some(&copy) = env.copy_table.get(&var) {
debug_assert!(env.target.contains(copy)); debug_assert!(env.target.contains(copy));
return copy; return copy;
} else if desc.rank != Rank::NONE { } else if desc.rank != Rank::GENERALIZED {
// DO NOTHING, Fall through // DO NOTHING, Fall through
// //
// The original copy_import can do // The original copy_import can do
@ -5324,7 +5325,7 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl
/// Function that converts rigids variables to flex variables /// Function that converts rigids variables to flex variables
/// this is used during the monomorphization process and deriving /// this is used during the monomorphization process and deriving
pub fn instantiate_rigids(subs: &mut Subs, var: Variable) { pub fn instantiate_rigids(subs: &mut Subs, var: Variable) {
let rank = Rank::NONE; let rank = Rank::GENERALIZED;
instantiate_rigids_help(subs, rank, var); instantiate_rigids_help(subs, rank, var);
@ -5350,7 +5351,7 @@ fn instantiate_rigids_help(subs: &mut Subs, max_rank: Rank, initial: Variable) {
} }
subs.modify(var, |desc| { subs.modify(var, |desc| {
desc.rank = Rank::NONE; desc.rank = Rank::GENERALIZED;
desc.mark = Mark::NONE; desc.mark = Mark::NONE;
desc.copy = OptVariable::from(var); desc.copy = OptVariable::from(var);
}); });
@ -5483,7 +5484,7 @@ fn instantiate_rigids_help(subs: &mut Subs, max_rank: Rank, initial: Variable) {
for var in visited { for var in visited {
subs.modify(var, |descriptor| { subs.modify(var, |descriptor| {
if descriptor.copy.is_some() { if descriptor.copy.is_some() {
descriptor.rank = Rank::NONE; descriptor.rank = Rank::GENERALIZED;
descriptor.mark = Mark::NONE; descriptor.mark = Mark::NONE;
descriptor.copy = OptVariable::NONE; descriptor.copy = OptVariable::NONE;
} }

View File

@ -26,7 +26,7 @@ pub struct Root {
impl Root { impl Root {
const NONE: Self = Self { const NONE: Self = Self {
rank: Rank::NONE, rank: Rank::GENERALIZED,
mark: Mark::NONE, mark: Mark::NONE,
copy: OptVariable::NONE, copy: OptVariable::NONE,
}; };