Skip to content

Commit 13b50d1

Browse files
committed
feat-types
Squashed commit of the following: commit cbdda4ff7614bee711d785036544b867f981c0bc Merge: b898560f 6fa675e Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Mon Jul 22 16:43:16 2024 +0200 Merge branch 'main' into feat-indirections commit b898560f3e93f13be9c452f85fac36e5e1ae4a7b Merge: 96844669 755811b0 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Wed Jun 26 11:42:24 2024 +0200 merge main into feat-types commit 755811b0f56e3d359a97f67881998c88523dad2e Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Wed Jun 26 10:52:47 2024 +0200 Revert "chore: Move `db.` to a new branch (#4349)" This reverts commit 76c4f76. commit 96844669f9c834fe43d18b79a79ceebe588ce6f0 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Fri Jun 14 09:31:57 2024 +0200 fix: infer types for empty arrays commit 70fd898c8c231c895cab9f3e033b9ef42127a9c4 Merge: e71ae6dd 80e4a1d7 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Fri Jun 14 09:20:11 2024 +0200 merge main into feat-types commit 80e4a1d7f50e95fecc51100353919d33e754cf2a Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Sat Jun 1 18:59:48 2024 +0200 Revert "chore: Move `db.` to a new branch (#4349)" This reverts commit 76c4f76. commit e71ae6dd4f5eda78472d6ad5fe65555c6bce4597 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Sun Jun 2 20:28:46 2024 +0200 fix: tuple type checking commit f0627d9 Merge: 041310e f0fd93b Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Sat Jun 1 19:29:53 2024 +0200 merge main into feat-types commit f0fd93b Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Sat Jun 1 18:59:48 2024 +0200 Revert "chore: Move `db.` to a new branch (#4349)" This reverts commit 76c4f76. commit 041310e Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Sun May 19 16:39:12 2024 +0200 refactor: minor cleanup commit 5867f62 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Sun May 19 16:36:24 2024 +0200 fix: lowering aggregate commit 2e67021 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Sun May 19 13:51:02 2024 +0200 refactor: scope commit fff7a75 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Sun May 19 12:14:32 2024 +0200 feat: infer type as array commit 87df34f Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Wed May 15 21:43:20 2024 +0200 fix: organize tests, minor fixes commit d855aa9 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Wed May 15 20:38:40 2024 +0200 fix: excluding fields commit 1980e03 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Wed May 15 19:31:48 2024 +0200 refactor: cleanup TyFunc commit 39cb797 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Wed May 15 19:17:47 2024 +0200 feat: nested tuple indirection commit f5fa4f3 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Tue May 14 14:27:45 2024 +0200 refactor: resolving tuple indirection commit 043047e Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Tue May 14 14:04:22 2024 +0200 feat: lowering for rq operators and relational literals commit 35eeb84 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Tue May 14 12:13:06 2024 +0200 feat: finalize global generics after each stmt commit 983c085 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Tue May 14 11:58:50 2024 +0200 refactor: cleanup LayeredModules commit 4b060ef Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Tue May 14 11:42:26 2024 +0200 refactor: lowering commit 9d37888 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Tue May 14 10:39:04 2024 +0200 feat: create generics for all unknown types commit f13c93d Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Mon May 13 20:19:25 2024 +0200 refactor: remove DeclKind::TableDecl in favor DeclKind::Expr commit f5d2588 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Mon May 13 19:52:06 2024 +0200 fix: relational functions commit 6990ff8 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Mon May 13 18:40:17 2024 +0200 fix: lowering and special_functions commit 5120b9a Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Mon May 13 18:17:25 2024 +0200 feat: local scopes instead of modules commit 1631528 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Mon May 13 13:52:47 2024 +0200 refactor: move table inference into name resolver commit db27409 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Mon May 13 12:47:25 2024 +0200 feat: unpack must come last commit 43255ec Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Mon May 13 12:10:04 2024 +0200 feat!: forbid functions without paramaters commit 85da349 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Sun May 12 12:08:05 2024 +0200 ignore failed tests commit 17af072 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Mon Apr 15 19:20:12 2024 +0200 feat: resolve functions without inlining commit e1ebdc4 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Mon Apr 15 15:35:27 2024 +0200 feat: split pl::FuncApplication from pl::Func commit 98e26f0 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Mon Apr 15 13:19:48 2024 +0200 refactor: cosmetic tweaks for types commit 4319c04 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Sun Apr 14 20:50:14 2024 +0200 feat: inference between generics commit e4f4e40 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Sun Apr 14 19:49:57 2024 +0200 refactor: merge local and global _generic modules commit 5e5c015 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Sun Apr 14 10:45:36 2024 +0200 refactor: validate_type commit b8f9895 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Thu Apr 4 13:24:04 2024 +0200 feat: move flatten and special functions into lowering commit 6d11a77 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Thu Apr 4 11:00:25 2024 +0200 feat: ty tuple exclude commit 33415ce Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Wed Apr 3 12:40:59 2024 +0200 refactors and fixes commit 03c6f51 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Wed Apr 3 10:04:01 2024 +0200 fmt commit ac36f23 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Tue Apr 2 13:51:09 2024 +0200 fix: a few tests commit f6c29cf Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Sun Mar 31 12:23:42 2024 +0200 feat: global generic arguments for table inference commit 2d47aeb Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Fri Mar 29 16:05:11 2024 +0100 refactor: generic type parameters commit 3eac276 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Fri Mar 29 15:42:47 2024 +0100 cleanup inference commit 2de7286 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Fri Mar 29 14:06:38 2024 +0100 feat: tuple unpacking commit b33153f Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Fri Mar 29 13:14:22 2024 +0100 feat: wildcard includes and excludes commit 9aa3397 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Fri Mar 29 11:54:19 2024 +0100 feat: implicit closures and joins commit 2b3233a Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Thu Mar 28 16:53:56 2024 +0100 feat: remove obsolete type machinery This includes: - TypeKind::Singleton, - TypeKind::Union, - type normalization, - subtyping, This commit also: - changes syntax for generic type arguments, - adds type annotations to transforms, Many tests now fail. commit 107c22e Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Thu Mar 28 12:24:03 2024 +0100 more lowering & test cases commit a8040ce Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Thu Mar 28 11:49:05 2024 +0100 feat: rewire lowering to work with indirections commit 4c53729 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Fri Feb 16 19:24:55 2024 +0100 feat: indirection commit 43bb7a7 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Thu Apr 4 13:27:22 2024 +0200 refactor: remove `debug eval` command commit 2e9795d Author: Aljaž Mur Eržen <aljazerzen@users.noreply.github.com> Date: Thu Mar 28 14:27:20 2024 +0100 refactor: minor changes to lowering (#4364) commit 125aafb Author: Aljaž Mur Eržen <aljazerzen@users.noreply.github.com> Date: Mon Mar 25 17:19:58 2024 +0100 feat!: resolve declaration names before the resolver (#4353) commit 7dbe057 Author: Aljaž Mur Eržen <aljaz@edgedb.com> Date: Mon Mar 25 14:21:41 2024 +0100 build: test for feat-types commit ee6b2ce Author: Aljaž Mur Eržen <aljazerzen@users.noreply.github.com> Date: Mon Mar 25 12:30:38 2024 +0100 feat: indirection parsing (#4356)
1 parent 9027941 commit 13b50d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+6063
-5815
lines changed

Cargo.lock

Lines changed: 3 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ members = [
88
"prqlc/prqlc-macros",
99
"prqlc/prqlc-parser",
1010
"prqlc/prqlc",
11-
"prqlc/prqlc/examples/compile-files", # An example
1211
"lutra/lutra",
1312
"lutra/bindings/python",
1413
"web/book",

prqlc/Taskfile.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,44 @@ tasks:
3737
--ignore-unknown \
3838
--log-level=warn
3939
40+
fmt-check:
41+
desc: Validate that source files are formatted
42+
cmds:
43+
- cargo fmt --check {{.packages_core}} {{.packages_addon}}
44+
{{.packages_bindings}}
45+
4046
test-fast:
4147
desc: A fast test used for feedback during compiler development
4248
cmds:
4349
- cmd: |
44-
INSTA_FORCE_PASS=1 cargo nextest run {{.packages_core}} --no-fail-fast
50+
INSTA_FORCE_PASS=1 cargo nextest run {{.packages_core}} -- {{.CLI_ARGS}}
4551
4652
- cmd: cargo insta review
4753

4854
- cmd: cargo clippy --all-targets {{.packages_core}}
4955

56+
test-types:
57+
desc:
58+
A subset of tests that should work on feat-types
59+
cmds:
60+
- cmd: |
61+
INSTA_FORCE_PASS=1 cargo nextest run --package prqlc --test=integration -- sql:: resolving::
62+
63+
- cmd: cargo insta review
64+
65+
- cmd: cargo clippy --all-targets {{.packages_core}}
66+
67+
- cmd: |
68+
echo -e '\n=======\nrunning just ignored tests, to see if any of them passes'
69+
cargo nextest run --package prqlc --test=integration --run-ignored=ignored-only --success-output=never --failure-output=never --status-level=pass --final-status-level=none -- sql:: resolving::
70+
5071
test:
5172
desc: |
5273
A full test of prqlc (excluding --test-dbs-external).
5374
Generates coverage report.
5475
cmds:
76+
- task: fmt-check
77+
5578
- cmd: |
5679
cargo \
5780
llvm-cov --lcov --output-path lcov.info \

prqlc/prqlc-parser/src/parser/expr.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,8 @@ where
481481
.then(ctrl(':').ignore_then(expr.clone().map(Box::new)).or_not());
482482

483483
let generic_args = ident_part()
484-
.then_ignore(ctrl(':'))
485-
.then(type_expr().separated_by(ctrl('|')))
486-
.map(|(name, domain)| GenericTypeParam { name, domain })
484+
.then(ctrl(':').ignore_then(type_expr()).or_not())
485+
.map(|(name, bound)| GenericTypeParam { name, bound })
487486
.separated_by(ctrl(','))
488487
.at_least(1)
489488
.delimited_by(ctrl('<'), ctrl('>'))
@@ -500,7 +499,10 @@ where
500499
.allow_trailing(),
501500
),
502501
// plain
503-
param.repeated().map(|params| (Vec::new(), params)),
502+
param
503+
.repeated()
504+
.at_least(1)
505+
.map(|params| (Vec::new(), params)),
504506
))
505507
.then_ignore(just(TokenKind::ArrowThin))
506508
// return type

