Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions prql-compiler/src/ast/pl/expr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ pub enum ExprKind {
name: String,
args: Vec<Expr>,
},
Set(SetExpr),
Type(TypeExpr),

/// a placeholder for values provided after query is compiled
Param(String),
Expand DownExpand Up@@ -599,8 +599,8 @@ impl Display for Expr {
ExprKind::BuiltInFunction { .. } => {
f.write_str("<built-in>")?;
}
ExprKind::Set(_) => {
writeln!(f, "<set-expr>")?;
ExprKind::Type(_) => {
writeln!(f, "<type-expr>")?;
}
ExprKind::Param(id) => {
writeln!(f, "${id}")?;
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/ast/pl/fold.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -119,7 +119,7 @@ pub fn fold_expr_kind<T: ?Sized + AstFold>(fold: &mut T, expr_kind: ExprKind) ->
Param(id) => Param(id),

// None of these capture variables, so we don't need to fold them.
Literal(_) | Set(_) => expr_kind,
Literal(_) | Type(_) => expr_kind,
})
}

Expand Down
56 changes: 28 additions & 28 deletions prql-compiler/src/ast/pl/types.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,37 +6,37 @@ use serde::{Deserialize, Serialize};
use super::{Frame, Literal};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum SetExpr {
/// Set of a built-in primitive type
pub enum TypeExpr {
/// Type of a built-in primitive type
Primitive(TyLit),

/// Set that contains only a literal value
/// Type that contains only a literal value
Singleton(Literal),

/// Union of sets (sum)
Union(Vec<(Option<String>, SetExpr)>),
Union(Vec<(Option<String>, TypeExpr)>),

/// Set of tuples (product)
/// Type of tuples (product)
Tuple(Vec<TupleElement>),

/// Set of arrays
Array(Box<SetExpr>),
/// Type of arrays
Array(Box<TypeExpr>),

/// Set of sets.
/// Type of sets.
/// Used for exprs that can be converted to SetExpr and then used as a Ty.
Set,
Type,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TupleElement {
Single(Option<String>, SetExpr),
Single(Option<String>, TypeExpr),
Wildcard,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum Ty {
/// Value is an element of this [SetExpr]
SetExpr(SetExpr),
TypeExpr(TypeExpr),

/// Value is a function described by [TyFunc]
// TODO: convert into [Ty::Domain].
Expand DownExpand Up@@ -93,7 +93,7 @@ impl Ty {
// Not handled here. See type_resolver.
(Ty::Infer, _) | (_, Ty::Infer) => false,

(Ty::SetExpr(left), Ty::SetExpr(right)) => left.is_superset_of(right),
(Ty::TypeExpr(left), Ty::TypeExpr(right)) => left.is_superset_of(right),

(Ty::Table(_), Ty::Table(_)) => true,

Expand All@@ -102,17 +102,17 @@ impl Ty {
}
}

impl SetExpr {
fn is_superset_of(&self, subset: &SetExpr) -> bool {
impl TypeExpr {
fn is_superset_of(&self, subset: &TypeExpr) -> bool {
match (self, subset) {
// TODO: convert these to array
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(TyLit::Column)) => true,
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(_)) => true,
(SetExpr::Primitive(_), SetExpr::Primitive(TyLit::Column)) => false,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(TyLit::Column)) => true,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(_)) => true,
(TypeExpr::Primitive(_), TypeExpr::Primitive(TyLit::Column)) => false,

(SetExpr::Primitive(l0), SetExpr::Primitive(r0)) => l0 == r0,
(SetExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, SetExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),
(TypeExpr::Primitive(l0), TypeExpr::Primitive(r0)) => l0 == r0,
(TypeExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, TypeExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),

(l, r) => l == r,
}
Expand All@@ -122,7 +122,7 @@ impl SetExpr {
impl Display for Ty {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
Ty::SetExpr(lit) => write!(f, "{:}", lit),
Ty::TypeExpr(lit) => write!(f, "{:}", lit),
Ty::Table(frame) => write!(f, "table<{frame}>"),
Ty::Infer => write!(f, "infer"),
Ty::Function(func) => {
Expand All@@ -138,11 +138,11 @@ impl Display for Ty {
}
}

impl Display for SetExpr {
impl Display for TypeExpr {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
SetExpr::Primitive(lit) => write!(f, "{:}", lit),
SetExpr::Union(ts) => {
TypeExpr::Primitive(lit) => write!(f, "{:}", lit),
TypeExpr::Union(ts) => {
for (i, (_, e)) in ts.iter().enumerate() {
write!(f, "{e}")?;
if i < ts.len() - 1 {
Expand All@@ -151,8 +151,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Singleton(lit) => write!(f, "{:}", lit),
SetExpr::Tuple(elements) => {
TypeExpr::Singleton(lit) => write!(f, "{:}", lit),
TypeExpr::Tuple(elements) => {
write!(f, "[")?;
for e in elements {
match e {
Expand All@@ -170,8 +170,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Set => write!(f, "set"),
SetExpr::Array(_) => todo!(),
TypeExpr::Type => write!(f, "set"),
TypeExpr::Array(_) => todo!(),
}
}
}
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -388,16 +388,16 @@ fn get_stdlib_decl(name: &str) -> Option<ExprKind> {
"timestamp" => TyLit::Timestamp,
"table" => {
// TODO: this is just a dummy that gets intercepted when resolving types
return Some(ExprKind::Set(SetExpr::Array(Box::new(SetExpr::Singleton(
Literal::Null,
)))));
return Some(ExprKind::Type(TypeExpr::Array(Box::new(
TypeExpr::Singleton(Literal::Null),
))));
}
"column" => TyLit::Column,
"list" => TyLit::List,
"scalar" => TyLit::Scalar,
_ => return None,
};
Some(ExprKind::Set(SetExpr::Primitive(ty_lit)))
Some(ExprKind::Type(TypeExpr::Primitive(ty_lit)))
}

impl Default for DeclKind {
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/lowering.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -662,7 +662,7 @@ impl Lowerer {
| pl::ExprKind::List(_)
| pl::ExprKind::Closure(_)
| pl::ExprKind::Pipeline(_)
| pl::ExprKind::Set(_)
| pl::ExprKind::Type(_)
| pl::ExprKind::TransformCall(_) => {
log::debug!("cannot lower {ast:?}");
return Err(Error::new(Reason::Unexpected {
Expand Down
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/resolver.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ impl AstFold for Resolver {
name: ty_def.name,
value: Box::new(ty_def.value.unwrap_or_else(|| {
let mut e = Expr::null();
e.ty = Some(Ty::SetExpr(SetExpr::Set));
e.ty = Some(Ty::TypeExpr(TypeExpr::Type));
e
})),
};
Expand DownExpand Up@@ -448,7 +448,7 @@ impl Resolver {
// evaluate
let needs_window = (closure.body_ty)
.as_ref()
.map(|ty| ty.is_superset_of(&Ty::SetExpr(SetExpr::Primitive(TyLit::Column))))
.map(|ty| ty.is_superset_of(&Ty::TypeExpr(TypeExpr::Primitive(TyLit::Column))))
.unwrap_or_default();

let mut res = match self.cast_built_in_function(closure)? {
Expand DownExpand Up@@ -780,11 +780,11 @@ impl Resolver {
let set_expr = type_resolver::coerce_to_set(expr, &self.context)?;

// TODO: workaround
if let SetExpr::Array(_) = set_expr {
if let TypeExpr::Array(_) = set_expr {
return Ok(Some(Ty::Table(Frame::default())));
}

Some(Ty::SetExpr(set_expr))
Some(Ty::TypeExpr(set_expr))
}
None => None,
})
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n func subtract a b -> a - b\n\n
target_id: 7
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: net_salary

Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
op: Add
Expand All@@ -53,6 +53,6 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
target_id: 8
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column

Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 2
ty:
SetExpr:
TypeExpr:
Primitive: Int
op: Add
right:
Expand All@@ -34,11 +34,11 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: b

Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ expression: "resolve_derive(r#\"\n from a\n derive one = (
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: one

Original file line numberDiff line numberDiff line change
Expand Up@@ -18,10 +18,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 3
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added
- id: 25
Expand All@@ -40,10 +40,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added_default

Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_salary
- id: 16
Expand All@@ -44,7 +44,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_cost

2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/transforms.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1132,7 +1132,7 @@ mod tests {
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
partition:
- id: 12
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
refactor: Rename `set` to `type` by max-sixty · Pull Request #2346 · PRQL/prql · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions prql-compiler/src/ast/pl/expr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ pub enum ExprKind {
name: String,
args: Vec<Expr>,
},
Set(SetExpr),
Type(TypeExpr),

/// a placeholder for values provided after query is compiled
Param(String),
Expand DownExpand Up@@ -599,8 +599,8 @@ impl Display for Expr {
ExprKind::BuiltInFunction { .. } => {
f.write_str("<built-in>")?;
}
ExprKind::Set(_) => {
writeln!(f, "<set-expr>")?;
ExprKind::Type(_) => {
writeln!(f, "<type-expr>")?;
}
ExprKind::Param(id) => {
writeln!(f, "${id}")?;
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/ast/pl/fold.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -119,7 +119,7 @@ pub fn fold_expr_kind<T: ?Sized + AstFold>(fold: &mut T, expr_kind: ExprKind) ->
Param(id) => Param(id),

// None of these capture variables, so we don't need to fold them.
Literal(_) | Set(_) => expr_kind,
Literal(_) | Type(_) => expr_kind,
})
}

Expand Down
56 changes: 28 additions & 28 deletions prql-compiler/src/ast/pl/types.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,37 +6,37 @@ use serde::{Deserialize, Serialize};
use super::{Frame, Literal};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum SetExpr {
/// Set of a built-in primitive type
pub enum TypeExpr {
/// Type of a built-in primitive type
Primitive(TyLit),

/// Set that contains only a literal value
/// Type that contains only a literal value
Singleton(Literal),

/// Union of sets (sum)
Union(Vec<(Option<String>, SetExpr)>),
Union(Vec<(Option<String>, TypeExpr)>),

/// Set of tuples (product)
/// Type of tuples (product)
Tuple(Vec<TupleElement>),

/// Set of arrays
Array(Box<SetExpr>),
/// Type of arrays
Array(Box<TypeExpr>),

/// Set of sets.
/// Type of sets.
/// Used for exprs that can be converted to SetExpr and then used as a Ty.
Set,
Type,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TupleElement {
Single(Option<String>, SetExpr),
Single(Option<String>, TypeExpr),
Wildcard,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum Ty {
/// Value is an element of this [SetExpr]
SetExpr(SetExpr),
TypeExpr(TypeExpr),

/// Value is a function described by [TyFunc]
// TODO: convert into [Ty::Domain].
Expand DownExpand Up@@ -93,7 +93,7 @@ impl Ty {
// Not handled here. See type_resolver.
(Ty::Infer, _) | (_, Ty::Infer) => false,

(Ty::SetExpr(left), Ty::SetExpr(right)) => left.is_superset_of(right),
(Ty::TypeExpr(left), Ty::TypeExpr(right)) => left.is_superset_of(right),

(Ty::Table(_), Ty::Table(_)) => true,

Expand All@@ -102,17 +102,17 @@ impl Ty {
}
}

impl SetExpr {
fn is_superset_of(&self, subset: &SetExpr) -> bool {
impl TypeExpr {
fn is_superset_of(&self, subset: &TypeExpr) -> bool {
match (self, subset) {
// TODO: convert these to array
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(TyLit::Column)) => true,
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(_)) => true,
(SetExpr::Primitive(_), SetExpr::Primitive(TyLit::Column)) => false,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(TyLit::Column)) => true,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(_)) => true,
(TypeExpr::Primitive(_), TypeExpr::Primitive(TyLit::Column)) => false,

(SetExpr::Primitive(l0), SetExpr::Primitive(r0)) => l0 == r0,
(SetExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, SetExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),
(TypeExpr::Primitive(l0), TypeExpr::Primitive(r0)) => l0 == r0,
(TypeExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, TypeExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),

(l, r) => l == r,
}
Expand All@@ -122,7 +122,7 @@ impl SetExpr {
impl Display for Ty {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
Ty::SetExpr(lit) => write!(f, "{:}", lit),
Ty::TypeExpr(lit) => write!(f, "{:}", lit),
Ty::Table(frame) => write!(f, "table<{frame}>"),
Ty::Infer => write!(f, "infer"),
Ty::Function(func) => {
Expand All@@ -138,11 +138,11 @@ impl Display for Ty {
}
}

impl Display for SetExpr {
impl Display for TypeExpr {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
SetExpr::Primitive(lit) => write!(f, "{:}", lit),
SetExpr::Union(ts) => {
TypeExpr::Primitive(lit) => write!(f, "{:}", lit),
TypeExpr::Union(ts) => {
for (i, (_, e)) in ts.iter().enumerate() {
write!(f, "{e}")?;
if i < ts.len() - 1 {
Expand All@@ -151,8 +151,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Singleton(lit) => write!(f, "{:}", lit),
SetExpr::Tuple(elements) => {
TypeExpr::Singleton(lit) => write!(f, "{:}", lit),
TypeExpr::Tuple(elements) => {
write!(f, "[")?;
for e in elements {
match e {
Expand All@@ -170,8 +170,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Set => write!(f, "set"),
SetExpr::Array(_) => todo!(),
TypeExpr::Type => write!(f, "set"),
TypeExpr::Array(_) => todo!(),
}
}
}
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -388,16 +388,16 @@ fn get_stdlib_decl(name: &str) -> Option<ExprKind> {
"timestamp" => TyLit::Timestamp,
"table" => {
// TODO: this is just a dummy that gets intercepted when resolving types
return Some(ExprKind::Set(SetExpr::Array(Box::new(SetExpr::Singleton(
Literal::Null,
)))));
return Some(ExprKind::Type(TypeExpr::Array(Box::new(
TypeExpr::Singleton(Literal::Null),
))));
}
"column" => TyLit::Column,
"list" => TyLit::List,
"scalar" => TyLit::Scalar,
_ => return None,
};
Some(ExprKind::Set(SetExpr::Primitive(ty_lit)))
Some(ExprKind::Type(TypeExpr::Primitive(ty_lit)))
}

impl Default for DeclKind {
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/lowering.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -662,7 +662,7 @@ impl Lowerer {
| pl::ExprKind::List(_)
| pl::ExprKind::Closure(_)
| pl::ExprKind::Pipeline(_)
| pl::ExprKind::Set(_)
| pl::ExprKind::Type(_)
| pl::ExprKind::TransformCall(_) => {
log::debug!("cannot lower {ast:?}");
return Err(Error::new(Reason::Unexpected {
Expand Down
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/resolver.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ impl AstFold for Resolver {
name: ty_def.name,
value: Box::new(ty_def.value.unwrap_or_else(|| {
let mut e = Expr::null();
e.ty = Some(Ty::SetExpr(SetExpr::Set));
e.ty = Some(Ty::TypeExpr(TypeExpr::Type));
e
})),
};
Expand DownExpand Up@@ -448,7 +448,7 @@ impl Resolver {
// evaluate
let needs_window = (closure.body_ty)
.as_ref()
.map(|ty| ty.is_superset_of(&Ty::SetExpr(SetExpr::Primitive(TyLit::Column))))
.map(|ty| ty.is_superset_of(&Ty::TypeExpr(TypeExpr::Primitive(TyLit::Column))))
.unwrap_or_default();

let mut res = match self.cast_built_in_function(closure)? {
Expand DownExpand Up@@ -780,11 +780,11 @@ impl Resolver {
let set_expr = type_resolver::coerce_to_set(expr, &self.context)?;

// TODO: workaround
if let SetExpr::Array(_) = set_expr {
if let TypeExpr::Array(_) = set_expr {
return Ok(Some(Ty::Table(Frame::default())));
}

Some(Ty::SetExpr(set_expr))
Some(Ty::TypeExpr(set_expr))
}
None => None,
})
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n func subtract a b -> a - b\n\n
target_id: 7
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: net_salary

Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
op: Add
Expand All@@ -53,6 +53,6 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
target_id: 8
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column

Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 2
ty:
SetExpr:
TypeExpr:
Primitive: Int
op: Add
right:
Expand All@@ -34,11 +34,11 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: b

Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ expression: "resolve_derive(r#\"\n from a\n derive one = (
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: one

Original file line numberDiff line numberDiff line change
Expand Up@@ -18,10 +18,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 3
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added
- id: 25
Expand All@@ -40,10 +40,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added_default

Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_salary
- id: 16
Expand All@@ -44,7 +44,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_cost

2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/transforms.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1132,7 +1132,7 @@ mod tests {
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
partition:
- id: 12
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor: Rename `set` to `type` by max-sixty · Pull Request #2346 · PRQL/prql · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions prql-compiler/src/ast/pl/expr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ pub enum ExprKind {
name: String,
args: Vec<Expr>,
},
Set(SetExpr),
Type(TypeExpr),

/// a placeholder for values provided after query is compiled
Param(String),
Expand DownExpand Up@@ -599,8 +599,8 @@ impl Display for Expr {
ExprKind::BuiltInFunction { .. } => {
f.write_str("<built-in>")?;
}
ExprKind::Set(_) => {
writeln!(f, "<set-expr>")?;
ExprKind::Type(_) => {
writeln!(f, "<type-expr>")?;
}
ExprKind::Param(id) => {
writeln!(f, "${id}")?;
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/ast/pl/fold.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -119,7 +119,7 @@ pub fn fold_expr_kind<T: ?Sized + AstFold>(fold: &mut T, expr_kind: ExprKind) ->
Param(id) => Param(id),

// None of these capture variables, so we don't need to fold them.
Literal(_) | Set(_) => expr_kind,
Literal(_) | Type(_) => expr_kind,
})
}

Expand Down
56 changes: 28 additions & 28 deletions prql-compiler/src/ast/pl/types.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,37 +6,37 @@ use serde::{Deserialize, Serialize};
use super::{Frame, Literal};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum SetExpr {
/// Set of a built-in primitive type
pub enum TypeExpr {
/// Type of a built-in primitive type
Primitive(TyLit),

/// Set that contains only a literal value
/// Type that contains only a literal value
Singleton(Literal),

/// Union of sets (sum)
Union(Vec<(Option<String>, SetExpr)>),
Union(Vec<(Option<String>, TypeExpr)>),

/// Set of tuples (product)
/// Type of tuples (product)
Tuple(Vec<TupleElement>),

/// Set of arrays
Array(Box<SetExpr>),
/// Type of arrays
Array(Box<TypeExpr>),

/// Set of sets.
/// Type of sets.
/// Used for exprs that can be converted to SetExpr and then used as a Ty.
Set,
Type,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TupleElement {
Single(Option<String>, SetExpr),
Single(Option<String>, TypeExpr),
Wildcard,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum Ty {
/// Value is an element of this [SetExpr]
SetExpr(SetExpr),
TypeExpr(TypeExpr),

/// Value is a function described by [TyFunc]
// TODO: convert into [Ty::Domain].
Expand DownExpand Up@@ -93,7 +93,7 @@ impl Ty {
// Not handled here. See type_resolver.
(Ty::Infer, _) | (_, Ty::Infer) => false,

(Ty::SetExpr(left), Ty::SetExpr(right)) => left.is_superset_of(right),
(Ty::TypeExpr(left), Ty::TypeExpr(right)) => left.is_superset_of(right),

(Ty::Table(_), Ty::Table(_)) => true,

Expand All@@ -102,17 +102,17 @@ impl Ty {
}
}

impl SetExpr {
fn is_superset_of(&self, subset: &SetExpr) -> bool {
impl TypeExpr {
fn is_superset_of(&self, subset: &TypeExpr) -> bool {
match (self, subset) {
// TODO: convert these to array
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(TyLit::Column)) => true,
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(_)) => true,
(SetExpr::Primitive(_), SetExpr::Primitive(TyLit::Column)) => false,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(TyLit::Column)) => true,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(_)) => true,
(TypeExpr::Primitive(_), TypeExpr::Primitive(TyLit::Column)) => false,

(SetExpr::Primitive(l0), SetExpr::Primitive(r0)) => l0 == r0,
(SetExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, SetExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),
(TypeExpr::Primitive(l0), TypeExpr::Primitive(r0)) => l0 == r0,
(TypeExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, TypeExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),

(l, r) => l == r,
}
Expand All@@ -122,7 +122,7 @@ impl SetExpr {
impl Display for Ty {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
Ty::SetExpr(lit) => write!(f, "{:}", lit),
Ty::TypeExpr(lit) => write!(f, "{:}", lit),
Ty::Table(frame) => write!(f, "table<{frame}>"),
Ty::Infer => write!(f, "infer"),
Ty::Function(func) => {
Expand All@@ -138,11 +138,11 @@ impl Display for Ty {
}
}

impl Display for SetExpr {
impl Display for TypeExpr {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
SetExpr::Primitive(lit) => write!(f, "{:}", lit),
SetExpr::Union(ts) => {
TypeExpr::Primitive(lit) => write!(f, "{:}", lit),
TypeExpr::Union(ts) => {
for (i, (_, e)) in ts.iter().enumerate() {
write!(f, "{e}")?;
if i < ts.len() - 1 {
Expand All@@ -151,8 +151,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Singleton(lit) => write!(f, "{:}", lit),
SetExpr::Tuple(elements) => {
TypeExpr::Singleton(lit) => write!(f, "{:}", lit),
TypeExpr::Tuple(elements) => {
write!(f, "[")?;
for e in elements {
match e {
Expand All@@ -170,8 +170,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Set => write!(f, "set"),
SetExpr::Array(_) => todo!(),
TypeExpr::Type => write!(f, "set"),
TypeExpr::Array(_) => todo!(),
}
}
}
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -388,16 +388,16 @@ fn get_stdlib_decl(name: &str) -> Option<ExprKind> {
"timestamp" => TyLit::Timestamp,
"table" => {
// TODO: this is just a dummy that gets intercepted when resolving types
return Some(ExprKind::Set(SetExpr::Array(Box::new(SetExpr::Singleton(
Literal::Null,
)))));
return Some(ExprKind::Type(TypeExpr::Array(Box::new(
TypeExpr::Singleton(Literal::Null),
))));
}
"column" => TyLit::Column,
"list" => TyLit::List,
"scalar" => TyLit::Scalar,
_ => return None,
};
Some(ExprKind::Set(SetExpr::Primitive(ty_lit)))
Some(ExprKind::Type(TypeExpr::Primitive(ty_lit)))
}

impl Default for DeclKind {
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/lowering.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -662,7 +662,7 @@ impl Lowerer {
| pl::ExprKind::List(_)
| pl::ExprKind::Closure(_)
| pl::ExprKind::Pipeline(_)
| pl::ExprKind::Set(_)
| pl::ExprKind::Type(_)
| pl::ExprKind::TransformCall(_) => {
log::debug!("cannot lower {ast:?}");
return Err(Error::new(Reason::Unexpected {
Expand Down
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/resolver.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ impl AstFold for Resolver {
name: ty_def.name,
value: Box::new(ty_def.value.unwrap_or_else(|| {
let mut e = Expr::null();
e.ty = Some(Ty::SetExpr(SetExpr::Set));
e.ty = Some(Ty::TypeExpr(TypeExpr::Type));
e
})),
};
Expand DownExpand Up@@ -448,7 +448,7 @@ impl Resolver {
// evaluate
let needs_window = (closure.body_ty)
.as_ref()
.map(|ty| ty.is_superset_of(&Ty::SetExpr(SetExpr::Primitive(TyLit::Column))))
.map(|ty| ty.is_superset_of(&Ty::TypeExpr(TypeExpr::Primitive(TyLit::Column))))
.unwrap_or_default();

let mut res = match self.cast_built_in_function(closure)? {
Expand DownExpand Up@@ -780,11 +780,11 @@ impl Resolver {
let set_expr = type_resolver::coerce_to_set(expr, &self.context)?;

// TODO: workaround
if let SetExpr::Array(_) = set_expr {
if let TypeExpr::Array(_) = set_expr {
return Ok(Some(Ty::Table(Frame::default())));
}

Some(Ty::SetExpr(set_expr))
Some(Ty::TypeExpr(set_expr))
}
None => None,
})
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n func subtract a b -> a - b\n\n
target_id: 7
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: net_salary

Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
op: Add
Expand All@@ -53,6 +53,6 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
target_id: 8
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column

Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 2
ty:
SetExpr:
TypeExpr:
Primitive: Int
op: Add
right:
Expand All@@ -34,11 +34,11 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: b

Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ expression: "resolve_derive(r#\"\n from a\n derive one = (
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: one

Original file line numberDiff line numberDiff line change
Expand Up@@ -18,10 +18,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 3
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added
- id: 25
Expand All@@ -40,10 +40,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added_default

Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_salary
- id: 16
Expand All@@ -44,7 +44,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_cost

2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/transforms.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1132,7 +1132,7 @@ mod tests {
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
partition:
- id: 12
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor: Rename `set` to `type` by max-sixty · Pull Request #2346 · PRQL/prql · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions prql-compiler/src/ast/pl/expr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ pub enum ExprKind {
name: String,
args: Vec<Expr>,
},
Set(SetExpr),
Type(TypeExpr),

/// a placeholder for values provided after query is compiled
Param(String),
Expand DownExpand Up@@ -599,8 +599,8 @@ impl Display for Expr {
ExprKind::BuiltInFunction { .. } => {
f.write_str("<built-in>")?;
}
ExprKind::Set(_) => {
writeln!(f, "<set-expr>")?;
ExprKind::Type(_) => {
writeln!(f, "<type-expr>")?;
}
ExprKind::Param(id) => {
writeln!(f, "${id}")?;
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/ast/pl/fold.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -119,7 +119,7 @@ pub fn fold_expr_kind<T: ?Sized + AstFold>(fold: &mut T, expr_kind: ExprKind) ->
Param(id) => Param(id),

// None of these capture variables, so we don't need to fold them.
Literal(_) | Set(_) => expr_kind,
Literal(_) | Type(_) => expr_kind,
})
}

Expand Down
56 changes: 28 additions & 28 deletions prql-compiler/src/ast/pl/types.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,37 +6,37 @@ use serde::{Deserialize, Serialize};
use super::{Frame, Literal};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum SetExpr {
/// Set of a built-in primitive type
pub enum TypeExpr {
/// Type of a built-in primitive type
Primitive(TyLit),

/// Set that contains only a literal value
/// Type that contains only a literal value
Singleton(Literal),

/// Union of sets (sum)
Union(Vec<(Option<String>, SetExpr)>),
Union(Vec<(Option<String>, TypeExpr)>),

/// Set of tuples (product)
/// Type of tuples (product)
Tuple(Vec<TupleElement>),

/// Set of arrays
Array(Box<SetExpr>),
/// Type of arrays
Array(Box<TypeExpr>),

/// Set of sets.
/// Type of sets.
/// Used for exprs that can be converted to SetExpr and then used as a Ty.
Set,
Type,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TupleElement {
Single(Option<String>, SetExpr),
Single(Option<String>, TypeExpr),
Wildcard,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum Ty {
/// Value is an element of this [SetExpr]
SetExpr(SetExpr),
TypeExpr(TypeExpr),

/// Value is a function described by [TyFunc]
// TODO: convert into [Ty::Domain].
Expand DownExpand Up@@ -93,7 +93,7 @@ impl Ty {
// Not handled here. See type_resolver.
(Ty::Infer, _) | (_, Ty::Infer) => false,

(Ty::SetExpr(left), Ty::SetExpr(right)) => left.is_superset_of(right),
(Ty::TypeExpr(left), Ty::TypeExpr(right)) => left.is_superset_of(right),

(Ty::Table(_), Ty::Table(_)) => true,

Expand All@@ -102,17 +102,17 @@ impl Ty {
}
}

impl SetExpr {
fn is_superset_of(&self, subset: &SetExpr) -> bool {
impl TypeExpr {
fn is_superset_of(&self, subset: &TypeExpr) -> bool {
match (self, subset) {
// TODO: convert these to array
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(TyLit::Column)) => true,
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(_)) => true,
(SetExpr::Primitive(_), SetExpr::Primitive(TyLit::Column)) => false,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(TyLit::Column)) => true,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(_)) => true,
(TypeExpr::Primitive(_), TypeExpr::Primitive(TyLit::Column)) => false,

(SetExpr::Primitive(l0), SetExpr::Primitive(r0)) => l0 == r0,
(SetExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, SetExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),
(TypeExpr::Primitive(l0), TypeExpr::Primitive(r0)) => l0 == r0,
(TypeExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, TypeExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),

(l, r) => l == r,
}
Expand All@@ -122,7 +122,7 @@ impl SetExpr {
impl Display for Ty {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
Ty::SetExpr(lit) => write!(f, "{:}", lit),
Ty::TypeExpr(lit) => write!(f, "{:}", lit),
Ty::Table(frame) => write!(f, "table<{frame}>"),
Ty::Infer => write!(f, "infer"),
Ty::Function(func) => {
Expand All@@ -138,11 +138,11 @@ impl Display for Ty {
}
}

impl Display for SetExpr {
impl Display for TypeExpr {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
SetExpr::Primitive(lit) => write!(f, "{:}", lit),
SetExpr::Union(ts) => {
TypeExpr::Primitive(lit) => write!(f, "{:}", lit),
TypeExpr::Union(ts) => {
for (i, (_, e)) in ts.iter().enumerate() {
write!(f, "{e}")?;
if i < ts.len() - 1 {
Expand All@@ -151,8 +151,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Singleton(lit) => write!(f, "{:}", lit),
SetExpr::Tuple(elements) => {
TypeExpr::Singleton(lit) => write!(f, "{:}", lit),
TypeExpr::Tuple(elements) => {
write!(f, "[")?;
for e in elements {
match e {
Expand All@@ -170,8 +170,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Set => write!(f, "set"),
SetExpr::Array(_) => todo!(),
TypeExpr::Type => write!(f, "set"),
TypeExpr::Array(_) => todo!(),
}
}
}
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -388,16 +388,16 @@ fn get_stdlib_decl(name: &str) -> Option<ExprKind> {
"timestamp" => TyLit::Timestamp,
"table" => {
// TODO: this is just a dummy that gets intercepted when resolving types
return Some(ExprKind::Set(SetExpr::Array(Box::new(SetExpr::Singleton(
Literal::Null,
)))));
return Some(ExprKind::Type(TypeExpr::Array(Box::new(
TypeExpr::Singleton(Literal::Null),
))));
}
"column" => TyLit::Column,
"list" => TyLit::List,
"scalar" => TyLit::Scalar,
_ => return None,
};
Some(ExprKind::Set(SetExpr::Primitive(ty_lit)))
Some(ExprKind::Type(TypeExpr::Primitive(ty_lit)))
}

impl Default for DeclKind {
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/lowering.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -662,7 +662,7 @@ impl Lowerer {
| pl::ExprKind::List(_)
| pl::ExprKind::Closure(_)
| pl::ExprKind::Pipeline(_)
| pl::ExprKind::Set(_)
| pl::ExprKind::Type(_)
| pl::ExprKind::TransformCall(_) => {
log::debug!("cannot lower {ast:?}");
return Err(Error::new(Reason::Unexpected {
Expand Down
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/resolver.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ impl AstFold for Resolver {
name: ty_def.name,
value: Box::new(ty_def.value.unwrap_or_else(|| {
let mut e = Expr::null();
e.ty = Some(Ty::SetExpr(SetExpr::Set));
e.ty = Some(Ty::TypeExpr(TypeExpr::Type));
e
})),
};
Expand DownExpand Up@@ -448,7 +448,7 @@ impl Resolver {
// evaluate
let needs_window = (closure.body_ty)
.as_ref()
.map(|ty| ty.is_superset_of(&Ty::SetExpr(SetExpr::Primitive(TyLit::Column))))
.map(|ty| ty.is_superset_of(&Ty::TypeExpr(TypeExpr::Primitive(TyLit::Column))))
.unwrap_or_default();

let mut res = match self.cast_built_in_function(closure)? {
Expand DownExpand Up@@ -780,11 +780,11 @@ impl Resolver {
let set_expr = type_resolver::coerce_to_set(expr, &self.context)?;

// TODO: workaround
if let SetExpr::Array(_) = set_expr {
if let TypeExpr::Array(_) = set_expr {
return Ok(Some(Ty::Table(Frame::default())));
}

Some(Ty::SetExpr(set_expr))
Some(Ty::TypeExpr(set_expr))
}
None => None,
})
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n func subtract a b -> a - b\n\n
target_id: 7
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: net_salary

Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
op: Add
Expand All@@ -53,6 +53,6 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
target_id: 8
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column

Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 2
ty:
SetExpr:
TypeExpr:
Primitive: Int
op: Add
right:
Expand All@@ -34,11 +34,11 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: b

Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ expression: "resolve_derive(r#\"\n from a\n derive one = (
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: one

Original file line numberDiff line numberDiff line change
Expand Up@@ -18,10 +18,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 3
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added
- id: 25
Expand All@@ -40,10 +40,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added_default

Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_salary
- id: 16
Expand All@@ -44,7 +44,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_cost

2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/transforms.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1132,7 +1132,7 @@ mod tests {
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
partition:
- id: 12
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' refactor: Rename `set` to `type` by max-sixty · Pull Request #2346 · PRQL/prql · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions prql-compiler/src/ast/pl/expr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ pub enum ExprKind {
name: String,
args: Vec<Expr>,
},
Set(SetExpr),
Type(TypeExpr),

/// a placeholder for values provided after query is compiled
Param(String),
Expand DownExpand Up@@ -599,8 +599,8 @@ impl Display for Expr {
ExprKind::BuiltInFunction { .. } => {
f.write_str("<built-in>")?;
}
ExprKind::Set(_) => {
writeln!(f, "<set-expr>")?;
ExprKind::Type(_) => {
writeln!(f, "<type-expr>")?;
}
ExprKind::Param(id) => {
writeln!(f, "${id}")?;
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/ast/pl/fold.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -119,7 +119,7 @@ pub fn fold_expr_kind<T: ?Sized + AstFold>(fold: &mut T, expr_kind: ExprKind) ->
Param(id) => Param(id),

// None of these capture variables, so we don't need to fold them.
Literal(_) | Set(_) => expr_kind,
Literal(_) | Type(_) => expr_kind,
})
}

Expand Down
56 changes: 28 additions & 28 deletions prql-compiler/src/ast/pl/types.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,37 +6,37 @@ use serde::{Deserialize, Serialize};
use super::{Frame, Literal};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum SetExpr {
/// Set of a built-in primitive type
pub enum TypeExpr {
/// Type of a built-in primitive type
Primitive(TyLit),

/// Set that contains only a literal value
/// Type that contains only a literal value
Singleton(Literal),

/// Union of sets (sum)
Union(Vec<(Option<String>, SetExpr)>),
Union(Vec<(Option<String>, TypeExpr)>),

/// Set of tuples (product)
/// Type of tuples (product)
Tuple(Vec<TupleElement>),

/// Set of arrays
Array(Box<SetExpr>),
/// Type of arrays
Array(Box<TypeExpr>),

/// Set of sets.
/// Type of sets.
/// Used for exprs that can be converted to SetExpr and then used as a Ty.
Set,
Type,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TupleElement {
Single(Option<String>, SetExpr),
Single(Option<String>, TypeExpr),
Wildcard,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum Ty {
/// Value is an element of this [SetExpr]
SetExpr(SetExpr),
TypeExpr(TypeExpr),

/// Value is a function described by [TyFunc]
// TODO: convert into [Ty::Domain].
Expand DownExpand Up@@ -93,7 +93,7 @@ impl Ty {
// Not handled here. See type_resolver.
(Ty::Infer, _) | (_, Ty::Infer) => false,

(Ty::SetExpr(left), Ty::SetExpr(right)) => left.is_superset_of(right),
(Ty::TypeExpr(left), Ty::TypeExpr(right)) => left.is_superset_of(right),

(Ty::Table(_), Ty::Table(_)) => true,

Expand All@@ -102,17 +102,17 @@ impl Ty {
}
}

impl SetExpr {
fn is_superset_of(&self, subset: &SetExpr) -> bool {
impl TypeExpr {
fn is_superset_of(&self, subset: &TypeExpr) -> bool {
match (self, subset) {
// TODO: convert these to array
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(TyLit::Column)) => true,
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(_)) => true,
(SetExpr::Primitive(_), SetExpr::Primitive(TyLit::Column)) => false,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(TyLit::Column)) => true,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(_)) => true,
(TypeExpr::Primitive(_), TypeExpr::Primitive(TyLit::Column)) => false,

(SetExpr::Primitive(l0), SetExpr::Primitive(r0)) => l0 == r0,
(SetExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, SetExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),
(TypeExpr::Primitive(l0), TypeExpr::Primitive(r0)) => l0 == r0,
(TypeExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, TypeExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),

(l, r) => l == r,
}
Expand All@@ -122,7 +122,7 @@ impl SetExpr {
impl Display for Ty {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
Ty::SetExpr(lit) => write!(f, "{:}", lit),
Ty::TypeExpr(lit) => write!(f, "{:}", lit),
Ty::Table(frame) => write!(f, "table<{frame}>"),
Ty::Infer => write!(f, "infer"),
Ty::Function(func) => {
Expand All@@ -138,11 +138,11 @@ impl Display for Ty {
}
}

impl Display for SetExpr {
impl Display for TypeExpr {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
SetExpr::Primitive(lit) => write!(f, "{:}", lit),
SetExpr::Union(ts) => {
TypeExpr::Primitive(lit) => write!(f, "{:}", lit),
TypeExpr::Union(ts) => {
for (i, (_, e)) in ts.iter().enumerate() {
write!(f, "{e}")?;
if i < ts.len() - 1 {
Expand All@@ -151,8 +151,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Singleton(lit) => write!(f, "{:}", lit),
SetExpr::Tuple(elements) => {
TypeExpr::Singleton(lit) => write!(f, "{:}", lit),
TypeExpr::Tuple(elements) => {
write!(f, "[")?;
for e in elements {
match e {
Expand All@@ -170,8 +170,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Set => write!(f, "set"),
SetExpr::Array(_) => todo!(),
TypeExpr::Type => write!(f, "set"),
TypeExpr::Array(_) => todo!(),
}
}
}
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -388,16 +388,16 @@ fn get_stdlib_decl(name: &str) -> Option<ExprKind> {
"timestamp" => TyLit::Timestamp,
"table" => {
// TODO: this is just a dummy that gets intercepted when resolving types
return Some(ExprKind::Set(SetExpr::Array(Box::new(SetExpr::Singleton(
Literal::Null,
)))));
return Some(ExprKind::Type(TypeExpr::Array(Box::new(
TypeExpr::Singleton(Literal::Null),
))));
}
"column" => TyLit::Column,
"list" => TyLit::List,
"scalar" => TyLit::Scalar,
_ => return None,
};
Some(ExprKind::Set(SetExpr::Primitive(ty_lit)))
Some(ExprKind::Type(TypeExpr::Primitive(ty_lit)))
}

impl Default for DeclKind {
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/lowering.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -662,7 +662,7 @@ impl Lowerer {
| pl::ExprKind::List(_)
| pl::ExprKind::Closure(_)
| pl::ExprKind::Pipeline(_)
| pl::ExprKind::Set(_)
| pl::ExprKind::Type(_)
| pl::ExprKind::TransformCall(_) => {
log::debug!("cannot lower {ast:?}");
return Err(Error::new(Reason::Unexpected {
Expand Down
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/resolver.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ impl AstFold for Resolver {
name: ty_def.name,
value: Box::new(ty_def.value.unwrap_or_else(|| {
let mut e = Expr::null();
e.ty = Some(Ty::SetExpr(SetExpr::Set));
e.ty = Some(Ty::TypeExpr(TypeExpr::Type));
e
})),
};
Expand DownExpand Up@@ -448,7 +448,7 @@ impl Resolver {
// evaluate
let needs_window = (closure.body_ty)
.as_ref()
.map(|ty| ty.is_superset_of(&Ty::SetExpr(SetExpr::Primitive(TyLit::Column))))
.map(|ty| ty.is_superset_of(&Ty::TypeExpr(TypeExpr::Primitive(TyLit::Column))))
.unwrap_or_default();

let mut res = match self.cast_built_in_function(closure)? {
Expand DownExpand Up@@ -780,11 +780,11 @@ impl Resolver {
let set_expr = type_resolver::coerce_to_set(expr, &self.context)?;

// TODO: workaround
if let SetExpr::Array(_) = set_expr {
if let TypeExpr::Array(_) = set_expr {
return Ok(Some(Ty::Table(Frame::default())));
}

Some(Ty::SetExpr(set_expr))
Some(Ty::TypeExpr(set_expr))
}
None => None,
})
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n func subtract a b -> a - b\n\n
target_id: 7
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: net_salary

Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
op: Add
Expand All@@ -53,6 +53,6 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
target_id: 8
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column

Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 2
ty:
SetExpr:
TypeExpr:
Primitive: Int
op: Add
right:
Expand All@@ -34,11 +34,11 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: b

Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ expression: "resolve_derive(r#\"\n from a\n derive one = (
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: one

Original file line numberDiff line numberDiff line change
Expand Up@@ -18,10 +18,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 3
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added
- id: 25
Expand All@@ -40,10 +40,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added_default

Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_salary
- id: 16
Expand All@@ -44,7 +44,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_cost

2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/transforms.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1132,7 +1132,7 @@ mod tests {
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
partition:
- id: 12
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor: Rename `set` to `type` by max-sixty · Pull Request #2346 · PRQL/prql · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions prql-compiler/src/ast/pl/expr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ pub enum ExprKind {
name: String,
args: Vec<Expr>,
},
Set(SetExpr),
Type(TypeExpr),

/// a placeholder for values provided after query is compiled
Param(String),
Expand DownExpand Up@@ -599,8 +599,8 @@ impl Display for Expr {
ExprKind::BuiltInFunction { .. } => {
f.write_str("<built-in>")?;
}
ExprKind::Set(_) => {
writeln!(f, "<set-expr>")?;
ExprKind::Type(_) => {
writeln!(f, "<type-expr>")?;
}
ExprKind::Param(id) => {
writeln!(f, "${id}")?;
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/ast/pl/fold.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -119,7 +119,7 @@ pub fn fold_expr_kind<T: ?Sized + AstFold>(fold: &mut T, expr_kind: ExprKind) ->
Param(id) => Param(id),

// None of these capture variables, so we don't need to fold them.
Literal(_) | Set(_) => expr_kind,
Literal(_) | Type(_) => expr_kind,
})
}

Expand Down
56 changes: 28 additions & 28 deletions prql-compiler/src/ast/pl/types.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,37 +6,37 @@ use serde::{Deserialize, Serialize};
use super::{Frame, Literal};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum SetExpr {
/// Set of a built-in primitive type
pub enum TypeExpr {
/// Type of a built-in primitive type
Primitive(TyLit),

/// Set that contains only a literal value
/// Type that contains only a literal value
Singleton(Literal),

/// Union of sets (sum)
Union(Vec<(Option<String>, SetExpr)>),
Union(Vec<(Option<String>, TypeExpr)>),

/// Set of tuples (product)
/// Type of tuples (product)
Tuple(Vec<TupleElement>),

/// Set of arrays
Array(Box<SetExpr>),
/// Type of arrays
Array(Box<TypeExpr>),

/// Set of sets.
/// Type of sets.
/// Used for exprs that can be converted to SetExpr and then used as a Ty.
Set,
Type,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TupleElement {
Single(Option<String>, SetExpr),
Single(Option<String>, TypeExpr),
Wildcard,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum Ty {
/// Value is an element of this [SetExpr]
SetExpr(SetExpr),
TypeExpr(TypeExpr),

/// Value is a function described by [TyFunc]
// TODO: convert into [Ty::Domain].
Expand DownExpand Up@@ -93,7 +93,7 @@ impl Ty {
// Not handled here. See type_resolver.
(Ty::Infer, _) | (_, Ty::Infer) => false,

(Ty::SetExpr(left), Ty::SetExpr(right)) => left.is_superset_of(right),
(Ty::TypeExpr(left), Ty::TypeExpr(right)) => left.is_superset_of(right),

(Ty::Table(_), Ty::Table(_)) => true,

Expand All@@ -102,17 +102,17 @@ impl Ty {
}
}

impl SetExpr {
fn is_superset_of(&self, subset: &SetExpr) -> bool {
impl TypeExpr {
fn is_superset_of(&self, subset: &TypeExpr) -> bool {
match (self, subset) {
// TODO: convert these to array
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(TyLit::Column)) => true,
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(_)) => true,
(SetExpr::Primitive(_), SetExpr::Primitive(TyLit::Column)) => false,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(TyLit::Column)) => true,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(_)) => true,
(TypeExpr::Primitive(_), TypeExpr::Primitive(TyLit::Column)) => false,

(SetExpr::Primitive(l0), SetExpr::Primitive(r0)) => l0 == r0,
(SetExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, SetExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),
(TypeExpr::Primitive(l0), TypeExpr::Primitive(r0)) => l0 == r0,
(TypeExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, TypeExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),

(l, r) => l == r,
}
Expand All@@ -122,7 +122,7 @@ impl SetExpr {
impl Display for Ty {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
Ty::SetExpr(lit) => write!(f, "{:}", lit),
Ty::TypeExpr(lit) => write!(f, "{:}", lit),
Ty::Table(frame) => write!(f, "table<{frame}>"),
Ty::Infer => write!(f, "infer"),
Ty::Function(func) => {
Expand All@@ -138,11 +138,11 @@ impl Display for Ty {
}
}

impl Display for SetExpr {
impl Display for TypeExpr {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
SetExpr::Primitive(lit) => write!(f, "{:}", lit),
SetExpr::Union(ts) => {
TypeExpr::Primitive(lit) => write!(f, "{:}", lit),
TypeExpr::Union(ts) => {
for (i, (_, e)) in ts.iter().enumerate() {
write!(f, "{e}")?;
if i < ts.len() - 1 {
Expand All@@ -151,8 +151,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Singleton(lit) => write!(f, "{:}", lit),
SetExpr::Tuple(elements) => {
TypeExpr::Singleton(lit) => write!(f, "{:}", lit),
TypeExpr::Tuple(elements) => {
write!(f, "[")?;
for e in elements {
match e {
Expand All@@ -170,8 +170,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Set => write!(f, "set"),
SetExpr::Array(_) => todo!(),
TypeExpr::Type => write!(f, "set"),
TypeExpr::Array(_) => todo!(),
}
}
}
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -388,16 +388,16 @@ fn get_stdlib_decl(name: &str) -> Option<ExprKind> {
"timestamp" => TyLit::Timestamp,
"table" => {
// TODO: this is just a dummy that gets intercepted when resolving types
return Some(ExprKind::Set(SetExpr::Array(Box::new(SetExpr::Singleton(
Literal::Null,
)))));
return Some(ExprKind::Type(TypeExpr::Array(Box::new(
TypeExpr::Singleton(Literal::Null),
))));
}
"column" => TyLit::Column,
"list" => TyLit::List,
"scalar" => TyLit::Scalar,
_ => return None,
};
Some(ExprKind::Set(SetExpr::Primitive(ty_lit)))
Some(ExprKind::Type(TypeExpr::Primitive(ty_lit)))
}

impl Default for DeclKind {
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/lowering.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -662,7 +662,7 @@ impl Lowerer {
| pl::ExprKind::List(_)
| pl::ExprKind::Closure(_)
| pl::ExprKind::Pipeline(_)
| pl::ExprKind::Set(_)
| pl::ExprKind::Type(_)
| pl::ExprKind::TransformCall(_) => {
log::debug!("cannot lower {ast:?}");
return Err(Error::new(Reason::Unexpected {
Expand Down
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/resolver.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ impl AstFold for Resolver {
name: ty_def.name,
value: Box::new(ty_def.value.unwrap_or_else(|| {
let mut e = Expr::null();
e.ty = Some(Ty::SetExpr(SetExpr::Set));
e.ty = Some(Ty::TypeExpr(TypeExpr::Type));
e
})),
};
Expand DownExpand Up@@ -448,7 +448,7 @@ impl Resolver {
// evaluate
let needs_window = (closure.body_ty)
.as_ref()
.map(|ty| ty.is_superset_of(&Ty::SetExpr(SetExpr::Primitive(TyLit::Column))))
.map(|ty| ty.is_superset_of(&Ty::TypeExpr(TypeExpr::Primitive(TyLit::Column))))
.unwrap_or_default();

let mut res = match self.cast_built_in_function(closure)? {
Expand DownExpand Up@@ -780,11 +780,11 @@ impl Resolver {
let set_expr = type_resolver::coerce_to_set(expr, &self.context)?;

// TODO: workaround
if let SetExpr::Array(_) = set_expr {
if let TypeExpr::Array(_) = set_expr {
return Ok(Some(Ty::Table(Frame::default())));
}

Some(Ty::SetExpr(set_expr))
Some(Ty::TypeExpr(set_expr))
}
None => None,
})
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n func subtract a b -> a - b\n\n
target_id: 7
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: net_salary

Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
op: Add
Expand All@@ -53,6 +53,6 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
target_id: 8
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column

Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 2
ty:
SetExpr:
TypeExpr:
Primitive: Int
op: Add
right:
Expand All@@ -34,11 +34,11 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: b

Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ expression: "resolve_derive(r#\"\n from a\n derive one = (
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: one

Original file line numberDiff line numberDiff line change
Expand Up@@ -18,10 +18,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 3
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added
- id: 25
Expand All@@ -40,10 +40,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added_default

Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_salary
- id: 16
Expand All@@ -44,7 +44,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_cost

2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/transforms.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1132,7 +1132,7 @@ mod tests {
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
partition:
- id: 12
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor: Rename `set` to `type` by max-sixty · Pull Request #2346 · PRQL/prql · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions prql-compiler/src/ast/pl/expr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ pub enum ExprKind {
name: String,
args: Vec<Expr>,
},
Set(SetExpr),
Type(TypeExpr),

/// a placeholder for values provided after query is compiled
Param(String),
Expand DownExpand Up@@ -599,8 +599,8 @@ impl Display for Expr {
ExprKind::BuiltInFunction { .. } => {
f.write_str("<built-in>")?;
}
ExprKind::Set(_) => {
writeln!(f, "<set-expr>")?;
ExprKind::Type(_) => {
writeln!(f, "<type-expr>")?;
}
ExprKind::Param(id) => {
writeln!(f, "${id}")?;
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/ast/pl/fold.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -119,7 +119,7 @@ pub fn fold_expr_kind<T: ?Sized + AstFold>(fold: &mut T, expr_kind: ExprKind) ->
Param(id) => Param(id),

// None of these capture variables, so we don't need to fold them.
Literal(_) | Set(_) => expr_kind,
Literal(_) | Type(_) => expr_kind,
})
}

Expand Down
56 changes: 28 additions & 28 deletions prql-compiler/src/ast/pl/types.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,37 +6,37 @@ use serde::{Deserialize, Serialize};
use super::{Frame, Literal};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum SetExpr {
/// Set of a built-in primitive type
pub enum TypeExpr {
/// Type of a built-in primitive type
Primitive(TyLit),

/// Set that contains only a literal value
/// Type that contains only a literal value
Singleton(Literal),

/// Union of sets (sum)
Union(Vec<(Option<String>, SetExpr)>),
Union(Vec<(Option<String>, TypeExpr)>),

/// Set of tuples (product)
/// Type of tuples (product)
Tuple(Vec<TupleElement>),

/// Set of arrays
Array(Box<SetExpr>),
/// Type of arrays
Array(Box<TypeExpr>),

/// Set of sets.
/// Type of sets.
/// Used for exprs that can be converted to SetExpr and then used as a Ty.
Set,
Type,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TupleElement {
Single(Option<String>, SetExpr),
Single(Option<String>, TypeExpr),
Wildcard,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum Ty {
/// Value is an element of this [SetExpr]
SetExpr(SetExpr),
TypeExpr(TypeExpr),

/// Value is a function described by [TyFunc]
// TODO: convert into [Ty::Domain].
Expand DownExpand Up@@ -93,7 +93,7 @@ impl Ty {
// Not handled here. See type_resolver.
(Ty::Infer, _) | (_, Ty::Infer) => false,

(Ty::SetExpr(left), Ty::SetExpr(right)) => left.is_superset_of(right),
(Ty::TypeExpr(left), Ty::TypeExpr(right)) => left.is_superset_of(right),

(Ty::Table(_), Ty::Table(_)) => true,

Expand All@@ -102,17 +102,17 @@ impl Ty {
}
}

impl SetExpr {
fn is_superset_of(&self, subset: &SetExpr) -> bool {
impl TypeExpr {
fn is_superset_of(&self, subset: &TypeExpr) -> bool {
match (self, subset) {
// TODO: convert these to array
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(TyLit::Column)) => true,
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(_)) => true,
(SetExpr::Primitive(_), SetExpr::Primitive(TyLit::Column)) => false,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(TyLit::Column)) => true,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(_)) => true,
(TypeExpr::Primitive(_), TypeExpr::Primitive(TyLit::Column)) => false,

(SetExpr::Primitive(l0), SetExpr::Primitive(r0)) => l0 == r0,
(SetExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, SetExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),
(TypeExpr::Primitive(l0), TypeExpr::Primitive(r0)) => l0 == r0,
(TypeExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, TypeExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),

(l, r) => l == r,
}
Expand All@@ -122,7 +122,7 @@ impl SetExpr {
impl Display for Ty {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
Ty::SetExpr(lit) => write!(f, "{:}", lit),
Ty::TypeExpr(lit) => write!(f, "{:}", lit),
Ty::Table(frame) => write!(f, "table<{frame}>"),
Ty::Infer => write!(f, "infer"),
Ty::Function(func) => {
Expand All@@ -138,11 +138,11 @@ impl Display for Ty {
}
}

impl Display for SetExpr {
impl Display for TypeExpr {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
SetExpr::Primitive(lit) => write!(f, "{:}", lit),
SetExpr::Union(ts) => {
TypeExpr::Primitive(lit) => write!(f, "{:}", lit),
TypeExpr::Union(ts) => {
for (i, (_, e)) in ts.iter().enumerate() {
write!(f, "{e}")?;
if i < ts.len() - 1 {
Expand All@@ -151,8 +151,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Singleton(lit) => write!(f, "{:}", lit),
SetExpr::Tuple(elements) => {
TypeExpr::Singleton(lit) => write!(f, "{:}", lit),
TypeExpr::Tuple(elements) => {
write!(f, "[")?;
for e in elements {
match e {
Expand All@@ -170,8 +170,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Set => write!(f, "set"),
SetExpr::Array(_) => todo!(),
TypeExpr::Type => write!(f, "set"),
TypeExpr::Array(_) => todo!(),
}
}
}
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -388,16 +388,16 @@ fn get_stdlib_decl(name: &str) -> Option<ExprKind> {
"timestamp" => TyLit::Timestamp,
"table" => {
// TODO: this is just a dummy that gets intercepted when resolving types
return Some(ExprKind::Set(SetExpr::Array(Box::new(SetExpr::Singleton(
Literal::Null,
)))));
return Some(ExprKind::Type(TypeExpr::Array(Box::new(
TypeExpr::Singleton(Literal::Null),
))));
}
"column" => TyLit::Column,
"list" => TyLit::List,
"scalar" => TyLit::Scalar,
_ => return None,
};
Some(ExprKind::Set(SetExpr::Primitive(ty_lit)))
Some(ExprKind::Type(TypeExpr::Primitive(ty_lit)))
}

impl Default for DeclKind {
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/lowering.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -662,7 +662,7 @@ impl Lowerer {
| pl::ExprKind::List(_)
| pl::ExprKind::Closure(_)
| pl::ExprKind::Pipeline(_)
| pl::ExprKind::Set(_)
| pl::ExprKind::Type(_)
| pl::ExprKind::TransformCall(_) => {
log::debug!("cannot lower {ast:?}");
return Err(Error::new(Reason::Unexpected {
Expand Down
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/resolver.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ impl AstFold for Resolver {
name: ty_def.name,
value: Box::new(ty_def.value.unwrap_or_else(|| {
let mut e = Expr::null();
e.ty = Some(Ty::SetExpr(SetExpr::Set));
e.ty = Some(Ty::TypeExpr(TypeExpr::Type));
e
})),
};
Expand DownExpand Up@@ -448,7 +448,7 @@ impl Resolver {
// evaluate
let needs_window = (closure.body_ty)
.as_ref()
.map(|ty| ty.is_superset_of(&Ty::SetExpr(SetExpr::Primitive(TyLit::Column))))
.map(|ty| ty.is_superset_of(&Ty::TypeExpr(TypeExpr::Primitive(TyLit::Column))))
.unwrap_or_default();

let mut res = match self.cast_built_in_function(closure)? {
Expand DownExpand Up@@ -780,11 +780,11 @@ impl Resolver {
let set_expr = type_resolver::coerce_to_set(expr, &self.context)?;

// TODO: workaround
if let SetExpr::Array(_) = set_expr {
if let TypeExpr::Array(_) = set_expr {
return Ok(Some(Ty::Table(Frame::default())));
}

Some(Ty::SetExpr(set_expr))
Some(Ty::TypeExpr(set_expr))
}
None => None,
})
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n func subtract a b -> a - b\n\n
target_id: 7
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: net_salary

Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
op: Add
Expand All@@ -53,6 +53,6 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
target_id: 8
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column

Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 2
ty:
SetExpr:
TypeExpr:
Primitive: Int
op: Add
right:
Expand All@@ -34,11 +34,11 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: b

Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ expression: "resolve_derive(r#\"\n from a\n derive one = (
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: one

Original file line numberDiff line numberDiff line change
Expand Up@@ -18,10 +18,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 3
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added
- id: 25
Expand All@@ -40,10 +40,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added_default

Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_salary
- id: 16
Expand All@@ -44,7 +44,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_cost

2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/transforms.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1132,7 +1132,7 @@ mod tests {
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
partition:
- id: 12
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); refactor: Rename `set` to `type` by max-sixty · Pull Request #2346 · PRQL/prql · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions prql-compiler/src/ast/pl/expr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ pub enum ExprKind {
name: String,
args: Vec<Expr>,
},
Set(SetExpr),
Type(TypeExpr),

/// a placeholder for values provided after query is compiled
Param(String),
Expand DownExpand Up@@ -599,8 +599,8 @@ impl Display for Expr {
ExprKind::BuiltInFunction { .. } => {
f.write_str("<built-in>")?;
}
ExprKind::Set(_) => {
writeln!(f, "<set-expr>")?;
ExprKind::Type(_) => {
writeln!(f, "<type-expr>")?;
}
ExprKind::Param(id) => {
writeln!(f, "${id}")?;
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/ast/pl/fold.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -119,7 +119,7 @@ pub fn fold_expr_kind<T: ?Sized + AstFold>(fold: &mut T, expr_kind: ExprKind) ->
Param(id) => Param(id),

// None of these capture variables, so we don't need to fold them.
Literal(_) | Set(_) => expr_kind,
Literal(_) | Type(_) => expr_kind,
})
}

Expand Down
56 changes: 28 additions & 28 deletions prql-compiler/src/ast/pl/types.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,37 +6,37 @@ use serde::{Deserialize, Serialize};
use super::{Frame, Literal};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum SetExpr {
/// Set of a built-in primitive type
pub enum TypeExpr {
/// Type of a built-in primitive type
Primitive(TyLit),

/// Set that contains only a literal value
/// Type that contains only a literal value
Singleton(Literal),

/// Union of sets (sum)
Union(Vec<(Option<String>, SetExpr)>),
Union(Vec<(Option<String>, TypeExpr)>),

/// Set of tuples (product)
/// Type of tuples (product)
Tuple(Vec<TupleElement>),

/// Set of arrays
Array(Box<SetExpr>),
/// Type of arrays
Array(Box<TypeExpr>),

/// Set of sets.
/// Type of sets.
/// Used for exprs that can be converted to SetExpr and then used as a Ty.
Set,
Type,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TupleElement {
Single(Option<String>, SetExpr),
Single(Option<String>, TypeExpr),
Wildcard,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumAsInner)]
pub enum Ty {
/// Value is an element of this [SetExpr]
SetExpr(SetExpr),
TypeExpr(TypeExpr),

/// Value is a function described by [TyFunc]
// TODO: convert into [Ty::Domain].
Expand DownExpand Up@@ -93,7 +93,7 @@ impl Ty {
// Not handled here. See type_resolver.
(Ty::Infer, _) | (_, Ty::Infer) => false,

(Ty::SetExpr(left), Ty::SetExpr(right)) => left.is_superset_of(right),
(Ty::TypeExpr(left), Ty::TypeExpr(right)) => left.is_superset_of(right),

(Ty::Table(_), Ty::Table(_)) => true,

Expand All@@ -102,17 +102,17 @@ impl Ty {
}
}

impl SetExpr {
fn is_superset_of(&self, subset: &SetExpr) -> bool {
impl TypeExpr {
fn is_superset_of(&self, subset: &TypeExpr) -> bool {
match (self, subset) {
// TODO: convert these to array
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(TyLit::Column)) => true,
(SetExpr::Primitive(TyLit::Column), SetExpr::Primitive(_)) => true,
(SetExpr::Primitive(_), SetExpr::Primitive(TyLit::Column)) => false,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(TyLit::Column)) => true,
(TypeExpr::Primitive(TyLit::Column), TypeExpr::Primitive(_)) => true,
(TypeExpr::Primitive(_), TypeExpr::Primitive(TyLit::Column)) => false,

(SetExpr::Primitive(l0), SetExpr::Primitive(r0)) => l0 == r0,
(SetExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, SetExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),
(TypeExpr::Primitive(l0), TypeExpr::Primitive(r0)) => l0 == r0,
(TypeExpr::Union(many), one) => many.iter().any(|(_, any)| any.is_superset_of(one)),
(one, TypeExpr::Union(many)) => many.iter().all(|(_, each)| one.is_superset_of(each)),

(l, r) => l == r,
}
Expand All@@ -122,7 +122,7 @@ impl SetExpr {
impl Display for Ty {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
Ty::SetExpr(lit) => write!(f, "{:}", lit),
Ty::TypeExpr(lit) => write!(f, "{:}", lit),
Ty::Table(frame) => write!(f, "table<{frame}>"),
Ty::Infer => write!(f, "infer"),
Ty::Function(func) => {
Expand All@@ -138,11 +138,11 @@ impl Display for Ty {
}
}

impl Display for SetExpr {
impl Display for TypeExpr {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match &self {
SetExpr::Primitive(lit) => write!(f, "{:}", lit),
SetExpr::Union(ts) => {
TypeExpr::Primitive(lit) => write!(f, "{:}", lit),
TypeExpr::Union(ts) => {
for (i, (_, e)) in ts.iter().enumerate() {
write!(f, "{e}")?;
if i < ts.len() - 1 {
Expand All@@ -151,8 +151,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Singleton(lit) => write!(f, "{:}", lit),
SetExpr::Tuple(elements) => {
TypeExpr::Singleton(lit) => write!(f, "{:}", lit),
TypeExpr::Tuple(elements) => {
write!(f, "[")?;
for e in elements {
match e {
Expand All@@ -170,8 +170,8 @@ impl Display for SetExpr {
}
Ok(())
}
SetExpr::Set => write!(f, "set"),
SetExpr::Array(_) => todo!(),
TypeExpr::Type => write!(f, "set"),
TypeExpr::Array(_) => todo!(),
}
}
}
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/context.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -388,16 +388,16 @@ fn get_stdlib_decl(name: &str) -> Option<ExprKind> {
"timestamp" => TyLit::Timestamp,
"table" => {
// TODO: this is just a dummy that gets intercepted when resolving types
return Some(ExprKind::Set(SetExpr::Array(Box::new(SetExpr::Singleton(
Literal::Null,
)))));
return Some(ExprKind::Type(TypeExpr::Array(Box::new(
TypeExpr::Singleton(Literal::Null),
))));
}
"column" => TyLit::Column,
"list" => TyLit::List,
"scalar" => TyLit::Scalar,
_ => return None,
};
Some(ExprKind::Set(SetExpr::Primitive(ty_lit)))
Some(ExprKind::Type(TypeExpr::Primitive(ty_lit)))
}

impl Default for DeclKind {
Expand Down
2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/lowering.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -662,7 +662,7 @@ impl Lowerer {
| pl::ExprKind::List(_)
| pl::ExprKind::Closure(_)
| pl::ExprKind::Pipeline(_)
| pl::ExprKind::Set(_)
| pl::ExprKind::Type(_)
| pl::ExprKind::TransformCall(_) => {
log::debug!("cannot lower {ast:?}");
return Err(Error::new(Reason::Unexpected {
Expand Down
8 changes: 4 additions & 4 deletions prql-compiler/src/semantic/resolver.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,7 +77,7 @@ impl AstFold for Resolver {
name: ty_def.name,
value: Box::new(ty_def.value.unwrap_or_else(|| {
let mut e = Expr::null();
e.ty = Some(Ty::SetExpr(SetExpr::Set));
e.ty = Some(Ty::TypeExpr(TypeExpr::Type));
e
})),
};
Expand DownExpand Up@@ -448,7 +448,7 @@ impl Resolver {
// evaluate
let needs_window = (closure.body_ty)
.as_ref()
.map(|ty| ty.is_superset_of(&Ty::SetExpr(SetExpr::Primitive(TyLit::Column))))
.map(|ty| ty.is_superset_of(&Ty::TypeExpr(TypeExpr::Primitive(TyLit::Column))))
.unwrap_or_default();

let mut res = match self.cast_built_in_function(closure)? {
Expand DownExpand Up@@ -780,11 +780,11 @@ impl Resolver {
let set_expr = type_resolver::coerce_to_set(expr, &self.context)?;

// TODO: workaround
if let SetExpr::Array(_) = set_expr {
if let TypeExpr::Array(_) = set_expr {
return Ok(Some(Ty::Table(Frame::default())));
}

Some(Ty::SetExpr(set_expr))
Some(Ty::TypeExpr(set_expr))
}
None => None,
})
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n func subtract a b -> a - b\n\n
target_id: 7
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: net_salary

Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
op: Add
Expand All@@ -53,6 +53,6 @@ expression: "resolve_derive(r#\"\n func lag_day x -> s\"lag_day_todo(
target_id: 8
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column

Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 2
ty:
SetExpr:
TypeExpr:
Primitive: Int
op: Add
right:
Expand All@@ -34,11 +34,11 @@ expression: "resolve_derive(r#\"\n func plus_one x -> x + 1\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: b

Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ expression: "resolve_derive(r#\"\n from a\n derive one = (
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: one

Original file line numberDiff line numberDiff line change
Expand Up@@ -18,10 +18,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 3
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added
- id: 25
Expand All@@ -40,10 +40,10 @@ expression: "resolve_derive(r#\"\n func add x to:1 -> x + to\n\n
Literal:
Integer: 1
ty:
SetExpr:
TypeExpr:
Primitive: Int
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: added_default

Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_salary
- id: 16
Expand All@@ -44,7 +44,7 @@ expression: "resolve_derive(r#\"\n from employees\n derive
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
alias: gross_cost

2 changes: 1 addition & 1 deletion prql-compiler/src/semantic/transforms.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1132,7 +1132,7 @@ mod tests {
target_id: 6
ty: Infer
ty:
SetExpr:
TypeExpr:
Primitive: Column
partition:
- id: 12
Expand Down
Loading