Try out converting subs to use soa stuff directly

This commit is contained in:
Richard Feldman 2024-10-10 00:06:02 -04:00
parent be0f1223eb
commit 4a7d7e42d6
No known key found for this signature in database
GPG key ID: 5DE4EE30BB738EDF
31 changed files with 539 additions and 731 deletions

View file

@ -20,3 +20,5 @@ ven_pretty = { path = "../../vendor/pretty" }
bumpalo.workspace = true
static_assertions.workspace = true
soa.workspace = true

View file

@ -1,8 +1,8 @@
#![allow(clippy::too_many_arguments)]
use crate::subs::{
self, AliasVariables, Content, FlatType, GetSubsSlice, Label, Subs, SubsIndex, UnionLabels,
UnsortedUnionLabels, Variable,
self, AliasVariables, Content, FlatType, Label, Subs, UnionLabels, UnsortedUnionLabels,
Variable,
};
use crate::types::{
name_type_var, name_type_var_with_hint, AbilitySet, Polarity, RecordField, Uls,
@ -11,6 +11,7 @@ use roc_collections::all::MutMap;
use roc_collections::VecSet;
use roc_module::ident::{Lowercase, TagName};
use roc_module::symbol::{Interns, ModuleId, Symbol};
use soa::{GetSlice, Index};
pub static WILDCARD: &str = "*";
static EMPTY_RECORD: &str = "{}";
@ -535,12 +536,12 @@ fn set_root_name(root: Variable, name: Lowercase, subs: &mut Subs) {
match old_content {
FlexVar(_) => {
let name_index = SubsIndex::push_new(&mut subs.field_names, name);
let name_index = Index::push_new(&mut subs.field_names, name);
let content = FlexVar(Some(name_index));
subs.set_content(root, content);
}
&FlexAbleVar(_, ability) => {
let name_index = SubsIndex::push_new(&mut subs.field_names, name);
let name_index = Index::push_new(&mut subs.field_names, name);
let content = FlexAbleVar(Some(name_index), ability);
subs.set_content(root, content);
}
@ -549,7 +550,7 @@ fn set_root_name(root: Variable, name: Lowercase, subs: &mut Subs) {
structure,
} => {
let structure = *structure;
let name_index = SubsIndex::push_new(&mut subs.field_names, name);
let name_index = Index::push_new(&mut subs.field_names, name);
let content = RecursionVar {
structure,
opt_name: Some(name_index),
@ -692,13 +693,13 @@ fn write_content<'a>(
let name = opt_name_index
.map(|name_index| subs.field_names[name_index.index as usize].as_str())
.unwrap_or(WILDCARD);
let abilities = AbilitySet::from_iter(subs.get_subs_slice(*abilities).iter().copied());
let abilities = AbilitySet::from_iter(subs.get_slice(*abilities).iter().copied());
ctx.able_variables.push((name, abilities));
buf.push_str(name);
}
RigidAbleVar(name_index, abilities) => {
let name = subs.field_names[name_index.index as usize].as_str();
let abilities = AbilitySet::from_iter(subs.get_subs_slice(*abilities).iter().copied());
let abilities = AbilitySet::from_iter(subs.get_slice(*abilities).iter().copied());
ctx.able_variables.push((name, abilities));
buf.push_str(name);
}
@ -859,11 +860,11 @@ fn write_content<'a>(
write_content(env, ctx, rec_var, subs, buf, parens, pol)
}
for Uls(var, member, region) in subs.get_subs_slice(*unspecialized) {
for Uls(var, member, region) in subs.get_slice(*unspecialized) {
buf.push_str(" + ");
write_content(env, ctx, *var, subs, buf, Parens::Unnecessary, pol);
buf.push(':');
buf.push_str(&print_symbol(member));
buf.push_str(&print_symbol(&member));
buf.push(':');
buf.push_str(&region.to_string());
}
@ -1106,7 +1107,7 @@ fn write_flat_type<'a>(
env,
ctx,
*symbol,
subs.get_subs_slice(*args),
subs.get_slice(*args),
subs,
buf,
parens,
@ -1118,7 +1119,7 @@ fn write_flat_type<'a>(
Func(args, closure, ret) => write_fn(
env,
ctx,
subs.get_subs_slice(*args),
subs.get_slice(*args),
*closure,
*ret,
subs,
@ -1267,7 +1268,7 @@ fn write_flat_type<'a>(
let mut tags: MutMap<TagName, _> = MutMap::default();
tags.extend(
subs.get_subs_slice(*tag_names)
subs.get_slice(*tag_names)
.iter()
.map(|t| (t.clone(), vec![])),
);
@ -1323,7 +1324,7 @@ pub fn push_union<L: Label>(
fields.reserve(tags.len());
for (name_index, slice_index) in tags.iter_all() {
let subs_slice = subs[slice_index];
let slice = subs.get_subs_slice(subs_slice);
let slice = subs.get_slice(subs_slice);
let tag_name = L::index_subs(subs, name_index).clone();
fields.push((tag_name, slice.to_vec()));
@ -1357,7 +1358,7 @@ pub fn chase_ext_tag_union(
}
Content::Structure(FunctionOrTagUnion(tag_names, _, ext_var)) => {
fields.extend(
subs.get_subs_slice(*tag_names)
subs.get_slice(*tag_names)
.iter()
.map(|t| (t.clone(), vec![])),
);

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,7 @@
use crate::num::NumericRange;
use crate::pretty_print::Parens;
use crate::subs::{
GetSubsSlice, RecordFields, Subs, TagExt, TupleElems, UnionTags, VarStore, Variable,
VariableSubsSlice,
RecordFields, Subs, TagExt, TupleElems, UnionTags, VarStore, Variable, VariableSlice,
};
use roc_collections::all::{HumanIndex, ImMap, ImSet, MutMap, MutSet, SendMap};
use roc_collections::soa::{Index, Slice};
@ -13,6 +12,7 @@ use roc_module::ident::{ForeignSymbol, Lowercase, TagName};
use roc_module::low_level::LowLevel;
use roc_module::symbol::{Interns, ModuleId, Symbol};
use roc_region::all::{Loc, Region};
use soa::GetSlice;
use std::fmt;
use std::fmt::Write;
use std::path::PathBuf;
@ -4273,13 +4273,7 @@ pub fn gather_tags_unsorted_iter(
subs: &Subs,
other_fields: UnionTags,
mut ext: TagExt,
) -> Result<
(
impl Iterator<Item = (&TagName, VariableSubsSlice)> + '_,
TagExt,
),
GatherTagsError,
> {
) -> Result<(impl Iterator<Item = (&TagName, VariableSlice)> + '_, TagExt), GatherTagsError> {
use crate::subs::Content::*;
use crate::subs::FlatType::*;
@ -4342,11 +4336,11 @@ pub fn gather_tags_slices(
subs: &Subs,
other_fields: UnionTags,
ext: TagExt,
) -> Result<(Vec<(TagName, VariableSubsSlice)>, TagExt), GatherTagsError> {
) -> Result<(Vec<(TagName, VariableSlice)>, TagExt), GatherTagsError> {
let (it, ext) = gather_tags_unsorted_iter(subs, other_fields, ext)?;
let mut result: Vec<_> = it
.map(|(ref_label, field): (_, VariableSubsSlice)| (ref_label.clone(), field))
.map(|(ref_label, field): (_, VariableSlice)| (ref_label.clone(), field))
.collect();
result.sort_by(|(a, _), (b, _)| a.cmp(b));
@ -4362,9 +4356,7 @@ pub fn gather_tags(
let (it, ext) = gather_tags_unsorted_iter(subs, other_fields, ext)?;
let mut result: Vec<_> = it
.map(|(ref_label, field): (_, VariableSubsSlice)| {
(ref_label.clone(), subs.get_subs_slice(field))
})
.map(|(ref_label, field): (_, VariableSlice)| (ref_label.clone(), subs.get_slice(field)))
.collect();
result.sort_by(|(a, _), (b, _)| a.cmp(b));

View file

@ -1,6 +1,6 @@
use std::hint::unreachable_unchecked;
use crate::subs::{Content, Descriptor, Mark, OptVariable, Rank, Variable, VariableSubsSlice};
use crate::subs::{Content, Descriptor, Mark, OptVariable, Rank, Variable, VariableSlice};
use roc_serialize::bytes;
#[derive(Clone, Default)]
@ -53,7 +53,7 @@ impl UnificationTable {
self.contents.is_empty()
}
pub fn reserve(&mut self, extra_length: usize) -> VariableSubsSlice {
pub fn reserve(&mut self, extra_length: usize) -> VariableSlice {
use std::iter::repeat;
let start = self.contents.len();
@ -63,7 +63,7 @@ impl UnificationTable {
self.metadata
.extend(repeat(Combine::NONE).take(extra_length));
VariableSubsSlice::new(start as _, extra_length as _)
VariableSlice::new(start as _, extra_length as _)
}
pub fn push(