Include simple patterns in the type extraction phase of pattern application. (#705)

This commit is contained in:
Richard Newman 2018-05-27 12:53:23 +01:00
parent afcc5f0100
commit 23a616db22

View file

@ -48,7 +48,6 @@ use mentat_query::{
WhereClause, WhereClause,
}; };
#[cfg(test)]
use mentat_query::{ use mentat_query::{
PatternNonValuePlace, PatternNonValuePlace,
}; };
@ -1068,11 +1067,31 @@ impl ConjoiningClauses {
Ok(()) Ok(())
} }
fn mark_as_ref(&mut self, pos: &PatternNonValuePlace) {
if let &PatternNonValuePlace::Variable(ref var) = pos {
self.constrain_var_to_type(var.clone(), ValueType::Ref)
}
}
pub(crate) fn apply_clauses(&mut self, known: Known, where_clauses: Vec<WhereClause>) -> Result<()> { pub(crate) fn apply_clauses(&mut self, known: Known, where_clauses: Vec<WhereClause>) -> Result<()> {
// We apply (top level) type predicates first as an optimization. // We apply (top level) type predicates first as an optimization.
for clause in where_clauses.iter() { for clause in where_clauses.iter() {
if let &WhereClause::TypeAnnotation(ref anno) = clause { match clause {
self.apply_type_anno(anno)?; &WhereClause::TypeAnnotation(ref anno) => {
self.apply_type_anno(anno)?;
},
// Patterns are common, so let's grab as much type information from
// them as we can.
&WhereClause::Pattern(ref p) => {
self.mark_as_ref(&p.entity);
self.mark_as_ref(&p.attribute);
self.mark_as_ref(&p.tx);
},
// TODO: if we wish we can include other kinds of clauses in this type
// extraction phase.
_ => {},
} }
} }