prqlc/prqlc-parser/src/parser/pr/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub struct GenericTypeParam {
165165
/// Assigned name of this generic type argument.
166166
pub name: String,
167167

168-
pub domain: Vec<Ty>,
168+
pub bound: Option<Ty>,
169169
}
170170

171171
/// A value and a series of functions that are to be applied to that value one after another.

prqlc/prqlc-parser/src/parser/pr/types.rs

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use schemars::JsonSchema;
33
use serde::{Deserialize, Serialize};
44
use strum::AsRefStr;
55

6-
use crate::lexer::lr::Literal;
76
use crate::parser::pr::ident::Ident;
7+
use crate::parser::pr::expr::GenericTypeParam;
88
use crate::span::Span;
99

10-
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
10+
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
1111
pub struct Ty {
1212
pub kind: TyKind,
1313

@@ -25,12 +25,6 @@ pub enum TyKind {
2525
/// Type of a built-in primitive type
2626
Primitive(PrimitiveSet),
2727

28-
/// Type that contains only a one value
29-
Singleton(Literal),
30-
31-
/// Union of sets (sum)
32-
Union(Vec<(Option<String>, Ty)>),
33-
3428
/// Type of tuples (product)
3529
Tuple(Vec<TyTupleField>),
3630

@@ -40,15 +34,9 @@ pub enum TyKind {
4034
/// Type of functions with defined params and return types.
4135
Function(Option<TyFunc>),
4236

43-
/// Type of every possible value. Super type of all other types.
44-
/// The breaker of chains. Mother of types.
45-
Any,
46-
47-
/// Type that is the largest subtype of `base` while not a subtype of `exclude`.
48-
Difference { base: Box<Ty>, exclude: Box<Ty> },
49-
50-
/// A generic argument. Contains id of the function call node and generic type param name.
51-
GenericArg((usize, String)),
37+
/// Tuples that have fields of `base` tuple, but don't have fields of `except` tuple.
38+
/// Implies that `base` has all fields of `except`.
39+
Exclude { base: Box<Ty>, except: Box<Ty> },
5240
}
5341

5442
impl TyKind {
@@ -66,9 +54,11 @@ pub enum TyTupleField {
6654
/// Named tuple element.
6755
Single(Option<String>, Option<Ty>),
6856

69-
/// Placeholder for possibly many elements.
70-
/// Means "and other unmentioned columns". Does not mean "all columns".
71-
Wildcard(Option<Ty>),
57+
/// Many tuple elements contained in a type that must eventually resolve to a tuple.
58+
/// In most cases, this starts as a generic type argument.
59+
// TODO: make this non-optional Ty
60+
// TODO: merge this into TyTuple (that does not exist at the moment)
61+
Unpack(Option<Ty>),
7262
}
7363

7464
/// Built-in sets.
@@ -103,9 +93,11 @@ pub enum PrimitiveSet {
10393
// Type of a function
10494
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
10595
pub struct TyFunc {
106-
pub name_hint: Option<Ident>,
10796
pub params: Vec<Option<Ty>>,
97+
10898
pub return_ty: Option<Box<Ty>>,
99+
100+
pub generic_type_params: Vec<GenericTypeParam>,
109101
}
110102

111103
impl Ty {
@@ -122,14 +114,6 @@ impl Ty {
122114
Ty::new(TyKind::Array(Box::new(tuple)))
123115
}
124116

125-
pub fn never() -> Self {
126-
Ty::new(TyKind::Union(Vec::new()))
127-
}
128-
129-
pub fn is_never(&self) -> bool {
130-
self.kind.as_union().map_or(false, |x| x.is_empty())
131-
}
132-
133117
pub fn as_relation(&self) -> Option<&Vec<TyTupleField>> {
134118
self.kind.as_array()?.kind.as_tuple()
135119
}
@@ -156,7 +140,7 @@ impl TyTupleField {
156140
pub fn ty(&self) -> Option<&Ty> {
157141
match self {
158142
TyTupleField::Single(_, ty) => ty.as_ref(),
159-
TyTupleField::Wildcard(ty) => ty.as_ref(),
143+
TyTupleField::Unpack(ty) => ty.as_ref(),
160144
}
161145
}
162146
}
@@ -173,8 +157,8 @@ impl From<TyFunc> for TyKind {
173157
}
174158
}
175159

176-
impl From<Literal> for TyKind {
177-
fn from(value: Literal) -> Self {
178-
TyKind::Singleton(value)
160+
impl PartialEq for Ty {
161+
fn eq(&self, other: &Self) -> bool {
162+
self.kind == other.kind && self.name == other.name
179163
}
180164
}

prqlc/prqlc-parser/src/parser/types.rs

Lines changed: 47 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ use crate::lexer::lr::TokenKind;
99
pub(crate) fn type_expr() -> impl Parser<TokenKind, Ty, Error = PError> + Clone {
1010
recursive(|nested_type_expr| {
1111
let basic = select! {
12-
TokenKind::Literal(lit) => TyKind::Singleton(lit),
12+
// TokenKind::Literal(lit) => TyKind::Singleton(lit),
1313
TokenKind::Ident(i) if i == "int"=> TyKind::Primitive(PrimitiveSet::Int),
1414
TokenKind::Ident(i) if i == "float"=> TyKind::Primitive(PrimitiveSet::Float),
1515
TokenKind::Ident(i) if i == "bool"=> TyKind::Primitive(PrimitiveSet::Bool),
1616
TokenKind::Ident(i) if i == "text"=> TyKind::Primitive(PrimitiveSet::Text),
1717
TokenKind::Ident(i) if i == "date"=> TyKind::Primitive(PrimitiveSet::Date),
1818
TokenKind::Ident(i) if i == "time"=> TyKind::Primitive(PrimitiveSet::Time),
1919
TokenKind::Ident(i) if i == "timestamp"=> TyKind::Primitive(PrimitiveSet::Timestamp),
20-
TokenKind::Ident(i) if i == "anytype"=> TyKind::Any,
20+
// TokenKind::Ident(i) if i == "anytype"=> TyKind::Any,
2121
};
2222

2323
let ident = ident().map(TyKind::Ident);
@@ -31,9 +31,9 @@ pub(crate) fn type_expr() -> impl Parser<TokenKind, Ty, Error = PError> + Clone
3131
.then_ignore(just(TokenKind::ArrowThin))
3232
.then(nested_type_expr.clone().map(Box::new).map(Some))
3333
.map(|(params, return_ty)| TyFunc {
34-
name_hint: None,
3534
params,
3635
return_ty,
36+
generic_type_params: vec![],
3737
})
3838
.or_not(),
3939
)
@@ -42,7 +42,7 @@ pub(crate) fn type_expr() -> impl Parser<TokenKind, Ty, Error = PError> + Clone
4242
let tuple = sequence(choice((
4343
select! { TokenKind::Range { bind_right: true, bind_left: _ } => () }
4444
.ignore_then(nested_type_expr.clone())
45-
.map(|ty| TyTupleField::Wildcard(Some(ty))),
45+
.map(|ty| TyTupleField::Unpack(Some(ty))),
4646
ident_part()
4747
.then_ignore(ctrl('='))
4848
.or_not()
@@ -63,7 +63,7 @@ pub(crate) fn type_expr() -> impl Parser<TokenKind, Ty, Error = PError> + Clone
6363
.try_map(|fields, span| {
6464
let without_last = &fields[0..fields.len().saturating_sub(1)];
6565

66-
if let Some(unpack) = without_last.iter().find_map(|f| f.as_wildcard()) {
66+
if let Some(unpack) = without_last.iter().find_map(|f| f.as_unpack()) {
6767
let span = unpack.as_ref().and_then(|s| s.span).unwrap_or(span);
6868
return Err(PError::custom(
6969
span,
@@ -76,32 +76,32 @@ pub(crate) fn type_expr() -> impl Parser<TokenKind, Ty, Error = PError> + Clone
7676
.map(TyKind::Tuple)
7777
.labelled("tuple");
7878

79-
let enum_ = keyword("enum")
80-
.ignore_then(
81-
sequence(
82-
ident_part()
83-
.then(ctrl('=').ignore_then(nested_type_expr.clone()).or_not())
84-
.map(|(name, ty)| {
85-
(
86-
Some(name),
87-
ty.unwrap_or_else(|| Ty::new(TyKind::Tuple(vec![]))),
88-
)
89-
}),
90-
)
91-
.delimited_by(ctrl('{'), ctrl('}'))
92-
.recover_with(nested_delimiters(
93-
TokenKind::Control('{'),
94-
TokenKind::Control('}'),
95-
[
96-
(TokenKind::Control('{'), TokenKind::Control('}')),
97-
(TokenKind::Control('('), TokenKind::Control(')')),
98-
(TokenKind::Control('['), TokenKind::Control(']')),
99-
],
100-
|_| vec![],
101-
)),
102-
)
103-
.map(TyKind::Union)
104-
.labelled("union");
79+
// let enum_ = keyword("enum")
80+
// .ignore_then(
81+
// sequence(
82+
// ident_part()
83+
// .then(ctrl('=').ignore_then(nested_type_expr.clone()).or_not())
84+
// .map(|(name, ty)| {
85+
// (
86+
// Some(name),
87+
// ty.unwrap_or_else(|| Ty::new(TyKind::Tuple(vec![]))),
88+
// )
89+
// }),
90+
// )
91+
// .delimited_by(ctrl('{'), ctrl('}'))
92+
// .recover_with(nested_delimiters(
93+
// TokenKind::Control('{'),
94+
// TokenKind::Control('}'),
95+
// [
96+
// (TokenKind::Control('{'), TokenKind::Control('}')),
97+
// (TokenKind::Control('('), TokenKind::Control(')')),
98+
// (TokenKind::Control('['), TokenKind::Control(']')),
99+
// ],
100+
// |_| vec![],
101+
// )),
102+
// )
103+
// .map(TyKind::Union)
104+
// .labelled("union");
105105

106106
let array = nested_type_expr
107107
.map(Box::new)
@@ -120,41 +120,27 @@ pub(crate) fn type_expr() -> impl Parser<TokenKind, Ty, Error = PError> + Clone
120120
.map(TyKind::Array)
121121
.labelled("array");
122122

123-
let term = choice((basic, ident, func, tuple, array, enum_))
123+
let term = choice((basic, ident, func, tuple, array))
124124
.map_with_span(TyKind::into_ty)
125125
.boxed();
126126

127127
// exclude
128-
// term.clone()
129-
// .then(ctrl('-').ignore_then(term).repeated())
130-
// .foldl(|left, right| {
131-
// let left_span = left.span.as_ref().unwrap();
132-
// let right_span = right.span.as_ref().unwrap();
133-
// let span = Span {
134-
// start: left_span.start,
135-
// end: right_span.end,
136-
// source_id: left_span.source_id,
137-
// };
138-
139-
// let kind = TyKind::Exclude {
140-
// base: Box::new(left),
141-
// except: Box::new(right),
142-
// };
143-
// into_ty(kind, span)
144-
// });
145-
146-
// union
147128
term.clone()
148-
.then(just(TokenKind::Or).ignore_then(term).repeated())
149-
.map_with_span(|(first, following), span| {
150-
if following.is_empty() {
151-
first
152-
} else {
153-
let mut all = Vec::with_capacity(following.len() + 1);
154-
all.push((None, first));
155-
all.extend(following.into_iter().map(|x| (None, x)));
156-
TyKind::Union(all).into_ty(span)
157-
}
129+
.then(ctrl('-').ignore_then(term).repeated())
130+
.foldl(|left, right| {
131+
let left_span = left.span.as_ref().unwrap();
132+
let right_span = right.span.as_ref().unwrap();
133+
let span = Span {
134+
start: left_span.start,
135+
end: right_span.end,
136+
source_id: left_span.source_id,
137+
};
138+
139+
let kind = TyKind::Exclude {
140+
base: Box::new(left),
141+
except: Box::new(right),
142+
};
143+
TyKind::into_ty(kind, span)
158144
})
159145
})
160146
.labelled("type expression")

0 commit comments

Comments
 (0)