mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Fix a test, delete some dead code
This commit is contained in:
parent
219a0398a2
commit
05e5fb4189
6 changed files with 128 additions and 213 deletions
|
@ -2,10 +2,9 @@ use crate::{
|
|||
foreign_symbol::ForeignSymbolId, mono_module::InternedStrId, mono_num::Number,
|
||||
mono_struct::MonoFieldId, mono_type::MonoTypeId, specialize_type::Problem,
|
||||
};
|
||||
use bumpalo::Bump;
|
||||
use roc_can::expr::{Field, Recursive};
|
||||
use roc_can::expr::Recursive;
|
||||
use roc_module::low_level::LowLevel;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_module::{ident::Lowercase, low_level::LowLevel};
|
||||
use roc_region::all::Region;
|
||||
use soa::{Id, Index, NonEmptySlice, Slice, Slice2, Slice3};
|
||||
use std::iter;
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use roc_can::expr::IntValue;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum Number {
|
||||
I8(i8),
|
||||
|
@ -16,75 +14,3 @@ pub enum Number {
|
|||
F64(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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,15 +9,9 @@ use crate::{
|
|||
MonoFieldId, MonoType,
|
||||
};
|
||||
use roc_collections::{Push, VecMap};
|
||||
use roc_module::{
|
||||
ident::{Lowercase, TagName},
|
||||
symbol::Symbol,
|
||||
};
|
||||
use roc_module::{ident::Lowercase, symbol::Symbol};
|
||||
use roc_solve::module::Solved;
|
||||
use roc_types::subs::{
|
||||
Content, FlatType, RecordFields, Subs, SubsSlice, TagExt, TupleElems, UnionLabels, UnionTags,
|
||||
Variable,
|
||||
};
|
||||
use roc_types::subs::{Content, FlatType, Subs, SubsSlice, Variable};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Problem {
|
||||
|
@ -409,139 +403,139 @@ fn num_args_to_mono_id(
|
|||
MonoTypeId::CRASH
|
||||
}
|
||||
|
||||
fn resolve_tag_ext(
|
||||
subs: &mut Subs,
|
||||
mono_types: &mut MonoTypes,
|
||||
problems: &mut impl Push<Problem>,
|
||||
mut tags: UnionTags,
|
||||
mut ext: TagExt,
|
||||
) -> Vec<(TagName, Vec<Variable>)> {
|
||||
let mut all_tags = Vec::new();
|
||||
// fn resolve_tag_ext(
|
||||
// subs: &mut Subs,
|
||||
// mono_types: &mut MonoTypes,
|
||||
// problems: &mut impl Push<Problem>,
|
||||
// mut tags: UnionTags,
|
||||
// mut ext: TagExt,
|
||||
// ) -> Vec<(TagName, Vec<Variable>)> {
|
||||
// let mut all_tags = Vec::new();
|
||||
|
||||
// Collapse (recursively) all the tags in ext_var into a flat list of tags.
|
||||
loop {
|
||||
for (tag, vars) in tags.iter_from_subs(subs) {
|
||||
all_tags.push((tag.clone(), vars.to_vec()));
|
||||
}
|
||||
// // Collapse (recursively) all the tags in ext_var into a flat list of tags.
|
||||
// loop {
|
||||
// for (tag, vars) in tags.iter_from_subs(subs) {
|
||||
// all_tags.push((tag.clone(), vars.to_vec()));
|
||||
// }
|
||||
|
||||
match subs.get_content_without_compacting(ext.var()) {
|
||||
Content::Structure(FlatType::TagUnion(new_tags, new_ext)) => {
|
||||
// Update tags and ext and loop back again to process them.
|
||||
tags = *new_tags;
|
||||
ext = *new_ext;
|
||||
}
|
||||
Content::Structure(FlatType::FunctionOrTagUnion(tag_names, _symbols, new_ext)) => {
|
||||
for index in tag_names.into_iter() {
|
||||
all_tags.push((subs[index].clone(), Vec::new()));
|
||||
}
|
||||
ext = *new_ext;
|
||||
}
|
||||
Content::Structure(FlatType::EmptyTagUnion) => break,
|
||||
Content::FlexVar(_) | Content::FlexAbleVar(_, _) => break,
|
||||
Content::Alias(_, _, real, _) => {
|
||||
// Follow the alias and process it on the next iteration of the loop.
|
||||
ext = TagExt::Any(*real);
|
||||
// match subs.get_content_without_compacting(ext.var()) {
|
||||
// Content::Structure(FlatType::TagUnion(new_tags, new_ext)) => {
|
||||
// // Update tags and ext and loop back again to process them.
|
||||
// tags = *new_tags;
|
||||
// ext = *new_ext;
|
||||
// }
|
||||
// Content::Structure(FlatType::FunctionOrTagUnion(tag_names, _symbols, new_ext)) => {
|
||||
// for index in tag_names.into_iter() {
|
||||
// all_tags.push((subs[index].clone(), Vec::new()));
|
||||
// }
|
||||
// ext = *new_ext;
|
||||
// }
|
||||
// Content::Structure(FlatType::EmptyTagUnion) => break,
|
||||
// Content::FlexVar(_) | Content::FlexAbleVar(_, _) => break,
|
||||
// Content::Alias(_, _, real, _) => {
|
||||
// // Follow the alias and process it on the next iteration of the loop.
|
||||
// ext = TagExt::Any(*real);
|
||||
|
||||
// We just processed these tags, so don't process them again!
|
||||
tags = UnionLabels::default();
|
||||
}
|
||||
_ => {
|
||||
// This should never happen! If it does, record a Problem and break.
|
||||
problems.push(Problem::TagUnionExtWasNotTagUnion);
|
||||
// // We just processed these tags, so don't process them again!
|
||||
// tags = UnionLabels::default();
|
||||
// }
|
||||
// _ => {
|
||||
// // This should never happen! If it does, record a Problem and break.
|
||||
// problems.push(Problem::TagUnionExtWasNotTagUnion);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
all_tags
|
||||
}
|
||||
// all_tags
|
||||
// }
|
||||
|
||||
fn lower_record<P: Push<Problem>>(
|
||||
env: &mut Env<'_, '_, '_, '_, '_, '_, P>,
|
||||
subs: &Subs,
|
||||
mut fields: RecordFields,
|
||||
mut ext: Variable,
|
||||
) -> Vec<(Lowercase, Option<MonoTypeId>)> {
|
||||
let mut labeled_mono_ids = Vec::with_capacity(fields.len());
|
||||
// fn lower_record<P: Push<Problem>>(
|
||||
// env: &mut Env<'_, '_, '_, '_, '_, '_, P>,
|
||||
// subs: &Subs,
|
||||
// mut fields: RecordFields,
|
||||
// mut ext: Variable,
|
||||
// ) -> Vec<(Lowercase, Option<MonoTypeId>)> {
|
||||
// let mut labeled_mono_ids = Vec::with_capacity(fields.len());
|
||||
|
||||
// Collapse (recursively) all the fields in ext into a flat list of fields.
|
||||
loop {
|
||||
// Add all the current fields to the answer.
|
||||
labeled_mono_ids.extend(
|
||||
fields
|
||||
.sorted_iterator(subs, ext)
|
||||
.map(|(label, field)| (label, lower_var(env, subs, *field.as_inner()))),
|
||||
);
|
||||
// // Collapse (recursively) all the fields in ext into a flat list of fields.
|
||||
// loop {
|
||||
// // Add all the current fields to the answer.
|
||||
// labeled_mono_ids.extend(
|
||||
// fields
|
||||
// .sorted_iterator(subs, ext)
|
||||
// .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.
|
||||
match subs.get_content_without_compacting(ext) {
|
||||
Content::Structure(FlatType::Record(new_fields, new_ext)) => {
|
||||
// Update fields and ext and loop back again to process them.
|
||||
fields = *new_fields;
|
||||
ext = *new_ext;
|
||||
}
|
||||
Content::Structure(FlatType::EmptyRecord)
|
||||
| Content::FlexVar(_)
|
||||
| Content::FlexAbleVar(_, _) => return labeled_mono_ids,
|
||||
Content::Alias(_, _, real, _) => {
|
||||
// Follow the alias and process it on the next iteration of the loop.
|
||||
ext = *real;
|
||||
// // 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) {
|
||||
// Content::Structure(FlatType::Record(new_fields, new_ext)) => {
|
||||
// // Update fields and ext and loop back again to process them.
|
||||
// fields = *new_fields;
|
||||
// ext = *new_ext;
|
||||
// }
|
||||
// Content::Structure(FlatType::EmptyRecord)
|
||||
// | Content::FlexVar(_)
|
||||
// | Content::FlexAbleVar(_, _) => return labeled_mono_ids,
|
||||
// Content::Alias(_, _, real, _) => {
|
||||
// // Follow the alias and process it on the next iteration of the loop.
|
||||
// ext = *real;
|
||||
|
||||
// We just processed these fields, so don't process them again!
|
||||
fields = RecordFields::empty();
|
||||
}
|
||||
_ => {
|
||||
// This should never happen! If it does, record a Problem and early return.
|
||||
env.problems.push(Problem::RecordExtWasNotRecord);
|
||||
// // We just processed these fields, so don't process them again!
|
||||
// fields = RecordFields::empty();
|
||||
// }
|
||||
// _ => {
|
||||
// // This should never happen! If it does, record a Problem and early return.
|
||||
// env.problems.push(Problem::RecordExtWasNotRecord);
|
||||
|
||||
return labeled_mono_ids;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// return labeled_mono_ids;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
fn resolve_tuple_ext(
|
||||
subs: &mut Subs,
|
||||
mono_types: &mut MonoTypes,
|
||||
problems: &mut impl Push<Problem>,
|
||||
mut elems: TupleElems,
|
||||
mut ext: Variable,
|
||||
) -> Vec<(usize, Variable)> {
|
||||
let mut all_elems = Vec::new();
|
||||
// fn resolve_tuple_ext(
|
||||
// subs: &mut Subs,
|
||||
// mono_types: &mut MonoTypes,
|
||||
// problems: &mut impl Push<Problem>,
|
||||
// mut elems: TupleElems,
|
||||
// mut ext: Variable,
|
||||
// ) -> Vec<(usize, Variable)> {
|
||||
// let mut all_elems = Vec::new();
|
||||
|
||||
// Collapse (recursively) all the elements in ext into a flat list of elements.
|
||||
loop {
|
||||
for (idx, var_index) in elems.iter_all() {
|
||||
all_elems.push((idx.index as usize, subs[var_index]));
|
||||
}
|
||||
// // Collapse (recursively) all the elements in ext into a flat list of elements.
|
||||
// loop {
|
||||
// for (idx, var_index) in elems.iter_all() {
|
||||
// all_elems.push((idx.index as usize, subs[var_index]));
|
||||
// }
|
||||
|
||||
match subs.get_content_without_compacting(ext) {
|
||||
Content::Structure(FlatType::Tuple(new_elems, new_ext)) => {
|
||||
// Update elems and ext and loop back again to process them.
|
||||
elems = *new_elems;
|
||||
ext = *new_ext;
|
||||
}
|
||||
Content::Structure(FlatType::EmptyTuple) => break,
|
||||
Content::FlexVar(_) | Content::FlexAbleVar(_, _) => break,
|
||||
Content::Alias(_, _, real, _) => {
|
||||
// Follow the alias and process it on the next iteration of the loop.
|
||||
ext = *real;
|
||||
// match subs.get_content_without_compacting(ext) {
|
||||
// Content::Structure(FlatType::Tuple(new_elems, new_ext)) => {
|
||||
// // Update elems and ext and loop back again to process them.
|
||||
// elems = *new_elems;
|
||||
// ext = *new_ext;
|
||||
// }
|
||||
// Content::Structure(FlatType::EmptyTuple) => break,
|
||||
// Content::FlexVar(_) | Content::FlexAbleVar(_, _) => break,
|
||||
// Content::Alias(_, _, real, _) => {
|
||||
// // Follow the alias and process it on the next iteration of the loop.
|
||||
// ext = *real;
|
||||
|
||||
// We just processed these elements, so don't process them again!
|
||||
elems = TupleElems::empty();
|
||||
}
|
||||
_ => {
|
||||
// This should never happen! If it does, record a Problem and break.
|
||||
problems.push(Problem::TupleExtWasNotTuple);
|
||||
// // We just processed these elements, so don't process them again!
|
||||
// elems = TupleElems::empty();
|
||||
// }
|
||||
// _ => {
|
||||
// // This should never happen! If it does, record a Problem and break.
|
||||
// problems.push(Problem::TupleExtWasNotTuple);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
all_elems
|
||||
}
|
||||
// all_elems
|
||||
// }
|
||||
|
||||
// /// Lower the given vars in-place.
|
||||
// fn lower_vars<'a>(
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#[macro_use]
|
||||
extern crate pretty_assertions;
|
||||
|
||||
extern crate bumpalo;
|
||||
|
||||
#[cfg(test)]
|
||||
mod helpers;
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
#[macro_use]
|
||||
extern crate pretty_assertions;
|
||||
|
||||
extern crate bumpalo;
|
||||
|
||||
#[cfg(test)]
|
||||
mod helpers;
|
||||
|
||||
#[cfg(test)]
|
||||
mod specialize_structs {
|
||||
use roc_specialize_types::{MonoExpr, Number};
|
||||
use roc_specialize_types::MonoExpr;
|
||||
|
||||
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]
|
||||
fn empty_record() {
|
||||
|
@ -46,10 +45,10 @@ mod specialize_structs {
|
|||
fn two_fields() {
|
||||
let one = 42;
|
||||
let two = 50;
|
||||
let expected = format!("{{ one: {one}, two: {two} }}");
|
||||
|
||||
expect_mono_expr_str(
|
||||
expected,
|
||||
format!("Struct([Number(I8({one:?})), Number(I8({two:?}))])"),
|
||||
format!("{{ one: {one}, two: {two} }}"),
|
||||
format!("Struct([Number(I8({one})), Number(I8({two}))])"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ extern crate pretty_assertions;
|
|||
#[macro_use]
|
||||
extern crate indoc;
|
||||
|
||||
extern crate bumpalo;
|
||||
|
||||
#[cfg(test)]
|
||||
mod specialize_types {
|
||||
use roc_load::LoadedModule;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue