Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SoA improvments part 2 #7163

Merged
merged 20 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions crates/compiler/can/src/abilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ impl IAbilitiesStore<Pending> {
}

mod serialize {
use roc_collections::{MutMap, VecMap};
use roc_collections::{soa::slice_extend_new, MutMap, VecMap};
use roc_module::symbol::Symbol;
use roc_region::all::Region;
use roc_serialize::bytes;
Expand Down Expand Up @@ -1034,11 +1034,11 @@ mod serialize {
specialization_lambda_sets,
} in spec_info
{
let regions = SubsSlice::extend_new(
let regions = slice_extend_new(
&mut spec_lambda_sets_regions,
specialization_lambda_sets.keys().copied(),
);
let vars = SubsSlice::extend_new(
let vars = slice_extend_new(
&mut spec_lambda_sets_vars,
specialization_lambda_sets.values().copied(),
);
Expand Down Expand Up @@ -1168,11 +1168,11 @@ mod serialize {
symbol,
specialization_lambda_sets,
}) => {
let regions = SubsSlice::extend_new(
let regions = slice_extend_new(
&mut spec_lambda_sets_regions,
specialization_lambda_sets.keys().copied(),
);
let vars = SubsSlice::extend_new(
let vars = slice_extend_new(
&mut spec_lambda_sets_vars,
specialization_lambda_sets.values().copied(),
);
Expand Down
35 changes: 18 additions & 17 deletions crates/compiler/can/src/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use std::sync::Arc;
use crate::abilities::SpecializationId;
use crate::exhaustive::{ExhaustiveContext, SketchedRows};
use crate::expected::{Expected, PExpected};
use roc_collections::soa::{EitherIndex, Index, Slice};
use roc_collections::soa::{index_push_new, slice_extend_new};
use roc_module::ident::TagName;
use roc_module::symbol::{ModuleId, Symbol};
use roc_region::all::{Loc, Region};
use roc_types::subs::{ExhaustiveMark, IllegalCycleMark, Variable};
use roc_types::types::{Category, PatternCategory, TypeTag, Types};
use soa::{EitherIndex, Index, Slice};

pub struct Constraints {
pub constraints: Vec<Constraint>,
Expand Down Expand Up @@ -205,11 +206,11 @@ impl Constraints {
}

pub fn push_expected_type(&mut self, expected: Expected<TypeOrVar>) -> ExpectedTypeIndex {
Index::push_new(&mut self.expectations, expected)
index_push_new(&mut self.expectations, expected)
}

pub fn push_pat_expected_type(&mut self, expected: PExpected<TypeOrVar>) -> PExpectedTypeIndex {
Index::push_new(&mut self.pattern_expectations, expected)
index_push_new(&mut self.pattern_expectations, expected)
}

#[inline(always)]
Expand All @@ -229,7 +230,7 @@ impl Constraints {
Category::List => Self::CATEGORY_LIST,
Category::Str => Self::CATEGORY_STR,
Category::Character => Self::CATEGORY_CHARACTER,
other => Index::push_new(&mut self.categories, other),
other => index_push_new(&mut self.categories, other),
}
}

Expand All @@ -247,7 +248,7 @@ impl Constraints {
PatternCategory::Int => Self::PCATEGORY_INT,
PatternCategory::Float => Self::PCATEGORY_FLOAT,
PatternCategory::Character => Self::PCATEGORY_CHARACTER,
other => Index::push_new(&mut self.pattern_categories, other),
other => index_push_new(&mut self.pattern_categories, other),
}
}

Expand Down Expand Up @@ -320,7 +321,7 @@ impl Constraints {
category: PatternCategory,
region: Region,
) -> Constraint {
let category_index = Index::push_new(&mut self.pattern_categories, category);
let category_index = index_push_new(&mut self.pattern_categories, category);

Constraint::PatternPresence(type_index, expected_index, category_index, region)
}
Expand All @@ -337,7 +338,7 @@ impl Constraints {
category: PatternCategory,
region: Region,
) -> Constraint {
let category_index = Index::push_new(&mut self.pattern_categories, category);
let category_index = index_push_new(&mut self.pattern_categories, category);

let includes_tag = IncludesTag {
type_index,
Expand All @@ -347,7 +348,7 @@ impl Constraints {
region,
};

let includes_tag_index = Index::push_new(&mut self.includes_tags, includes_tag);
let includes_tag_index = index_push_new(&mut self.includes_tags, includes_tag);

Constraint::IncludesTag(includes_tag_index)
}
Expand Down Expand Up @@ -614,7 +615,7 @@ impl Constraints {
filename: &'static str,
line_number: u32,
) -> Constraint {
let string_index = Index::push_new(&mut self.strings, filename);
let string_index = index_push_new(&mut self.strings, filename);

Constraint::Store(type_index, variable, string_index, line_number)
}
Expand All @@ -632,19 +633,19 @@ impl Constraints {
exhaustive: ExhaustiveMark,
) -> Constraint {
let real_var = Self::push_type_variable(real_var);
let sketched_rows = Index::push_new(&mut self.sketched_rows, sketched_rows);
let sketched_rows = index_push_new(&mut self.sketched_rows, sketched_rows);

let equality = match category_and_expectation {
Ok((category, expected)) => {
let category = Index::push_new(&mut self.categories, category);
let category = index_push_new(&mut self.categories, category);
let equality = Eq(real_var, expected, category, real_region);
let equality = Index::push_new(&mut self.eq, equality);
let equality = index_push_new(&mut self.eq, equality);
Ok(equality)
}
Err((category, expected)) => {
let category = Index::push_new(&mut self.pattern_categories, category);
let category = index_push_new(&mut self.pattern_categories, category);
let equality = PatternEq(real_var, expected, category, real_region);
let equality = Index::push_new(&mut self.pattern_eq, equality);
let equality = index_push_new(&mut self.pattern_eq, equality);
Err(equality)
}
};
Expand All @@ -662,18 +663,18 @@ impl Constraints {
I: IntoIterator<Item = (Symbol, Region)>,
I1: IntoIterator<Item = Region>,
{
let def_names = Slice::extend_new(&mut self.loc_symbols, loc_symbols);
let def_names = slice_extend_new(&mut self.loc_symbols, loc_symbols);

// we add a dummy symbol to these regions, so we can store the data in the loc_symbols vec
let it = expr_regions.into_iter().map(|r| (Symbol::ATTR_ATTR, r));
let expr_regions = Slice::extend_new(&mut self.loc_symbols, it);
let expr_regions = slice_extend_new(&mut self.loc_symbols, it);
let expr_regions = Slice::new(expr_regions.start() as _, expr_regions.len() as _);

let cycle = Cycle {
def_names,
expr_regions,
};
let cycle_index = Index::push_new(&mut self.cycles, cycle);
let cycle_index = index_push_new(&mut self.cycles, cycle);

Constraint::CheckCycle(cycle_index, cycle_mark)
}
Expand Down
50 changes: 26 additions & 24 deletions crates/compiler/can/src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
},
pattern::{DestructType, ListPatterns, Pattern, RecordDestruct, TupleDestruct},
};
use roc_collections::soa::{index_push_new, slice_extend_new};
use roc_module::{
ident::{Lowercase, TagName},
symbol::Symbol,
Expand Down Expand Up @@ -155,12 +156,12 @@ impl<'a> CopyEnv for AcrossSubs<'a> {

#[inline(always)]
fn clone_name(&mut self, name: SubsIndex<Lowercase>) -> SubsIndex<Lowercase> {
SubsIndex::push_new(&mut self.target.field_names, self.source[name].clone())
index_push_new(&mut self.target.field_names, self.source[name].clone())
}

#[inline(always)]
fn clone_field_names(&mut self, field_names: SubsSlice<Lowercase>) -> SubsSlice<Lowercase> {
SubsSlice::extend_new(
slice_extend_new(
&mut self.target.field_names,
self.source.get_subs_slice(field_names).iter().cloned(),
)
Expand All @@ -171,7 +172,7 @@ impl<'a> CopyEnv for AcrossSubs<'a> {
&mut self,
tuple_elem_indices: SubsSlice<usize>,
) -> SubsSlice<usize> {
SubsSlice::extend_new(
slice_extend_new(
&mut self.target.tuple_elem_indices,
self.source
.get_subs_slice(tuple_elem_indices)
Expand All @@ -182,15 +183,15 @@ impl<'a> CopyEnv for AcrossSubs<'a> {

#[inline(always)]
fn clone_tag_names(&mut self, tag_names: SubsSlice<TagName>) -> SubsSlice<TagName> {
SubsSlice::extend_new(
slice_extend_new(
&mut self.target.tag_names,
self.source.get_subs_slice(tag_names).iter().cloned(),
)
}

#[inline(always)]
fn clone_lambda_names(&mut self, lambda_names: SubsSlice<Symbol>) -> SubsSlice<Symbol> {
SubsSlice::extend_new(
slice_extend_new(
&mut self.target.symbol_names,
self.source.get_subs_slice(lambda_names).iter().cloned(),
)
Expand All @@ -201,7 +202,7 @@ impl<'a> CopyEnv for AcrossSubs<'a> {
&mut self,
record_fields: SubsSlice<RecordField<()>>,
) -> SubsSlice<RecordField<()>> {
SubsSlice::extend_new(
slice_extend_new(
&mut self.target.record_fields,
self.source.get_subs_slice(record_fields).iter().copied(),
)
Expand Down Expand Up @@ -993,9 +994,9 @@ fn deep_copy_type_vars<C: CopyEnv>(
let new_fields = {
RecordFields {
length: fields.length,
field_names_start: new_field_names.start,
variables_start: new_variables.start,
field_types_start: new_record_fields.start,
field_names_start: new_field_names.start(),
variables_start: new_variables.start(),
field_types_start: new_record_fields.start(),
}
};

Expand All @@ -1014,8 +1015,8 @@ fn deep_copy_type_vars<C: CopyEnv>(
let new_elems = {
TupleElems {
length: elems.length,
variables_start: new_variables.start,
elem_index_start: new_elem_indices.start,
variables_start: new_variables.start(),
elem_index_start: new_elem_indices.start(),
}
};

Expand Down Expand Up @@ -1106,7 +1107,7 @@ fn deep_copy_type_vars<C: CopyEnv>(
perform_clone!({
let new_variables = clone_var_slice!(arguments.all_variables());
let new_arguments = AliasVariables {
variables_start: new_variables.start,
variables_start: new_variables.start(),
..arguments
};

Expand Down Expand Up @@ -1187,13 +1188,14 @@ mod test {
};

use super::{deep_copy_expr_across_subs, deep_copy_type_vars};
use roc_collections::soa::{index_push_new, slice_extend_new};
use roc_error_macros::internal_error;
use roc_module::{ident::TagName, symbol::Symbol};
use roc_region::all::Loc;
use roc_types::{
subs::{
self, Content, Content::*, Descriptor, FlatType, GetSubsSlice, Mark, OptVariable, Rank,
Subs, SubsIndex, SubsSlice, Variable,
Subs, Variable,
},
types::Uls,
};
Expand All @@ -1212,7 +1214,7 @@ mod test {
fn copy_flex_var() {
let mut subs = Subs::new();

let field_name = SubsIndex::push_new(&mut subs.field_names, "a".into());
let field_name = index_push_new(&mut subs.field_names, "a".into());
let var = new_var(&mut subs, FlexVar(Some(field_name)));

let mut copied = vec![];
Expand All @@ -1233,7 +1235,7 @@ mod test {
fn copy_rigid_var() {
let mut subs = Subs::new();

let field_name = SubsIndex::push_new(&mut subs.field_names, "a".into());
let field_name = index_push_new(&mut subs.field_names, "a".into());
let var = new_var(&mut subs, RigidVar(field_name));

let mut copied = vec![];
Expand All @@ -1254,8 +1256,8 @@ mod test {
fn copy_flex_able_var() {
let mut subs = Subs::new();

let field_name = SubsIndex::push_new(&mut subs.field_names, "a".into());
let abilities = SubsSlice::extend_new(&mut subs.symbol_names, [Symbol::UNDERSCORE]);
let field_name = index_push_new(&mut subs.field_names, "a".into());
let abilities = slice_extend_new(&mut subs.symbol_names, [Symbol::UNDERSCORE]);
let var = new_var(&mut subs, FlexAbleVar(Some(field_name), abilities));

let mut copied = vec![];
Expand All @@ -1277,8 +1279,8 @@ mod test {
fn copy_rigid_able_var() {
let mut subs = Subs::new();

let field_name = SubsIndex::push_new(&mut subs.field_names, "a".into());
let abilities = SubsSlice::extend_new(&mut subs.symbol_names, [Symbol::UNDERSCORE]);
let field_name = index_push_new(&mut subs.field_names, "a".into());
let abilities = slice_extend_new(&mut subs.symbol_names, [Symbol::UNDERSCORE]);
let var = new_var(&mut subs, RigidAbleVar(field_name, abilities));

let mut copied = vec![];
Expand All @@ -1299,8 +1301,8 @@ mod test {
fn copy_deep_expr() {
let mut subs = Subs::new();

let a = SubsIndex::push_new(&mut subs.field_names, "a".into());
let b = SubsIndex::push_new(&mut subs.field_names, "b".into());
let a = index_push_new(&mut subs.field_names, "a".into());
let b = index_push_new(&mut subs.field_names, "b".into());
let var1 = new_var(&mut subs, FlexVar(Some(a)));
let var2 = new_var(&mut subs, FlexVar(Some(b)));

Expand Down Expand Up @@ -1385,8 +1387,8 @@ mod test {
let mut source = Subs::new();
let mut target = Subs::new();

let a = SubsIndex::push_new(&mut source.field_names, "a".into());
let b = SubsIndex::push_new(&mut source.field_names, "b".into());
let a = index_push_new(&mut source.field_names, "a".into());
let b = index_push_new(&mut source.field_names, "b".into());
let var1 = new_var(&mut source, FlexVar(Some(a)));
let var2 = new_var(&mut source, FlexVar(Some(b)));

Expand Down Expand Up @@ -1467,7 +1469,7 @@ mod test {
let mut target = Subs::new();

let a = new_var(&mut source, FlexVar(None));
let uls = SubsSlice::extend_new(
let uls = slice_extend_new(
&mut source.unspecialized_lambda_sets,
vec![Uls(a, Symbol::UNDERSCORE, 3)],
);
Expand Down
Loading