Skip to content

Commit

Permalink
aa
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Westerlind committed Feb 15, 2022
1 parent 77fbdbb commit f39b0c2
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 27 deletions.
7 changes: 1 addition & 6 deletions libflux/flux-core/src/semantic/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ impl<'a> Converter<'a> {
&& prop.name.name.starts_with(char::is_uppercase)
{
let tvar = tvars
.entry(prop.name.name)
.entry(prop.name.name.clone())
.or_insert_with(|| self.sub.fresh())
.clone();
tvar.into()
Expand Down Expand Up @@ -1029,13 +1029,8 @@ impl<'a> Converter<'a> {
test,
consequent,
alternate,
<<<<<<< HEAD
typ: MonoType::Error,
}
=======
typ: MonoType::Var(self.sub.fresh()),
})
>>>>>>> 48a598b5 (feat: Merge the types in conditionl expressions)
}

fn convert_object_expression(&mut self, expr: &ast::ObjectExpr) -> ObjectExpr {
Expand Down
6 changes: 0 additions & 6 deletions libflux/flux-core/src/semantic/formatter/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,8 @@ fn format_block_statement() {
expect![[r##"
package main
(r) => {
<<<<<<< HEAD
v = (if r:#A <:bool 0 then -r:#A:#A else r:#A):#A
return v:#A *:#A v:#A
}:(r:#A) => #A"##]],
=======
v = (if r:t10 <:bool 0 then -r:t10:t10 else r:t10):t10
return v:t10 *:t10 v:t10
}:(r:t10) => t10"#]],
>>>>>>> 48a598b5 (feat: Merge the types in conditionl expressions)
)
}
2 changes: 1 addition & 1 deletion libflux/flux-core/src/semantic/fresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Fresh for PolyType {
impl Fresh for MonoType {
fn fresh_ref(&self, f: &mut Fresher, sub: &mut TvarMap) -> Option<Self> {
match self {
MonoType::Error | MonoType::Builtin(_) => None,
MonoType::Error | MonoType::Builtin(_) | MonoType::Label(_) => None,
MonoType::BoundVar(tvr) => tvr.fresh_ref(f, sub).map(MonoType::BoundVar),
MonoType::Var(tvr) => tvr.fresh_ref(f, sub).map(MonoType::Var),
MonoType::Collection(app) => app.fresh_ref(f, sub).map(MonoType::app),
Expand Down
2 changes: 1 addition & 1 deletion libflux/flux-core/src/semantic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::{
infer::Constraints,
nodes::Symbol,
sub::Substitution,
types::{Label, MonoType, PolyType, PolyTypeHashMap, Property, Record, RecordLabel},
types::{MonoType, PolyType, PolyTypeHashMap, Property, Record, RecordLabel},
},
};

Expand Down
6 changes: 3 additions & 3 deletions libflux/flux-core/src/semantic/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,12 @@ where
pkg.infer(&mut infer)
.map_err(|err| err.apply(&FinalizeTypes { sub: infer.sub }))?;

infer.env.apply_mut(&FinalizeTypes { sub: &infer.sub });
infer.env.apply_mut(&FinalizeTypes { sub: infer.sub });

if infer.errors.has_errors() {
let sub = BindVars::new(infer.sub);
for err in &mut infer.errors {
err.apply_mut(&FinalizeTypes { sub: infer.sub });
err.apply_mut(&FinalizeTypes { sub: &sub });
}
Err(infer.errors)
} else {
Expand All @@ -447,7 +447,7 @@ pub fn inject_pkg_types(pkg: Package, sub: &Substitution) -> Package {
}

struct FinalizeTypes<'a> {
sub: &'a Substitution,
sub: &'a dyn Substituter,
}

impl Substituter for FinalizeTypes<'_> {
Expand Down
1 change: 1 addition & 0 deletions libflux/flux-core/src/semantic/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl fmt::Debug for Substitution {
#[derive(Debug)]
struct Root<T> {
variables: Vec<Tvar>,
#[allow(dead_code)]
value: T,
}
for i in 0..table.len() as u32 {
Expand Down
3 changes: 2 additions & 1 deletion libflux/flux-core/src/semantic/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ fn parse_map(package: Option<&str>, m: HashMap<&str, &str>) -> PolyTypeHashMap<S
if let Err(err) = ast::check::check(ast::walk::Node::TypeExpression(&typ_expr)) {
panic!("TypeExpression parsing failed for {}. {}", name, err);
}
let poly = convert_polytype(&typ_expr, &mut Substitution::default());
let poly = convert_polytype(&typ_expr, &mut Substitution::default())
.unwrap_or_else(|err| panic!("{}", err));

(
match package {
Expand Down
21 changes: 20 additions & 1 deletion libflux/flux-core/src/semantic/tests/labels.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

#[test]
fn labels() {
fn labels_simple() {
test_infer! {
env: map![
"fill" => "(<-tables: [{ A with B: C }], ?column: B, ?value: D) => [{ A with B: D }]
Expand All @@ -18,3 +18,22 @@ fn labels() {
],
}
}

#[test]
fn labels_dynamic_string() {
test_infer! {
env: map![
"fill" => "(<-tables: [{ A with B: C }], ?column: B, ?value: D) => [{ A with B: D }]
where B: Label
"
],
src: r#"
column = "" + "a"
x = [{ a: 1 }] |> fill(column: column, value: "x")
"#,
exp: map![
"x" => "string",
"x" => "[{ a: string }]",
],
}
}
28 changes: 20 additions & 8 deletions libflux/flux-core/src/semantic/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,9 +1019,17 @@ impl MonoType {

fn walk(&self, visitor: &mut impl TypeVisitor) -> Option<MonoType> {
match self {
MonoType::Error | MonoType::Builtin(_) | MonoType::Label(_) | MonoType::Var(_) => None,
MonoType::Arr(arr) => arr.0.visit(visitor).map(|v| MonoType::from(Array(v))),
MonoType::Vector(vector) => vector.0.visit(visitor).map(|v| MonoType::from(Vector(v))),
MonoType::Error
| MonoType::Builtin(_)
| MonoType::Label(_)
| MonoType::Var(_)
| MonoType::BoundVar(_) => None,
MonoType::Collection(app) => app.arg.visit(visitor).map(|arg| {
MonoType::from(Collection {
collection: app.collection,
arg,
})
}),
MonoType::Dict(dict) => merge(
&dict.key,
dict.key.visit(visitor),
Expand Down Expand Up @@ -1117,8 +1125,8 @@ impl ena::unify::UnifyKey for Tvar {
}
impl ena::unify::UnifyValue for MonoType {
type Error = ena::unify::NoError;
fn unify_values(_value1: &Self, _value2: &Self) -> Result<Self, ena::unify::NoError> {
unreachable!("We should never unify two values with each other within the substitution. If we reach this we did not resolve the variable before unifying")
fn unify_values(value1: &Self, value2: &Self) -> Result<Self, ena::unify::NoError> {
unreachable!("We should never unify two values with each other within the substitution. If we reach this we did not resolve the variable before unifying {} <=> {}", value1, value2)
}
}

Expand Down Expand Up @@ -1348,7 +1356,7 @@ impl fmt::Display for Record {
}
}

fn collect_record(mut record: &Record) -> (RefMonoTypeVecMap<'_, Label>, Option<&MonoType>) {
fn collect_record(mut record: &Record) -> (RefMonoTypeVecMap<'_, RecordLabel>, Option<&MonoType>) {
let mut a = RefMonoTypeVecMap::new();
let t = loop {
match record {
Expand Down Expand Up @@ -1527,10 +1535,14 @@ impl Record {
) if a != b => {
match (a, b) {
(RecordLabel::Variable(a), RecordLabel::Concrete(b)) => {
a.unify(&MonoType::Label(b.clone()), unifier)
if unifier.sub.try_apply(*a).is_none() {
a.unify(&MonoType::Label(b.clone()), unifier)
}
}
(RecordLabel::Concrete(a), RecordLabel::Variable(b)) => {
b.unify(&MonoType::Label(a.clone()), unifier)
if unifier.sub.try_apply(*b).is_none() {
b.unify(&MonoType::Label(a.clone()), unifier)
}
}
_ => (),
}
Expand Down

0 comments on commit f39b0c2

Please sign in to comment.