Remove Cells from Types

This commit is contained in:
Ayaz Hafiz 2022-11-15 09:00:16 -06:00
parent f4fcb9f421
commit b30e8fc9b2
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
5 changed files with 89 additions and 117 deletions

View file

@ -34,7 +34,7 @@ use roc_types::subs::{
};
use roc_types::types::{
gather_fields_unsorted_iter, AliasKind, AliasShared, Category, OptAbleVar, Polarity, Reason,
RecordField, Type, TypeCell, TypeExtension, TypeTag, Types, Uls,
RecordField, Type, TypeExtension, TypeTag, Types, Uls,
};
use roc_unify::unify::{
unify, unify_introduced_ability_specialization, Env as UEnv, Mode, Obligated,
@ -138,7 +138,7 @@ impl DelayedAliasVariables {
#[derive(Debug, Default)]
pub struct Aliases {
aliases: Vec<(Symbol, Index<TypeCell>, DelayedAliasVariables, AliasKind)>,
aliases: Vec<(Symbol, Index<TypeTag>, DelayedAliasVariables, AliasKind)>,
variables: Vec<OptAbleVar>,
}
@ -195,7 +195,7 @@ impl Aliases {
}
};
// TODO: can we construct Aliases from TypeCell directly?
// TODO: can we construct Aliases from TypeTag directly?
let alias_typ = types.from_old_type(&alias.typ);
self.aliases
@ -2254,9 +2254,9 @@ pub(crate) fn type_to_var(
pools: &mut Pools,
types: &mut Types,
aliases: &mut Aliases,
typ: Index<TypeCell>,
typ: Index<TypeTag>,
) -> Variable {
if let TypeTag::Variable(var) = types[typ].get() {
if let TypeTag::Variable(var) = types[typ] {
var
} else {
let mut arena = take_scratchpad();
@ -2297,11 +2297,11 @@ impl RegisterVariable {
pools: &mut Pools,
arena: &'_ bumpalo::Bump,
types: &mut Types,
typ: Index<TypeCell>,
typ: Index<TypeTag>,
) -> Self {
use RegisterVariable::*;
match types[typ].get() {
match types[typ] {
TypeTag::Variable(var) => Direct(var),
TypeTag::EmptyRecord => Direct(Variable::EMPTY_RECORD),
TypeTag::EmptyTagUnion => Direct(Variable::EMPTY_TAG_UNION),
@ -2334,7 +2334,7 @@ impl RegisterVariable {
pools: &mut Pools,
arena: &'_ bumpalo::Bump,
types: &mut Types,
typ: Index<TypeCell>,
typ: Index<TypeTag>,
stack: &mut bumpalo::collections::Vec<'_, TypeToVar>,
) -> Variable {
match Self::from_type(subs, rank, pools, arena, types, typ) {
@ -2405,7 +2405,7 @@ impl AmbientFunctionPolicy {
#[derive(Debug)]
enum TypeToVar {
Defer {
typ: Index<TypeCell>,
typ: Index<TypeTag>,
destination: Variable,
ambient_function: AmbientFunctionPolicy,
},
@ -2422,7 +2422,7 @@ fn type_to_variable<'a>(
arena: &'a bumpalo::Bump,
aliases: &mut Aliases,
types: &mut Types,
typ: Index<TypeCell>,
typ: Index<TypeTag>,
// Helpers for instantiating ambient functions of lambda set variables from type aliases.
is_alias_lambda_set_arg: bool,
) -> Variable {
@ -2466,7 +2466,7 @@ fn type_to_variable<'a>(
}) = stack.pop()
{
use TypeTag::*;
match types[typ].get() {
match types[typ] {
Variable(_) | EmptyRecord | EmptyTagUnion => {
unreachable!("This variant should never be deferred!")
}
@ -2773,7 +2773,7 @@ fn type_to_variable<'a>(
}
StructuralAlias { shared, actual } | OpaqueAlias { shared, actual } => {
let kind = match types[typ].get() {
let kind = match types[typ] {
StructuralAlias { .. } => AliasKind::Structural,
OpaqueAlias { .. } => AliasKind::Opaque,
_ => internal_error!(),
@ -3023,10 +3023,10 @@ fn roc_result_to_var(
pools: &mut Pools,
arena: &'_ bumpalo::Bump,
types: &mut Types,
result_type: Index<TypeCell>,
result_type: Index<TypeTag>,
stack: &mut bumpalo::collections::Vec<'_, TypeToVar>,
) -> Variable {
match types[result_type].get() {
match types[result_type] {
TypeTag::TagUnion(tags) => {
let ext_slice = types.get_type_arguments(result_type);
@ -3206,7 +3206,7 @@ fn register_tag_arguments(
arena: &'_ bumpalo::Bump,
types: &mut Types,
stack: &mut bumpalo::collections::Vec<'_, TypeToVar>,
arguments: Slice<TypeCell>,
arguments: Slice<TypeTag>,
) -> VariableSubsSlice {
if arguments.is_empty() {
VariableSubsSlice::default()
@ -3335,7 +3335,7 @@ fn type_to_union_tags(
arena: &'_ bumpalo::Bump,
types: &mut Types,
union_tags: UnionTags,
opt_ext_slice: Slice<TypeCell>,
opt_ext_slice: Slice<TypeTag>,
stack: &mut bumpalo::collections::Vec<'_, TypeToVar>,
) -> (UnionTags, Variable) {
use bumpalo::collections::Vec;
@ -3391,7 +3391,7 @@ fn create_union_lambda(
arena: &'_ bumpalo::Bump,
types: &mut Types,
closure: Symbol,
capture_types: Slice<TypeCell>,
capture_types: Slice<TypeTag>,
stack: &mut bumpalo::collections::Vec<'_, TypeToVar>,
) -> UnionLambdas {
let variable_slice =