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