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

@ -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)
}