Merge pull request #222 from rtfeldman/workspace

Use a workspace at the root
This commit is contained in:
Richard Feldman 2020-03-05 17:58:05 -05:00 committed by GitHub
commit f265651ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
110 changed files with 600 additions and 426 deletions

73
Cargo.lock generated
View File

@ -311,7 +311,7 @@ checksum = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7"
dependencies = [
"proc-macro-hack",
"proc-macro2 1.0.9",
"quote 1.0.2",
"quote 1.0.3",
"syn 1.0.16",
]
@ -373,9 +373,9 @@ dependencies = [
[[package]]
name = "im"
version = "14.2.0"
version = "14.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e302bf26ba21de289e808230f80fe799fd371268d853783ee7f844c7cb5704b7"
checksum = "696059c87b83c5a258817ecd67c3af915e3ed141891fc35a1e79908801cf0ce7"
dependencies = [
"bitmaps",
"rand_core 0.5.1",
@ -387,9 +387,9 @@ dependencies = [
[[package]]
name = "im-rc"
version = "14.2.0"
version = "14.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5df50c85553397f6320fad21751d7ba9007de512c7971cb8746238f1a155d3c9"
checksum = "303f7e6256d546e01979071417432425f15c1891fb309a5f2d724ee908fabd6e"
dependencies = [
"bitmaps",
"rand_core 0.5.1",
@ -426,7 +426,7 @@ checksum = "b714fc08d0961716390977cdff1536234415ac37b509e34e5a983def8340fb75"
dependencies = [
"proc-macro-hack",
"proc-macro2 1.0.9",
"quote 1.0.2",
"quote 1.0.3",
"syn 1.0.16",
"unindent",
]
@ -610,7 +610,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5"
dependencies = [
"proc-macro2 1.0.9",
"quote 1.0.2",
"quote 1.0.3",
"syn 1.0.16",
]
@ -672,9 +672,9 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.2"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f"
dependencies = [
"proc-macro2 1.0.9",
]
@ -840,9 +840,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.6.14"
version = "0.6.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b28dfe3fe9badec5dbf0a79a9cccad2cfc2ab5484bdb3e44cbd1ae8b3ba2be06"
checksum = "1132f845907680735a84409c3bebc64d1364a5683ffbce899550cd09d5eaefc1"
[[package]]
name = "region"
@ -878,11 +878,58 @@ dependencies = [
"pretty_assertions",
"quickcheck",
"quickcheck_macros",
"roc_collections",
"roc_module",
"roc_parse",
"roc_region",
"target-lexicon",
"tokio",
"wyhash",
]
[[package]]
name = "roc_collections"
version = "0.1.0"
dependencies = [
"bumpalo",
"im",
"im-rc",
"wyhash",
]
[[package]]
name = "roc_module"
version = "0.1.0"
dependencies = [
"bumpalo",
"indoc",
"inlinable_string",
"lazy_static",
"maplit",
"pretty_assertions",
"roc_collections",
"roc_region",
]
[[package]]
name = "roc_parse"
version = "0.1.0"
dependencies = [
"bumpalo",
"indoc",
"inlinable_string",
"pretty_assertions",
"quickcheck",
"quickcheck_macros",
"roc_collections",
"roc_module",
"roc_region",
]
[[package]]
name = "roc_region"
version = "0.1.0"
[[package]]
name = "rustc_version"
version = "0.2.3"
@ -953,7 +1000,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "123bd9499cfb380418d509322d7a6d52e5315f064fe4b3ad18a53d6b92c07859"
dependencies = [
"proc-macro2 1.0.9",
"quote 1.0.2",
"quote 1.0.3",
"unicode-xid 0.2.0",
]
@ -979,7 +1026,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7b51e1fbc44b5a0840be594fbc0f960be09050f2617e61e6aa43bef97cd3ef4"
dependencies = [
"proc-macro2 1.0.9",
"quote 1.0.2",
"quote 1.0.3",
"syn 1.0.16",
]

View File

@ -1,36 +1,9 @@
[package]
name = "roc"
version = "0.1.0"
authors = ["Richard Feldman <oss@rtfeldman.com>"]
edition = "2018"
[workspace]
[dependencies]
log = "0.4.8"
petgraph = { version = "0.4.5", optional = true }
im = "14" # im and im-rc should always have the same version!
im-rc = "14" # im and im-rc should always have the same version!
wyhash = "0.3"
tokio = { version = "0.2", features = ["blocking", "fs", "sync", "rt-threaded"] }
bumpalo = "2.6"
inlinable_string = "0.1.0"
# NOTE: Breaking API changes get pushed directly to this Inkwell branch, so be
# very careful when running `cargo update` to get a new revision into Cargo.lock.
#
# We have to depend on `branch` instead of a specific `rev` here because, although
# `rev` works locally, it causes an error on GitHub Actions. (It's unclear why,
# but after several hours of trying unsuccessfully to fix it, `branch` is it.)
inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "llvm8-0" }
futures = "0.3"
lazy_static = "1.4"
target-lexicon = "0.10" # NOTE: we must use the same version of target-lexicon as cranelift!
cranelift = "0.59" # All cranelift crates should have the same version!
cranelift-simplejit = "0.59" # All cranelift crates should have the same version!
cranelift-module = "0.59" # All cranelift crates should have the same version!
cranelift-codegen = "0.59" # All cranelift crates should have the same version!
[dev-dependencies]
pretty_assertions = "0.5.1 "
maplit = "1.0.1"
indoc = "0.3.3"
quickcheck = "0.8"
quickcheck_macros = "0.8"
members = [
"compiler",
"compiler/region",
"compiler/collections",
"compiler/module",
"compiler/parse"
]

40
compiler/Cargo.toml Normal file
View File

@ -0,0 +1,40 @@
[package]
name = "roc"
version = "0.1.0"
authors = ["Richard Feldman <oss@rtfeldman.com>"]
edition = "2018"
[dependencies]
roc_collections = { path = "./collections" }
roc_region = { path = "./region" }
roc_module = { path = "./module" }
roc_parse = { path = "./parse" }
log = "0.4.8"
petgraph = { version = "0.4.5", optional = true }
im = "14" # im and im-rc should always have the same version!
im-rc = "14" # im and im-rc should always have the same version!
wyhash = "0.3"
tokio = { version = "0.2", features = ["blocking", "fs", "sync", "rt-threaded"] }
bumpalo = "2.6"
inlinable_string = "0.1.0"
# NOTE: Breaking API changes get pushed directly to this Inkwell branch, so be
# very careful when running `cargo update` to get a new revision into Cargo.lock.
#
# We have to depend on `branch` instead of a specific `rev` here because, although
# `rev` works locally, it causes an error on GitHub Actions. (It's unclear why,
# but after several hours of trying unsuccessfully to fix it, `branch` is it.)
inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "llvm8-0" }
futures = "0.3"
lazy_static = "1.4"
target-lexicon = "0.10" # NOTE: we must use the same version of target-lexicon as cranelift!
cranelift = "0.59" # All cranelift crates should have the same version!
cranelift-simplejit = "0.59" # All cranelift crates should have the same version!
cranelift-module = "0.59" # All cranelift crates should have the same version!
cranelift-codegen = "0.59" # All cranelift crates should have the same version!
[dev-dependencies]
pretty_assertions = "0.5.1 "
maplit = "1.0.1"
indoc = "0.3.3"
quickcheck = "0.8"
quickcheck_macros = "0.8"

View File

@ -0,0 +1,11 @@
[package]
name = "roc_collections"
version = "0.1.0"
authors = ["Richard Feldman <oss@rtfeldman.com>"]
edition = "2018"
[dependencies]
im = "14" # im and im-rc should always have the same version!
im-rc = "14" # im and im-rc should always have the same version!
wyhash = "0.3"
bumpalo = "2.6"

View File

@ -0,0 +1,14 @@
#![warn(clippy::all, clippy::dbg_macro)]
// I'm skeptical that clippy:large_enum_variant is a good lint to have globally enabled.
//
// It warns about a performance problem where the only quick remediation is
// to allocate more on the heap, which has lots of tradeoffs - including making it
// long-term unclear which allocations *need* to happen for compilation's sake
// (e.g. recursive structures) versus those which were only added to appease clippy.
//
// Effectively optimizing data struture memory layout isn't a quick fix,
// and encouraging shortcuts here creates bad incentives. I would rather temporarily
// re-enable this when working on performance optimizations than have it block PRs.
#![allow(clippy::large_enum_variant)]
pub mod all;

View File

@ -0,0 +1,17 @@
[package]
name = "roc_module"
version = "0.1.0"
authors = ["Richard Feldman <oss@rtfeldman.com>"]
edition = "2018"
[dependencies]
roc_region = { path = "../region" }
roc_collections = { path = "../collections" }
bumpalo = "2.6"
inlinable_string = "0.1.0"
lazy_static = "1.4"
[dev-dependencies]
pretty_assertions = "0.5.1 "
maplit = "1.0.1"
indoc = "0.3.3"

View File

@ -1,4 +1,4 @@
use crate::module::symbol::{Interns, ModuleId, Symbol};
use crate::symbol::{Interns, ModuleId, Symbol};
use inlinable_string::InlinableString;
use std::fmt;

View File

@ -0,0 +1,5 @@
pub mod ident;
pub mod symbol;
#[macro_use]
extern crate lazy_static;

View File

@ -1,7 +1,7 @@
use crate::can::ident::Ident;
use crate::collections::{default_hasher, ImMap, MutMap};
use crate::region::Region;
use crate::ident::Ident;
use inlinable_string::InlinableString;
use roc_collections::all::{default_hasher, ImMap, MutMap};
use roc_region::all::Region;
use std::collections::HashMap;
use std::{fmt, u32};
@ -153,12 +153,12 @@ lazy_static! {
/// which displays not only the Module ID, but also the Module Name which
/// corresponds to that ID.
///
static ref DEBUG_MODULE_ID_NAMES: std::sync::Mutex<crate::collections::MutMap<u32, Box<str>>> =
static ref DEBUG_MODULE_ID_NAMES: std::sync::Mutex<roc_collections::all::MutMap<u32, Box<str>>> =
// This stores a u32 key instead of a ModuleId key so that if there's
// a problem with ModuleId's Debug implementation, logging this for diagnostic
// purposes won't recursively trigger ModuleId's Debug instance in the course of printing
// this out.
std::sync::Mutex::new(crate::collections::MutMap::default());
std::sync::Mutex::new(roc_collections::all::MutMap::default());
}
#[derive(Debug)]
@ -195,12 +195,12 @@ lazy_static! {
/// This is used in Debug builds only, to let us have a Debug instance
/// which displays not only the Module ID, but also the Module Name which
/// corresponds to that ID.
static ref DEBUG_IDENT_IDS_BY_MODULE_ID: std::sync::Mutex<crate::collections::MutMap<u32, IdentIds>> =
static ref DEBUG_IDENT_IDS_BY_MODULE_ID: std::sync::Mutex<roc_collections::all::MutMap<u32, IdentIds>> =
// This stores a u32 key instead of a ModuleId key so that if there's
// a problem with ModuleId's Debug implementation, logging this for diagnostic
// purposes won't recursively trigger ModuleId's Debug instance in the course of printing
// this out.
std::sync::Mutex::new(crate::collections::MutMap::default());
std::sync::Mutex::new(roc_collections::all::MutMap::default());
}
/// A globally unique ID that gets assigned to each module as it is loaded.

18
compiler/parse/Cargo.toml Normal file
View File

@ -0,0 +1,18 @@
[package]
name = "roc_parse"
version = "0.1.0"
authors = ["Richard Feldman <oss@rtfeldman.com>"]
edition = "2018"
[dependencies]
roc_collections = { path = "../collections" }
roc_region = { path = "../region" }
roc_module = { path = "../module" }
bumpalo = "2.6"
inlinable_string = "0.1.0"
[dev-dependencies]
pretty_assertions = "0.5.1 "
indoc = "0.3.3"
quickcheck = "0.8"
quickcheck_macros = "0.8"

View File

@ -1,11 +1,11 @@
use crate::module::header::ModuleName;
use crate::header::ModuleName;
use crate::ident::Ident;
use crate::operator::CalledVia;
use crate::operator::{BinOp, UnaryOp};
use crate::parse::ident::Ident;
use crate::region::{Loc, Region};
use bumpalo::collections::String;
use bumpalo::collections::Vec;
use bumpalo::Bump;
use roc_region::all::{Loc, Region};
#[derive(Clone, Debug, PartialEq)]
pub enum Module<'a> {

View File

@ -1,10 +1,10 @@
use crate::parse::ast::CommentOrNewline::{self, *};
use crate::parse::ast::Spaceable;
use crate::parse::parser::{self, and, unexpected, unexpected_eof, Parser, State};
use crate::region::Located;
use crate::ast::CommentOrNewline::{self, *};
use crate::ast::Spaceable;
use crate::parser::{self, and, unexpected, unexpected_eof, Parser, State};
use bumpalo::collections::string::String;
use bumpalo::collections::vec::Vec;
use bumpalo::Bump;
use roc_region::all::Located;
/// Parses the given expression with 0 or more (spaces/comments/newlines) before and/or after it.
/// Returns a Located<Expr> where the location is around the Expr, ignoring the spaces.

View File

@ -1,33 +1,22 @@
#[macro_use]
pub mod parser;
pub mod ast;
pub mod blankspace;
pub mod ident;
pub mod keyword;
pub mod module;
pub mod number_literal;
pub mod problems;
pub mod string_literal;
pub mod type_annotation;
use bumpalo::collections::string::String;
use crate::operator::{BinOp, CalledVia, UnaryOp};
use crate::parse::ast::{
use crate::ast::{
AssignedField, Attempting, CommentOrNewline, Def, Expr, Pattern, Spaceable, TypeAnnotation,
};
use crate::parse::blankspace::{
use crate::blankspace::{
space0, space0_after, space0_around, space0_before, space1, space1_around, space1_before,
};
use crate::parse::ident::{global_tag_or_ident, ident, lowercase_ident, Ident};
use crate::parse::number_literal::number_literal;
use crate::parse::parser::{
allocated, char, fail, not, not_followed_by, optional, sep_by1, string, then, unexpected,
use crate::ident::{global_tag_or_ident, ident, lowercase_ident, Ident};
use crate::keyword;
use crate::number_literal::number_literal;
use crate::operator::{BinOp, CalledVia, UnaryOp};
use crate::parser::{
self, allocated, char, fail, not, not_followed_by, optional, sep_by1, string, then, unexpected,
unexpected_eof, Either, Fail, FailReason, ParseResult, Parser, State,
};
use crate::region::{Located, Region};
use crate::type_annotation;
use bumpalo::collections::string::String;
use bumpalo::collections::Vec;
use bumpalo::Bump;
use roc_region::all::{Located, Region};
pub fn expr<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>> {
// Recursive parsers must not directly invoke functions which return (impl Parser),
@ -210,7 +199,7 @@ pub fn unary_op<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>> {
}
fn parse_expr<'a>(min_indent: u16, arena: &'a Bump, state: State<'a>) -> ParseResult<'a, Expr<'a>> {
let expr_parser = crate::parse::parser::map_with_arena(
let expr_parser = crate::parser::map_with_arena(
and!(
// First parse the body without operators, then try to parse possible operators after.
move |arena, state| loc_parse_expr_body_without_operators(min_indent, arena, state),
@ -516,7 +505,7 @@ fn annotation_or_alias<'a>(
region: Region,
loc_ann: Located<TypeAnnotation<'a>>,
) -> Def<'a> {
use crate::parse::ast::Pattern::*;
use crate::ast::Pattern::*;
match pattern {
// Type aliases initially parse as either global tags
@ -887,15 +876,10 @@ fn number_pattern<'a>() -> impl Parser<'a, Pattern<'a>> {
}
fn string_pattern<'a>() -> impl Parser<'a, Pattern<'a>> {
map!(
crate::parse::string_literal::parse(),
|result| match result {
crate::parse::string_literal::StringLiteral::Line(string) =>
Pattern::StrLiteral(string),
crate::parse::string_literal::StringLiteral::Block(lines) =>
Pattern::BlockStrLiteral(lines),
}
)
map!(crate::string_literal::parse(), |result| match result {
crate::string_literal::StringLiteral::Line(string) => Pattern::StrLiteral(string),
crate::string_literal::StringLiteral::Block(lines) => Pattern::BlockStrLiteral(lines),
})
}
fn underscore_pattern<'a>() -> impl Parser<'a, Pattern<'a>> {
@ -958,7 +942,7 @@ fn ident_pattern<'a>() -> impl Parser<'a, Pattern<'a>> {
mod when {
use super::*;
use crate::parse::ast::WhenBranch;
use crate::ast::WhenBranch;
/// Parser for when expressions.
pub fn expr<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>> {
@ -1420,7 +1404,7 @@ pub fn colon_with_indent<'a>() -> impl Parser<'a, u16> {
}
}
fn ident_to_expr<'a>(arena: &'a Bump, src: Ident<'a>) -> Expr<'a> {
pub fn ident_to_expr<'a>(arena: &'a Bump, src: Ident<'a>) -> Expr<'a> {
match src {
Ident::GlobalTag(string) => Expr::GlobalTag(string),
Ident::PrivateTag(string) => Expr::PrivateTag(string),
@ -1614,7 +1598,7 @@ pub fn record_literal<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>> {
}
/// This is mainly for matching tags in closure params, e.g. \@Foo -> ...
fn private_tag<'a>() -> impl Parser<'a, &'a str> {
pub fn private_tag<'a>() -> impl Parser<'a, &'a str> {
map_with_arena!(
skip_first!(char('@'), global_tag()),
|arena: &'a Bump, name: &'a str| {
@ -1628,16 +1612,13 @@ fn private_tag<'a>() -> impl Parser<'a, &'a str> {
}
/// This is mainly for matching tags in closure params, e.g. \Foo -> ...
fn global_tag<'a>() -> impl Parser<'a, &'a str> {
pub fn global_tag<'a>() -> impl Parser<'a, &'a str> {
global_tag_or_ident(|first_char| first_char.is_uppercase())
}
pub fn string_literal<'a>() -> impl Parser<'a, Expr<'a>> {
map!(
crate::parse::string_literal::parse(),
|result| match result {
crate::parse::string_literal::StringLiteral::Line(string) => Expr::Str(string),
crate::parse::string_literal::StringLiteral::Block(lines) => Expr::BlockStr(lines),
}
)
map!(crate::string_literal::parse(), |result| match result {
crate::string_literal::StringLiteral::Line(string) => Expr::Str(string),
crate::string_literal::StringLiteral::Block(lines) => Expr::BlockStr(lines),
})
}

View File

@ -1,7 +1,7 @@
use crate::parse::ast::CommentOrNewline;
use crate::region::Loc;
use crate::ast::CommentOrNewline;
use bumpalo::collections::Vec;
use inlinable_string::InlinableString;
use roc_region::all::Loc;
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
pub struct ModuleName<'a>(&'a str);

View File

@ -1,13 +1,11 @@
use crate::collections::arena_join;
use crate::parse::ast::Attempting;
use crate::parse::keyword;
use crate::parse::parser::{
unexpected, unexpected_eof, Fail, FailReason, ParseResult, Parser, State,
};
use crate::region::Region;
use crate::ast::Attempting;
use crate::keyword;
use crate::parser::{unexpected, unexpected_eof, Fail, FailReason, ParseResult, Parser, State};
use bumpalo::collections::string::String;
use bumpalo::collections::vec::Vec;
use bumpalo::Bump;
use roc_collections::all::arena_join;
use roc_region::all::Region;
/// The parser accepts all of these in any position where any one of them could
/// appear. This way, canonicalization can give more helpful error messages like

14
compiler/parse/src/lib.rs Normal file
View File

@ -0,0 +1,14 @@
#[macro_use]
pub mod parser;
pub mod ast;
pub mod blankspace;
pub mod expr;
pub mod header;
pub mod ident;
pub mod keyword;
pub mod module;
pub mod number_literal;
pub mod operator;
pub mod problems;
pub mod string_literal;
pub mod type_annotation;

View File

@ -1,16 +1,14 @@
use crate::module::header::ModuleName;
use crate::parse;
use crate::parse::ast::{
use crate::ast::{
AppHeader, Attempting, CommentOrNewline, Def, ExposesEntry, ImportsEntry, InterfaceHeader,
Module,
};
use crate::parse::blankspace::{space0_around, space1};
use crate::parse::ident::unqualified_ident;
use crate::parse::parser::{
self, char, loc, optional, string, unexpected, unexpected_eof, Parser, State,
};
use crate::region::Located;
use crate::blankspace::{space0_around, space1};
use crate::expr::def;
use crate::header::ModuleName;
use crate::ident::unqualified_ident;
use crate::parser::{self, char, loc, optional, string, unexpected, unexpected_eof, Parser, State};
use bumpalo::collections::{String, Vec};
use roc_region::all::Located;
pub fn header<'a>() -> impl Parser<'a, Module<'a>> {
one_of!(interface_module(), app_module())
@ -136,7 +134,7 @@ fn app_header<'a>() -> impl Parser<'a, AppHeader<'a>> {
#[inline(always)]
pub fn module_defs<'a>() -> impl Parser<'a, Vec<'a, Located<Def<'a>>>> {
zero_or_more!(space0_around(loc(parse::def(0)), 0))
zero_or_more!(space0_around(loc(def(0)), 0))
}
#[inline(always)]

View File

@ -1,5 +1,5 @@
use crate::parse::ast::{Attempting, Base, Expr};
use crate::parse::parser::{unexpected, unexpected_eof, ParseResult, Parser, State};
use crate::ast::{Attempting, Base, Expr};
use crate::parser::{unexpected, unexpected_eof, ParseResult, Parser, State};
use std::char;
pub fn number_literal<'a>() -> impl Parser<'a, Expr<'a>> {

View File

@ -1,7 +1,7 @@
use crate::parse::ast::Attempting;
use crate::region::{Located, Region};
use crate::ast::Attempting;
use bumpalo::collections::vec::Vec;
use bumpalo::Bump;
use roc_region::all::{Located, Region};
use std::{char, u16};
/// A position in a source file.
@ -575,8 +575,8 @@ where
#[macro_export]
macro_rules! loc {
($parser:expr) => {
move |arena, state: $crate::parse::parser::State<'a>| {
use $crate::region::{Located, Region};
move |arena, state: $crate::parser::State<'a>| {
use roc_region::all::{Located, Region};
let start_col = state.column;
let start_line = state.line;
@ -604,8 +604,8 @@ macro_rules! loc {
#[macro_export]
macro_rules! skip_first {
($p1:expr, $p2:expr) => {
move |arena, state: $crate::parse::parser::State<'a>| {
use $crate::parse::parser::Fail;
move |arena, state: $crate::parser::State<'a>| {
use $crate::parser::Fail;
let original_attempting = state.attempting;
@ -637,8 +637,8 @@ macro_rules! skip_first {
#[macro_export]
macro_rules! skip_second {
($p1:expr, $p2:expr) => {
move |arena, state: $crate::parse::parser::State<'a>| {
use $crate::parse::parser::Fail;
move |arena, state: $crate::parser::State<'a>| {
use $crate::parser::Fail;
let original_attempting = state.attempting;
@ -679,17 +679,17 @@ macro_rules! collection {
// changed by the formatter back into `[]`.
//
// We don't allow newlines or comments in the middle of empty
// collections because those are normally stored in an Expr,
// roc_collections because those are normally stored in an Expr,
// and there's no Expr in which to store them in an empty collection!
//
// We could change the AST to add extra storage specifically to
// support empty literals containing newlines or comments, but this
// does not seem worth even the tiniest regression in compiler performance.
zero_or_more!($crate::parse::parser::char(' ')),
zero_or_more!($crate::parser::char(' ')),
skip_second!(
$crate::parse::parser::sep_by0(
$crate::parser::sep_by0(
$delimiter,
$crate::parse::blankspace::space0_around($elem, $min_indent)
$crate::blankspace::space0_around($elem, $min_indent)
),
$closing_brace
)
@ -701,8 +701,8 @@ macro_rules! collection {
#[macro_export]
macro_rules! and {
($p1:expr, $p2:expr) => {
move |arena: &'a bumpalo::Bump, state: $crate::parse::parser::State<'a>| {
use $crate::parse::parser::Fail;
move |arena: &'a bumpalo::Bump, state: $crate::parser::State<'a>| {
use $crate::parser::Fail;
// We have to clone this because if the first parser passes and then
// the second one fails, we need to revert back to the original state.
@ -734,7 +734,7 @@ macro_rules! and {
#[macro_export]
macro_rules! one_of {
($p1:expr, $p2:expr) => {
move |arena: &'a bumpalo::Bump, state: $crate::parse::parser::State<'a>| {
move |arena: &'a bumpalo::Bump, state: $crate::parser::State<'a>| {
let original_attempting = state.attempting;
match $p1.parse(arena, state) {
@ -840,8 +840,8 @@ macro_rules! one_or_more {
#[macro_export]
macro_rules! attempt {
($attempting:expr, $parser:expr) => {
move |arena, state: $crate::parse::parser::State<'a>| {
use crate::parse::parser::State;
move |arena, state: $crate::parser::State<'a>| {
use crate::parser::State;
let original_attempting = state.attempting;
@ -871,8 +871,8 @@ macro_rules! attempt {
#[macro_export]
macro_rules! either {
($p1:expr, $p2:expr) => {
move |arena: &'a bumpalo::Bump, state: $crate::parse::parser::State<'a>| {
use $crate::parse::parser::Fail;
move |arena: &'a bumpalo::Bump, state: $crate::parser::State<'a>| {
use $crate::parser::Fail;
let original_attempting = state.attempting;
@ -906,14 +906,11 @@ macro_rules! between {
macro_rules! record_field {
($val_parser:expr, $min_indent:expr) => {
move |arena: &'a bumpalo::Bump,
state: $crate::parse::parser::State<'a>|
-> $crate::parse::parser::ParseResult<
'a,
$crate::parse::ast::AssignedField<'a, _>,
> {
use $crate::parse::ast::AssignedField::*;
use $crate::parse::blankspace::{space0, space0_before};
use $crate::parse::ident::lowercase_ident;
state: $crate::parser::State<'a>|
-> $crate::parser::ParseResult<'a, $crate::ast::AssignedField<'a, _>> {
use $crate::ast::AssignedField::*;
use $crate::blankspace::{space0, space0_before};
use $crate::ident::lowercase_ident;
// You must have a field name, e.g. "email"
let (loc_label, state) = loc!(lowercase_ident()).parse(arena, state)?;
@ -921,7 +918,7 @@ macro_rules! record_field {
let (spaces, state) = space0($min_indent).parse(arena, state)?;
// Having a value is optional; both `{ email }` and `{ email: blah }` work.
// (This is true in both literals and types.)
let (opt_loc_val, state) = $crate::parse::parser::optional(skip_first!(
let (opt_loc_val, state) = $crate::parser::optional(skip_first!(
char(':'),
space0_before($val_parser, $min_indent)
))
@ -962,23 +959,23 @@ macro_rules! record_without_update {
macro_rules! record {
($val_parser:expr, $min_indent:expr) => {
skip_first!(
$crate::parse::parser::char('{'),
$crate::parser::char('{'),
and!(
// You can optionally have an identifier followed by an '&' to
// make this a record update, e.g. { Foo.user & username: "blah" }.
$crate::parse::parser::optional(skip_second!(
$crate::parse::blankspace::space0_around(
$crate::parser::optional(skip_second!(
$crate::blankspace::space0_around(
// We wrap the ident in an Expr here,
// so that we have a Spaceable value to work with,
// and then in canonicalization verify that it's an Expr::Var
// (and not e.g. an `Expr::Access`) and extract its string.
loc!(map_with_arena!(
$crate::parse::ident(),
$crate::parse::ident_to_expr
$crate::expr::ident(),
$crate::expr::ident_to_expr
)),
$min_indent
),
$crate::parse::parser::char('&')
$crate::parser::char('&')
)),
loc!(skip_first!(
// We specifically allow space characters inside here, so that
@ -986,22 +983,22 @@ macro_rules! record {
// changed by the formatter back into `{}`.
//
// We don't allow newlines or comments in the middle of empty
// collections because those are normally stored in an Expr,
// roc_collections because those are normally stored in an Expr,
// and there's no Expr in which to store them in an empty collection!
//
// We could change the AST to add extra storage specifically to
// support empty literals containing newlines or comments, but this
// does not seem worth even the tiniest regression in compiler performance.
zero_or_more!($crate::parse::parser::char(' ')),
zero_or_more!($crate::parser::char(' ')),
skip_second!(
$crate::parse::parser::sep_by0(
$crate::parse::parser::char(','),
$crate::parse::blankspace::space0_around(
$crate::parser::sep_by0(
$crate::parser::char(','),
$crate::blankspace::space0_around(
loc!(record_field!($val_parser, $min_indent)),
$min_indent
)
),
$crate::parse::parser::char('}')
$crate::parser::char('}')
)
))
)

View File

@ -1,4 +1,4 @@
use crate::region::Loc;
use roc_region::all::Loc;
pub type Problems = Vec<Loc<Problem>>;

View File

@ -1,5 +1,5 @@
use crate::parse::ast::Attempting;
use crate::parse::parser::{unexpected, unexpected_eof, ParseResult, Parser, State};
use crate::ast::Attempting;
use crate::parser::{unexpected, unexpected_eof, ParseResult, Parser, State};
use bumpalo::collections::vec::Vec;
use bumpalo::Bump;
use std::char;

View File

@ -1,17 +1,17 @@
use crate::collections::arena_join;
use crate::parse::ast::{AssignedField, Attempting, CommentOrNewline, Tag, TypeAnnotation};
use crate::parse::blankspace::{space0_around, space0_before, space1, space1_before};
use crate::parse::ident::join_module_parts;
use crate::parse::keyword;
use crate::parse::parser::{
use crate::ast::{AssignedField, Attempting, CommentOrNewline, Tag, TypeAnnotation};
use crate::blankspace::{space0_around, space0_before, space1, space1_before};
use crate::expr::{global_tag, private_tag};
use crate::ident::join_module_parts;
use crate::keyword;
use crate::parser::{
allocated, char, not, optional, string, unexpected, unexpected_eof, Either, ParseResult,
Parser, State,
};
use crate::parse::{global_tag, private_tag};
use crate::region::{Located, Region};
use bumpalo::collections::string::String;
use bumpalo::collections::vec::Vec;
use bumpalo::Bump;
use roc_collections::all::arena_join;
use roc_region::all::{Located, Region};
pub fn located<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>>> {
expression(min_indent)
@ -152,7 +152,7 @@ fn tag_type<'a>(min_indent: u16) -> impl Parser<'a, Tag<'a>> {
#[inline(always)]
fn record_type<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>> {
use crate::parse::type_annotation::TypeAnnotation::*;
use crate::type_annotation::TypeAnnotation::*;
map!(
and!(
@ -204,7 +204,7 @@ fn applied_type<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>> {
}
fn expression<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>>> {
use crate::parse::blankspace::space0;
use crate::blankspace::space0;
move |arena, state: State<'a>| {
let (first, state) = space0_before(term(min_indent), min_indent).parse(arena, state)?;
let (rest, state) = zero_or_more!(skip_first!(

View File

@ -0,0 +1,23 @@
extern crate bumpalo;
use self::bumpalo::Bump;
use roc_parse::ast::{self, Attempting};
use roc_parse::blankspace::space0_before;
use roc_parse::parser::{loc, Fail, Parser, State};
use roc_region::all::Located;
#[allow(dead_code)]
pub fn parse_with<'a>(arena: &'a Bump, input: &'a str) -> Result<ast::Expr<'a>, Fail> {
parse_loc_with(arena, input).map(|loc_expr| loc_expr.value)
}
#[allow(dead_code)]
pub fn parse_loc_with<'a>(arena: &'a Bump, input: &'a str) -> Result<Located<ast::Expr<'a>>, Fail> {
let state = State::new(&input, Attempting::Module);
let parser = space0_before(loc(roc_parse::expr::expr(0)), 0);
let answer = parser.parse(&arena, state);
answer
.map(|(loc_expr, _)| loc_expr)
.map_err(|(fail, _)| fail)
}

View File

@ -3,13 +3,14 @@ extern crate pretty_assertions;
#[macro_use]
extern crate indoc;
extern crate bumpalo;
extern crate roc;
extern crate quickcheck;
#[macro_use(quickcheck)]
extern crate quickcheck_macros;
extern crate roc_module;
extern crate roc_parse;
mod helpers;
#[cfg(test)]
@ -17,20 +18,20 @@ mod test_parse {
use crate::helpers::parse_with;
use bumpalo::collections::vec::Vec;
use bumpalo::{self, Bump};
use roc::module::header::ModuleName;
use roc::operator::BinOp::*;
use roc::operator::CalledVia;
use roc::operator::UnaryOp;
use roc::parse::ast::AssignedField::*;
use roc::parse::ast::CommentOrNewline::*;
use roc::parse::ast::Expr::{self, *};
use roc::parse::ast::Pattern::{self, *};
use roc::parse::ast::{
use roc_parse::ast::AssignedField::*;
use roc_parse::ast::CommentOrNewline::*;
use roc_parse::ast::Expr::{self, *};
use roc_parse::ast::Pattern::{self, *};
use roc_parse::ast::{
Attempting, Def, InterfaceHeader, Spaceable, Tag, TypeAnnotation, WhenBranch,
};
use roc::parse::module::{interface_header, module_defs};
use roc::parse::parser::{Fail, FailReason, Parser, State};
use roc::region::{Located, Region};
use roc_parse::header::ModuleName;
use roc_parse::module::{interface_header, module_defs};
use roc_parse::operator::BinOp::*;
use roc_parse::operator::CalledVia;
use roc_parse::operator::UnaryOp;
use roc_parse::parser::{Fail, FailReason, Parser, State};
use roc_region::all::{Located, Region};
use std::{f64, i64};
fn assert_parses_to<'a>(input: &'a str, expected_expr: Expr<'a>) {
@ -2135,7 +2136,7 @@ mod test_parse {
#[test]
fn standalone_module_defs() {
use roc::parse::ast::Def::*;
use roc_parse::ast::Def::*;
let arena = Bump::new();
let newlines1 = bumpalo::vec![in &arena; Newline, Newline];

View File

@ -0,0 +1,6 @@
[package]
name = "roc_region"
version = "0.1.0"
authors = ["Richard Feldman <oss@rtfeldman.com>"]
edition = "2018"

View File

@ -0,0 +1 @@
pub mod all;

View File

@ -1,9 +1,9 @@
use crate::can::ident::TagName;
use crate::collections::{default_hasher, MutMap};
use crate::module::symbol::Symbol;
use crate::region::{Located, Region};
use crate::solve::{BuiltinAlias, SolvedType};
use crate::subs::VarId;
use roc_collections::all::{default_hasher, MutMap};
use roc_module::ident::TagName;
use roc_module::symbol::Symbol;
use roc_region::all::{Located, Region};
use std::collections::HashMap;
#[derive(Clone, Copy)]

View File

@ -1,15 +1,15 @@
use crate::can;
use crate::can::env::Env;
use crate::can::ident::Ident;
use crate::can::ident::{Lowercase, TagName};
use crate::can::scope::Scope;
use crate::collections::{ImMap, MutMap, MutSet, SendMap};
use crate::module::symbol::Symbol;
use crate::parse::ast::{AssignedField, Tag, TypeAnnotation};
use crate::region::Located;
use crate::region::Region;
use crate::subs::{VarStore, Variable};
use crate::types::{Alias, Problem, Type};
use roc_collections::all::{ImMap, MutMap, MutSet, SendMap};
use roc_module::ident::Ident;
use roc_module::ident::{Lowercase, TagName};
use roc_module::symbol::Symbol;
use roc_parse::ast::{AssignedField, Tag, TypeAnnotation};
use roc_region::all::Located;
use roc_region::all::Region;
#[derive(Clone, Debug, PartialEq)]
pub struct Annotation {
@ -23,7 +23,7 @@ pub struct Annotation {
pub fn canonicalize_annotation(
env: &mut Env,
scope: &mut Scope,
annotation: &crate::parse::ast::TypeAnnotation,
annotation: &roc_parse::ast::TypeAnnotation,
region: Region,
var_store: &VarStore,
) -> Annotation {
@ -69,7 +69,7 @@ pub fn canonicalize_annotation(
#[allow(clippy::too_many_arguments)]
fn can_annotation_help(
env: &mut Env,
annotation: &crate::parse::ast::TypeAnnotation,
annotation: &roc_parse::ast::TypeAnnotation,
region: Region,
scope: &mut Scope,
var_store: &VarStore,
@ -77,7 +77,7 @@ fn can_annotation_help(
local_aliases: &mut SendMap<Symbol, Alias>,
references: &mut MutSet<Symbol>,
) -> Type {
use crate::parse::ast::TypeAnnotation::*;
use roc_parse::ast::TypeAnnotation::*;
match annotation {
Function(argument_types, return_type) => {
@ -360,7 +360,7 @@ fn can_assigned_field<'a>(
field_types: &mut SendMap<Lowercase, Type>,
references: &mut MutSet<Symbol>,
) {
use crate::parse::ast::AssignedField::*;
use roc_parse::ast::AssignedField::*;
match field {
LabeledValue(field_name, _, annotation) => {

View File

@ -5,20 +5,20 @@ use crate::can::expr::{
canonicalize_expr, local_successors, references_from_call, references_from_local, Output,
Recursive,
};
use crate::can::ident::{Ident, Lowercase};
use crate::can::pattern::PatternType;
use crate::can::pattern::{bindings_from_patterns, canonicalize_pattern, Pattern};
use crate::can::problem::Problem;
use crate::can::problem::RuntimeError;
use crate::can::procedure::References;
use crate::can::scope::Scope;
use crate::collections::{default_hasher, ImMap, ImSet, MutMap, MutSet, SendMap};
use crate::graph::{strongly_connected_components, topological_sort_into_groups};
use crate::module::symbol::Symbol;
use crate::parse::ast;
use crate::region::{Located, Region};
use crate::subs::{VarStore, Variable};
use crate::types::{Alias, Type};
use roc_collections::all::{default_hasher, ImMap, ImSet, MutMap, MutSet, SendMap};
use roc_module::ident::{Ident, Lowercase};
use roc_module::symbol::Symbol;
use roc_parse::ast;
use roc_region::all::{Located, Region};
use std::collections::HashMap;
use std::fmt::Debug;
@ -121,7 +121,7 @@ pub fn canonicalize_defs<'a>(
// This naturally handles recursion too, because a given exper which refers
// to itself won't be processed until after its def has been added to scope.
use crate::parse::ast::Def::*;
use roc_parse::ast::Def::*;
// Record both the original and final idents from the scope,
// so we can diff them while detecting unused defs.
@ -1249,7 +1249,7 @@ fn to_pending_def<'a>(
scope: &mut Scope,
pattern_type: PatternType,
) -> PendingDef<'a> {
use crate::parse::ast::Def::*;
use roc_parse::ast::Def::*;
match def {
Annotation(loc_pattern, loc_ann) => {

View File

@ -1,9 +1,9 @@
use crate::can::problem::{Problem, RuntimeError};
use crate::can::procedure::References;
use crate::collections::{MutMap, MutSet};
use crate::module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
use crate::region::Region;
use inlinable_string::InlinableString;
use roc_collections::all::{MutMap, MutSet};
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
use roc_region::all::Region;
/// The canonicalization environment for a particular module.
pub struct Env<'a> {

View File

@ -1,6 +1,5 @@
use crate::can::def::{can_defs_with_return, Def};
use crate::can::env::Env;
use crate::can::ident::{Lowercase, TagName};
use crate::can::num::{
finish_parsing_base, finish_parsing_float, finish_parsing_int, float_expr_from_result,
int_expr_from_result,
@ -10,13 +9,14 @@ use crate::can::pattern::{canonicalize_pattern, Pattern};
use crate::can::problem::{Problem, RuntimeError};
use crate::can::procedure::References;
use crate::can::scope::Scope;
use crate::collections::{ImSet, MutMap, MutSet, SendMap};
use crate::module::symbol::Symbol;
use crate::operator::CalledVia;
use crate::parse::ast;
use crate::region::{Located, Region};
use crate::subs::{VarStore, Variable};
use crate::types::Alias;
use roc_collections::all::{ImSet, MutMap, MutSet, SendMap};
use roc_module::ident::{Lowercase, TagName};
use roc_module::symbol::Symbol;
use roc_parse::ast;
use roc_parse::operator::CalledVia;
use roc_region::all::{Located, Region};
use std::fmt::Debug;
use std::i64;
use std::ops::Neg;
@ -842,7 +842,7 @@ fn canonicalize_field<'a>(
field: &'a ast::AssignedField<'a, ast::Expr<'a>>,
region: Region,
) -> (Lowercase, Located<Expr>, Output, Variable) {
use crate::parse::ast::AssignedField::*;
use roc_parse::ast::AssignedField::*;
match field {
// Both a label and a value, e.g. `{ name: "blah" }`

View File

@ -2,7 +2,6 @@ pub mod annotation;
pub mod def;
pub mod env;
pub mod expr;
pub mod ident;
pub mod module;
pub mod num;
pub mod operator;

View File

@ -1,19 +1,19 @@
use crate::can::def::{canonicalize_defs, sort_can_defs, Declaration};
use crate::can::env::Env;
use crate::can::expr::Output;
use crate::can::ident::Ident;
use crate::can::ident::Lowercase;
use crate::can::operator::desugar_def;
use crate::can::pattern::PatternType;
use crate::can::problem::{Problem, RuntimeError};
use crate::can::scope::Scope;
use crate::collections::{MutMap, MutSet};
use crate::module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
use crate::parse::ast;
use crate::region::{Located, Region};
use crate::subs::{VarStore, Variable};
use crate::types::Alias;
use bumpalo::Bump;
use roc_collections::all::{MutMap, MutSet};
use roc_module::ident::Ident;
use roc_module::ident::Lowercase;
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
use roc_parse::ast;
use roc_region::all::{Located, Region};
#[derive(Debug)]
pub struct ModuleOutput {

View File

@ -2,8 +2,8 @@ use crate::can::env::Env;
use crate::can::expr::Expr;
use crate::can::problem::Problem;
use crate::can::problem::RuntimeError::*;
use crate::parse::ast::Base;
use crate::subs::VarStore;
use roc_parse::ast::Base;
use std::i64;
#[inline(always)]

View File

@ -1,11 +1,11 @@
use crate::can::ident::ModuleName;
use crate::operator::BinOp::Pizza;
use crate::operator::{BinOp, CalledVia};
use crate::parse::ast::Expr::{self, *};
use crate::parse::ast::{AssignedField, Def, Pattern, WhenBranch};
use crate::region::{Located, Region};
use bumpalo::collections::Vec;
use bumpalo::Bump;
use roc_module::ident::ModuleName;
use roc_parse::ast::Expr::{self, *};
use roc_parse::ast::{AssignedField, Def, Pattern, WhenBranch};
use roc_parse::operator::BinOp::Pizza;
use roc_parse::operator::{BinOp, CalledVia};
use roc_region::all::{Located, Region};
// BinOp precedence logic adapted from Gluon by Markus Westerlind, MIT licensed
// https://github.com/gluon-lang/gluon
@ -32,7 +32,7 @@ fn new_op_expr<'a>(
}
pub fn desugar_def<'a>(arena: &'a Bump, def: &'a Def<'a>) -> Def<'a> {
use crate::parse::ast::Def::*;
use roc_parse::ast::Def::*;
match def {
Body(loc_pattern, loc_expr) | Nested(Body(loc_pattern, loc_expr)) => {
@ -195,7 +195,7 @@ pub fn desugar_expr<'a>(arena: &'a Bump, loc_expr: &'a Located<Expr<'a>>) -> &'a
})
}
UnaryOp(loc_arg, loc_op) | Nested(UnaryOp(loc_arg, loc_op)) => {
use crate::operator::UnaryOp::*;
use roc_parse::operator::UnaryOp::*;
let region = loc_op.region;
let op = loc_op.value;
@ -257,7 +257,7 @@ fn desugar_field<'a>(
arena: &'a Bump,
field: &'a AssignedField<'a, Expr<'a>>,
) -> AssignedField<'a, Expr<'a>> {
use crate::parse::ast::AssignedField::*;
use roc_parse::ast::AssignedField::*;
match field {
LabeledValue(loc_str, spaces, loc_expr) => AssignedField::LabeledValue(
@ -321,7 +321,7 @@ fn binop_to_function(binop: BinOp) -> (&'static str, &'static str) {
}
fn desugar_bin_op<'a>(arena: &'a Bump, loc_expr: &'a Located<Expr<'_>>) -> &'a Located<Expr<'a>> {
use crate::operator::Associativity::*;
use roc_parse::operator::Associativity::*;
use std::cmp::Ordering;
let mut infixes = Infixes::new(loc_expr);

View File

@ -1,13 +1,13 @@
use crate::can::env::Env;
use crate::can::ident::{Ident, Lowercase, TagName};
use crate::can::num::{finish_parsing_base, finish_parsing_float, finish_parsing_int};
use crate::can::problem::{Problem, RuntimeError};
use crate::can::scope::Scope;
use crate::module::symbol::Symbol;
use crate::parse::ast;
use crate::region::{Located, Region};
use crate::subs::VarStore;
use crate::subs::Variable;
use roc_module::ident::{Ident, Lowercase, TagName};
use roc_module::symbol::Symbol;
use roc_parse::ast;
use roc_region::all::{Located, Region};
/// A pattern, including possible problems (e.g. shadowing) so that
/// codegen can generate a runtime error if this pattern is reached.
@ -87,7 +87,7 @@ pub fn canonicalize_pattern<'a>(
pattern: &ast::Pattern<'a>,
region: Region,
) -> Located<Pattern> {
use crate::parse::ast::Pattern::*;
use roc_parse::ast::Pattern::*;
use PatternType::*;
let can_pattern = match pattern {

View File

@ -1,10 +1,10 @@
use crate::can::ident::Ident;
use crate::can::pattern::PatternType;
use crate::module::symbol::{ModuleId, Symbol};
use crate::operator::BinOp;
use crate::region::{Located, Region};
use crate::types;
use inlinable_string::InlinableString;
use roc_module::ident::Ident;
use roc_module::symbol::{ModuleId, Symbol};
use roc_parse::operator::BinOp;
use roc_region::all::{Located, Region};
/// Problems that can occur in the course of canonicalization.
#[derive(Clone, Debug, PartialEq)]

View File

@ -1,9 +1,9 @@
use crate::can::expr::Expr;
use crate::can::pattern::Pattern;
use crate::collections::ImSet;
use crate::module::symbol::Symbol;
use crate::region::{Located, Region};
use crate::subs::Variable;
use roc_collections::all::ImSet;
use roc_module::symbol::Symbol;
use roc_region::all::{Located, Region};
#[derive(Clone, Debug, PartialEq)]
pub struct Procedure {

View File

@ -1,10 +1,10 @@
use crate::can::ident::{Ident, Lowercase};
use crate::can::problem::RuntimeError;
use crate::collections::ImMap;
use crate::module::symbol::{IdentIds, ModuleId, Symbol};
use crate::region::{Located, Region};
use crate::subs::Variable;
use crate::types::{Alias, Type};
use roc_collections::all::ImMap;
use roc_module::ident::{Ident, Lowercase};
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
use roc_region::all::{Located, Region};
#[derive(Clone, Debug, PartialEq)]
pub struct Scope {

View File

@ -1,13 +1,13 @@
// use bumpalo::collections::string::String;
// use bumpalo::collections::vec::Vec;
use crate::parse::ast::Expr;
use bumpalo::Bump;
// use crate::parse::ast::{Attempting, Expr};
// use crate::parse::ident;
// use crate::parse::parser::{unexpected, unexpected_eof, Fail, Parser, State};
// use crate::parse::problems::{Problem, Problems};
// use crate::region::{Loc, Region};
use crate::region::Region;
use roc_parse::ast::Expr;
// use roc_parse::ast::{Attempting, Expr};
// use roc_parse::ident;
// use roc_parse::parser::{unexpected, unexpected_eof, Fail, Parser, State};
// use roc_parse::problems::{Problem, Problems};
// use roc_region::all::{Loc, Region};
use roc_region::all::Region;
// use std::char;
// use std::iter::Peekable;

View File

@ -1,11 +1,11 @@
use crate::collections::SendMap;
use crate::module::symbol::Symbol;
use crate::region::Region;
use crate::subs::Variable;
use crate::types::Constraint::{self, *};
use crate::types::Expected::{self, *};
use crate::types::Type::{self, *};
use crate::types::{LetConstraint, Reason};
use roc_collections::all::SendMap;
use roc_module::symbol::Symbol;
use roc_region::all::Region;
#[inline(always)]
pub fn int_literal(num_var: Variable, expected: Expected<Type>, region: Region) -> Constraint {

View File

@ -1,15 +1,11 @@
use crate::can::def::{Declaration, Def};
use crate::can::expr::Expr::{self, *};
use crate::can::expr::Field;
use crate::can::ident::{Lowercase, TagName};
use crate::can::pattern::Pattern;
use crate::collections::{ImMap, SendMap};
use crate::constrain::builtins::{
empty_list_type, float_literal, int_literal, list_type, str_type,
};
use crate::constrain::pattern::{constrain_pattern, PatternState};
use crate::module::symbol::{ModuleId, Symbol};
use crate::region::{Located, Region};
use crate::subs::Variable;
use crate::types::Alias;
use crate::types::AnnotationSource::{self, *};
@ -18,6 +14,10 @@ use crate::types::Expected::{self, *};
use crate::types::PReason;
use crate::types::Type::{self, *};
use crate::types::{LetConstraint, PExpected, Reason};
use roc_collections::all::{ImMap, SendMap};
use roc_module::ident::{Lowercase, TagName};
use roc_module::symbol::{ModuleId, Symbol};
use roc_region::all::{Located, Region};
/// This is for constraining Defs
#[derive(Default, Debug)]

View File

@ -1,15 +1,15 @@
use crate::builtins;
use crate::can::def::Declaration;
use crate::can::ident::Lowercase;
use crate::collections::{ImMap, MutMap, SendMap};
use crate::constrain::expr::constrain_decls;
use crate::module::symbol::{ModuleId, Symbol};
use crate::region::Located;
use crate::solve::{BuiltinAlias, SolvedAtom, SolvedType};
use crate::subs::{VarId, VarStore, Variable};
use crate::types::{Alias, Constraint, LetConstraint, Type};
use crate::uniqueness;
use crate::uniqueness::boolean_algebra::{Atom, Bool};
use roc_collections::all::{ImMap, MutMap, SendMap};
use roc_module::ident::Lowercase;
use roc_module::symbol::{ModuleId, Symbol};
use roc_region::all::Located;
#[inline(always)]
pub fn constrain_module(

View File

@ -1,12 +1,12 @@
use crate::can::ident::Lowercase;
use crate::can::pattern::Pattern::{self, *};
use crate::can::pattern::RecordDestruct;
use crate::collections::SendMap;
use crate::constrain::builtins;
use crate::module::symbol::Symbol;
use crate::region::{Located, Region};
use crate::subs::Variable;
use crate::types::{Constraint, Expected, PExpected, PatternCategory, Type};
use roc_collections::all::SendMap;
use roc_module::ident::Lowercase;
use roc_module::symbol::Symbol;
use roc_region::all::{Located, Region};
pub struct PatternState {
pub headers: SendMap<Symbol, Located<Type>>,

View File

@ -13,12 +13,12 @@ use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_codegen::Context;
use cranelift_module::{Backend, FuncId, Linkage, Module};
use crate::collections::ImMap;
use crate::crane::convert::{sig_from_layout, type_from_layout};
use crate::module::symbol::{Interns, Symbol};
use crate::mono::expr::{Expr, Proc, Procs};
use crate::mono::layout::{Builtin, Layout};
use crate::subs::{Subs, Variable};
use roc_collections::all::ImMap;
use roc_module::symbol::{Interns, Symbol};
type Scope = ImMap<Symbol, ScopeEntry>;

View File

@ -1,11 +1,11 @@
use crate::fmt::expr::{fmt_expr, is_multiline_expr};
use crate::fmt::pattern::fmt_pattern;
use crate::fmt::spaces::{fmt_spaces, newline, INDENT};
use crate::parse::ast::{Def, Expr};
use bumpalo::collections::String;
use roc_parse::ast::{Def, Expr};
pub fn fmt_def<'a>(buf: &mut String<'a>, def: &'a Def<'a>, indent: u16) {
use crate::parse::ast::Def::*;
use roc_parse::ast::Def::*;
match def {
Annotation(_, _) => panic!("TODO have format_def support Annotation"),

View File

@ -3,11 +3,11 @@ use crate::fmt::pattern::fmt_pattern;
use crate::fmt::spaces::{
add_spaces, fmt_comments_only, fmt_condition_spaces, fmt_spaces, is_comment, newline, INDENT,
};
use crate::operator;
use crate::operator::BinOp;
use crate::parse::ast::{AssignedField, Base, CommentOrNewline, Expr, Pattern, WhenBranch};
use crate::region::Located;
use bumpalo::collections::{String, Vec};
use roc_parse::ast::{AssignedField, Base, CommentOrNewline, Expr, Pattern, WhenBranch};
use roc_parse::operator;
use roc_parse::operator::BinOp;
use roc_region::all::Located;
pub fn fmt_expr<'a>(
buf: &mut String<'a>,
@ -391,7 +391,7 @@ pub fn fmt_field<'a>(
}
pub fn empty_line_before_expr<'a>(expr: &'a Expr<'a>) -> bool {
use crate::parse::ast::Expr::*;
use roc_parse::ast::Expr::*;
match expr {
SpaceBefore(_, spaces) => {
@ -444,7 +444,7 @@ pub fn is_multiline_pattern<'a>(pattern: &'a Pattern<'a>) -> bool {
}
pub fn is_multiline_expr<'a>(expr: &'a Expr<'a>) -> bool {
use crate::parse::ast::Expr::*;
use roc_parse::ast::Expr::*;
// TODO cache these answers using a Map<Pointer, bool>, so
// we don't have to traverse subexpressions repeatedly

View File

@ -1,7 +1,7 @@
use crate::fmt::spaces::{fmt_spaces, INDENT};
use crate::parse::ast::{AppHeader, ExposesEntry, ImportsEntry, InterfaceHeader, Module};
use crate::region::Located;
use bumpalo::collections::{String, Vec};
use roc_parse::ast::{AppHeader, ExposesEntry, ImportsEntry, InterfaceHeader, Module};
use roc_region::all::Located;
pub fn fmt_module<'a>(buf: &mut String<'a>, module: &'a Module<'a>) {
match module {
@ -127,7 +127,7 @@ fn fmt_exposes<'a>(
}
fn fmt_exposes_entry<'a>(buf: &mut String<'a>, entry: &'a ExposesEntry<'a>, indent: u16) {
use crate::parse::ast::ExposesEntry::*;
use roc_parse::ast::ExposesEntry::*;
match entry {
Ident(ident) => buf.push_str(ident),
@ -144,7 +144,7 @@ fn fmt_exposes_entry<'a>(buf: &mut String<'a>, entry: &'a ExposesEntry<'a>, inde
}
fn fmt_imports_entry<'a>(buf: &mut String<'a>, entry: &'a ImportsEntry<'a>, indent: u16) {
use crate::parse::ast::ImportsEntry::*;
use roc_parse::ast::ImportsEntry::*;
match entry {
Module(module, loc_exposes_entries) => {

View File

@ -1,6 +1,6 @@
use crate::fmt::spaces::{fmt_comments_only, fmt_spaces};
use crate::parse::ast::{Base, Pattern};
use bumpalo::collections::String;
use roc_parse::ast::{Base, Pattern};
pub fn fmt_pattern<'a>(
buf: &mut String<'a>,

View File

@ -1,5 +1,5 @@
use crate::parse::ast::CommentOrNewline;
use bumpalo::collections::String;
use roc_parse::ast::CommentOrNewline;
/// The number of spaces to indent.
pub const INDENT: u16 = 4;

View File

@ -22,7 +22,7 @@
// Secondarily, SipHash isn't the fastest hashing algorithm out there, so we can get
// slightly better performance by using a faster hasher.
use crate::collections::{default_hasher, BuildHasher, MutSet};
use roc_collections::all::{default_hasher, BuildHasher, MutSet};
use std::collections::{HashMap, HashSet, VecDeque};
use std::hash::Hash;
use std::mem;

View File

@ -1,7 +1,7 @@
use crate::collections::{MutMap, SendMap};
use crate::solve::{self, Solved};
use crate::subs::{Content, Subs, Variable};
use crate::types::{Constraint, Problem};
use roc_collections::all::{MutMap, SendMap};
pub fn infer_expr(
subs: Subs,

View File

@ -12,11 +12,7 @@
#![allow(clippy::large_enum_variant)]
pub mod can;
pub mod collections;
pub mod graph;
pub mod operator;
pub mod parse;
pub mod region;
pub mod uniqueness;
pub mod string;
@ -31,7 +27,6 @@ pub mod fmt;
pub mod infer;
pub mod llvm;
pub mod load;
pub mod module;
pub mod mono;
pub mod pretty_print_types;
pub mod solve;
@ -41,6 +36,3 @@ pub mod unify;
#[macro_use]
extern crate log;
#[macro_use]
extern crate lazy_static;

View File

@ -8,12 +8,12 @@ use inkwell::values::BasicValueEnum::{self, *};
use inkwell::values::{FunctionValue, IntValue, PointerValue};
use inkwell::{FloatPredicate, IntPredicate};
use crate::collections::ImMap;
use crate::llvm::convert::{basic_type_from_layout, get_fn_type};
use crate::module::symbol::{Interns, Symbol};
use crate::mono::expr::{Expr, Proc, Procs};
use crate::mono::layout::Layout;
use crate::subs::{Subs, Variable};
use roc_collections::all::ImMap;
use roc_module::symbol::{Interns, Symbol};
/// This is for Inkwell's FunctionValue::verify - we want to know the verification
/// output in debug builds, but we don't want it to print to stdout in release builds!

View File

@ -2,22 +2,22 @@ use crate::builtins;
use crate::builtins::StdLib;
use crate::can;
use crate::can::def::Declaration;
use crate::can::ident::{Ident, Lowercase, ModuleName};
use crate::can::module::{canonicalize_module_defs, ModuleOutput};
use crate::collections::{default_hasher, MutMap, MutSet, SendMap};
use crate::constrain::module::{
constrain_imported_aliases, constrain_imported_values, constrain_module, load_builtin_aliases,
Import,
};
use crate::module::symbol::{IdentIds, Interns, ModuleId, ModuleIds, Symbol};
use crate::parse::ast::{self, Attempting, ExposesEntry, ImportsEntry, InterfaceHeader};
use crate::parse::module::{self, module_defs};
use crate::parse::parser::{Fail, Parser, State};
use crate::region::{Located, Region};
use crate::solve::{self, BuiltinAlias, ExposedModuleTypes, Solved, SolvedType, SubsByModule};
use crate::subs::{Subs, VarStore, Variable};
use crate::types::{self, Alias, Constraint};
use bumpalo::Bump;
use roc_collections::all::{default_hasher, MutMap, MutSet, SendMap};
use roc_module::ident::{Ident, Lowercase, ModuleName};
use roc_module::symbol::{IdentIds, Interns, ModuleId, ModuleIds, Symbol};
use roc_parse::ast::{self, Attempting, ExposesEntry, ImportsEntry, InterfaceHeader};
use roc_parse::module::module_defs;
use roc_parse::parser::{Fail, Parser, State};
use roc_region::all::{Located, Region};
use std::collections::{HashMap, HashSet};
use std::fs::read_to_string;
use std::io;
@ -511,7 +511,7 @@ fn load_filename(
// without introducing a borrow error. ("let and return" is literally
// what the borrow checker suggested using here to fix the problem, so...)
#[allow(clippy::let_and_return)]
let answer = match module::header().parse(&arena, state) {
let answer = match roc_parse::module::header().parse(&arena, state) {
Ok((ast::Module::Interface { header }, state)) => {
let module_id = send_interface_header(header, state, module_ids, msg_tx);
@ -1067,7 +1067,7 @@ fn parse_and_constrain(
}
fn exposed_from_import(entry: &ImportsEntry<'_>) -> (ModuleName, Vec<Ident>) {
use crate::parse::ast::ImportsEntry::*;
use roc_parse::ast::ImportsEntry::*;
match entry {
Module(module_name, exposes) => {
@ -1088,7 +1088,7 @@ fn exposed_from_import(entry: &ImportsEntry<'_>) -> (ModuleName, Vec<Ident>) {
}
fn ident_from_exposed(entry: &ExposesEntry<'_>) -> Ident {
use crate::parse::ast::ExposesEntry::*;
use roc_parse::ast::ExposesEntry::*;
match entry {
Ident(ident) => (*ident).into(),

View File

@ -1,15 +1,13 @@
use crate::can::pattern::Pattern;
use crate::can::{
self,
ident::{Lowercase, TagName},
};
use crate::collections::MutMap;
use crate::module::symbol::{IdentIds, ModuleId, Symbol};
use crate::can::{self};
use crate::mono::layout::{Builtin, Layout};
use crate::region::Located;
use crate::subs::{Subs, Variable};
use crate::subs::{Content, Subs, Variable};
use bumpalo::collections::Vec;
use bumpalo::Bump;
use roc_collections::all::MutMap;
use roc_module::ident::{Lowercase, TagName};
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
use roc_region::all::Located;
pub type Procs<'a> = MutMap<Symbol, Option<Proc<'a>>>;
@ -211,7 +209,34 @@ fn from_can<'a>(
}
match from_can(env, loc_expr.value, procs, None) {
Expr::Load(proc_name) => Expr::CallByName(proc_name, args.into_bump_slice()),
Expr::Load(proc_name) => {
// Some functions can potentially mutate in-place.
// If we have one of those, switch to the in-place version if appropriate.
match proc_name {
Symbol::LIST_SET => {
let subs = &env.subs;
let fn_content = subs.get_without_compacting(fn_var).content;
match fn_content {
Content::Alias(Symbol::ATTR_ATTR, attr_args, _) => {
debug_assert!(attr_args.len() == 2);
let _is_unique =
match subs.get_without_compacting(attr_args[0].1).content {
Content::FlexVar(_) => true,
_ => false,
};
let _wrapped_var = attr_args[1].1;
Expr::CallByName(proc_name, args.into_bump_slice())
}
_ => Expr::CallByName(proc_name, args.into_bump_slice()),
}
}
_ => Expr::CallByName(proc_name, args.into_bump_slice()),
}
}
ptr => {
// Call by pointer - the closure was anonymous, e.g.
//

View File

@ -1,9 +1,9 @@
use crate::can::ident::{Lowercase, TagName};
use crate::collections::MutMap;
use crate::module::symbol::Symbol;
use crate::subs::{Content, FlatType, Subs, Variable};
use bumpalo::collections::Vec;
use bumpalo::Bump;
use roc_collections::all::MutMap;
use roc_module::ident::{Lowercase, TagName};
use roc_module::symbol::Symbol;
/// Types for code gen must be monomorphic. No type variables allowed!
#[derive(Clone, Debug, PartialEq, Eq)]

View File

@ -1,9 +1,9 @@
use crate::can::ident::{Lowercase, TagName};
use crate::collections::{ImSet, MutMap, MutSet};
use crate::module::symbol::{Interns, ModuleId, Symbol};
use crate::subs::{Content, FlatType, Subs, Variable};
use crate::types::name_type_var;
use crate::uniqueness::boolean_algebra::{Atom, Bool};
use roc_collections::all::{ImSet, MutMap, MutSet};
use roc_module::ident::{Lowercase, TagName};
use roc_module::symbol::{Interns, ModuleId, Symbol};
static WILDCARD: &str = "*";
static EMPTY_RECORD: &str = "{}";

View File

@ -1,7 +1,3 @@
use crate::can::ident::{Lowercase, TagName};
use crate::collections::{ImMap, MutMap, SendMap};
use crate::module::symbol::{ModuleId, Symbol};
use crate::region::{Located, Region};
use crate::subs::{Content, Descriptor, FlatType, Mark, OptVariable, Rank, Subs, VarId, Variable};
use crate::types::Alias;
use crate::types::Constraint::{self, *};
@ -9,6 +5,10 @@ use crate::types::Problem;
use crate::types::Type::{self, *};
use crate::unify::{unify, Unified};
use crate::uniqueness::boolean_algebra::{self, Atom};
use roc_collections::all::{ImMap, MutMap, SendMap};
use roc_module::ident::{Lowercase, TagName};
use roc_module::symbol::{ModuleId, Symbol};
use roc_region::all::{Located, Region};
// Type checking system adapted from Elm by Evan Czaplicki, BSD-3-Clause Licensed
// https://github.com/elm/compiler

View File

@ -1,9 +1,9 @@
use crate::can::ident::{Lowercase, TagName};
use crate::collections::{ImMap, ImSet, MutMap, MutSet, SendMap};
use crate::ena::unify::{InPlace, UnificationTable, UnifyKey};
use crate::module::symbol::Symbol;
use crate::types::{name_type_var, ErrorType, Problem, TypeExt};
use crate::uniqueness::boolean_algebra;
use roc_collections::all::{ImMap, ImSet, MutMap, MutSet, SendMap};
use roc_module::ident::{Lowercase, TagName};
use roc_module::symbol::Symbol;
use std::fmt;
use std::iter::{once, Iterator};
use std::sync::atomic::{AtomicU32, Ordering};

View File

@ -1,13 +1,13 @@
use crate::can::ident::{Ident, Lowercase, TagName};
use crate::can::pattern::Pattern;
use crate::collections::{ImMap, ImSet, MutSet, SendMap};
use crate::module::symbol::Symbol;
use crate::operator::{ArgSide, BinOp};
use crate::region::Located;
use crate::region::Region;
use crate::subs::{VarStore, Variable};
use crate::uniqueness::boolean_algebra;
use inlinable_string::InlinableString;
use roc_collections::all::{ImMap, ImSet, MutSet, SendMap};
use roc_module::ident::{Ident, Lowercase, TagName};
use roc_module::symbol::Symbol;
use roc_parse::operator::{ArgSide, BinOp};
use roc_region::all::Located;
use roc_region::all::Region;
use std::fmt;
pub const TYPE_NUM: &str = "Num";

View File

@ -1,10 +1,10 @@
use crate::can::ident::{Lowercase, TagName};
use crate::collections::{relative_complement, union, MutMap, SendSet};
use crate::module::symbol::Symbol;
use crate::subs::Content::{self, *};
use crate::subs::{Descriptor, FlatType, Mark, OptVariable, Subs, Variable};
use crate::types::{Mismatch, Problem};
use crate::uniqueness::boolean_algebra::{Atom, Bool};
use roc_collections::all::{relative_complement, union, MutMap, SendSet};
use roc_module::ident::{Lowercase, TagName};
use roc_module::symbol::Symbol;
use std::hash::Hash;
macro_rules! mismatch {

View File

@ -1,11 +1,11 @@
use crate::builtins;
use crate::builtins::StdLib;
use crate::can::ident::TagName;
use crate::collections::{default_hasher, MutMap};
use crate::module::symbol::Symbol;
use crate::region::{Located, Region};
use crate::solve::{BuiltinAlias, SolvedAtom, SolvedType};
use crate::subs::VarId;
use roc_collections::all::{default_hasher, MutMap};
use roc_module::ident::TagName;
use roc_module::symbol::Symbol;
use roc_region::all::{Located, Region};
use std::collections::HashMap;
/// Keep this up to date by hand!
@ -451,10 +451,7 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
add_type(
Symbol::LIST_GET_UNSAFE,
unique_function(
vec![list_type(UVAR1, TVAR1), int_type(UVAR2)],
attr_type(UVAR3, TVAR1),
),
unique_function(vec![list_type(UVAR1, TVAR1), int_type(UVAR2)], flex(TVAR1)),
);
// set : Attr (w | u | v) (List (Attr u a))

View File

@ -1,6 +1,6 @@
use self::Atom::*;
use crate::collections::SendSet;
use crate::subs::{Content, FlatType, Subs, Variable};
use roc_collections::all::SendSet;
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Bool(pub Atom, pub SendSet<Atom>);

View File

@ -1,12 +1,12 @@
use crate::collections::SendMap;
use crate::module::symbol::Symbol;
use crate::region::Region;
use crate::subs::Variable;
use crate::types::Constraint::{self, *};
use crate::types::Expected::{self, *};
use crate::types::Type::{self, *};
use crate::types::{LetConstraint, Reason};
use crate::uniqueness::boolean_algebra::Bool;
use roc_collections::all::SendMap;
use roc_module::symbol::Symbol;
use roc_region::all::Region;
#[inline(always)]
pub fn int_literal(num_var: Variable, expected: Expected<Type>, region: Region) -> Constraint {

View File

@ -1,12 +1,8 @@
use crate::can::def::{Declaration, Def};
use crate::can::expr::Expr;
use crate::can::expr::Field;
use crate::can::ident::{Ident, Lowercase, TagName};
use crate::can::pattern::{Pattern, RecordDestruct};
use crate::collections::{ImMap, ImSet, SendMap};
use crate::constrain::expr::{exists, exists_with_aliases, Info};
use crate::module::symbol::{ModuleId, Symbol};
use crate::region::{Located, Region};
use crate::subs::{VarStore, Variable};
use crate::types::Alias;
use crate::types::AnnotationSource::{self, *};
@ -20,6 +16,10 @@ use crate::types::Type::{self, *};
use crate::uniqueness::boolean_algebra::{Atom, Bool};
use crate::uniqueness::builtins::{attr_type, list_type, str_type};
use crate::uniqueness::sharing::{Container, FieldAccess, Mark, Usage, VarUsage};
use roc_collections::all::{ImMap, ImSet, SendMap};
use roc_module::ident::{Ident, Lowercase, TagName};
use roc_module::symbol::{ModuleId, Symbol};
use roc_region::all::{Located, Region};
pub use crate::can::expr::Expr::*;

View File

@ -1,9 +1,9 @@
use crate::can::expr::Expr;
use crate::can::ident::Lowercase;
use crate::collections::{ImMap, ImSet};
use crate::module::symbol::Symbol;
use crate::region::Located;
use crate::subs::Variable;
use roc_collections::all::{ImMap, ImSet};
use roc_module::ident::Lowercase;
use roc_module::symbol::Symbol;
use roc_region::all::Located;
// fake field names for container elements
// e.g. for lists, internally it's a record with a `list_elem` field

Some files were not shown because too many files have changed in this diff Show More