mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Remove more push_new and extend_new usages
This commit is contained in:
parent
b2ea0b842c
commit
49d1786f6c
10 changed files with 517 additions and 269 deletions
|
@ -1034,14 +1034,16 @@ mod serialize {
|
|||
specialization_lambda_sets,
|
||||
} in spec_info
|
||||
{
|
||||
let regions = SubsSlice::extend_new(
|
||||
&mut spec_lambda_sets_regions,
|
||||
specialization_lambda_sets.keys().copied(),
|
||||
);
|
||||
let vars = SubsSlice::extend_new(
|
||||
&mut spec_lambda_sets_vars,
|
||||
specialization_lambda_sets.values().copied(),
|
||||
);
|
||||
let regions = {
|
||||
let start = spec_lambda_sets_regions.len() as u32;
|
||||
spec_lambda_sets_regions.extend(specialization_lambda_sets.keys().copied());
|
||||
SubsSlice::new(start, spec_lambda_sets_regions.len() as u16)
|
||||
};
|
||||
let vars = {
|
||||
let start = spec_lambda_sets_vars.len() as u32;
|
||||
spec_lambda_sets_vars.extend(specialization_lambda_sets.values().copied());
|
||||
SubsSlice::new(start, spec_lambda_sets_vars.len() as u16)
|
||||
};
|
||||
ser_member_spec_infos.push(SerMemberSpecInfo(*symbol, regions, vars));
|
||||
}
|
||||
|
||||
|
@ -1168,14 +1170,18 @@ mod serialize {
|
|||
symbol,
|
||||
specialization_lambda_sets,
|
||||
}) => {
|
||||
let regions = SubsSlice::extend_new(
|
||||
&mut spec_lambda_sets_regions,
|
||||
specialization_lambda_sets.keys().copied(),
|
||||
);
|
||||
let vars = SubsSlice::extend_new(
|
||||
&mut spec_lambda_sets_vars,
|
||||
specialization_lambda_sets.values().copied(),
|
||||
);
|
||||
let regions = {
|
||||
let start = spec_lambda_sets_regions.len() as u32;
|
||||
spec_lambda_sets_regions
|
||||
.extend(specialization_lambda_sets.keys().copied());
|
||||
SubsSlice::new(start, spec_lambda_sets_regions.len() as u16)
|
||||
};
|
||||
let vars = {
|
||||
let start = spec_lambda_sets_vars.len() as u32;
|
||||
spec_lambda_sets_vars
|
||||
.extend(specialization_lambda_sets.values().copied());
|
||||
SubsSlice::new(start, spec_lambda_sets_vars.len() as u16)
|
||||
};
|
||||
SerResolvedImpl::Impl(SerMemberSpecInfo(*symbol, regions, vars))
|
||||
}
|
||||
ResolvedImpl::Error => SerResolvedImpl::Error,
|
||||
|
|
|
@ -155,15 +155,13 @@ 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())
|
||||
self.target.push_field_name(self.source[name].clone())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn clone_field_names(&mut self, field_names: SubsSlice<Lowercase>) -> SubsSlice<Lowercase> {
|
||||
SubsSlice::extend_new(
|
||||
&mut self.target.field_names,
|
||||
self.source.get_subs_slice(field_names).iter().cloned(),
|
||||
)
|
||||
self.target
|
||||
.extend_field_names(self.source.get_subs_slice(field_names).iter().cloned())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -171,29 +169,26 @@ impl<'a> CopyEnv for AcrossSubs<'a> {
|
|||
&mut self,
|
||||
tuple_elem_indices: SubsSlice<usize>,
|
||||
) -> SubsSlice<usize> {
|
||||
SubsSlice::extend_new(
|
||||
&mut self.target.tuple_elem_indices,
|
||||
let start = self.target.tuple_elem_indices.len() as u32;
|
||||
self.target.tuple_elem_indices.extend(
|
||||
self.source
|
||||
.get_subs_slice(tuple_elem_indices)
|
||||
.iter()
|
||||
.cloned(),
|
||||
)
|
||||
);
|
||||
SubsSlice::new(start, self.target.tuple_elem_indices.len() as u16)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn clone_tag_names(&mut self, tag_names: SubsSlice<TagName>) -> SubsSlice<TagName> {
|
||||
SubsSlice::extend_new(
|
||||
&mut self.target.tag_names,
|
||||
self.source.get_subs_slice(tag_names).iter().cloned(),
|
||||
)
|
||||
self.target
|
||||
.extend_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(
|
||||
&mut self.target.symbol_names,
|
||||
self.source.get_subs_slice(lambda_names).iter().cloned(),
|
||||
)
|
||||
self.target
|
||||
.extend_symbol_names(self.source.get_subs_slice(lambda_names).iter().cloned())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -201,10 +196,11 @@ impl<'a> CopyEnv for AcrossSubs<'a> {
|
|||
&mut self,
|
||||
record_fields: SubsSlice<RecordField<()>>,
|
||||
) -> SubsSlice<RecordField<()>> {
|
||||
SubsSlice::extend_new(
|
||||
&mut self.target.record_fields,
|
||||
self.source.get_subs_slice(record_fields).iter().copied(),
|
||||
)
|
||||
let start = self.target.record_fields.len() as u32;
|
||||
self.target
|
||||
.record_fields
|
||||
.extend(self.source.get_subs_slice(record_fields).iter().copied());
|
||||
SubsSlice::new(start, self.target.record_fields.len() as u16)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -993,9 +989,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() as u32,
|
||||
variables_start: new_variables.start() as u32,
|
||||
field_types_start: new_record_fields.start() as u32,
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1014,8 +1010,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() as u32,
|
||||
elem_index_start: new_elem_indices.start() as u32,
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1106,7 +1102,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() as u32,
|
||||
..arguments
|
||||
};
|
||||
|
||||
|
@ -1193,7 +1189,7 @@ mod test {
|
|||
use roc_types::{
|
||||
subs::{
|
||||
self, Content, Content::*, Descriptor, FlatType, GetSubsSlice, Mark, OptVariable, Rank,
|
||||
Subs, SubsIndex, SubsSlice, Variable,
|
||||
Subs, SubsSlice, Variable,
|
||||
},
|
||||
types::Uls,
|
||||
};
|
||||
|
@ -1212,7 +1208,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 = subs.push_field_name("a".into());
|
||||
let var = new_var(&mut subs, FlexVar(Some(field_name)));
|
||||
|
||||
let mut copied = vec![];
|
||||
|
@ -1233,7 +1229,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 = subs.push_field_name("a".into());
|
||||
let var = new_var(&mut subs, RigidVar(field_name));
|
||||
|
||||
let mut copied = vec![];
|
||||
|
@ -1254,8 +1250,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 = subs.push_field_name("a".into());
|
||||
let abilities = subs.extend_symbol_names([Symbol::UNDERSCORE]);
|
||||
let var = new_var(&mut subs, FlexAbleVar(Some(field_name), abilities));
|
||||
|
||||
let mut copied = vec![];
|
||||
|
@ -1277,8 +1273,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 = subs.push_field_name("a".into());
|
||||
let abilities = subs.extend_symbol_names([Symbol::UNDERSCORE]);
|
||||
let var = new_var(&mut subs, RigidAbleVar(field_name, abilities));
|
||||
|
||||
let mut copied = vec![];
|
||||
|
@ -1299,8 +1295,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 = subs.push_field_name("a".into());
|
||||
let b = subs.push_field_name("b".into());
|
||||
let var1 = new_var(&mut subs, FlexVar(Some(a)));
|
||||
let var2 = new_var(&mut subs, FlexVar(Some(b)));
|
||||
|
||||
|
@ -1385,8 +1381,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 = source.push_field_name("a".into());
|
||||
let b = source.push_field_name("b".into());
|
||||
let var1 = new_var(&mut source, FlexVar(Some(a)));
|
||||
let var2 = new_var(&mut source, FlexVar(Some(b)));
|
||||
|
||||
|
@ -1467,10 +1463,13 @@ mod test {
|
|||
let mut target = Subs::new();
|
||||
|
||||
let a = new_var(&mut source, FlexVar(None));
|
||||
let uls = SubsSlice::extend_new(
|
||||
&mut source.unspecialized_lambda_sets,
|
||||
vec![Uls(a, Symbol::UNDERSCORE, 3)],
|
||||
);
|
||||
let uls = {
|
||||
let start = source.unspecialized_lambda_sets.len() as u32;
|
||||
source
|
||||
.unspecialized_lambda_sets
|
||||
.extend([Uls(a, Symbol::UNDERSCORE, 3)]);
|
||||
SubsSlice::new(start, source.unspecialized_lambda_sets.len() as u16)
|
||||
};
|
||||
let lambda_set_var = new_var(
|
||||
&mut source,
|
||||
LambdaSet(subs::LambdaSet {
|
||||
|
|
|
@ -318,7 +318,7 @@ fn to_encoder_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 {
|
||||
|
@ -527,7 +527,7 @@ fn to_encoder_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 {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#![allow(clippy::too_many_arguments)]
|
||||
|
||||
use crate::subs::{
|
||||
self, AliasVariables, Content, FlatType, GetSubsSlice, Label, Subs, SubsIndex, UnionLabels,
|
||||
self, AliasVariables, Content, FlatType, GetSubsSlice, Label, Subs, UnionLabels,
|
||||
UnsortedUnionLabels, Variable,
|
||||
};
|
||||
use crate::types::{
|
||||
|
@ -152,7 +152,7 @@ fn find_names_needed(
|
|||
|
||||
// User-defined names are already taken.
|
||||
// We must not accidentally generate names that collide with them!
|
||||
let name = subs.field_names[name_index.index as usize].clone();
|
||||
let name = subs.field_names[name_index.index()].clone();
|
||||
match names_taken.get(&name) {
|
||||
Some(var) if *var == root => {}
|
||||
Some(_) => {
|
||||
|
@ -535,12 +535,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 = subs.push_field_name(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 = subs.push_field_name(name);
|
||||
let content = FlexAbleVar(Some(name_index), ability);
|
||||
subs.set_content(root, content);
|
||||
}
|
||||
|
@ -549,7 +549,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 = subs.push_field_name(name);
|
||||
let content = RecursionVar {
|
||||
structure,
|
||||
opt_name: Some(name_index),
|
||||
|
@ -680,24 +680,24 @@ fn write_content<'a>(
|
|||
|
||||
match subs.get_content_without_compacting(var) {
|
||||
FlexVar(Some(name_index)) => {
|
||||
let name = &subs.field_names[name_index.index as usize];
|
||||
let name = &subs.field_names[name_index.index()];
|
||||
buf.push_str(name.as_str())
|
||||
}
|
||||
FlexVar(None) => buf.push_str(WILDCARD),
|
||||
RigidVar(name_index) => {
|
||||
let name = &subs.field_names[name_index.index as usize];
|
||||
let name = &subs.field_names[name_index.index()];
|
||||
buf.push_str(name.as_str())
|
||||
}
|
||||
FlexAbleVar(opt_name_index, abilities) => {
|
||||
let name = opt_name_index
|
||||
.map(|name_index| subs.field_names[name_index.index as usize].as_str())
|
||||
.map(|name_index| subs.field_names[name_index.index()].as_str())
|
||||
.unwrap_or(WILDCARD);
|
||||
let abilities = AbilitySet::from_iter(subs.get_subs_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 name = subs.field_names[name_index.index()].as_str();
|
||||
let abilities = AbilitySet::from_iter(subs.get_subs_slice(*abilities).iter().copied());
|
||||
ctx.able_variables.push((name, abilities));
|
||||
buf.push_str(name);
|
||||
|
@ -713,7 +713,7 @@ fn write_content<'a>(
|
|||
|
||||
ctx.recursion_structs_to_expand.insert(structure_root);
|
||||
} else {
|
||||
let name = &subs.field_names[name_index.index as usize];
|
||||
let name = &subs.field_names[name_index.index()];
|
||||
buf.push_str(name.as_str())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,8 +150,14 @@ impl Subs {
|
|||
let mut slices: Vec<SubsSlice<u8>> = Vec::new();
|
||||
|
||||
for field_name in lowercases {
|
||||
let slice =
|
||||
SubsSlice::extend_new(&mut buf, field_name.as_str().as_bytes().iter().copied());
|
||||
let bytes = field_name.as_str().as_bytes();
|
||||
let slice = {
|
||||
let start = buf.len() as u32;
|
||||
|
||||
buf.extend(bytes.iter().copied());
|
||||
|
||||
SubsSlice::new(start, bytes.len() as u16)
|
||||
};
|
||||
slices.push(slice);
|
||||
}
|
||||
|
||||
|
@ -170,8 +176,14 @@ impl Subs {
|
|||
let mut slices: Vec<SerializedTagName> = Vec::new();
|
||||
|
||||
for TagName(uppercase) in tag_names {
|
||||
let slice =
|
||||
SubsSlice::extend_new(&mut buf, uppercase.as_str().as_bytes().iter().copied());
|
||||
let bytes = uppercase.as_str().as_bytes();
|
||||
let slice = {
|
||||
let start = buf.len() as u32;
|
||||
|
||||
buf.extend(bytes.iter().copied());
|
||||
|
||||
SubsSlice::new(start, bytes.len() as u16)
|
||||
};
|
||||
let serialized = SerializedTagName(slice);
|
||||
slices.push(serialized);
|
||||
}
|
||||
|
@ -413,10 +425,10 @@ impl Default for Subs {
|
|||
}
|
||||
|
||||
/// A slice into the Vec<T> of subs
|
||||
pub type SubsSlice<T> = Slice<Subs, T>;
|
||||
pub type SubsSlice<T> = Slice<T>;
|
||||
|
||||
/// An index into the Vec<T> of subs
|
||||
pub type SubsIndex<T> = Index<Subs, T>;
|
||||
pub type SubsIndex<T> = Index<T>;
|
||||
|
||||
// make `subs[some_index]` work. The types/trait resolution make sure we get the
|
||||
// element from the right vector
|
||||
|
@ -425,13 +437,13 @@ impl std::ops::Index<SubsIndex<Variable>> for Subs {
|
|||
type Output = Variable;
|
||||
|
||||
fn index(&self, index: SubsIndex<Variable>) -> &Self::Output {
|
||||
&self.variables[index.index as usize]
|
||||
&self.variables[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::IndexMut<SubsIndex<Variable>> for Subs {
|
||||
fn index_mut(&mut self, index: SubsIndex<Variable>) -> &mut Self::Output {
|
||||
&mut self.variables[index.index as usize]
|
||||
&mut self.variables[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -439,7 +451,7 @@ impl std::ops::Index<SubsIndex<Lowercase>> for Subs {
|
|||
type Output = Lowercase;
|
||||
|
||||
fn index(&self, index: SubsIndex<Lowercase>) -> &Self::Output {
|
||||
&self.field_names[index.index as usize]
|
||||
&self.field_names[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -447,7 +459,7 @@ impl std::ops::Index<SubsIndex<usize>> for Subs {
|
|||
type Output = usize;
|
||||
|
||||
fn index(&self, index: SubsIndex<usize>) -> &Self::Output {
|
||||
&self.tuple_elem_indices[index.index as usize]
|
||||
&self.tuple_elem_indices[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -455,13 +467,13 @@ impl std::ops::Index<SubsIndex<TagName>> for Subs {
|
|||
type Output = TagName;
|
||||
|
||||
fn index(&self, index: SubsIndex<TagName>) -> &Self::Output {
|
||||
&self.tag_names[index.index as usize]
|
||||
&self.tag_names[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::IndexMut<SubsIndex<TagName>> for Subs {
|
||||
fn index_mut(&mut self, index: SubsIndex<TagName>) -> &mut Self::Output {
|
||||
&mut self.tag_names[index.index as usize]
|
||||
&mut self.tag_names[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -469,13 +481,13 @@ impl std::ops::Index<SubsIndex<Symbol>> for Subs {
|
|||
type Output = Symbol;
|
||||
|
||||
fn index(&self, index: SubsIndex<Symbol>) -> &Self::Output {
|
||||
&self.symbol_names[index.index as usize]
|
||||
&self.symbol_names[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::IndexMut<SubsIndex<Symbol>> for Subs {
|
||||
fn index_mut(&mut self, index: SubsIndex<Symbol>) -> &mut Self::Output {
|
||||
&mut self.symbol_names[index.index as usize]
|
||||
&mut self.symbol_names[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -483,19 +495,19 @@ impl std::ops::Index<SubsIndex<Uls>> for Subs {
|
|||
type Output = Uls;
|
||||
|
||||
fn index(&self, index: SubsIndex<Uls>) -> &Self::Output {
|
||||
&self.unspecialized_lambda_sets[index.index as usize]
|
||||
&self.unspecialized_lambda_sets[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::IndexMut<SubsIndex<Uls>> for Subs {
|
||||
fn index_mut(&mut self, index: SubsIndex<Uls>) -> &mut Self::Output {
|
||||
&mut self.unspecialized_lambda_sets[index.index as usize]
|
||||
&mut self.unspecialized_lambda_sets[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::IndexMut<SubsIndex<Lowercase>> for Subs {
|
||||
fn index_mut(&mut self, index: SubsIndex<Lowercase>) -> &mut Self::Output {
|
||||
&mut self.field_names[index.index as usize]
|
||||
&mut self.field_names[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -503,13 +515,13 @@ impl std::ops::Index<SubsIndex<RecordField<()>>> for Subs {
|
|||
type Output = RecordField<()>;
|
||||
|
||||
fn index(&self, index: SubsIndex<RecordField<()>>) -> &Self::Output {
|
||||
&self.record_fields[index.index as usize]
|
||||
&self.record_fields[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::IndexMut<SubsIndex<RecordField<()>>> for Subs {
|
||||
fn index_mut(&mut self, index: SubsIndex<RecordField<()>>) -> &mut Self::Output {
|
||||
&mut self.record_fields[index.index as usize]
|
||||
&mut self.record_fields[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -517,13 +529,13 @@ impl std::ops::Index<SubsIndex<VariableSubsSlice>> for Subs {
|
|||
type Output = VariableSubsSlice;
|
||||
|
||||
fn index(&self, index: SubsIndex<VariableSubsSlice>) -> &Self::Output {
|
||||
&self.variable_slices[index.index as usize]
|
||||
&self.variable_slices[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::IndexMut<SubsIndex<VariableSubsSlice>> for Subs {
|
||||
fn index_mut(&mut self, index: SubsIndex<VariableSubsSlice>) -> &mut Self::Output {
|
||||
&mut self.variable_slices[index.index as usize]
|
||||
&mut self.variable_slices[index.index()]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1634,6 +1646,63 @@ impl Subs {
|
|||
self.utable.reserve(entries);
|
||||
}
|
||||
|
||||
pub fn push_field_name(&mut self, name: Lowercase) -> Index<Lowercase> {
|
||||
let index = SubsIndex::new(self.field_names.len() as u32);
|
||||
self.field_names.push(name);
|
||||
index
|
||||
}
|
||||
|
||||
pub fn push_tag_name(&mut self, name: TagName) -> Index<TagName> {
|
||||
let index = SubsIndex::new(self.tag_names.len() as u32);
|
||||
self.tag_names.push(name);
|
||||
index
|
||||
}
|
||||
|
||||
pub fn push_symbol_name(&mut self, name: Symbol) -> Index<Symbol> {
|
||||
let index = SubsIndex::new(self.symbol_names.len() as u32);
|
||||
self.symbol_names.push(name);
|
||||
index
|
||||
}
|
||||
|
||||
pub fn extend_tag_names<I>(&mut self, values: I) -> Slice<TagName>
|
||||
where
|
||||
I: IntoIterator<Item = TagName>,
|
||||
{
|
||||
let start = self.tag_names.len() as u32;
|
||||
|
||||
self.tag_names.extend(values);
|
||||
|
||||
let end = self.tag_names.len() as u32;
|
||||
|
||||
Slice::new(start, (end - start) as u16)
|
||||
}
|
||||
|
||||
pub fn extend_field_names<I>(&mut self, values: I) -> Slice<Lowercase>
|
||||
where
|
||||
I: IntoIterator<Item = Lowercase>,
|
||||
{
|
||||
let start = self.field_names.len() as u32;
|
||||
|
||||
self.field_names.extend(values);
|
||||
|
||||
let end = self.field_names.len() as u32;
|
||||
|
||||
Slice::new(start, (end - start) as u16)
|
||||
}
|
||||
|
||||
pub fn extend_symbol_names<I>(&mut self, values: I) -> Slice<Symbol>
|
||||
where
|
||||
I: IntoIterator<Item = Symbol>,
|
||||
{
|
||||
let start = self.symbol_names.len() as u32;
|
||||
|
||||
self.symbol_names.extend(values);
|
||||
|
||||
let end = self.symbol_names.len() as u32;
|
||||
|
||||
Slice::new(start, (end - start) as u16)
|
||||
}
|
||||
|
||||
/// Reserve space for `length` variables in the subs.variables array
|
||||
///
|
||||
/// This is useful when we know how many variables e.g. a loop will produce,
|
||||
|
@ -1709,7 +1778,7 @@ impl Subs {
|
|||
}
|
||||
|
||||
pub fn rigid_var(&mut self, var: Variable, name: Lowercase) {
|
||||
let name_index = SubsIndex::push_new(&mut self.field_names, name);
|
||||
let name_index = self.push_field_name(name);
|
||||
let content = Content::RigidVar(name_index);
|
||||
let desc = Descriptor::from(content);
|
||||
|
||||
|
@ -1717,8 +1786,8 @@ impl Subs {
|
|||
}
|
||||
|
||||
pub fn rigid_able_var(&mut self, var: Variable, name: Lowercase, abilities: AbilitySet) {
|
||||
let name_index = SubsIndex::push_new(&mut self.field_names, name);
|
||||
let abilities = SubsSlice::extend_new(&mut self.symbol_names, abilities.into_sorted_iter());
|
||||
let name_index = self.push_field_name(name);
|
||||
let abilities = self.extend_symbol_names(abilities.into_sorted_iter());
|
||||
let content = Content::RigidAbleVar(name_index, abilities);
|
||||
let desc = Descriptor::from(content);
|
||||
|
||||
|
@ -2584,10 +2653,10 @@ impl Label for TagName {
|
|||
subs.get_subs_slice(slice)
|
||||
}
|
||||
fn push_new(subs: &mut Subs, name: Self) -> SubsIndex<Self> {
|
||||
SubsIndex::push_new(&mut subs.tag_names, name)
|
||||
subs.push_tag_name(name)
|
||||
}
|
||||
fn extend_new(subs: &mut Subs, slice: impl IntoIterator<Item = Self>) -> SubsSlice<Self> {
|
||||
SubsSlice::extend_new(&mut subs.tag_names, slice)
|
||||
subs.extend_tag_names(slice)
|
||||
}
|
||||
fn reserve(subs: &mut Subs, size_hint: usize) -> u32 {
|
||||
let tag_names_start = subs.tag_names.len() as u32;
|
||||
|
@ -2603,10 +2672,10 @@ impl Label for Symbol {
|
|||
subs.get_subs_slice(slice)
|
||||
}
|
||||
fn push_new(subs: &mut Subs, name: Self) -> SubsIndex<Self> {
|
||||
SubsIndex::push_new(&mut subs.symbol_names, name)
|
||||
subs.push_symbol_name(name)
|
||||
}
|
||||
fn extend_new(subs: &mut Subs, slice: impl IntoIterator<Item = Self>) -> SubsSlice<Self> {
|
||||
SubsSlice::extend_new(&mut subs.symbol_names, slice)
|
||||
subs.extend_symbol_names(slice)
|
||||
}
|
||||
fn reserve(subs: &mut Subs, size_hint: usize) -> u32 {
|
||||
let symbol_names_start = subs.symbol_names.len() as u32;
|
||||
|
@ -2646,13 +2715,13 @@ where
|
|||
}
|
||||
|
||||
let slice = subs.variable_slices[self.values_start as usize];
|
||||
slice.length == 1
|
||||
slice.len() == 1
|
||||
}
|
||||
|
||||
pub fn from_tag_name_index(index: SubsIndex<L>) -> Self {
|
||||
Self::from_slices(
|
||||
SubsSlice::new(index.index, 1),
|
||||
SubsSlice::new(0, 1), // the first variablesubsslice is the empty slice
|
||||
index.as_slice(),
|
||||
SubsSlice::new(0, 1), // the first VariableSubsSlice is the empty slice
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -2665,8 +2734,8 @@ where
|
|||
|
||||
Self {
|
||||
length: labels.len() as u16,
|
||||
labels_start: labels.start,
|
||||
values_start: variables.start,
|
||||
labels_start: labels.start() as u32,
|
||||
values_start: variables.start() as u32,
|
||||
_marker: Default::default(),
|
||||
}
|
||||
}
|
||||
|
@ -2721,7 +2790,7 @@ where
|
|||
|
||||
Self {
|
||||
length: 1,
|
||||
labels_start: idx.index,
|
||||
labels_start: idx.index() as u32,
|
||||
values_start: 0,
|
||||
_marker: Default::default(),
|
||||
}
|
||||
|
@ -3854,7 +3923,7 @@ fn add_name<F>(
|
|||
where
|
||||
F: FnOnce(SubsIndex<Lowercase>) -> Content,
|
||||
{
|
||||
let given_name = subs.field_names[given_name_index.index as usize].clone();
|
||||
let given_name = subs.field_names[given_name_index.index()].clone();
|
||||
|
||||
let indexed_name = if index == 0 {
|
||||
given_name.clone()
|
||||
|
@ -3867,8 +3936,7 @@ where
|
|||
match taken_names.get(&indexed_name) {
|
||||
None => {
|
||||
if indexed_name != given_name {
|
||||
let indexed_name_index =
|
||||
SubsIndex::push_new(&mut subs.field_names, indexed_name.clone());
|
||||
let indexed_name_index = subs.push_field_name(indexed_name.clone());
|
||||
subs.set_content(var, content_from_name(indexed_name_index));
|
||||
}
|
||||
|
||||
|
@ -3930,11 +3998,11 @@ fn content_to_err_type(
|
|||
|
||||
FlexVar(opt_name) => {
|
||||
let name = match opt_name {
|
||||
Some(name_index) => subs.field_names[name_index.index as usize].clone(),
|
||||
Some(name_index) => subs.field_names[name_index.index()].clone(),
|
||||
None => {
|
||||
// set the name so when this variable occurs elsewhere in the type it gets the same name
|
||||
let name = get_fresh_error_var_name(state);
|
||||
let name_index = SubsIndex::push_new(&mut subs.field_names, name.clone());
|
||||
let name_index = subs.push_field_name(name.clone());
|
||||
|
||||
subs.set_content(var, FlexVar(Some(name_index)));
|
||||
|
||||
|
@ -3946,17 +4014,17 @@ fn content_to_err_type(
|
|||
}
|
||||
|
||||
RigidVar(name_index) => {
|
||||
let name = subs.field_names[name_index.index as usize].clone();
|
||||
let name = subs.field_names[name_index.index()].clone();
|
||||
ErrorType::RigidVar(name)
|
||||
}
|
||||
|
||||
FlexAbleVar(opt_name, abilities) => {
|
||||
let name = match opt_name {
|
||||
Some(name_index) => subs.field_names[name_index.index as usize].clone(),
|
||||
Some(name_index) => subs.field_names[name_index.index()].clone(),
|
||||
None => {
|
||||
// set the name so when this variable occurs elsewhere in the type it gets the same name
|
||||
let name = get_fresh_error_var_name(state);
|
||||
let name_index = SubsIndex::push_new(&mut subs.field_names, name.clone());
|
||||
let name_index = subs.push_field_name(name.clone());
|
||||
|
||||
subs.set_content(var, FlexVar(Some(name_index)));
|
||||
|
||||
|
@ -3969,7 +4037,7 @@ fn content_to_err_type(
|
|||
}
|
||||
|
||||
RigidAbleVar(name_index, abilities) => {
|
||||
let name = subs.field_names[name_index.index as usize].clone();
|
||||
let name = subs.field_names[name_index.index()].clone();
|
||||
let ability_set = AbilitySet::from_iter(subs.get_subs_slice(abilities).iter().copied());
|
||||
ErrorType::RigidAbleVar(name, ability_set)
|
||||
}
|
||||
|
@ -3979,10 +4047,10 @@ fn content_to_err_type(
|
|||
structure,
|
||||
} => {
|
||||
let name = match opt_name {
|
||||
Some(name_index) => subs.field_names[name_index.index as usize].clone(),
|
||||
Some(name_index) => subs.field_names[name_index.index()].clone(),
|
||||
None => {
|
||||
let name = get_fresh_error_var_name(state);
|
||||
let name_index = SubsIndex::push_new(&mut subs.field_names, name.clone());
|
||||
let name_index = subs.push_field_name(name.clone());
|
||||
|
||||
subs.set_content(var, FlexVar(Some(name_index)));
|
||||
|
||||
|
@ -4654,7 +4722,7 @@ impl StorageSubs {
|
|||
offsets: &StorageSubsOffsets,
|
||||
mut ability_names: SubsSlice<Symbol>,
|
||||
) -> SubsSlice<Symbol> {
|
||||
ability_names.start += offsets.symbol_names;
|
||||
ability_names.advance(offsets.symbol_names);
|
||||
|
||||
ability_names
|
||||
}
|
||||
|
@ -4691,7 +4759,7 @@ impl StorageSubs {
|
|||
offsets: &StorageSubsOffsets,
|
||||
mut tag_names: SubsSlice<TagName>,
|
||||
) -> SubsSlice<TagName> {
|
||||
tag_names.start += offsets.tag_names;
|
||||
tag_names.advance(offsets.tag_names);
|
||||
|
||||
tag_names
|
||||
}
|
||||
|
@ -4709,13 +4777,13 @@ impl StorageSubs {
|
|||
offsets: &StorageSubsOffsets,
|
||||
mut slice: VariableSubsSlice,
|
||||
) -> VariableSubsSlice {
|
||||
slice.start += offsets.variables;
|
||||
slice.advance(offsets.variables);
|
||||
|
||||
slice
|
||||
}
|
||||
|
||||
fn offset_uls_slice(offsets: &StorageSubsOffsets, mut slice: SubsSlice<Uls>) -> SubsSlice<Uls> {
|
||||
slice.start += offsets.unspecialized_lambda_sets;
|
||||
slice.advance(offsets.unspecialized_lambda_sets);
|
||||
|
||||
slice
|
||||
}
|
||||
|
@ -4907,9 +4975,9 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) ->
|
|||
.extend(record_fields.iter().copied());
|
||||
|
||||
RecordFields {
|
||||
length: fields.len() as _,
|
||||
length: fields.len() as u16,
|
||||
field_names_start,
|
||||
variables_start: new_variables.start,
|
||||
variables_start: new_variables.start() as u32,
|
||||
field_types_start,
|
||||
}
|
||||
};
|
||||
|
@ -4934,8 +5002,8 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) ->
|
|||
env.target.tuple_elem_indices.extend(0..elems.len());
|
||||
|
||||
TupleElems {
|
||||
length: elems.len() as _,
|
||||
variables_start: new_variables.start,
|
||||
length: elems.len() as u16,
|
||||
variables_start: new_variables.start() as u32,
|
||||
elem_index_start,
|
||||
}
|
||||
};
|
||||
|
@ -4951,15 +5019,13 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) ->
|
|||
}
|
||||
|
||||
FunctionOrTagUnion(tag_names, symbols, ext) => {
|
||||
let new_tag_names = SubsSlice::extend_new(
|
||||
&mut env.target.tag_names,
|
||||
env.source.get_subs_slice(tag_names).iter().cloned(),
|
||||
);
|
||||
let new_tag_names = env
|
||||
.target
|
||||
.extend_tag_names(env.source.get_subs_slice(tag_names).iter().cloned());
|
||||
|
||||
let new_symbols = SubsSlice::extend_new(
|
||||
&mut env.target.symbol_names,
|
||||
env.source.get_subs_slice(symbols).iter().cloned(),
|
||||
);
|
||||
let new_symbols = env
|
||||
.target
|
||||
.extend_symbol_names(env.source.get_subs_slice(symbols).iter().cloned());
|
||||
|
||||
FunctionOrTagUnion(
|
||||
new_tag_names,
|
||||
|
@ -4985,8 +5051,8 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) ->
|
|||
}
|
||||
|
||||
FlexVar(Some(name_index)) => {
|
||||
let name = env.source.field_names[name_index.index as usize].clone();
|
||||
let new_name_index = SubsIndex::push_new(&mut env.target.field_names, name);
|
||||
let name = env.source.field_names[name_index.index()].clone();
|
||||
let new_name_index = env.target.push_field_name(name);
|
||||
|
||||
let content = FlexVar(Some(new_name_index));
|
||||
env.target.set_content(copy, content);
|
||||
|
@ -5016,8 +5082,8 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) ->
|
|||
}
|
||||
|
||||
RigidVar(name_index) => {
|
||||
let name = env.source.field_names[name_index.index as usize].clone();
|
||||
let new_name_index = SubsIndex::push_new(&mut env.target.field_names, name);
|
||||
let name = env.source.field_names[name_index.index()].clone();
|
||||
let new_name_index = env.target.push_field_name(name);
|
||||
env.target
|
||||
.set(copy, make_descriptor(FlexVar(Some(new_name_index))));
|
||||
|
||||
|
@ -5026,13 +5092,12 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) ->
|
|||
|
||||
FlexAbleVar(opt_name_index, abilities) => {
|
||||
let new_name_index = opt_name_index.map(|name_index| {
|
||||
let name = env.source.field_names[name_index.index as usize].clone();
|
||||
SubsIndex::push_new(&mut env.target.field_names, name)
|
||||
let name = env.source.field_names[name_index.index()].clone();
|
||||
env.target.push_field_name(name)
|
||||
});
|
||||
let new_abilities_slice = SubsSlice::extend_new(
|
||||
&mut env.target.symbol_names,
|
||||
env.source.get_subs_slice(abilities).iter().copied(),
|
||||
);
|
||||
let new_abilities_slice = env
|
||||
.target
|
||||
.extend_symbol_names(env.source.get_subs_slice(abilities).iter().copied());
|
||||
|
||||
let content = FlexAbleVar(new_name_index, new_abilities_slice);
|
||||
env.target.set_content(copy, content);
|
||||
|
@ -5041,12 +5106,11 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) ->
|
|||
}
|
||||
|
||||
RigidAbleVar(name_index, abilities) => {
|
||||
let name = env.source.field_names[name_index.index as usize].clone();
|
||||
let new_name_index = SubsIndex::push_new(&mut env.target.field_names, name);
|
||||
let new_abilities_slice = SubsSlice::extend_new(
|
||||
&mut env.target.symbol_names,
|
||||
env.source.get_subs_slice(abilities).iter().copied(),
|
||||
);
|
||||
let name = env.source.field_names[name_index.index()].clone();
|
||||
let new_name_index = env.target.push_field_name(name);
|
||||
let new_abilities_slice = env
|
||||
.target
|
||||
.extend_symbol_names(env.source.get_subs_slice(abilities).iter().copied());
|
||||
|
||||
env.target.set(
|
||||
copy,
|
||||
|
@ -5069,7 +5133,7 @@ fn storage_copy_var_to_help(env: &mut StorageCopyVarToEnv<'_>, var: Variable) ->
|
|||
}
|
||||
|
||||
let new_arguments = AliasVariables {
|
||||
variables_start: new_variables.start,
|
||||
variables_start: new_variables.start() as u32,
|
||||
..arguments
|
||||
};
|
||||
|
||||
|
@ -5377,9 +5441,9 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl
|
|||
.extend(record_fields.iter().copied());
|
||||
|
||||
RecordFields {
|
||||
length: fields.len() as _,
|
||||
length: fields.len() as u16,
|
||||
field_names_start,
|
||||
variables_start: new_variables.start,
|
||||
variables_start: new_variables.start() as u32,
|
||||
field_types_start,
|
||||
}
|
||||
};
|
||||
|
@ -5404,8 +5468,8 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl
|
|||
env.target.tuple_elem_indices.extend(0..elems.len());
|
||||
|
||||
TupleElems {
|
||||
length: elems.len() as _,
|
||||
variables_start: new_variables.start,
|
||||
length: elems.len() as u16,
|
||||
variables_start: new_variables.start() as u32,
|
||||
elem_index_start,
|
||||
}
|
||||
};
|
||||
|
@ -5422,15 +5486,13 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl
|
|||
}
|
||||
|
||||
FunctionOrTagUnion(tag_names, symbols, ext) => {
|
||||
let new_tag_names = SubsSlice::extend_new(
|
||||
&mut env.target.tag_names,
|
||||
env.source.get_subs_slice(tag_names).iter().cloned(),
|
||||
);
|
||||
let new_tag_names = env
|
||||
.target
|
||||
.extend_tag_names(env.source.get_subs_slice(tag_names).iter().cloned());
|
||||
|
||||
let new_symbols = SubsSlice::extend_new(
|
||||
&mut env.target.symbol_names,
|
||||
env.source.get_subs_slice(symbols).iter().cloned(),
|
||||
);
|
||||
let new_symbols = env
|
||||
.target
|
||||
.extend_symbol_names(env.source.get_subs_slice(symbols).iter().cloned());
|
||||
|
||||
let new_ext = ext.map(|v| copy_import_to_help(env, max_rank, v));
|
||||
|
||||
|
@ -5455,8 +5517,8 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl
|
|||
|
||||
FlexVar(opt_name_index) => {
|
||||
if let Some(name_index) = opt_name_index {
|
||||
let name = env.source.field_names[name_index.index as usize].clone();
|
||||
let new_name_index = SubsIndex::push_new(&mut env.target.field_names, name);
|
||||
let name = env.source.field_names[name_index.index()].clone();
|
||||
let new_name_index = env.target.push_field_name(name);
|
||||
|
||||
let content = FlexVar(Some(new_name_index));
|
||||
env.target.set_content(copy, content);
|
||||
|
@ -5469,17 +5531,16 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl
|
|||
|
||||
FlexAbleVar(opt_name_index, abilities) => {
|
||||
let new_opt_name_index = if let Some(name_index) = opt_name_index {
|
||||
let name = env.source.field_names[name_index.index as usize].clone();
|
||||
let new_name_index = SubsIndex::push_new(&mut env.target.field_names, name);
|
||||
let name = env.source.field_names[name_index.index()].clone();
|
||||
let new_name_index = env.target.push_field_name(name);
|
||||
Some(new_name_index)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let new_abilities = SubsSlice::extend_new(
|
||||
&mut env.target.symbol_names,
|
||||
env.source.get_subs_slice(abilities).iter().copied(),
|
||||
);
|
||||
let new_abilities = env
|
||||
.target
|
||||
.extend_symbol_names(env.source.get_subs_slice(abilities).iter().copied());
|
||||
|
||||
let content = FlexAbleVar(new_opt_name_index, new_abilities);
|
||||
env.target.set_content(copy, content);
|
||||
|
@ -5498,8 +5559,8 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl
|
|||
}
|
||||
|
||||
RigidVar(name_index) => {
|
||||
let name = env.source.field_names[name_index.index as usize].clone();
|
||||
let new_name_index = SubsIndex::push_new(&mut env.target.field_names, name);
|
||||
let name = env.source.field_names[name_index.index()].clone();
|
||||
let new_name_index = env.target.push_field_name(name);
|
||||
|
||||
// If we are copying the import as generalized, we can keep it as rigid.
|
||||
// Otherwise we must make it flex, as this is copying to a non-generalized site.
|
||||
|
@ -5520,13 +5581,11 @@ fn copy_import_to_help(env: &mut CopyImportEnv<'_>, max_rank: Rank, var: Variabl
|
|||
}
|
||||
|
||||
RigidAbleVar(name_index, abilities) => {
|
||||
let name = env.source.field_names[name_index.index as usize].clone();
|
||||
let new_name_index = SubsIndex::push_new(&mut env.target.field_names, name);
|
||||
|
||||
let new_abilities = SubsSlice::extend_new(
|
||||
&mut env.target.symbol_names,
|
||||
env.source.get_subs_slice(abilities).iter().copied(),
|
||||
);
|
||||
let name = env.source.field_names[name_index.index()].clone();
|
||||
let new_name_index = env.target.push_field_name(name);
|
||||
let new_abilities = env
|
||||
.target
|
||||
.extend_symbol_names(env.source.get_subs_slice(abilities).iter().copied());
|
||||
|
||||
// If we are copying the import as generalized, we can keep it as rigid.
|
||||
// Otherwise we must make it flex, as this is copying to a non-generalized site.
|
||||
|
@ -5578,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,
|
||||
variables_start: new_variables.start() as u32,
|
||||
..arguments
|
||||
};
|
||||
|
||||
|
@ -5751,7 +5810,7 @@ fn instantiate_rigids_help(subs: &mut Subs, max_rank: Rank, initial: Variable) {
|
|||
let ext = *ext;
|
||||
|
||||
for slice_index in tags.variables() {
|
||||
let slice = subs.variable_slices[slice_index.index as usize];
|
||||
let slice = subs.variable_slices[slice_index.index()];
|
||||
stack.extend(var_slice!(slice));
|
||||
}
|
||||
|
||||
|
@ -5767,7 +5826,7 @@ fn instantiate_rigids_help(subs: &mut Subs, max_rank: Rank, initial: Variable) {
|
|||
let rec_var = *rec_var;
|
||||
|
||||
for slice_index in tags.variables() {
|
||||
let slice = subs.variable_slices[slice_index.index as usize];
|
||||
let slice = subs.variable_slices[slice_index.index()];
|
||||
stack.extend(var_slice!(slice));
|
||||
}
|
||||
|
||||
|
@ -5790,7 +5849,7 @@ fn instantiate_rigids_help(subs: &mut Subs, max_rank: Rank, initial: Variable) {
|
|||
ambient_function: _,
|
||||
}) => {
|
||||
for slice_index in solved.variables() {
|
||||
let slice = subs.variable_slices[slice_index.index as usize];
|
||||
let slice = subs.variable_slices[slice_index.index()];
|
||||
stack.extend(var_slice!(slice));
|
||||
}
|
||||
|
||||
|
|
|
@ -1787,7 +1787,11 @@ fn unify_unspecialized_lambdas<M: MetaCollector>(
|
|||
);
|
||||
|
||||
Ok((
|
||||
SubsSlice::extend_new(&mut env.unspecialized_lambda_sets, merged_uls),
|
||||
{
|
||||
let start = env.unspecialized_lambda_sets.len() as u32;
|
||||
env.unspecialized_lambda_sets.extend(merged_uls);
|
||||
SubsSlice::new(start, env.unspecialized_lambda_sets.len() as u16)
|
||||
},
|
||||
whole_outcome,
|
||||
))
|
||||
}
|
||||
|
@ -3325,19 +3329,23 @@ fn unify_flat_type<M: MetaCollector>(
|
|||
*ext2,
|
||||
),
|
||||
(TagUnion(tags1, ext1), FunctionOrTagUnion(tag_names, _, ext2)) => {
|
||||
let empty_tag_var_slices = SubsSlice::extend_new(
|
||||
&mut env.variable_slices,
|
||||
std::iter::repeat(Default::default()).take(tag_names.len()),
|
||||
);
|
||||
let empty_tag_var_slices = {
|
||||
let start = env.variable_slices.len() as u32;
|
||||
env.variable_slices
|
||||
.extend(std::iter::repeat(SubsSlice::empty()).take(tag_names.len()));
|
||||
SubsSlice::new(start, env.variable_slices.len() as u16)
|
||||
};
|
||||
let tags2 = UnionTags::from_slices(*tag_names, empty_tag_var_slices);
|
||||
|
||||
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(
|
||||
&mut env.variable_slices,
|
||||
std::iter::repeat(Default::default()).take(tag_names.len()),
|
||||
);
|
||||
let empty_tag_var_slices = {
|
||||
let start = env.variable_slices.len() as u32;
|
||||
env.variable_slices
|
||||
.extend(std::iter::repeat(SubsSlice::empty()).take(tag_names.len()));
|
||||
SubsSlice::new(start, env.variable_slices.len() as u16)
|
||||
};
|
||||
let tags1 = UnionTags::from_slices(*tag_names, empty_tag_var_slices);
|
||||
|
||||
unify_tag_unions(env, pool, ctx, tags1, *ext1, *tags2, *ext2)
|
||||
|
@ -3347,10 +3355,12 @@ 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(
|
||||
&mut env.variable_slices,
|
||||
std::iter::repeat(Default::default()).take(tag_names.len()),
|
||||
);
|
||||
let empty_tag_var_slices = {
|
||||
let start = env.variable_slices.len() as u32;
|
||||
env.variable_slices
|
||||
.extend(std::iter::repeat(SubsSlice::empty()).take(tag_names.len()));
|
||||
SubsSlice::new(start, env.variable_slices.len() as u16)
|
||||
};
|
||||
let tags2 = UnionTags::from_slices(*tag_names, empty_tag_var_slices);
|
||||
|
||||
unify_tag_unions(env, pool, ctx, *tags1, *ext1, tags2, *ext2)
|
||||
|
@ -3359,10 +3369,12 @@ 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(
|
||||
&mut env.variable_slices,
|
||||
std::iter::repeat(Default::default()).take(tag_names.len()),
|
||||
);
|
||||
let empty_tag_var_slices = {
|
||||
let start = env.variable_slices.len() as u32;
|
||||
env.variable_slices
|
||||
.extend(std::iter::repeat(SubsSlice::empty()).take(tag_names.len()));
|
||||
SubsSlice::new(start, env.variable_slices.len() as u16)
|
||||
};
|
||||
let tags1 = UnionTags::from_slices(*tag_names, empty_tag_var_slices);
|
||||
|
||||
unify_tag_unions(env, pool, ctx, tags1, *ext1, *tags2, *ext2)
|
||||
|
@ -3587,7 +3599,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)
|
||||
subs.extend_symbol_names(merged)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -3888,11 +3900,13 @@ 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(
|
||||
&mut env.variable_slices,
|
||||
std::iter::repeat(Default::default()).take(new_lambda_names.len()),
|
||||
);
|
||||
let new_lambda_names = env.extend_symbol_names(lambda_names);
|
||||
let empty_captures_slices = {
|
||||
let start = env.variable_slices.len() as u32;
|
||||
env.variable_slices
|
||||
.extend(std::iter::repeat(SubsSlice::empty()).take(new_lambda_names.len()));
|
||||
SubsSlice::new(start, env.variable_slices.len() as u16)
|
||||
};
|
||||
let union_tags = UnionLambdas::from_slices(new_lambda_names, empty_captures_slices);
|
||||
|
||||
let ambient_function_var = if left { ctx.first } else { ctx.second };
|
||||
|
@ -3955,7 +3969,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)
|
||||
env.extend_tag_names(all_tags)
|
||||
};
|
||||
let merged_lambdas = {
|
||||
let mut all_lambdas: Vec<_> = (env.get_subs_slice(tag_symbols_1).iter())
|
||||
|
@ -3964,7 +3978,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)
|
||||
env.extend_symbol_names(all_lambdas)
|
||||
};
|
||||
|
||||
let mut outcome = unify_pool(env, pool, ext1.var(), ext2.var(), ctx.mode);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue