mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Use Collection in Expr::TagUnion
This commit is contained in:
parent
d63405d824
commit
1fabc64fdf
6 changed files with 21 additions and 49 deletions
|
@ -428,7 +428,7 @@ pub fn to_type2<'a>(
|
|||
Type2::Record(field_types, ext_type)
|
||||
}
|
||||
TagUnion { tags, ext, .. } => {
|
||||
let tag_types_vec = can_tags(env, scope, references, tags, region);
|
||||
let tag_types_vec = can_tags(env, scope, references, tags.items, region);
|
||||
|
||||
let tag_types = PoolVec::with_capacity(tag_types_vec.len() as u32, env.pool);
|
||||
|
||||
|
|
|
@ -417,7 +417,7 @@ fn can_annotation_help(
|
|||
TagUnion { tags, ext, .. } => {
|
||||
let tag_types = can_tags(
|
||||
env,
|
||||
tags,
|
||||
tags.items,
|
||||
region,
|
||||
scope,
|
||||
var_store,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::spaces::{fmt_comments_only, fmt_spaces, newline, NewlineAt, INDENT};
|
||||
use bumpalo::collections::String;
|
||||
use roc_parse::ast::{AssignedField, Collection, Expr, Tag, TypeAnnotation};
|
||||
use roc_parse::ast::{AssignedField, Expr, Tag, TypeAnnotation};
|
||||
use roc_region::all::Located;
|
||||
|
||||
/// Does an AST node need parens around it?
|
||||
|
@ -81,9 +81,9 @@ where
|
|||
}
|
||||
|
||||
macro_rules! format_sequence {
|
||||
($buf: expr, $indent:expr, $start:expr, $end:expr, $items:expr, $final_comments:expr, $newline:expr, $t:ident) => {
|
||||
let is_multiline =
|
||||
$items.iter().any(|item| item.value.is_multiline()) || !$final_comments.is_empty();
|
||||
($buf: expr, $indent:expr, $start:expr, $end:expr, $items:expr, $newline:expr, $t:ident) => {
|
||||
let is_multiline = $items.iter().any(|item| item.value.is_multiline())
|
||||
|| !$items.final_comments.is_empty();
|
||||
|
||||
if is_multiline {
|
||||
let braces_indent = $indent + INDENT;
|
||||
|
@ -138,7 +138,12 @@ macro_rules! format_sequence {
|
|||
}
|
||||
}
|
||||
}
|
||||
fmt_comments_only($buf, $final_comments.iter(), NewlineAt::Top, item_indent);
|
||||
fmt_comments_only(
|
||||
$buf,
|
||||
$items.final_comments.iter(),
|
||||
NewlineAt::Top,
|
||||
item_indent,
|
||||
);
|
||||
newline($buf, braces_indent);
|
||||
$buf.push($end);
|
||||
} else {
|
||||
|
@ -192,11 +197,7 @@ impl<'a> Formattable<'a> for TypeAnnotation<'a> {
|
|||
fields.items.iter().any(|field| field.value.is_multiline())
|
||||
}
|
||||
|
||||
TagUnion {
|
||||
tags,
|
||||
ext,
|
||||
final_comments: _,
|
||||
} => {
|
||||
TagUnion { tags, ext } => {
|
||||
match ext {
|
||||
Some(ann) if ann.value.is_multiline() => return true,
|
||||
_ => {}
|
||||
|
@ -279,36 +280,16 @@ impl<'a> Formattable<'a> for TypeAnnotation<'a> {
|
|||
BoundVariable(v) => buf.push_str(v),
|
||||
Wildcard => buf.push('*'),
|
||||
|
||||
TagUnion {
|
||||
tags,
|
||||
ext,
|
||||
final_comments,
|
||||
} => {
|
||||
format_sequence!(buf, indent, '[', ']', tags, final_comments, newlines, Tag);
|
||||
TagUnion { tags, ext } => {
|
||||
format_sequence!(buf, indent, '[', ']', tags, newlines, Tag);
|
||||
|
||||
if let Some(loc_ext_ann) = *ext {
|
||||
loc_ext_ann.value.format(buf, indent);
|
||||
}
|
||||
}
|
||||
|
||||
Record {
|
||||
fields:
|
||||
Collection {
|
||||
items,
|
||||
final_comments,
|
||||
},
|
||||
ext,
|
||||
} => {
|
||||
format_sequence!(
|
||||
buf,
|
||||
indent,
|
||||
'{',
|
||||
'}',
|
||||
items,
|
||||
final_comments,
|
||||
newlines,
|
||||
AssignedField
|
||||
);
|
||||
Record { fields, ext } => {
|
||||
format_sequence!(buf, indent, '{', '}', fields, newlines, AssignedField);
|
||||
|
||||
if let Some(loc_ext_ann) = *ext {
|
||||
loc_ext_ann.value.format(buf, indent);
|
||||
|
|
|
@ -235,16 +235,12 @@ fn generate_entry_doc<'a>(
|
|||
|
||||
fn type_to_docs(in_func_type_ann: bool, type_annotation: ast::TypeAnnotation) -> TypeAnnotation {
|
||||
match type_annotation {
|
||||
ast::TypeAnnotation::TagUnion {
|
||||
tags,
|
||||
ext,
|
||||
final_comments: _,
|
||||
} => {
|
||||
ast::TypeAnnotation::TagUnion { tags, ext } => {
|
||||
let mut tags_to_render: Vec<Tag> = Vec::new();
|
||||
|
||||
let mut any_tags_are_private = false;
|
||||
|
||||
for tag in tags {
|
||||
for tag in tags.iter() {
|
||||
match tag_to_doc(in_func_type_ann, tag.value) {
|
||||
None => {
|
||||
any_tags_are_private = true;
|
||||
|
|
|
@ -266,11 +266,10 @@ pub enum TypeAnnotation<'a> {
|
|||
|
||||
/// A tag union, e.g. `[
|
||||
TagUnion {
|
||||
tags: &'a [Loc<Tag<'a>>],
|
||||
/// The row type variable in an open tag union, e.g. the `a` in `[ Foo, Bar ]a`.
|
||||
/// This is None if it's a closed tag union like `[ Foo, Bar]`.
|
||||
ext: Option<&'a Loc<TypeAnnotation<'a>>>,
|
||||
final_comments: &'a [CommentOrNewline<'a>],
|
||||
tags: Collection<'a, Loc<Tag<'a>>>,
|
||||
},
|
||||
|
||||
/// The `*` type variable, e.g. in (List *)
|
||||
|
|
|
@ -40,11 +40,7 @@ fn tag_union_type<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>, ET
|
|||
)))
|
||||
.parse(arena, state)?;
|
||||
|
||||
let result = TypeAnnotation::TagUnion {
|
||||
tags: tags.items,
|
||||
ext,
|
||||
final_comments: tags.final_comments,
|
||||
};
|
||||
let result = TypeAnnotation::TagUnion { tags, ext };
|
||||
|
||||
Ok((MadeProgress, result, state))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue