mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Rename IsImplicitOpennessVar
This commit is contained in:
parent
5fceb9ceb7
commit
c9460ecf3f
4 changed files with 33 additions and 36 deletions
|
@ -9,7 +9,7 @@ use roc_problem::can::ShadowKind;
|
|||
use roc_region::all::{Loc, Region};
|
||||
use roc_types::subs::{VarStore, Variable};
|
||||
use roc_types::types::{
|
||||
name_type_var, AbilitySet, Alias, AliasCommon, AliasKind, AliasVar, IsImplicitOpennessVar,
|
||||
name_type_var, AbilitySet, Alias, AliasCommon, AliasKind, AliasVar, ExtImplicitOpenness,
|
||||
LambdaSet, OptAbleType, OptAbleVar, RecordField, Type, TypeExtension,
|
||||
};
|
||||
|
||||
|
@ -889,7 +889,7 @@ fn can_annotation_help(
|
|||
);
|
||||
|
||||
debug_assert!(
|
||||
!is_implicit_openness.0,
|
||||
matches!(is_implicit_openness, ExtImplicitOpenness::No),
|
||||
"records should never be implicitly inferred open"
|
||||
);
|
||||
|
||||
|
@ -1111,7 +1111,7 @@ fn can_extension_type<'a>(
|
|||
references: &mut VecSet<Symbol>,
|
||||
opt_ext: &Option<&Loc<TypeAnnotation<'a>>>,
|
||||
ext_problem_kind: roc_problem::can::ExtensionTypeKind,
|
||||
) -> (Type, IsImplicitOpennessVar) {
|
||||
) -> (Type, ExtImplicitOpenness) {
|
||||
fn valid_record_ext_type(typ: &Type) -> bool {
|
||||
// Include erroneous types so that we don't overreport errors.
|
||||
matches!(
|
||||
|
@ -1158,7 +1158,7 @@ fn can_extension_type<'a>(
|
|||
})
|
||||
}
|
||||
|
||||
(ext_type, IsImplicitOpennessVar::NO)
|
||||
(ext_type, ExtImplicitOpenness::No)
|
||||
} else {
|
||||
// Report an error but mark the extension variable to be inferred
|
||||
// so that we're as permissive as possible.
|
||||
|
@ -1177,24 +1177,24 @@ fn can_extension_type<'a>(
|
|||
(
|
||||
Type::Variable(var),
|
||||
// Since this is an error anyway, just be permissive
|
||||
IsImplicitOpennessVar::NO,
|
||||
ExtImplicitOpenness::No,
|
||||
)
|
||||
}
|
||||
}
|
||||
None => match ext_problem_kind {
|
||||
ExtensionTypeKind::Record => (Type::EmptyRec, IsImplicitOpennessVar::NO),
|
||||
ExtensionTypeKind::Record => (Type::EmptyRec, ExtImplicitOpenness::No),
|
||||
ExtensionTypeKind::TagUnion => {
|
||||
// In negative positions a missing extension variable forces a closed tag union;
|
||||
// otherwise, open-in-output-position means we give the tag an inference variable.
|
||||
match pol {
|
||||
CanPolarity::Neg | CanPolarity::InOpaque => {
|
||||
(Type::EmptyTagUnion, IsImplicitOpennessVar::NO)
|
||||
(Type::EmptyTagUnion, ExtImplicitOpenness::No)
|
||||
}
|
||||
CanPolarity::Pos | CanPolarity::InAlias => {
|
||||
let var = var_store.fresh();
|
||||
introduced_variables.insert_infer_ext_in_output(var);
|
||||
|
||||
(Type::Variable(var), IsImplicitOpennessVar::YES)
|
||||
(Type::Variable(var), ExtImplicitOpenness::Yes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ use roc_types::subs::{
|
|||
UnionTags, Variable, VariableSubsSlice,
|
||||
};
|
||||
use roc_types::types::{
|
||||
gather_fields_unsorted_iter, AliasKind, AliasShared, Category, IsImplicitOpennessVar,
|
||||
OptAbleVar, Polarity, Reason, RecordField, Type, TypeExtension, TypeTag, Types, Uls,
|
||||
gather_fields_unsorted_iter, AliasKind, AliasShared, Category, ExtImplicitOpenness, OptAbleVar,
|
||||
Polarity, Reason, RecordField, Type, TypeExtension, TypeTag, Types, Uls,
|
||||
};
|
||||
use roc_unify::unify::{
|
||||
unify, unify_introduced_ability_specialization, Env as UEnv, Mode, Obligated,
|
||||
|
@ -2688,11 +2688,7 @@ fn type_to_variable<'a>(
|
|||
let temp_ext = match ext_slice.into_iter().next() {
|
||||
Some(ext) => {
|
||||
let var = helper!(ext);
|
||||
if ext_openness.0 {
|
||||
TagExt::Openness(var)
|
||||
} else {
|
||||
TagExt::Any(var)
|
||||
}
|
||||
TagExt::from_can(var, ext_openness)
|
||||
}
|
||||
None => TagExt::Any(roc_types::subs::Variable::EMPTY_TAG_UNION),
|
||||
};
|
||||
|
@ -3408,7 +3404,7 @@ fn type_to_union_tags(
|
|||
types: &mut Types,
|
||||
union_tags: UnionTags,
|
||||
opt_ext_slice: Slice<TypeTag>,
|
||||
ext_openness: IsImplicitOpennessVar,
|
||||
ext_openness: ExtImplicitOpenness,
|
||||
stack: &mut bumpalo::collections::Vec<'_, TypeToVar>,
|
||||
) -> (UnionTags, TagExt) {
|
||||
use bumpalo::collections::Vec;
|
||||
|
@ -3438,11 +3434,7 @@ fn type_to_union_tags(
|
|||
let temp_ext = {
|
||||
let temp_ext_var =
|
||||
RegisterVariable::with_stack(subs, rank, pools, arena, types, ext, stack);
|
||||
if ext_openness.0 {
|
||||
TagExt::Openness(temp_ext_var)
|
||||
} else {
|
||||
TagExt::Any(temp_ext_var)
|
||||
}
|
||||
TagExt::from_can(temp_ext_var, ext_openness)
|
||||
};
|
||||
let (it, ext) =
|
||||
roc_types::types::gather_tags_unsorted_iter(subs, UnionTags::default(), temp_ext)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#![deny(unsafe_op_in_unsafe_fn)]
|
||||
use crate::types::{
|
||||
name_type_var, AbilitySet, AliasKind, ErrorType, Polarity, RecordField, RecordFieldsError,
|
||||
TypeExt, Uls,
|
||||
name_type_var, AbilitySet, AliasKind, ErrorType, ExtImplicitOpenness, Polarity, RecordField,
|
||||
RecordFieldsError, TypeExt, Uls,
|
||||
};
|
||||
use roc_collections::all::{FnvMap, ImMap, ImSet, MutSet, SendMap};
|
||||
use roc_collections::{VecMap, VecSet};
|
||||
|
@ -2549,6 +2549,13 @@ impl TagExt {
|
|||
pub fn is_any(&self) -> bool {
|
||||
matches!(self, Self::Any(..))
|
||||
}
|
||||
|
||||
pub fn from_can(var: Variable, ext_openness: ExtImplicitOpenness) -> Self {
|
||||
match ext_openness {
|
||||
ExtImplicitOpenness::Yes => Self::Openness(var),
|
||||
ExtImplicitOpenness::No => Self::Any(var),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
|
|
@ -397,7 +397,7 @@ pub enum TypeTag {
|
|||
},
|
||||
// type extension is implicit
|
||||
// tag name is in the `single_tag_union_tag_names` map
|
||||
FunctionOrTagUnion(Symbol, IsImplicitOpennessVar),
|
||||
FunctionOrTagUnion(Symbol, ExtImplicitOpenness),
|
||||
UnspecializedLambdaSet {
|
||||
unspecialized: Uls,
|
||||
},
|
||||
|
@ -433,8 +433,8 @@ pub enum TypeTag {
|
|||
// TypeExtension is implicit in the type slice
|
||||
// it is length zero for closed, length 1 for existing
|
||||
// if not closed, IsImplicitOpennessVar is whether the extension is an Openness variable
|
||||
TagUnion(UnionTags, IsImplicitOpennessVar),
|
||||
RecursiveTagUnion(Variable, UnionTags, IsImplicitOpennessVar),
|
||||
TagUnion(UnionTags, ExtImplicitOpenness),
|
||||
RecursiveTagUnion(Variable, UnionTags, ExtImplicitOpenness),
|
||||
Record(RecordFields),
|
||||
}
|
||||
|
||||
|
@ -1798,22 +1798,20 @@ impl Clone for OptAbleType {
|
|||
/// but can't grow more monomorphic tags.
|
||||
/// E.g. `[]_a` can unify with `[]` or `[]*` but not `[A, B]`.
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||
pub struct IsImplicitOpennessVar(pub bool);
|
||||
|
||||
impl IsImplicitOpennessVar {
|
||||
pub const YES: Self = Self(true);
|
||||
pub const NO: Self = Self(false);
|
||||
pub enum ExtImplicitOpenness {
|
||||
Yes,
|
||||
No,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub enum TypeExtension {
|
||||
Open(Box<Type>, IsImplicitOpennessVar),
|
||||
Open(Box<Type>, ExtImplicitOpenness),
|
||||
Closed,
|
||||
}
|
||||
|
||||
impl TypeExtension {
|
||||
#[inline(always)]
|
||||
pub fn from_type(typ: Type, is_implicit_openness: IsImplicitOpennessVar) -> Self {
|
||||
pub fn from_type(typ: Type, is_implicit_openness: ExtImplicitOpenness) -> Self {
|
||||
match typ {
|
||||
Type::EmptyTagUnion | Type::EmptyRec => Self::Closed,
|
||||
_ => Self::Open(Box::new(typ), is_implicit_openness),
|
||||
|
@ -1824,7 +1822,7 @@ impl TypeExtension {
|
|||
pub fn from_non_annotation_type(typ: Type) -> Self {
|
||||
match typ {
|
||||
Type::EmptyTagUnion | Type::EmptyRec => Self::Closed,
|
||||
_ => Self::Open(Box::new(typ), IsImplicitOpennessVar::NO),
|
||||
_ => Self::Open(Box::new(typ), ExtImplicitOpenness::No),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1845,10 +1843,10 @@ impl TypeExtension {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn is_implicit_openness(&self) -> IsImplicitOpennessVar {
|
||||
fn is_implicit_openness(&self) -> ExtImplicitOpenness {
|
||||
match self {
|
||||
TypeExtension::Open(_, is_implicit_openness) => *is_implicit_openness,
|
||||
TypeExtension::Closed => IsImplicitOpennessVar::NO,
|
||||
TypeExtension::Closed => ExtImplicitOpenness::No,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue