mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Simplify AbilitySet storage
This commit is contained in:
parent
191798cfd6
commit
db8e135a05
2 changed files with 20 additions and 16 deletions
|
@ -2819,7 +2819,7 @@ fn type_to_variable<'a>(
|
|||
let lambda_set_vars_offset = type_arguments_offset + type_arguments.len();
|
||||
let infer_ext_vars_offset = lambda_set_vars_offset + lambda_set_variables.len();
|
||||
|
||||
for (((target_index, arg_type), arg_region), opt_ability) in
|
||||
for (((target_index, arg_type), arg_region), abilities) in
|
||||
(new_variables.indices().skip(type_arguments_offset))
|
||||
.zip(type_arguments.into_iter())
|
||||
.zip(type_argument_regions.into_iter())
|
||||
|
@ -2827,9 +2827,9 @@ fn type_to_variable<'a>(
|
|||
{
|
||||
let copy_var = helper!(arg_type);
|
||||
subs.variables[target_index] = copy_var;
|
||||
if types[opt_ability].is_some() {
|
||||
if !types[abilities].is_empty() {
|
||||
let arg_region = types[arg_region];
|
||||
bind_to_abilities.push((Loc::at(arg_region, copy_var), opt_ability));
|
||||
bind_to_abilities.push((Loc::at(arg_region, copy_var), abilities));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2917,7 +2917,7 @@ fn type_to_variable<'a>(
|
|||
|
||||
let new_variables = VariableSubsSlice::reserve_into_subs(subs, all_vars_length);
|
||||
|
||||
for (((target_index, typ), region), opt_abilities) in
|
||||
for (((target_index, typ), region), abilities) in
|
||||
(new_variables.indices().skip(type_arguments_offset))
|
||||
.zip(type_arguments.into_iter())
|
||||
.zip(type_argument_regions.into_iter())
|
||||
|
@ -2925,9 +2925,9 @@ fn type_to_variable<'a>(
|
|||
{
|
||||
let copy_var = helper!(typ);
|
||||
subs.variables[target_index] = copy_var;
|
||||
if types[opt_abilities].is_some() {
|
||||
if !types[abilities].is_empty() {
|
||||
let region = types[region];
|
||||
bind_to_abilities.push((Loc::at(region, copy_var), opt_abilities));
|
||||
bind_to_abilities.push((Loc::at(region, copy_var), abilities));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3063,11 +3063,7 @@ fn type_to_variable<'a>(
|
|||
}
|
||||
|
||||
for (Loc { value: var, region }, abilities) in bind_to_abilities {
|
||||
// TODO: SoA represent as Some<Index<AbilitySet>>, not the other way
|
||||
let abilities = types[abilities]
|
||||
.as_ref()
|
||||
.expect("should only have been added if it was Some");
|
||||
|
||||
let abilities = &types[abilities];
|
||||
match *subs.get_content_unchecked(var) {
|
||||
Content::RigidVar(a) => {
|
||||
// TODO(multi-abilities): check run cache
|
||||
|
|
|
@ -297,6 +297,10 @@ impl AbilitySet {
|
|||
pub fn into_sorted_iter(self) -> impl ExactSizeIterator<Item = Symbol> {
|
||||
self.0.into_iter()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromIterator<Symbol> for AbilitySet {
|
||||
|
@ -363,7 +367,7 @@ impl std::ops::Neg for Polarity {
|
|||
|
||||
pub struct AliasShared {
|
||||
pub symbol: Symbol,
|
||||
pub type_argument_abilities: Slice<Option<AbilitySet>>,
|
||||
pub type_argument_abilities: Slice<AbilitySet>,
|
||||
pub type_argument_regions: Slice<Region>,
|
||||
pub lambda_set_variables: Slice<TypeTag>,
|
||||
pub infer_ext_in_output_variables: Slice<TypeTag>,
|
||||
|
@ -468,7 +472,7 @@ pub struct Types {
|
|||
field_names: Vec<Lowercase>,
|
||||
|
||||
// aliases
|
||||
type_arg_abilities: Vec<Option<AbilitySet>>, // TODO: structural sharing for `AbilitySet`s themselves
|
||||
type_arg_abilities: Vec<AbilitySet>, // TODO: structural sharing for `AbilitySet`s themselves
|
||||
aliases: Vec<AliasShared>,
|
||||
|
||||
// these tag types are relatively rare, and so we store them in a way that reduces space, at
|
||||
|
@ -650,7 +654,9 @@ impl Types {
|
|||
|
||||
let type_argument_abilities = Slice::extend_new(
|
||||
&mut self.type_arg_abilities,
|
||||
type_arguments.iter().map(|a| a.opt_abilities.clone()),
|
||||
type_arguments
|
||||
.iter()
|
||||
.map(|a| a.opt_abilities.as_ref().cloned().unwrap_or_default()),
|
||||
);
|
||||
|
||||
// TODO: populate correctly
|
||||
|
@ -836,7 +842,9 @@ impl Types {
|
|||
|
||||
let type_argument_abilities = Slice::extend_new(
|
||||
&mut self.type_arg_abilities,
|
||||
type_arguments.iter().map(|a| a.value.opt_abilities.clone()),
|
||||
type_arguments
|
||||
.iter()
|
||||
.map(|a| a.value.opt_abilities.as_ref().cloned().unwrap_or_default()),
|
||||
);
|
||||
|
||||
let alias_shared = AliasShared {
|
||||
|
@ -987,7 +995,7 @@ macro_rules! impl_types_index_slice {
|
|||
impl_types_index! {
|
||||
tags, TypeTag
|
||||
aliases, AliasShared
|
||||
type_arg_abilities, Option<AbilitySet>
|
||||
type_arg_abilities, AbilitySet
|
||||
regions, Region
|
||||
tag_names, TagName
|
||||
field_types, RecordField<()>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue