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
Binary file modified embed/stdlib/contrib/RohanSreerama5/naiveBayesClassifier.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/anaisdg/anomalydetection.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/anaisdg/statsmodels.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/bonitoo-io/alerta.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/bonitoo-io/servicenow.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/bonitoo-io/tickscript.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/bonitoo-io/victorops.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/bonitoo-io/zenoss.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/chobbs/discord.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/jsternberg/aggregate.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/jsternberg/influxdb.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/jsternberg/math.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/rhajek/bigpanda.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/sranka/opsgenie.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/sranka/sensu.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/sranka/teams.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/sranka/telegram.fc
Binary file not shown.
Binary file modified embed/stdlib/contrib/sranka/webexteams.fc
Binary file not shown.
Binary file modified embed/stdlib/date.fc
Binary file not shown.
Binary file modified embed/stdlib/experimental.fc
Binary file not shown.
Binary file modified embed/stdlib/experimental/aggregate.fc
Binary file not shown.
Binary file modified embed/stdlib/experimental/array.fc
Binary file not shown.
Binary file modified embed/stdlib/experimental/csv.fc
Binary file not shown.
Binary file modified embed/stdlib/experimental/geo.fc
Binary file not shown.
Binary file modified embed/stdlib/experimental/oee.fc
Binary file not shown.
Binary file modified embed/stdlib/experimental/prometheus.fc
Binary file not shown.
Binary file modified embed/stdlib/experimental/query.fc
Binary file not shown.
Binary file modified embed/stdlib/experimental/usage.fc
Binary file not shown.
Binary file modified embed/stdlib/http.fc
Binary file not shown.
Binary file modified embed/stdlib/influxdata/influxdb/monitor.fc
Binary file not shown.
Binary file modified embed/stdlib/influxdata/influxdb/sample.fc
Binary file not shown.
Binary file modified embed/stdlib/influxdata/influxdb/schema.fc
Binary file not shown.
Binary file modified embed/stdlib/influxdata/influxdb/tasks.fc
Binary file not shown.
Binary file modified embed/stdlib/influxdata/influxdb/v1.fc
Binary file not shown.
Binary file modified embed/stdlib/internal/promql.fc
Binary file not shown.
Binary file modified embed/stdlib/pagerduty.fc
Binary file not shown.
Binary file modified embed/stdlib/pushbullet.fc
Binary file not shown.
Binary file modified embed/stdlib/sampledata.fc
Binary file not shown.
Binary file modified embed/stdlib/slack.fc
Binary file not shown.
Binary file modified embed/stdlib/testing.fc
Binary file not shown.
Binary file modified embed/stdlib/timezone.fc
Binary file not shown.
Binary file modified embed/stdlib/universe.fc
Binary file not shown.
40 changes: 15 additions & 25 deletions libflux/flux-core/src/semantic/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,20 +610,9 @@ impl<'a> Converter<'a> {
for con in &type_expression.constraints {
if con.tvar.name == name {
for k in &con.kinds {
match k.name.as_str() {
"Addable" => kinds.push(types::Kind::Addable),
"Subtractable" => kinds.push(types::Kind::Subtractable),
"Divisible" => kinds.push(types::Kind::Divisible),
"Numeric" => kinds.push(types::Kind::Numeric),
"Comparable" => kinds.push(types::Kind::Comparable),
"Equatable" => kinds.push(types::Kind::Equatable),
"Nullable" => kinds.push(types::Kind::Nullable),
"Negatable" => kinds.push(types::Kind::Negatable),
"Timeable" => kinds.push(types::Kind::Timeable),
"Record" => kinds.push(types::Kind::Record),
"Basic" => kinds.push(types::Kind::Basic),
"Stringable" => kinds.push(types::Kind::Stringable),
_ => {
match k.name.parse() {
Ok(kind) => kinds.push(kind),
Err(()) => {
self.errors.push(located(
k.base.location.clone(),
ErrorKind::InvalidConstraint(k.name.clone()),
Expand Down Expand Up @@ -770,7 +759,7 @@ impl<'a> Converter<'a> {

Ok(FunctionExpr {
loc: expr.base.location,
typ: MonoType::Var(self.sub.fresh()),
typ: MonoType::Error,
params,
body,
vectorized: None,
Expand Down Expand Up @@ -958,7 +947,7 @@ impl<'a> Converter<'a> {
}?;
Ok(CallExpr {
loc: expr.base.location,
typ: MonoType::Var(self.sub.fresh()),
typ: MonoType::Error,
callee,
arguments,
pipe: None,
Expand All @@ -974,7 +963,7 @@ impl<'a> Converter<'a> {
let property = self.symbols.lookup_property_key(&property);
Ok(MemberExpr {
loc: expr.base.location,
typ: MonoType::Var(self.sub.fresh()),
typ: MonoType::Error,
object,
property,
})
Expand All @@ -985,7 +974,7 @@ impl<'a> Converter<'a> {
let index = self.convert_expression(expr.index)?;
Ok(IndexExpr {
loc: expr.base.location,
typ: MonoType::Var(self.sub.fresh()),
typ: MonoType::Error,
array,
index,
})
Expand All @@ -1003,7 +992,7 @@ impl<'a> Converter<'a> {
let right = self.convert_expression(expr.right)?;
Ok(BinaryExpr {
loc: expr.base.location,
typ: MonoType::Var(self.sub.fresh()),
typ: MonoType::Error,
operator: expr.operator,
left,
right,
Expand All @@ -1014,7 +1003,7 @@ impl<'a> Converter<'a> {
let argument = self.convert_expression(expr.argument)?;
Ok(UnaryExpr {
loc: expr.base.location,
typ: MonoType::Var(self.sub.fresh()),
typ: MonoType::Error,
operator: expr.operator,
argument,
})
Expand Down Expand Up @@ -1043,6 +1032,7 @@ impl<'a> Converter<'a> {
test,
consequent,
alternate,
typ: MonoType::Error,
})
}

Expand All @@ -1058,7 +1048,7 @@ impl<'a> Converter<'a> {
};
Ok(ObjectExpr {
loc: expr.base.location,
typ: MonoType::Var(self.sub.fresh()),
typ: MonoType::Error,
with,
properties,
})
Expand All @@ -1080,7 +1070,7 @@ impl<'a> Converter<'a> {
Some(expr) => self.convert_expression(expr)?,
None => Expression::Identifier(IdentifierExpr {
loc: key.loc.clone(),
typ: MonoType::Var(self.sub.fresh()),
typ: MonoType::Error,
name: self
.symbols
.lookup_option(&key.name)
Expand All @@ -1102,7 +1092,7 @@ impl<'a> Converter<'a> {
.collect::<Result<Vec<Expression>>>()?;
Ok(ArrayExpr {
loc: expr.base.location,
typ: MonoType::Var(self.sub.fresh()),
typ: MonoType::Error,
elements,
})
}
Expand All @@ -1117,7 +1107,7 @@ impl<'a> Converter<'a> {
}
Ok(DictExpr {
loc: expr.base.location,
typ: MonoType::Var(self.sub.fresh()),
typ: MonoType::Error,
elements,
})
}
Expand Down Expand Up @@ -1150,7 +1140,7 @@ impl<'a> Converter<'a> {

fn convert_identifier_expression(&mut self, id: ast::Identifier) -> Result<IdentifierExpr> {
Ok(IdentifierExpr {
typ: MonoType::Var(self.sub.fresh()),
typ: MonoType::Error,
name: self.symbols.lookup(&id.name),
loc: id.base.location,
})
Expand Down
30 changes: 27 additions & 3 deletions libflux/flux-core/src/semantic/flatbuffers/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ use chrono::FixedOffset;

use super::semantic_generated::fbsemantic;
use crate::{
ast, semantic,
ast,
semantic::{
convert,
self, convert,
env::Environment,
import::Packages,
nodes::{FunctionExpr, Package},
sub,
walk::{walk, Node},
types::{MonoType, Tvar},
walk::{walk, walk_mut, Node, NodeMut},
Analyzer,
},
};
Expand Down Expand Up @@ -105,6 +106,29 @@ re !~ /foo/
return;
}
};

// We can't serialize the error types so replace any `typ` fields with a dummy variable instead
walk_mut(
&mut |n: &mut NodeMut<'_>| {
let typ = match n {
NodeMut::ArrayExpr(a) => &mut a.typ,
NodeMut::DictExpr(a) => &mut a.typ,
NodeMut::FunctionExpr(a) => &mut a.typ,
NodeMut::BinaryExpr(a) => &mut a.typ,
NodeMut::CallExpr(a) => &mut a.typ,
NodeMut::ConditionalExpr(a) => &mut a.typ,
NodeMut::MemberExpr(a) => &mut a.typ,
NodeMut::IndexExpr(a) => &mut a.typ,
NodeMut::ObjectExpr(a) => &mut a.typ,
NodeMut::UnaryExpr(a) => &mut a.typ,
NodeMut::IdentifierExpr(a) => &mut a.typ,
_ => return,
};
*typ = MonoType::Var(Tvar(0));
},
&mut NodeMut::Package(&mut pkg),
);

let (vec, offset) = match super::serialize_pkg(&mut pkg) {
Ok((v, o)) => (v, o),
Err(e) => {
Expand Down
2 changes: 1 addition & 1 deletion libflux/flux-core/src/semantic/formatter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ impl Formatter {
self.unindent();
}
self.write_rune(')');
self.write_string(&format!(":{}", &n.consequent.type_of()));
self.write_string(&format!(":{}", &n.typ));
}

fn format_member_assignment(&mut self, n: &semantic::nodes::MemberAssgn) {
Expand Down
18 changes: 9 additions & 9 deletions libflux/flux-core/src/semantic/formatter/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ fn format_function_expression() {
expect![[r#"
package main
(a) => {
return a:t19
}:(a:t19) => t19
return a:A
}:(a:A) => A
f = (a, b=1) => {
return a:t21 +:t21 b:t21
}:(a:t21, ?b:t21) => t21
return a:C +:C b:C
}:(a:C, ?b:C) => C
x = f:(a:int, ?b:int) => int(a: 2):int
y = f:(a:int, ?b:int) => int(a: x:int, b: f:(a:int, ?b:int) => int(a: x:int):int):int
g = (t) => {
return t:t28
}:(<-t:t28) => t28"#]],
return t:t12
}:(<-t:t12) => t12"#]],
)
}

Expand Down Expand Up @@ -265,8 +265,8 @@ fn format_block_statement() {
expect![[r#"
package main
(r) => {
v = (if r:J <:bool 0 then -r:J:J else r:J):J
return v:J *:J v:J
}:(r:J) => J"#]],
v = (if r:A <:bool 0 then -r:A:A else r:A):A
return v:A *:A v:A
}:(r:A) => A"#]],
)
}
2 changes: 1 addition & 1 deletion libflux/flux-core/src/semantic/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub fn equal(
act: &MonoType,
loc: &SourceLocation,
sub: &mut Substitution,
) -> Result<(), Located<Errors<types::Error>>> {
) -> Result<MonoType, Located<Errors<types::Error>>> {
log::debug!("Constraint::Equal {:?}: {} <===> {}", loc.source, exp, act);
exp.try_unify(act, sub).map_err(|error| Located {
location: loc.clone(),
Expand Down
65 changes: 31 additions & 34 deletions libflux/flux-core/src/semantic/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,17 @@ impl InferState<'_, '_> {
}
}

fn equal(&mut self, exp: &MonoType, act: &MonoType, loc: &ast::SourceLocation) {
if let Err(err) = infer::equal(exp, act, loc, self.sub) {
self.errors
.extend(err.error.into_iter().map(|error| Located {
location: loc.clone(),
error: error.into(),
}));
fn equal(&mut self, exp: &MonoType, act: &MonoType, loc: &ast::SourceLocation) -> MonoType {
match infer::equal(exp, act, loc, self.sub) {
Ok(typ) => typ,
Err(err) => {
self.errors
.extend(err.error.into_iter().map(|error| Located {
location: loc.clone(),
error: error.into(),
}));
MonoType::Error
}
}
}

Expand Down Expand Up @@ -272,7 +276,7 @@ impl Expression {
Expression::Binary(e) => e.typ.clone(),
Expression::Unary(e) => e.typ.clone(),
Expression::Call(e) => e.typ.clone(),
Expression::Conditional(e) => e.alternate.type_of(),
Expression::Conditional(e) => e.typ.clone(),
Expression::StringExpr(_) => MonoType::STRING,
Expression::Integer(_) => MonoType::INT,
Expression::Float(_) => MonoType::FLOAT,
Expand Down Expand Up @@ -859,7 +863,9 @@ impl ArrayExpr {
None => {
elt = Some(el.type_of());
}
Some(elt) => infer.equal(elt, &el.type_of(), el.loc()),
Some(elt) => {
infer.equal(elt, &el.type_of(), el.loc());
}
}
}
let elt = elt.unwrap_or_else(|| MonoType::Var(infer.sub.fresh()));
Expand Down Expand Up @@ -1303,20 +1309,9 @@ impl BinaryExpr {
let binop_arithmetic_constraints =
|this: &mut BinaryExpr, infer: &mut InferState<'_, '_>, kind| {
let left = this.left.type_of();
this.typ = left.clone();

infer.solve(&[
Constraint::Equal {
exp: left.clone(),
act: this.right.type_of(),
loc: this.right.loc().clone(),
},
Constraint::Kind {
act: left,
exp: kind,
loc: this.loc.clone(),
},
]);
this.typ = infer.equal(&left, &this.right.type_of(), this.right.loc());
infer.constrain(kind, &left, &this.loc);
};
let binop_compare_constraints =
|this: &mut BinaryExpr, infer: &mut InferState<'_, '_>, kind| {
Expand Down Expand Up @@ -1432,6 +1427,7 @@ pub struct CallExpr {

impl CallExpr {
fn infer(&mut self, infer: &mut InferState<'_, '_>) -> Result {
self.typ = MonoType::Var(infer.sub.fresh());
// First, recursively infer every type of the children of this call expression,
// update the environment and the constraints, and use the inferred types to
// build the fields of the type for this call expression.
Expand Down Expand Up @@ -1524,25 +1520,23 @@ pub struct ConditionalExpr {
pub test: Expression,
pub consequent: Expression,
pub alternate: Expression,
pub typ: MonoType,
}

impl ConditionalExpr {
fn infer(&mut self, infer: &mut InferState<'_, '_>) -> Result {
self.test.infer(infer)?;
infer.equal(&MonoType::BOOL, &self.test.type_of(), self.test.loc());

self.consequent.infer(infer)?;
self.alternate.infer(infer)?;
infer.solve(&[
Constraint::Equal {
exp: MonoType::BOOL,
act: self.test.type_of(),
loc: self.test.loc().clone(),
},
Constraint::Equal {
exp: self.consequent.type_of(),
act: self.alternate.type_of(),
loc: self.alternate.loc().clone(),
},
]);

self.typ = infer.equal(
&self.consequent.type_of(),
&self.alternate.type_of(),
self.alternate.loc(),
);

Ok(())
}
fn apply(mut self, sub: &Substitution) -> Self {
Expand Down Expand Up @@ -1620,6 +1614,7 @@ impl MemberExpr {
}

let r = {
self.typ = MonoType::Var(infer.sub.fresh());
let head = types::Property {
k: Label::from(self.property.to_owned()),
v: self.typ.to_owned(),
Expand Down Expand Up @@ -1659,6 +1654,8 @@ impl IndexExpr {
self.array.infer(infer)?;
self.index.infer(infer)?;

self.typ = MonoType::Var(infer.sub.fresh());

infer.solve(&[
Constraint::Equal {
act: self.index.type_of(),
Expand Down
8 changes: 4 additions & 4 deletions libflux/flux-core/src/semantic/tests/vectorize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn vectorize_field_access() -> anyhow::Result<()> {

expect_test::expect![[r#"
(r) => {
return {a: r:{J with b:v[D], a:v[B]}.a:v[B], b: r:{J with b:v[D], a:v[B]}.b:v[D]}:{a:v[B], b:v[D]}
}:(r:{J with b:D, a:B}) => {a:B, b:D}"#]].assert_eq(&crate::semantic::formatter::format_node(
return {a: r:{F with b:v[B], a:v[D]}.a:v[D], b: r:{F with b:v[B], a:v[D]}.b:v[B]}:{a:v[D], b:v[B]}
}:(r:{F with b:B, a:D}) => {a:D, b:B}"#]].assert_eq(&crate::semantic::formatter::format_node(
Node::FunctionExpr(function),
)?);

Expand All @@ -52,8 +52,8 @@ fn vectorize_with_construction() -> anyhow::Result<()> {

expect_test::expect![[r#"
(r) => {
return {r:{G with a:v[B]} with b: r:{G with a:v[B]}.a:v[B]}:{G with b:v[B], a:v[B]}
}:(r:{G with a:B}) => {G with b:B, a:B}"#]]
return {r:{C with a:v[B]} with b: r:{C with a:v[B]}.a:v[B]}:{C with b:v[B], a:v[B]}
}:(r:{C with a:B}) => {C with b:B, a:B}"#]]
.assert_eq(&crate::semantic::formatter::format_node(
Node::FunctionExpr(function),
)?);
Expand Down
Loading