mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
Commit local changes (whoops!)
This commit is contained in:
parent
04d4a8ca79
commit
4df0880e7a
9 changed files with 41 additions and 33 deletions
|
@ -395,7 +395,8 @@ pub fn to_type2<'a>(
|
||||||
Type2::Variable(var)
|
Type2::Variable(var)
|
||||||
}
|
}
|
||||||
Record { fields, ext, .. } => {
|
Record { fields, ext, .. } => {
|
||||||
let field_types_map = can_assigned_fields(env, scope, references, &fields.items, region);
|
let field_types_map =
|
||||||
|
can_assigned_fields(env, scope, references, &fields.items, region);
|
||||||
|
|
||||||
let field_types = PoolVec::with_capacity(field_types_map.len() as u32, env.pool);
|
let field_types = PoolVec::with_capacity(field_types_map.len() as u32, env.pool);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::spaces::{fmt_comments_only, fmt_spaces, newline, NewlineAt, INDENT};
|
use crate::spaces::{fmt_comments_only, fmt_spaces, newline, NewlineAt, INDENT};
|
||||||
use bumpalo::collections::String;
|
use bumpalo::collections::String;
|
||||||
use roc_parse::ast::{AssignedField, Expr, Tag, TypeAnnotation, Collection};
|
use roc_parse::ast::{AssignedField, Collection, Expr, Tag, TypeAnnotation};
|
||||||
use roc_region::all::Located;
|
use roc_region::all::Located;
|
||||||
|
|
||||||
/// Does an AST node need parens around it?
|
/// Does an AST node need parens around it?
|
||||||
|
@ -183,10 +183,7 @@ impl<'a> Formattable<'a> for TypeAnnotation<'a> {
|
||||||
Apply(_, _, args) => args.iter().any(|loc_arg| loc_arg.value.is_multiline()),
|
Apply(_, _, args) => args.iter().any(|loc_arg| loc_arg.value.is_multiline()),
|
||||||
As(lhs, _, rhs) => lhs.value.is_multiline() || rhs.value.is_multiline(),
|
As(lhs, _, rhs) => lhs.value.is_multiline() || rhs.value.is_multiline(),
|
||||||
|
|
||||||
Record {
|
Record { fields, ext } => {
|
||||||
fields,
|
|
||||||
ext,
|
|
||||||
} => {
|
|
||||||
match ext {
|
match ext {
|
||||||
Some(ann) if ann.value.is_multiline() => return true,
|
Some(ann) if ann.value.is_multiline() => return true,
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -295,7 +292,11 @@ impl<'a> Formattable<'a> for TypeAnnotation<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Record {
|
Record {
|
||||||
fields: Collection { items, final_comments },
|
fields:
|
||||||
|
Collection {
|
||||||
|
items,
|
||||||
|
final_comments,
|
||||||
|
},
|
||||||
ext,
|
ext,
|
||||||
} => {
|
} => {
|
||||||
format_sequence!(
|
format_sequence!(
|
||||||
|
|
|
@ -293,10 +293,7 @@ fn type_to_docs(in_func_type_ann: bool, type_annotation: ast::TypeAnnotation) ->
|
||||||
|
|
||||||
Apply { name, parts }
|
Apply { name, parts }
|
||||||
}
|
}
|
||||||
ast::TypeAnnotation::Record {
|
ast::TypeAnnotation::Record { fields, ext } => {
|
||||||
fields,
|
|
||||||
ext,
|
|
||||||
} => {
|
|
||||||
let mut doc_fields = Vec::new();
|
let mut doc_fields = Vec::new();
|
||||||
|
|
||||||
let mut any_fields_include_private_tags = false;
|
let mut any_fields_include_private_tags = false;
|
||||||
|
|
|
@ -2630,7 +2630,7 @@ fn parse_header<'a>(
|
||||||
std::str::from_utf8_unchecked(&src_bytes[..chomped])
|
std::str::from_utf8_unchecked(&src_bytes[..chomped])
|
||||||
};
|
};
|
||||||
|
|
||||||
let packages = header.packages.into_bump_slice();
|
let packages = header.packages.items;
|
||||||
|
|
||||||
let info = HeaderInfo {
|
let info = HeaderInfo {
|
||||||
loc_name: Located {
|
loc_name: Located {
|
||||||
|
|
|
@ -13,7 +13,17 @@ pub struct Collection<'a, T> {
|
||||||
|
|
||||||
impl<'a, T> Collection<'a, T> {
|
impl<'a, T> Collection<'a, T> {
|
||||||
pub fn empty() -> Collection<'a, T> {
|
pub fn empty() -> Collection<'a, T> {
|
||||||
Collection { items: &[], final_comments: &[] }
|
Collection {
|
||||||
|
items: &[],
|
||||||
|
final_comments: &[],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_items(items: &'a [T]) -> Collection<'a, T> {
|
||||||
|
Collection {
|
||||||
|
items,
|
||||||
|
final_comments: &[],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::ast::{CommentOrNewline, Spaceable, StrLiteral, TypeAnnotation};
|
use crate::ast::{Collection, CommentOrNewline, Spaceable, StrLiteral, TypeAnnotation};
|
||||||
use crate::blankspace::space0_e;
|
use crate::blankspace::space0_e;
|
||||||
use crate::ident::lowercase_ident;
|
use crate::ident::lowercase_ident;
|
||||||
use crate::parser::Progress::{self, *};
|
use crate::parser::Progress::{self, *};
|
||||||
|
@ -81,7 +81,7 @@ pub enum To<'a> {
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct AppHeader<'a> {
|
pub struct AppHeader<'a> {
|
||||||
pub name: Loc<StrLiteral<'a>>,
|
pub name: Loc<StrLiteral<'a>>,
|
||||||
pub packages: Vec<'a, Loc<PackageEntry<'a>>>,
|
pub packages: Collection<'a, Loc<PackageEntry<'a>>>,
|
||||||
pub imports: Vec<'a, Loc<ImportsEntry<'a>>>,
|
pub imports: Vec<'a, Loc<ImportsEntry<'a>>>,
|
||||||
pub provides: Vec<'a, Loc<ExposesEntry<'a, &'a str>>>,
|
pub provides: Vec<'a, Loc<ExposesEntry<'a, &'a str>>>,
|
||||||
pub to: Loc<To<'a>>,
|
pub to: Loc<To<'a>>,
|
||||||
|
@ -146,7 +146,7 @@ pub struct PlatformHeader<'a> {
|
||||||
pub name: Loc<PackageName<'a>>,
|
pub name: Loc<PackageName<'a>>,
|
||||||
pub requires: PlatformRequires<'a>,
|
pub requires: PlatformRequires<'a>,
|
||||||
pub exposes: Vec<'a, Loc<ExposesEntry<'a, ModuleName<'a>>>>,
|
pub exposes: Vec<'a, Loc<ExposesEntry<'a, ModuleName<'a>>>>,
|
||||||
pub packages: Vec<'a, Loc<PackageEntry<'a>>>,
|
pub packages: Collection<'a, Loc<PackageEntry<'a>>>,
|
||||||
pub imports: Vec<'a, Loc<ImportsEntry<'a>>>,
|
pub imports: Vec<'a, Loc<ImportsEntry<'a>>>,
|
||||||
pub provides: Vec<'a, Loc<ExposesEntry<'a, &'a str>>>,
|
pub provides: Vec<'a, Loc<ExposesEntry<'a, &'a str>>>,
|
||||||
pub effects: Effects<'a>,
|
pub effects: Effects<'a>,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::ast::{CommentOrNewline, Def, Module};
|
use crate::ast::{Collection, CommentOrNewline, Def, Module};
|
||||||
use crate::blankspace::{space0_around_ee, space0_before_e, space0_e};
|
use crate::blankspace::{space0_around_ee, space0_before_e, space0_e};
|
||||||
use crate::header::{
|
use crate::header::{
|
||||||
package_entry, package_name, package_or_path, AppHeader, Effects, ExposesEntry, ImportsEntry,
|
package_entry, package_name, package_or_path, AppHeader, Effects, ExposesEntry, ImportsEntry,
|
||||||
|
@ -203,7 +203,7 @@ fn app_header<'a>() -> impl Parser<'a, AppHeader<'a>, EHeader<'a>> {
|
||||||
let (_, provides, state) =
|
let (_, provides, state) =
|
||||||
specialize(EHeader::Provides, provides_to()).parse(arena, state)?;
|
specialize(EHeader::Provides, provides_to()).parse(arena, state)?;
|
||||||
|
|
||||||
let (before_packages, after_packages, package_entries) = match opt_pkgs {
|
let (before_packages, after_packages, packages) = match opt_pkgs {
|
||||||
Some(pkgs) => {
|
Some(pkgs) => {
|
||||||
let pkgs: Packages<'a> = pkgs; // rustc must be told the type here
|
let pkgs: Packages<'a> = pkgs; // rustc must be told the type here
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ fn app_header<'a>() -> impl Parser<'a, AppHeader<'a>, EHeader<'a>> {
|
||||||
pkgs.entries,
|
pkgs.entries,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
None => (&[] as _, &[] as _, Vec::new_in(arena)),
|
None => (&[] as _, &[] as _, Collection::empty()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// rustc must be told the type here
|
// rustc must be told the type here
|
||||||
|
@ -229,7 +229,7 @@ fn app_header<'a>() -> impl Parser<'a, AppHeader<'a>, EHeader<'a>> {
|
||||||
|
|
||||||
let header = AppHeader {
|
let header = AppHeader {
|
||||||
name,
|
name,
|
||||||
packages: package_entries,
|
packages,
|
||||||
imports,
|
imports,
|
||||||
provides: provides.entries,
|
provides: provides.entries,
|
||||||
to: provides.to,
|
to: provides.to,
|
||||||
|
@ -582,11 +582,9 @@ where
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Packages<'a> {
|
struct Packages<'a> {
|
||||||
entries: Vec<'a, Located<PackageEntry<'a>>>,
|
entries: Collection<'a, Located<PackageEntry<'a>>>,
|
||||||
|
|
||||||
before_packages_keyword: &'a [CommentOrNewline<'a>],
|
before_packages_keyword: &'a [CommentOrNewline<'a>],
|
||||||
after_packages_keyword: &'a [CommentOrNewline<'a>],
|
after_packages_keyword: &'a [CommentOrNewline<'a>],
|
||||||
final_comments: &'a [CommentOrNewline<'a>],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -615,12 +613,11 @@ fn packages<'a>() -> impl Parser<'a, Packages<'a>, EPackages<'a>> {
|
||||||
PackageEntry::SpaceBefore
|
PackageEntry::SpaceBefore
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|((before_packages_keyword, after_packages_keyword), (entries, final_comments))| {
|
|((before_packages_keyword, after_packages_keyword), entries): ((_, _), Collection<'a, _>)| {
|
||||||
Packages {
|
Packages {
|
||||||
entries,
|
entries,
|
||||||
before_packages_keyword,
|
before_packages_keyword,
|
||||||
after_packages_keyword,
|
after_packages_keyword,
|
||||||
final_comments,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::ast::{AssignedField, Tag, TypeAnnotation, Collection};
|
use crate::ast::{AssignedField, Collection, Tag, TypeAnnotation};
|
||||||
use crate::blankspace::{space0_around_ee, space0_before_e, space0_e};
|
use crate::blankspace::{space0_around_ee, space0_before_e, space0_e};
|
||||||
use crate::keyword;
|
use crate::keyword;
|
||||||
use crate::parser::{
|
use crate::parser::{
|
||||||
|
|
|
@ -23,7 +23,9 @@ mod test_parse {
|
||||||
use roc_parse::ast::Pattern::{self, *};
|
use roc_parse::ast::Pattern::{self, *};
|
||||||
use roc_parse::ast::StrLiteral::{self, *};
|
use roc_parse::ast::StrLiteral::{self, *};
|
||||||
use roc_parse::ast::StrSegment::*;
|
use roc_parse::ast::StrSegment::*;
|
||||||
use roc_parse::ast::{self, Def, EscapedChar, Spaceable, TypeAnnotation, WhenBranch, Collection};
|
use roc_parse::ast::{
|
||||||
|
self, Collection, Def, EscapedChar, Spaceable, TypeAnnotation, WhenBranch,
|
||||||
|
};
|
||||||
use roc_parse::header::{
|
use roc_parse::header::{
|
||||||
AppHeader, Effects, ExposesEntry, ImportsEntry, InterfaceHeader, ModuleName, PackageEntry,
|
AppHeader, Effects, ExposesEntry, ImportsEntry, InterfaceHeader, ModuleName, PackageEntry,
|
||||||
PackageName, PackageOrPath, PlatformHeader, PlatformRequires, PlatformRigid, To,
|
PackageName, PackageOrPath, PlatformHeader, PlatformRequires, PlatformRigid, To,
|
||||||
|
@ -3089,7 +3091,7 @@ mod test_parse {
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_app_header() {
|
fn empty_app_header() {
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
let packages = Vec::new_in(&arena);
|
let packages = Collection::empty();
|
||||||
let imports = Vec::new_in(&arena);
|
let imports = Vec::new_in(&arena);
|
||||||
let provides = Vec::new_in(&arena);
|
let provides = Vec::new_in(&arena);
|
||||||
let module_name = StrLiteral::PlainLine("test-app");
|
let module_name = StrLiteral::PlainLine("test-app");
|
||||||
|
@ -3129,7 +3131,7 @@ mod test_parse {
|
||||||
use PackageOrPath::Path;
|
use PackageOrPath::Path;
|
||||||
|
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
let packages = Vec::new_in(&arena);
|
let packages = Collection::empty();
|
||||||
let imports = Vec::new_in(&arena);
|
let imports = Vec::new_in(&arena);
|
||||||
let provides = Vec::new_in(&arena);
|
let provides = Vec::new_in(&arena);
|
||||||
let module_name = StrLiteral::PlainLine("test-app");
|
let module_name = StrLiteral::PlainLine("test-app");
|
||||||
|
@ -3178,7 +3180,7 @@ mod test_parse {
|
||||||
};
|
};
|
||||||
let loc_pkg_entry = Located::new(1, 1, 15, 33, pkg_entry);
|
let loc_pkg_entry = Located::new(1, 1, 15, 33, pkg_entry);
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
let packages = bumpalo::vec![in &arena; loc_pkg_entry];
|
let packages = Collection::with_items(arena.alloc([loc_pkg_entry]));
|
||||||
let import = ImportsEntry::Package("foo", ModuleName::new("Bar.Baz"), Vec::new_in(&arena));
|
let import = ImportsEntry::Package("foo", ModuleName::new("Bar.Baz"), Vec::new_in(&arena));
|
||||||
let loc_import = Located::new(2, 2, 14, 25, import);
|
let loc_import = Located::new(2, 2, 14, 25, import);
|
||||||
let imports = bumpalo::vec![in &arena; loc_import];
|
let imports = bumpalo::vec![in &arena; loc_import];
|
||||||
|
@ -3234,7 +3236,7 @@ mod test_parse {
|
||||||
};
|
};
|
||||||
let loc_pkg_entry = Located::new(1, 1, 15, 33, pkg_entry);
|
let loc_pkg_entry = Located::new(1, 1, 15, 33, pkg_entry);
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
let packages = bumpalo::vec![in &arena; loc_pkg_entry];
|
let packages = Collection::with_items(arena.alloc([loc_pkg_entry]));
|
||||||
let import = ImportsEntry::Package("foo", ModuleName::new("Bar.Baz"), Vec::new_in(&arena));
|
let import = ImportsEntry::Package("foo", ModuleName::new("Bar.Baz"), Vec::new_in(&arena));
|
||||||
let loc_import = Located::new(2, 2, 14, 25, import);
|
let loc_import = Located::new(2, 2, 14, 25, import);
|
||||||
let imports = bumpalo::vec![in &arena; loc_import];
|
let imports = bumpalo::vec![in &arena; loc_import];
|
||||||
|
@ -3321,7 +3323,7 @@ mod test_parse {
|
||||||
name: Located::new(0, 0, 9, 23, pkg_name),
|
name: Located::new(0, 0, 9, 23, pkg_name),
|
||||||
requires,
|
requires,
|
||||||
exposes: Vec::new_in(&arena),
|
exposes: Vec::new_in(&arena),
|
||||||
packages: Vec::new_in(&arena),
|
packages: Collection::empty(),
|
||||||
imports: Vec::new_in(&arena),
|
imports: Vec::new_in(&arena),
|
||||||
provides: Vec::new_in(&arena),
|
provides: Vec::new_in(&arena),
|
||||||
effects,
|
effects,
|
||||||
|
@ -3364,7 +3366,7 @@ mod test_parse {
|
||||||
};
|
};
|
||||||
let loc_pkg_entry = Located::new(3, 3, 15, 27, pkg_entry);
|
let loc_pkg_entry = Located::new(3, 3, 15, 27, pkg_entry);
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
let packages = bumpalo::vec![in &arena; loc_pkg_entry];
|
let packages = Collection::with_items(arena.alloc([loc_pkg_entry]));
|
||||||
let imports = Vec::new_in(&arena);
|
let imports = Vec::new_in(&arena);
|
||||||
let provide_entry = Located::new(5, 5, 15, 26, Exposed("mainForHost"));
|
let provide_entry = Located::new(5, 5, 15, 26, Exposed("mainForHost"));
|
||||||
let provides = bumpalo::vec![in &arena; provide_entry];
|
let provides = bumpalo::vec![in &arena; provide_entry];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue