Fix a test, delete some dead code

This commit is contained in:
Richard Feldman 2024-11-16 18:53:53 -05:00
parent 219a0398a2
commit 05e5fb4189
No known key found for this signature in database
GPG key ID: DAC334802F365236
6 changed files with 128 additions and 213 deletions

View file

@ -2,10 +2,9 @@ use crate::{
foreign_symbol::ForeignSymbolId, mono_module::InternedStrId, mono_num::Number, foreign_symbol::ForeignSymbolId, mono_module::InternedStrId, mono_num::Number,
mono_struct::MonoFieldId, mono_type::MonoTypeId, specialize_type::Problem, mono_struct::MonoFieldId, mono_type::MonoTypeId, specialize_type::Problem,
}; };
use bumpalo::Bump; use roc_can::expr::Recursive;
use roc_can::expr::{Field, Recursive}; use roc_module::low_level::LowLevel;
use roc_module::symbol::Symbol; use roc_module::symbol::Symbol;
use roc_module::{ident::Lowercase, low_level::LowLevel};
use roc_region::all::Region; use roc_region::all::Region;
use soa::{Id, Index, NonEmptySlice, Slice, Slice2, Slice3}; use soa::{Id, Index, NonEmptySlice, Slice, Slice2, Slice3};
use std::iter; use std::iter;

View file

