mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Move pretty_print_types into types crate
This commit is contained in:
parent
45bda2e0c7
commit
3b26a982f0
10 changed files with 72 additions and 70 deletions
|
@ -4,7 +4,7 @@ use roc_module::symbol::Symbol;
|
|||
use roc_types::boolean_algebra::{Atom, Bool};
|
||||
use roc_types::subs::Content::{self, *};
|
||||
use roc_types::subs::{Descriptor, FlatType, Mark, OptVariable, Subs, Variable};
|
||||
use roc_types::types::{Mismatch, Problem};
|
||||
use roc_types::types::{gather_fields, Mismatch, Problem, RecordStructure};
|
||||
use std::hash::Hash;
|
||||
|
||||
macro_rules! mismatch {
|
||||
|
@ -30,9 +30,9 @@ struct Context {
|
|||
second_desc: Descriptor,
|
||||
}
|
||||
|
||||
pub struct RecordStructure {
|
||||
pub fields: MutMap<Lowercase, Variable>,
|
||||
pub ext: Variable,
|
||||
pub struct Unified {
|
||||
pub vars: Pool,
|
||||
pub mismatches: Vec<Problem>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -41,11 +41,6 @@ struct TagUnionStructure {
|
|||
ext: Variable,
|
||||
}
|
||||
|
||||
pub struct Unified {
|
||||
pub vars: Pool,
|
||||
pub mismatches: Vec<Problem>,
|
||||
}
|
||||
|
||||
type Outcome = Vec<Mismatch>;
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -663,48 +658,6 @@ fn unify_flex(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn gather_fields(
|
||||
subs: &mut Subs,
|
||||
fields: MutMap<Lowercase, Variable>,
|
||||
var: Variable,
|
||||
) -> RecordStructure {
|
||||
use roc_types::subs::FlatType::*;
|
||||
|
||||
match subs.get(var).content {
|
||||
Structure(Record(sub_fields, sub_ext)) => {
|
||||
gather_fields(subs, union(fields, &sub_fields), sub_ext)
|
||||
}
|
||||
|
||||
Alias(_, _, var) => {
|
||||
// TODO according to elm/compiler: "TODO may be dropping useful alias info here"
|
||||
gather_fields(subs, fields, var)
|
||||
}
|
||||
|
||||
_ => RecordStructure { fields, ext: var },
|
||||
}
|
||||
}
|
||||
|
||||
fn gather_tags(
|
||||
subs: &mut Subs,
|
||||
tags: MutMap<TagName, Vec<Variable>>,
|
||||
var: Variable,
|
||||
) -> TagUnionStructure {
|
||||
use roc_types::subs::FlatType::*;
|
||||
|
||||
match subs.get(var).content {
|
||||
Structure(TagUnion(sub_tags, sub_ext)) => {
|
||||
gather_tags(subs, union(tags, &sub_tags), sub_ext)
|
||||
}
|
||||
|
||||
Alias(_, _, var) => {
|
||||
// TODO according to elm/compiler: "TODO may be dropping useful alias info here"
|
||||
gather_tags(subs, tags, var)
|
||||
}
|
||||
|
||||
_ => TagUnionStructure { tags, ext: var },
|
||||
}
|
||||
}
|
||||
|
||||
fn merge(subs: &mut Subs, ctx: &Context, content: Content) -> Outcome {
|
||||
let rank = ctx.first_desc.rank.min(ctx.second_desc.rank);
|
||||
let desc = Descriptor {
|
||||
|
@ -739,3 +692,25 @@ fn fresh(subs: &mut Subs, pool: &mut Pool, ctx: &Context, content: Content) -> V
|
|||
pool,
|
||||
)
|
||||
}
|
||||
|
||||
fn gather_tags(
|
||||
subs: &mut Subs,
|
||||
tags: MutMap<TagName, Vec<Variable>>,
|
||||
var: Variable,
|
||||
) -> TagUnionStructure {
|
||||
use roc_types::subs::Content::*;
|
||||
use roc_types::subs::FlatType::*;
|
||||
|
||||
match subs.get(var).content {
|
||||
Structure(TagUnion(sub_tags, sub_ext)) => {
|
||||
gather_tags(subs, union(tags, &sub_tags), sub_ext)
|
||||
}
|
||||
|
||||
Alias(_, _, var) => {
|
||||
// TODO according to elm/compiler: "TODO may be dropping useful alias info here"
|
||||
gather_tags(subs, tags, var)
|
||||
}
|
||||
|
||||
_ => TagUnionStructure { tags, ext: var },
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue