Updates for making soa no_std

This commit is contained in:
Richard Feldman 2024-10-12 21:27:41 -04:00
parent 178bc469e6
commit 44d00e1f13
No known key found for this signature in database
GPG key ID: DAC334802F365236
21 changed files with 164 additions and 151 deletions

View file

@ -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;
@ -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(),
);
@ -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(),
);

View file

@ -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,
@ -12,7 +13,7 @@ use roc_module::{
use roc_types::{
subs::{
self, AliasVariables, Descriptor, GetSubsSlice, OptVariable, RecordFields, Subs, SubsIndex,
SubsSlice, TupleElems, UnionLambdas, UnionTags, Variable, VariableSubsSlice,
SubsSlice, TupleElems, UnionLambdas, UnionTags, Variable,
},
types::{RecordField, Uls},
};
@ -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(),
)
@ -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)
@ -182,7 +183,7 @@ 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(),
)
@ -190,7 +191,7 @@ impl<'a> CopyEnv for AcrossSubs<'a> {
#[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(),
)
@ -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(),
)
@ -919,8 +920,7 @@ fn deep_copy_type_vars<C: CopyEnv>(
macro_rules! clone_var_slice {
($slice:expr) => {{
let new_arguments =
VariableSubsSlice::reserve_into_subs(env.target(), $slice.len());
let new_arguments = env.target().reserve_into_vars($slice.len());
for (target_index, var_index) in (new_arguments.indices()).zip($slice) {
let var = env.source()[var_index];
let copy_var = env.get_copy(var).into_variable().unwrap_or(var);
@ -994,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(),
}
};
@ -1015,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(),
}
};
@ -1032,8 +1032,7 @@ fn deep_copy_type_vars<C: CopyEnv>(
}
perform_clone!({
let new_variable_slices =
SubsSlice::reserve_variable_slices(env.target(), tags.len());
let new_variable_slices = env.target().reserve_variable_slices(tags.len());
let it = (new_variable_slices.indices()).zip(tags.variables());
for (target_index, index) in it {
let slice = env.source()[index];
@ -1058,8 +1057,7 @@ fn deep_copy_type_vars<C: CopyEnv>(
}
perform_clone!({
let new_variable_slices =
SubsSlice::reserve_variable_slices(env.target(), tags.len());
let new_variable_slices = env.target().reserve_variable_slices(tags.len());
let it = (new_variable_slices.indices()).zip(tags.variables());
for (target_index, index) in it {
let slice = env.source()[index];
@ -1109,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
};
@ -1135,8 +1133,7 @@ fn deep_copy_type_vars<C: CopyEnv>(
let new_ambient_function = descend_var!(ambient_function);
perform_clone!({
let new_variable_slices =
SubsSlice::reserve_variable_slices(env.target(), solved.len());
let new_variable_slices = env.target().reserve_variable_slices(solved.len());
let it = (new_variable_slices.indices()).zip(solved.variables());
for (target_index, index) in it {
let slice = env.source()[index];
@ -1150,8 +1147,7 @@ fn deep_copy_type_vars<C: CopyEnv>(
let new_solved =
UnionLambdas::from_slices(new_solved_labels, new_variable_slices);
let new_unspecialized =
SubsSlice::reserve_uls_slice(env.target(), unspecialized.len());
let new_unspecialized = env.target().reserve_uls_slice(unspecialized.len());
for (target_index, uls_index) in
(new_unspecialized.into_iter()).zip(unspecialized.into_iter())
{
@ -1192,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,
};
@ -1217,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![];
@ -1238,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![];
@ -1259,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![];
@ -1282,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![];
@ -1304,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)));
@ -1390,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)));
@ -1472,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)],
);

View file

@ -16,3 +16,5 @@ im-rc.workspace = true
im.workspace = true
wyhash.workspace = true
smallvec.workspace = true
soa.workspace = true

View file

@ -191,3 +191,34 @@ impl<T, U> EitherIndex<T, U> {
self.index = self.index.saturating_sub(1);
}
}
/// Push to a std::vec::Vec<T> and then return an index to that new element's
/// position in the Vec.
///
/// This is not a method on soa::Index because the `soa` is `no_std` by design.
/// Long-term, our arena-allocated vectors should have this as a method!
pub fn index_push_new<T>(vector: &mut Vec<T>, value: T) -> soa::Index<T> {
let index = soa::Index::new(vector.len() as u32);
vector.push(value);
index
}
/// Extend a std::vec::Vec<T> and then return a slice to the new elements'
/// positions in the Vec.
///
/// This is not a method on soa::Slice because the `soa` is `no_std` by design.
/// Long-term, our arena-allocated vectors should have this as a method!
pub fn slice_extend_new<T>(
vector: &mut Vec<T>,
values: impl IntoIterator<Item = T>,
) -> soa::Slice<T> {
let start = vector.len() as u32;
vector.extend(values);
let end = vector.len() as u32;
soa::Slice::new(start, (end - start) as u16)
}

View file

@ -7,6 +7,7 @@ use roc_can::{
num::{IntBound, IntLitWidth},
pattern::Pattern,
};
use roc_collections::soa::{index_push_new, slice_extend_new};
use roc_derive_key::hash::FlatHashKey;
use roc_error_macros::internal_error;
use roc_module::{
@ -19,8 +20,7 @@ use roc_types::{
num::int_lit_width_to_variable,
subs::{
Content, ExhaustiveMark, FlatType, GetSubsSlice, LambdaSet, OptVariable, RecordFields,
RedundantMark, Subs, SubsIndex, SubsSlice, TagExt, TupleElems, UnionLambdas, UnionTags,
Variable,
RedundantMark, Subs, SubsSlice, TagExt, TupleElems, UnionLambdas, UnionTags, Variable,
},
types::RecordField,
};
@ -372,8 +372,8 @@ fn hash_newtype_tag_union(
}
let variables_slices_slice =
SubsSlice::extend_new(&mut env.subs.variable_slices, [variables_slice]);
let tag_name_index = SubsIndex::push_new(&mut env.subs.tag_names, label.clone());
slice_extend_new(&mut env.subs.variable_slices, [variables_slice]);
let tag_name_index = index_push_new(&mut env.subs.tag_names, label.clone());
let union_tags = UnionTags::from_slices(tag_name_index.as_slice(), variables_slices_slice);
let tag_union_var = synth_var(

View file

@ -329,7 +329,7 @@ fn to_inspector_record(
.map(|(field_name_index, field_var_index, _)| {
let field_name = env.subs[field_name_index].clone();
let field_var = env.subs[field_var_index];
let field_var_slice = VariableSubsSlice::new(field_var_index.index, 1);
let field_var_slice = VariableSubsSlice::new(field_var_index.index() as u32, 1);
// key: "a"
let key_field = Field {
@ -539,7 +539,7 @@ fn to_inspector_tuple(
.map(|(elem_index, elem_var_index)| {
let index = env.subs[elem_index];
let elem_var = env.subs[elem_var_index];
let elem_var_slice = VariableSubsSlice::new(elem_var_index.index, 1);
let elem_var_slice = VariableSubsSlice::new(elem_var_index.index() as u32, 1);
// tup.0
let tuple_access = TupleAccess {

View file

@ -20,6 +20,7 @@ use roc_can::module::{
canonicalize_module_defs, ExposedByModule, ExposedForModule, ExposedModuleTypes, Module,
ModuleParams, ResolvedImplementations, TypeState,
};
use roc_collections::soa::slice_extend_new;
use roc_collections::{default_hasher, BumpMap, MutMap, MutSet, VecMap, VecSet};
use roc_constrain::module::constrain_module;
use roc_debug_flags::dbg_do;
@ -4369,7 +4370,7 @@ fn synth_list_len_type(subs: &mut Subs) -> Variable {
// List.len : List a -> U64
let a = synth_import(subs, Content::FlexVar(None));
let a_slice = SubsSlice::extend_new(&mut subs.variables, [a]);
let a_slice = slice_extend_new(&mut subs.variables, [a]);
let list_a = synth_import(
subs,
Content::Structure(FlatType::Apply(Symbol::LIST_LIST, a_slice)),
@ -4385,7 +4386,7 @@ fn synth_list_len_type(subs: &mut Subs) -> Variable {
ambient_function: fn_var,
}),
);
let fn_args_slice = SubsSlice::extend_new(&mut subs.variables, [list_a]);
let fn_args_slice = slice_extend_new(&mut subs.variables, [list_a]);
subs.set_content(
fn_var,
Content::Structure(FlatType::Func(fn_args_slice, clos_list_len, Variable::U64)),

View file

@ -10124,7 +10124,7 @@ fn find_lambda_sets_help(
| FlatType::RecursiveTagUnion(_, union_tags, ext) => {
for tag in union_tags.variables() {
stack.extend(
subs.get_subs_slice(subs.variable_slices[tag.index as usize])
subs.get_subs_slice(subs.variable_slices[tag.index()])
.iter()
.rev(),
);
@ -10146,7 +10146,7 @@ fn find_lambda_sets_help(
// the lambda set itself should already be caught by Func above, but the
// capture can itself contain more lambda sets
for index in lambda_set.solved.variables() {
let subs_slice = subs.variable_slices[index.index as usize];
let subs_slice = subs.variable_slices[index.index()];
stack.extend(subs.variables[subs_slice.indices()].iter());
}
}

View file

@ -1,5 +1,8 @@
use roc_can::abilities::AbilitiesStore;
use roc_collections::{soa::Index, MutMap};
use roc_collections::{
soa::{slice_extend_new, Index},
MutMap,
};
use roc_error_macros::internal_error;
use roc_module::symbol::Symbol;
use roc_solve_problem::TypeError;
@ -131,7 +134,7 @@ impl Aliases {
let ok_slice = SubsSlice::new(alias_variables.variables_start, 1);
let variable_slices =
SubsSlice::extend_new(&mut env.subs.variable_slices, [err_slice, ok_slice]);
slice_extend_new(&mut env.subs.variable_slices, [err_slice, ok_slice]);
let union_tags = UnionTags::from_slices(tag_names_slice, variable_slices);
let ext_var = TagExt::Any(Variable::EMPTY_TAG_UNION);

View file

@ -1,11 +1,12 @@
use std::ops::ControlFlow;
use bumpalo::Bump;
use roc_collections::soa::slice_extend_new;
use roc_error_macros::internal_error;
use roc_types::{
subs::{
self, AliasVariables, Content, Descriptor, FlatType, GetSubsSlice, Mark, OptVariable, Rank,
RecordFields, Subs, SubsSlice, TagExt, TupleElems, UnionLabels, Variable,
RecordFields, Subs, TagExt, TupleElems, UnionLabels, Variable,
},
types::{RecordField, Uls},
};
@ -201,7 +202,7 @@ fn deep_copy_var_help(
let new_field_types_start = if has_rigid_optional_field {
let field_types = field_types.to_vec();
let slice = SubsSlice::extend_new(
let slice = slice_extend_new(
&mut subs.record_fields,
field_types.into_iter().map(|f| match f {
RecordField::RigidOptional(())
@ -212,7 +213,7 @@ fn deep_copy_var_help(
| RecordField::Optional(_) => f,
}),
);
slice.start
slice.start()
} else {
fields.field_types_start
};
@ -220,7 +221,7 @@ fn deep_copy_var_help(
RecordFields {
length: fields.length,
field_names_start: fields.field_names_start,
variables_start: new_variables.start,
variables_start: new_variables.start(),
field_types_start: new_field_types_start,
}
};
@ -234,7 +235,7 @@ fn deep_copy_var_help(
TupleElems {
length: elems.length,
variables_start: new_variables.start,
variables_start: new_variables.start(),
elem_index_start: elems.elem_index_start,
}
};
@ -291,7 +292,7 @@ fn deep_copy_var_help(
copy_sequence!(arguments.all_variables_len, arguments.all_variables());
let new_arguments = AliasVariables {
variables_start: new_variables.start,
variables_start: new_variables.start(),
..arguments
};

View file

@ -3,7 +3,7 @@
use std::collections::VecDeque;
use roc_can::abilities::{AbilitiesStore, ImplKey};
use roc_collections::{VecMap, VecSet};
use roc_collections::{soa::slice_extend_new, VecMap, VecSet};
use roc_debug_flags::dbg_do;
#[cfg(debug_assertions)]
use roc_debug_flags::ROC_TRACE_COMPACTION;
@ -14,7 +14,7 @@ use roc_solve_schema::UnificationMode;
use roc_types::{
subs::{
get_member_lambda_sets_at_region, Content, Descriptor, GetSubsSlice, LambdaSet, Mark,
OptVariable, Rank, Subs, SubsSlice, UlsOfVar, Variable,
OptVariable, Rank, Subs, UlsOfVar, Variable,
},
types::{AliasKind, MemberImpl, Polarity, Uls},
};
@ -360,7 +360,7 @@ pub fn compact_lambda_sets_of_vars<P: Phase>(
// The first lambda set contains one concrete lambda, plus all solved
// lambdas, plus all other unspecialized lambdas.
// l' = [solved_lambdas + t1 + ... + tm + C:f:r]
let unspecialized = SubsSlice::extend_new(
let unspecialized = slice_extend_new(
&mut env.subs.unspecialized_lambda_sets,
not_concrete
.drain(..)
@ -371,7 +371,7 @@ pub fn compact_lambda_sets_of_vars<P: Phase>(
// All the other lambda sets consists only of their respective concrete
// lambdas.
// ln = [[] + C:fn:rn]
let unspecialized = SubsSlice::extend_new(
let unspecialized = slice_extend_new(
&mut env.subs.unspecialized_lambda_sets,
[concrete_lambda],
);
@ -521,10 +521,7 @@ fn compact_lambda_set<P: Phase>(
let t_f1_lambda_set_without_concrete = LambdaSet {
solved,
recursion_var,
unspecialized: SubsSlice::extend_new(
&mut env.subs.unspecialized_lambda_sets,
new_unspecialized,
),
unspecialized: slice_extend_new(&mut env.subs.unspecialized_lambda_sets, new_unspecialized),
ambient_function: t_f1,
};
env.subs.set_content(

View file

@ -1,7 +1,7 @@
use std::cell::RefCell;
use roc_can::{abilities::AbilitiesStore, constraint::TypeOrVar, expected::Expected};
use roc_collections::soa::{Index, Slice};
use roc_collections::soa::{slice_extend_new, Index, Slice};
use roc_error_macros::internal_error;
use roc_module::{ident::TagName, symbol::Symbol};
use roc_region::all::Loc;
@ -372,7 +372,7 @@ pub(crate) fn type_to_var_help(
}
}
UnspecializedLambdaSet { unspecialized } => {
let unspecialized_slice = SubsSlice::extend_new(
let unspecialized_slice = slice_extend_new(
&mut env.subs.unspecialized_lambda_sets,
std::iter::once(unspecialized),
);
@ -545,8 +545,8 @@ pub(crate) fn type_to_var_help(
unreachable!("we assert that the ext var is empty; otherwise we'd already know it was a tag union!");
}
let tag_names = SubsSlice::extend_new(&mut env.subs.tag_names, [tag_name]);
let symbols = SubsSlice::extend_new(&mut env.subs.symbol_names, [symbol]);
let tag_names = slice_extend_new(&mut env.subs.tag_names, [tag_name]);
let symbols = slice_extend_new(&mut env.subs.symbol_names, [symbol]);
let content =
Content::Structure(FlatType::FunctionOrTagUnion(tag_names, symbols, ext));
@ -651,7 +651,7 @@ pub(crate) fn type_to_var_help(
}
AliasVariables {
variables_start: new_variables.start,
variables_start: new_variables.start(),
type_variables_len: type_arguments.len() as _,
lambda_set_variables_len: lambda_set_variables.len() as _,
all_variables_len: all_vars_length as _,
@ -734,7 +734,7 @@ pub(crate) fn type_to_var_help(
}
AliasVariables {
variables_start: new_variables.start,
variables_start: new_variables.start(),
type_variables_len: type_arguments.len() as _,
lambda_set_variables_len: lambda_set_variables.len() as _,
all_variables_len: all_vars_length as _,
@ -763,10 +763,8 @@ pub(crate) fn type_to_var_help(
match *env.subs.get_content_unchecked(var) {
Content::RigidVar(a) => {
// TODO(multi-abilities): check run cache
let abilities_slice = SubsSlice::extend_new(
&mut env.subs.symbol_names,
abilities.sorted_iter().copied(),
);
let abilities_slice =
slice_extend_new(&mut env.subs.symbol_names, abilities.sorted_iter().copied());
env.subs
.set_content(var, Content::RigidAbleVar(a, abilities_slice));
}
@ -776,10 +774,8 @@ pub(crate) fn type_to_var_help(
// pass, already bound
}
_ => {
let abilities_slice = SubsSlice::extend_new(
&mut env.subs.symbol_names,
abilities.sorted_iter().copied(),
);
let abilities_slice =
slice_extend_new(&mut env.subs.symbol_names, abilities.sorted_iter().copied());
let flex_ability = env.register(rank, Content::FlexAbleVar(None, abilities_slice));
@ -967,7 +963,7 @@ fn find_tag_name_run(slice: &[TagName], subs: &mut Subs) -> Option<SubsSlice<Tag
Some(occupied) => {
let subs_slice = *occupied;
let prefix_slice = SubsSlice::new(subs_slice.start, slice.len() as _);
let prefix_slice = SubsSlice::new(subs_slice.start(), slice.len() as _);
if slice.len() == 1 {
return Some(prefix_slice);
@ -976,7 +972,7 @@ fn find_tag_name_run(slice: &[TagName], subs: &mut Subs) -> Option<SubsSlice<Tag
match slice.len().cmp(&subs_slice.len()) {
Ordering::Less => {
// we might have a prefix
let tag_names = &subs.tag_names[subs_slice.start as usize..];
let tag_names = &subs.tag_names[subs_slice.start() as usize..];
for (from_subs, from_slice) in tag_names.iter().zip(slice.iter()) {
if from_subs != from_slice {
@ -1054,8 +1050,7 @@ fn insert_tags_fast_path(
let variable_slice =
register_tag_arguments(env, rank, arena, types, stack, arguments_slice);
let new_variable_slices =
SubsSlice::extend_new(&mut env.subs.variable_slices, [variable_slice]);
let new_variable_slices = slice_extend_new(&mut env.subs.variable_slices, [variable_slice]);
macro_rules! subs_tag_name {
($tag_name_slice:expr) => {
@ -1206,10 +1201,9 @@ fn create_union_lambda(
stack: &mut bumpalo::collections::Vec<'_, TypeToVar>,
) -> UnionLambdas {
let variable_slice = register_tag_arguments(env, rank, arena, types, stack, capture_types);
let new_variable_slices =
SubsSlice::extend_new(&mut env.subs.variable_slices, [variable_slice]);
let new_variable_slices = slice_extend_new(&mut env.subs.variable_slices, [variable_slice]);
let lambda_name_slice = SubsSlice::extend_new(&mut env.subs.symbol_names, [closure]);
let lambda_name_slice = slice_extend_new(&mut env.subs.symbol_names, [closure]);
UnionLambdas::from_slices(lambda_name_slice, new_variable_slices)
}

View file

@ -17,7 +17,10 @@ roc_can = { path = "../can" }
roc_collections = { path = "../collections" }
roc_constrain = { path = "../constrain" }
roc_debug_flags = { path = "../debug_flags" }
roc_derive = { path = "../derive", features = ["debug-derived-symbols", "open-extension-vars"] }
roc_derive = { path = "../derive", features = [
"debug-derived-symbols",
"open-extension-vars",
] }
roc_derive_key = { path = "../derive_key" }
roc_load_internal = { path = "../load_internal" }
roc_module = { path = "../module" }

View file

@ -1,12 +1,11 @@
use std::fmt::Write as _; // import without risk of name clashing
use std::path::PathBuf;
use bumpalo::Bump;
use roc_packaging::cache::RocCacheDir;
use roc_solve::{
module::{SolveConfig, SolveOutput},
FunctionKind,
};
use std::fmt::Write as _; // import without risk of name clashing
use std::path::PathBuf;
use ven_pretty::DocAllocator;
use roc_can::{
@ -116,12 +115,12 @@ macro_rules! v {
}
}};
([ $($tag:ident $($payload:expr)*),* ] as $rec_var:ident) => {{
use roc_types::subs::{Subs, SubsIndex, Variable, Content, FlatType, TagExt, UnionTags};
use roc_types::subs::{Subs, Variable, Content, FlatType, TagExt, UnionTags};
use roc_module::ident::TagName;
|subs: &mut Subs| {
let $rec_var = subs.fresh_unnamed_flex_var();
let rec_name_index =
SubsIndex::push_new(&mut subs.field_names, stringify!($rec).into());
roc_collections::soa::index_push_new(&mut subs.field_names, stringify!($rec).into());
$(
let $tag = vec![ $( $payload(subs), )* ];
@ -193,12 +192,12 @@ macro_rules! v {
|subs: &mut Subs| { roc_derive::synth_var(subs, Content::FlexVar(None)) }
}};
($name:ident implements $ability:path) => {{
use roc_types::subs::{Subs, SubsIndex, SubsSlice, Content};
use roc_types::subs::{Subs, Content};
|subs: &mut Subs| {
let name_index =
SubsIndex::push_new(&mut subs.field_names, stringify!($name).into());
roc_collections::soa::index_push_new(&mut subs.field_names, stringify!($name).into());
let abilities_slice = SubsSlice::extend_new(&mut subs.symbol_names, [$ability]);
let abilities_slice = roc_collections::soa::slice_extend_new(&mut subs.symbol_names, [$ability]);
roc_derive::synth_var(subs, Content::FlexAbleVar(Some(name_index), abilities_slice))
}

View file

@ -540,6 +540,7 @@ pub fn try_run_lib_function<T>(
}
}
#[allow(dead_code)]
// only used in tests
pub(crate) fn llvm_evals_to<T, U, F>(
src: &str,
@ -589,6 +590,7 @@ pub(crate) fn llvm_evals_to<T, U, F>(
}
}
#[allow(unused_macros)]
macro_rules! assert_llvm_evals_to {
($src:expr, $expected:expr, $ty:ty, $transform:expr, $ignore_problems:expr) => {
crate::helpers::llvm::llvm_evals_to::<$ty, _, _>(
@ -653,6 +655,7 @@ macro_rules! assert_evals_to {
}};
}
#[allow(unused_macros)]
macro_rules! assert_evals_to_erased {
($src:expr, $expected:expr, $ty:ty) => {{
crate::helpers::llvm::llvm_evals_to::<$ty, _, _>(
@ -665,12 +668,16 @@ macro_rules! assert_evals_to_erased {
}};
}
#[allow(dead_code)]
pub fn identity<T>(value: T) -> T {
value
}
#[allow(unused_imports)]
pub(crate) use assert_evals_to;
#[allow(unused_imports)]
pub(crate) use assert_evals_to_erased;
#[allow(unused_imports)]
pub(crate) use assert_llvm_evals_to;
#[cfg(feature = "gen-llvm-wasm")]
pub(crate) use assert_wasm_evals_to;

View file

@ -2734,8 +2734,8 @@ where
Self {
length: labels.len() as u16,
labels_start: labels.start() as u32,
values_start: variables.start() as u32,
labels_start: labels.start(),
values_start: variables.start(),
_marker: Default::default(),
}
}
@ -4977,7 +4977,7 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) ->
RecordFields {
length: fields.len() as u16,
field_names_start,
variables_start: new_variables.start() as u32,
variables_start: new_variables.start(),
field_types_start,
}
};
@ -5003,7 +5003,7 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) ->
TupleElems {
length: elems.len() as u16,
variables_start: new_variables.start() as u32,
variables_start: new_variables.start(),
elem_index_start,
}
};
@ -5133,7 +5133,7 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) ->
}
let new_arguments = AliasVariables {
variables_start: new_variables.start() as u32,
variables_start: new_variables.start(),
..arguments
};
@ -5443,7 +5443,7 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl
RecordFields {
length: fields.len() as u16,
field_names_start,
variables_start: new_variables.start() as u32,
variables_start: new_variables.start(),
field_types_start,
}
};
@ -5469,7 +5469,7 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl
TupleElems {
length: elems.len() as u16,
variables_start: new_variables.start() as u32,
variables_start: new_variables.start(),
elem_index_start,
}
};
@ -5637,7 +5637,7 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl
}
let new_arguments = AliasVariables {
variables_start: new_variables.start() as u32,
variables_start: new_variables.start(),
..arguments
};

View file

@ -1,3 +1,4 @@
use roc_collections::soa::slice_extend_new;
use roc_collections::VecMap;
use roc_debug_flags::{dbg_do, dbg_set};
#[cfg(debug_assertions)]
@ -1787,7 +1788,7 @@ fn unify_unspecialized_lambdas<M: MetaCollector>(
);
Ok((
SubsSlice::extend_new(&mut env.unspecialized_lambda_sets, merged_uls),
slice_extend_new(&mut env.unspecialized_lambda_sets, merged_uls),
whole_outcome,
))
}
@ -3242,7 +3243,7 @@ fn unify_flat_type<M: MetaCollector>(
let mut outcome = unify_zip_slices(env, pool, *l_args, *r_args, ctx.mode);
if outcome.mismatches.is_empty() {
let chosen_args = SubsSlice::reserve_into_subs(env, l_args.len());
let chosen_args = env.reserve_into_vars(l_args.len());
for ((store, var1), var2) in chosen_args
.into_iter()
.zip(l_args.into_iter())
@ -3325,7 +3326,7 @@ fn unify_flat_type<M: MetaCollector>(
*ext2,
),
(TagUnion(tags1, ext1), FunctionOrTagUnion(tag_names, _, ext2)) => {
let empty_tag_var_slices = SubsSlice::extend_new(
let empty_tag_var_slices = slice_extend_new(
&mut env.variable_slices,
std::iter::repeat(Default::default()).take(tag_names.len()),
);
@ -3334,7 +3335,7 @@ fn unify_flat_type<M: MetaCollector>(
unify_tag_unions(env, pool, ctx, *tags1, *ext1, tags2, *ext2)
}
(FunctionOrTagUnion(tag_names, _, ext1), TagUnion(tags2, ext2)) => {
let empty_tag_var_slices = SubsSlice::extend_new(
let empty_tag_var_slices = slice_extend_new(
&mut env.variable_slices,
std::iter::repeat(Default::default()).take(tag_names.len()),
);
@ -3347,7 +3348,7 @@ fn unify_flat_type<M: MetaCollector>(
// this never happens in type-correct programs, but may happen if there is a type error
debug_assert!(is_recursion_var(env, *recursion_var));
let empty_tag_var_slices = SubsSlice::extend_new(
let empty_tag_var_slices = slice_extend_new(
&mut env.variable_slices,
std::iter::repeat(Default::default()).take(tag_names.len()),
);
@ -3359,7 +3360,7 @@ fn unify_flat_type<M: MetaCollector>(
(FunctionOrTagUnion(tag_names, _, ext1), RecursiveTagUnion(recursion_var, tags2, ext2)) => {
debug_assert!(is_recursion_var(env, *recursion_var));
let empty_tag_var_slices = SubsSlice::extend_new(
let empty_tag_var_slices = slice_extend_new(
&mut env.variable_slices,
std::iter::repeat(Default::default()).take(tag_names.len()),
);
@ -3587,7 +3588,7 @@ pub fn merged_ability_slices(
let merged = merge_sorted_keys(left.iter().copied(), right.iter().copied());
// TODO: check if there's an existing run in subs rather than re-inserting
SubsSlice::extend_new(&mut subs.symbol_names, merged)
slice_extend_new(&mut subs.symbol_names, merged)
}
#[inline(always)]
@ -3888,8 +3889,8 @@ fn unify_function_or_tag_union_and_func<M: MetaCollector>(
{
let lambda_names = env.get_subs_slice(tag_fn_lambdas).to_vec();
let new_lambda_names = SubsSlice::extend_new(&mut env.symbol_names, lambda_names);
let empty_captures_slices = SubsSlice::extend_new(
let new_lambda_names = slice_extend_new(&mut env.symbol_names, lambda_names);
let empty_captures_slices = slice_extend_new(
&mut env.variable_slices,
std::iter::repeat(Default::default()).take(new_lambda_names.len()),
);
@ -3955,7 +3956,7 @@ fn unify_two_function_or_tag_unions<M: MetaCollector>(
.collect();
all_tags.sort();
all_tags.dedup();
SubsSlice::extend_new(&mut env.tag_names, all_tags)
slice_extend_new(&mut env.tag_names, all_tags)
};
let merged_lambdas = {
let mut all_lambdas: Vec<_> = (env.get_subs_slice(tag_symbols_1).iter())
@ -3964,7 +3965,7 @@ fn unify_two_function_or_tag_unions<M: MetaCollector>(
.collect();
all_lambdas.sort();
all_lambdas.dedup();
SubsSlice::extend_new(&mut env.symbol_names, all_lambdas)
slice_extend_new(&mut env.symbol_names, all_lambdas)
};
let mut outcome = unify_pool(env, pool, ext1.var(), ext2.var(), ctx.mode);