@ -1,5 +1,3 @@
use roc_can::expr::IntValue;
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
pub enum Number { pub enum Number {
I8(i8), I8(i8),
@ -16,75 +14,3 @@ pub enum Number {
F64(f64), F64(f64),
Dec(f64), Dec(f64),
} }
impl Number {
fn u8(val: IntValue) -> Self {
match val {
IntValue::I128(i128) => Self::U8(i128::from_ne_bytes(i128) as u8),
IntValue::U128(u128) => Self::U8(u128::from_ne_bytes(u128) as u8),
}
}
fn i8(val: IntValue) -> Self {
match val {
IntValue::I128(i128) => Self::I8(i128::from_ne_bytes(i128) as i8),
IntValue::U128(u128) => Self::I8(u128::from_ne_bytes(u128) as i8),
}
}
fn u16(val: IntValue) -> Self {
match val {
IntValue::I128(i128) => Self::U16(i128::from_ne_bytes(i128) as u16),
IntValue::U128(u128) => Self::U16(u128::from_ne_bytes(u128) as u16),
}
}
fn i16(val: IntValue) -> Self {
match val {
IntValue::I128(i128) => Self::I16(i128::from_ne_bytes(i128) as i16),
IntValue::U128(u128) => Self::I16(u128::from_ne_bytes(u128) as i16),
}
}
fn u32(val: IntValue) -> Self {
match val {
IntValue::I128(i128) => Self::U32(i128::from_ne_bytes(i128) as u32),
IntValue::U128(u128) => Self::U32(u128::from_ne_bytes(u128) as u32),
}
}
fn i32(val: IntValue) -> Self {
match val {
IntValue::I128(i128) => Self::I32(i128::from_ne_bytes(i128) as i32),
IntValue::U128(u128) => Self::I32(u128::from_ne_bytes(u128) as i32),
}
}
fn u64(val: IntValue) -> Self {
match val {
IntValue::I128(i128) => Self::U64(i128::from_ne_bytes(i128) as u64),
IntValue::U128(u128) => Self::U64(u128::from_ne_bytes(u128) as u64),
}
}
fn i64(val: IntValue) -> Self {
match val {
IntValue::I128(i128) => Self::I64(i128::from_ne_bytes(i128) as i64),
IntValue::U128(u128) => Self::I64(u128::from_ne_bytes(u128) as i64),
}
}
fn u128(val: IntValue) -> Self {
match val {
IntValue::I128(i128) => Self::U128(i128::from_ne_bytes(i128) as u128),
IntValue::U128(u128) => Self::U128(u128::from_ne_bytes(u128)),
}
}
fn i128(val: IntValue) -> Self {
match val {
IntValue::I128(i128) => Self::I128(i128::from_ne_bytes(i128)),
IntValue::U128(u128) => Self::I128(u128::from_ne_bytes(u128) as i128),
}
}
}

View file

@ -9,15 +9,9 @@ use crate::{
MonoFieldId, MonoType, MonoFieldId, MonoType,
}; };
use roc_collections::{Push, VecMap}; use roc_collections::{Push, VecMap};
use roc_module::{ use roc_module::{ident::Lowercase, symbol::Symbol};
ident::{Lowercase, TagName},
symbol::Symbol,
};
use roc_solve::module::Solved; use roc_solve::module::Solved;
use roc_types::subs::{ use roc_types::subs::{Content, FlatType, Subs, SubsSlice, Variable};
Content, FlatType, RecordFields, Subs, SubsSlice, TagExt, TupleElems, UnionLabels, UnionTags,
Variable,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Problem { pub enum Problem {
@ -409,139 +403,139 @@ fn num_args_to_mono_id(
MonoTypeId::CRASH MonoTypeId::CRASH
} }
fn resolve_tag_ext( // fn resolve_tag_ext(
subs: &mut Subs, // subs: &mut Subs,
mono_types: &mut MonoTypes, // mono_types: &mut MonoTypes,
problems: &mut impl Push<Problem>, // problems: &mut impl Push<Problem>,
mut tags: UnionTags, // mut tags: UnionTags,
mut ext: TagExt, // mut ext: TagExt,
) -> Vec<(TagName, Vec<Variable>)> { // ) -> Vec<(TagName, Vec<Variable>)> {
let mut all_tags = Vec::new(); // let mut all_tags = Vec::new();
// Collapse (recursively) all the tags in ext_var into a flat list of tags. // // Collapse (recursively) all the tags in ext_var into a flat list of tags.
loop { // loop {
for (tag, vars) in tags.iter_from_subs(subs) { // for (tag, vars) in tags.iter_from_subs(subs) {
all_tags.push((tag.clone(), vars.to_vec())); // all_tags.push((tag.clone(), vars.to_vec()));
} // }
match subs.get_content_without_compacting(ext.var()) { // match subs.get_content_without_compacting(ext.var()) {
Content::Structure(FlatType::TagUnion(new_tags, new_ext)) => { // Content::Structure(FlatType::TagUnion(new_tags, new_ext)) => {
// Update tags and ext and loop back again to process them. // // Update tags and ext and loop back again to process them.
tags = *new_tags; // tags = *new_tags;
ext = *new_ext; // ext = *new_ext;
} // }
Content::Structure(FlatType::FunctionOrTagUnion(tag_names, _symbols, new_ext)) => { // Content::Structure(FlatType::FunctionOrTagUnion(tag_names, _symbols, new_ext)) => {
for index in tag_names.into_iter() { // for index in tag_names.into_iter() {
all_tags.push((subs[index].clone(), Vec::new())); // all_tags.push((subs[index].clone(), Vec::new()));
} // }
ext = *new_ext; // ext = *new_ext;
} // }
Content::Structure(FlatType::EmptyTagUnion) => break, // Content::Structure(FlatType::EmptyTagUnion) => break,
Content::FlexVar(_) | Content::FlexAbleVar(_, _) => break, // Content::FlexVar(_) | Content::FlexAbleVar(_, _) => break,
Content::Alias(_, _, real, _) => { // Content::Alias(_, _, real, _) => {
// Follow the alias and process it on the next iteration of the loop. // // Follow the alias and process it on the next iteration of the loop.
ext = TagExt::Any(*real); // ext = TagExt::Any(*real);
// We just processed these tags, so don't process them again! // // We just processed these tags, so don't process them again!
tags = UnionLabels::default(); // tags = UnionLabels::default();
} // }
_ => { // _ => {
// This should never happen! If it does, record a Problem and break. // // This should never happen! If it does, record a Problem and break.
problems.push(Problem::TagUnionExtWasNotTagUnion); // problems.push(Problem::TagUnionExtWasNotTagUnion);
break; // break;
} // }
} // }
} // }
all_tags // all_tags
} // }
fn lower_record<P: Push<Problem>>( // fn lower_record<P: Push<Problem>>(
env: &mut Env<'_, '_, '_, '_, '_, '_, P>, // env: &mut Env<'_, '_, '_, '_, '_, '_, P>,
subs: &Subs, // subs: &Subs,
mut fields: RecordFields, // mut fields: RecordFields,
mut ext: Variable, // mut ext: Variable,
) -> Vec<(Lowercase, Option<MonoTypeId>)> { // ) -> Vec<(Lowercase, Option<MonoTypeId>)> {
let mut labeled_mono_ids = Vec::with_capacity(fields.len()); // let mut labeled_mono_ids = Vec::with_capacity(fields.len());
// Collapse (recursively) all the fields in ext into a flat list of fields. // // Collapse (recursively) all the fields in ext into a flat list of fields.
loop { // loop {
// Add all the current fields to the answer. // // Add all the current fields to the answer.
labeled_mono_ids.extend( // labeled_mono_ids.extend(
fields // fields
.sorted_iterator(subs, ext) // .sorted_iterator(subs, ext)
.map(|(label, field)| (label, lower_var(env, subs, *field.as_inner()))), // .map(|(label, field)| (label, lower_var(env, subs, *field.as_inner()))),
); // );
// If the ext record is nonempty, set its fields to be the next ones we handle, and loop back. // // If the ext record is nonempty, set its fields to be the next ones we handle, and loop back.
match subs.get_content_without_compacting(ext) { // match subs.get_content_without_compacting(ext) {
Content::Structure(FlatType::Record(new_fields, new_ext)) => { // Content::Structure(FlatType::Record(new_fields, new_ext)) => {
// Update fields and ext and loop back again to process them. // // Update fields and ext and loop back again to process them.
fields = *new_fields; // fields = *new_fields;
ext = *new_ext; // ext = *new_ext;
} // }
Content::Structure(FlatType::EmptyRecord) // Content::Structure(FlatType::EmptyRecord)
| Content::FlexVar(_) // | Content::FlexVar(_)
| Content::FlexAbleVar(_, _) => return labeled_mono_ids, // | Content::FlexAbleVar(_, _) => return labeled_mono_ids,
Content::Alias(_, _, real, _) => { // Content::Alias(_, _, real, _) => {
// Follow the alias and process it on the next iteration of the loop. // // Follow the alias and process it on the next iteration of the loop.
ext = *real; // ext = *real;
// We just processed these fields, so don't process them again! // // We just processed these fields, so don't process them again!
fields = RecordFields::empty(); // fields = RecordFields::empty();
} // }
_ => { // _ => {
// This should never happen! If it does, record a Problem and early return. // // This should never happen! If it does, record a Problem and early return.
env.problems.push(Problem::RecordExtWasNotRecord); // env.problems.push(Problem::RecordExtWasNotRecord);
return labeled_mono_ids; // return labeled_mono_ids;
} // }
} // }
} // }
} // }
fn resolve_tuple_ext( // fn resolve_tuple_ext(
subs: &mut Subs, // subs: &mut Subs,
mono_types: &mut MonoTypes, // mono_types: &mut MonoTypes,
problems: &mut impl Push<Problem>, // problems: &mut impl Push<Problem>,
mut elems: TupleElems, // mut elems: TupleElems,
mut ext: Variable, // mut ext: Variable,
) -> Vec<(usize, Variable)> { // ) -> Vec<(usize, Variable)> {
let mut all_elems = Vec::new(); // let mut all_elems = Vec::new();
// Collapse (recursively) all the elements in ext into a flat list of elements. // // Collapse (recursively) all the elements in ext into a flat list of elements.
loop { // loop {
for (idx, var_index) in elems.iter_all() { // for (idx, var_index) in elems.iter_all() {
all_elems.push((idx.index as usize, subs[var_index])); // all_elems.push((idx.index as usize, subs[var_index]));
} // }
match subs.get_content_without_compacting(ext) { // match subs.get_content_without_compacting(ext) {
Content::Structure(FlatType::Tuple(new_elems, new_ext)) => { // Content::Structure(FlatType::Tuple(new_elems, new_ext)) => {
// Update elems and ext and loop back again to process them. // // Update elems and ext and loop back again to process them.
elems = *new_elems; // elems = *new_elems;
ext = *new_ext; // ext = *new_ext;
} // }
Content::Structure(FlatType::EmptyTuple) => break, // Content::Structure(FlatType::EmptyTuple) => break,
Content::FlexVar(_) | Content::FlexAbleVar(_, _) => break, // Content::FlexVar(_) | Content::FlexAbleVar(_, _) => break,
Content::Alias(_, _, real, _) => { // Content::Alias(_, _, real, _) => {
// Follow the alias and process it on the next iteration of the loop. // // Follow the alias and process it on the next iteration of the loop.
ext = *real; // ext = *real;
// We just processed these elements, so don't process them again! // // We just processed these elements, so don't process them again!
elems = TupleElems::empty(); // elems = TupleElems::empty();
} // }
_ => { // _ => {
// This should never happen! If it does, record a Problem and break. // // This should never happen! If it does, record a Problem and break.
problems.push(Problem::TupleExtWasNotTuple); // problems.push(Problem::TupleExtWasNotTuple);
break; // break;
} // }
} // }
} // }
all_elems // all_elems
} // }
// /// Lower the given vars in-place. // /// Lower the given vars in-place.
// fn lower_vars<'a>( // fn lower_vars<'a>(

View file

@ -1,8 +1,7 @@
#[macro_use] #[macro_use]
extern crate pretty_assertions; extern crate pretty_assertions;
extern crate bumpalo; #[cfg(test)]
mod helpers; mod helpers;
#[cfg(test)] #[cfg(test)]

View file

@ -1,17 +1,16 @@
#[macro_use] #[macro_use]
extern crate pretty_assertions; extern crate pretty_assertions;
extern crate bumpalo; #[cfg(test)]
mod helpers; mod helpers;
#[cfg(test)] #[cfg(test)]
mod specialize_structs { mod specialize_structs {
use roc_specialize_types::{MonoExpr, Number}; use roc_specialize_types::MonoExpr;
use crate::helpers::expect_mono_expr_str; use crate::helpers::expect_mono_expr_str;
use super::helpers::{expect_mono_expr, expect_mono_expr_with_interns, expect_no_expr}; use super::helpers::{expect_mono_expr_with_interns, expect_no_expr};
#[test] #[test]
fn empty_record() { fn empty_record() {
@ -46,10 +45,10 @@ mod specialize_structs {
fn two_fields() { fn two_fields() {
let one = 42; let one = 42;
let two = 50; let two = 50;
let expected = format!("{{ one: {one}, two: {two} }}");
expect_mono_expr_str( expect_mono_expr_str(
expected, format!("{{ one: {one}, two: {two} }}"),
format!("Struct([Number(I8({one:?})), Number(I8({two:?}))])"), format!("Struct([Number(I8({one})), Number(I8({two}))])"),
); );
} }
} }

View file

@ -3,8 +3,6 @@ extern crate pretty_assertions;
#[macro_use] #[macro_use]
extern crate indoc; extern crate indoc;
extern crate bumpalo;
#[cfg(test)] #[cfg(test)]
mod specialize_types { mod specialize_types {
use roc_load::LoadedModule; use roc_load::LoadedModule;