From 0ed93dff151ccc55b4711b68e4e0906418f629a5 Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Fri, 7 Jan 2022 16:21:21 +0100 Subject: [PATCH] aa --- libflux/flux-core/src/semantic/convert.rs | 7 +------ .../flux-core/src/semantic/formatter/tests.rs | 6 ------ libflux/flux-core/src/semantic/fresh.rs | 2 +- libflux/flux-core/src/semantic/mod.rs | 2 +- libflux/flux-core/src/semantic/nodes.rs | 6 +++--- libflux/flux-core/src/semantic/sub.rs | 1 + libflux/flux-core/src/semantic/tests.rs | 3 ++- .../flux-core/src/semantic/tests/labels.rs | 21 ++++++++++++++++++- libflux/flux-core/src/semantic/types.rs | 20 ++++++++++++------ 9 files changed, 43 insertions(+), 25 deletions(-) diff --git a/libflux/flux-core/src/semantic/convert.rs b/libflux/flux-core/src/semantic/convert.rs index 3f9da76e29..5259e40cea 100644 --- a/libflux/flux-core/src/semantic/convert.rs +++ b/libflux/flux-core/src/semantic/convert.rs @@ -570,7 +570,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() @@ -1031,13 +1031,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 { diff --git a/libflux/flux-core/src/semantic/formatter/tests.rs b/libflux/flux-core/src/semantic/formatter/tests.rs index b369bf4611..41fb94b3df 100644 --- a/libflux/flux-core/src/semantic/formatter/tests.rs +++ b/libflux/flux-core/src/semantic/formatter/tests.rs @@ -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) ) } diff --git a/libflux/flux-core/src/semantic/fresh.rs b/libflux/flux-core/src/semantic/fresh.rs index 283e5c79de..0191c98043 100644 --- a/libflux/flux-core/src/semantic/fresh.rs +++ b/libflux/flux-core/src/semantic/fresh.rs @@ -149,7 +149,7 @@ impl Fresh for PolyType { impl Fresh for MonoType { fn fresh_ref(&self, f: &mut Fresher, sub: &mut TvarMap) -> Option { 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::Arr(arr) => arr.fresh_ref(f, sub).map(MonoType::arr), diff --git a/libflux/flux-core/src/semantic/mod.rs b/libflux/flux-core/src/semantic/mod.rs index 94a102f1e7..346009ec1d 100644 --- a/libflux/flux-core/src/semantic/mod.rs +++ b/libflux/flux-core/src/semantic/mod.rs @@ -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}, }, }; diff --git a/libflux/flux-core/src/semantic/nodes.rs b/libflux/flux-core/src/semantic/nodes.rs index 9ea3f73d1a..92f8532200 100644 --- a/libflux/flux-core/src/semantic/nodes.rs +++ b/libflux/flux-core/src/semantic/nodes.rs @@ -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 { @@ -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<'_> { diff --git a/libflux/flux-core/src/semantic/sub.rs b/libflux/flux-core/src/semantic/sub.rs index 2ac356f28c..f1acf0d49e 100644 --- a/libflux/flux-core/src/semantic/sub.rs +++ b/libflux/flux-core/src/semantic/sub.rs @@ -29,6 +29,7 @@ impl fmt::Debug for Substitution { #[derive(Debug)] struct Root { variables: Vec, + #[allow(dead_code)] value: T, } for i in 0..table.len() as u32 { diff --git a/libflux/flux-core/src/semantic/tests.rs b/libflux/flux-core/src/semantic/tests.rs index 6463c6c31c..d91f47f78c 100644 --- a/libflux/flux-core/src/semantic/tests.rs +++ b/libflux/flux-core/src/semantic/tests.rs @@ -55,7 +55,8 @@ fn parse_map(package: Option<&str>, m: HashMap<&str, &str>) -> PolyTypeHashMap "(<-tables: [{ A with B: C }], ?column: B, ?value: D) => [{ A with B: D }] @@ -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 }]", + ], + } +} diff --git a/libflux/flux-core/src/semantic/types.rs b/libflux/flux-core/src/semantic/types.rs index e2d9d7a191..03cb68a404 100644 --- a/libflux/flux-core/src/semantic/types.rs +++ b/libflux/flux-core/src/semantic/types.rs @@ -993,7 +993,11 @@ impl MonoType { fn walk(&self, visitor: &mut impl TypeVisitor) -> Option { match self { - MonoType::Error | MonoType::Builtin(_) | MonoType::Label(_) | MonoType::Var(_) => None, + MonoType::Error + | MonoType::Builtin(_) + | MonoType::Label(_) + | MonoType::Var(_) + | MonoType::BoundVar(_) => 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::Dict(dict) => merge( @@ -1089,8 +1093,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 { - 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 { + 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) } } @@ -1348,7 +1352,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 { @@ -1527,10 +1531,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) + } } _ => (), }