Merge remote-tracking branch 'origin/trunk' into low-level-ops

This commit is contained in:
Richard Feldman 2020-07-07 21:02:03 -04:00
commit 1cd49689c2
29 changed files with 1630 additions and 440 deletions

View file

@ -78,24 +78,33 @@ pub fn constrain_decls(
sharing::annotate_usage(&def.loc_expr.value, &mut var_usage);
}
}
Declaration::InvalidCycle(_, _) => panic!("TODO handle invalid cycle"),
Declaration::InvalidCycle(_, _) => {
// any usage of a value defined in an invalid cycle will blow up
// so for the analysis usage by such values doesn't count
continue;
}
}
}
aliases_to_attr_type(var_store, &mut aliases);
let mut env = Env {
home,
rigids: ImMap::default(),
};
for decl in decls.iter().rev() {
// NOTE: rigids are empty because they are not shared between top-level definitions
// clear the set of rigids from the previous iteration.
// rigids are not shared between top-level definitions.
env.rigids.clear();
match decl {
Declaration::Declare(def) | Declaration::Builtin(def) => {
constraint = exists_with_aliases(
aliases.clone(),
Vec::new(),
constrain_def(
&Env {
home,
rigids: ImMap::default(),
},
&env,
var_store,
&var_usage,
&mut ImSet::default(),
@ -109,10 +118,7 @@ pub fn constrain_decls(
aliases.clone(),
Vec::new(),
constrain_recursive_defs(
&Env {
home,
rigids: ImMap::default(),
},
&env,
var_store,
&var_usage,
&mut ImSet::default(),
@ -121,7 +127,10 @@ pub fn constrain_decls(
),
);
}
Declaration::InvalidCycle(_, _) => panic!("TODO handle invalid cycle"),
Declaration::InvalidCycle(_, _) => {
// invalid cycles give a canonicalization error. we skip them here.
continue;
}
}
}
@ -333,7 +342,7 @@ fn constrain_pattern(
state.constraints.push(tag_con);
}
Underscore | Shadowed(_, _) | UnsupportedPattern(_) => {
Underscore | Shadowed(_, _) | MalformedPattern(_, _) | UnsupportedPattern(_) => {
// no constraints
}
}
@ -1385,10 +1394,7 @@ pub fn constrain_expr(
And(vec![Eq(fn_type, expected, category, region), record_con]),
)
}
RuntimeError(_) => {
// Runtime Errors have no constraints because they're going to crash.
True
}
RuntimeError(_) => True,
}
}
@ -1980,6 +1986,9 @@ fn aliases_to_attr_type(var_store: &mut VarStore, aliases: &mut SendMap<Symbol,
_ => unreachable!("`annotation_to_attr_type` always gives back an Attr"),
}
// Check that if the alias is a recursive tag union, all structures containing the
// recursion variable get the same uniqueness as the recursion variable (and thus as the
// recursive tag union itself)
if let Some(b) = &alias.uniqueness {
fix_mutual_recursive_alias(&mut alias.typ, b);
}
@ -2407,10 +2416,12 @@ fn fix_mutual_recursive_alias_help_help(rec_var: Variable, attribute: &Type, int
}
RecursiveTagUnion(_, tags, ext) | TagUnion(tags, ext) => {
fix_mutual_recursive_alias_help(rec_var, attribute, ext);
tags.iter_mut()
.map(|v| v.1.iter_mut())
.flatten()
.for_each(|arg| fix_mutual_recursive_alias_help(rec_var, attribute, arg));
for (_tag, args) in tags.iter_mut() {
for arg in args.iter_mut() {
fix_mutual_recursive_alias_help(rec_var, attribute, arg);
}
}
}
Record(fields, ext) => {
@ -2420,7 +2431,8 @@ fn fix_mutual_recursive_alias_help_help(rec_var: Variable, attribute: &Type, int
.for_each(|arg| fix_mutual_recursive_alias_help(rec_var, attribute, arg));
}
Alias(_, _, actual_type) => {
fix_mutual_recursive_alias_help(rec_var, attribute, actual_type);
// call help_help, because actual_type is not wrapped in ATTR
fix_mutual_recursive_alias_help_help(rec_var, attribute, actual_type);
}
Apply(_, args) => {
args.iter_mut()