mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Rename some things
This commit is contained in:
parent
9012cad4c2
commit
5ff26476fd
4 changed files with 29 additions and 22 deletions
|
@ -32,7 +32,7 @@ use std::fmt::Debug;
|
||||||
pub struct Def {
|
pub struct Def {
|
||||||
pub pattern: Located<Pattern>,
|
pub pattern: Located<Pattern>,
|
||||||
pub expr: Located<Expr>,
|
pub expr: Located<Expr>,
|
||||||
pub variables_by_symbol: SendMap<Symbol, Variable>,
|
pub vars_by_symbol: SendMap<Symbol, Variable>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -98,6 +98,7 @@ pub fn canonicalize_defs<'a>(
|
||||||
it.next();
|
it.next();
|
||||||
|
|
||||||
let typed = TypedDef(body_pattern, annotation.clone(), body_expr);
|
let typed = TypedDef(body_pattern, annotation.clone(), body_expr);
|
||||||
|
|
||||||
canonicalize_def(
|
canonicalize_def(
|
||||||
rigids,
|
rigids,
|
||||||
found_rigids,
|
found_rigids,
|
||||||
|
@ -174,6 +175,7 @@ pub fn sort_can_defs(
|
||||||
let mut visited_symbols = MutSet::default();
|
let mut visited_symbols = MutSet::default();
|
||||||
|
|
||||||
let returned_locals = ImSet::clone(&output.references.locals);
|
let returned_locals = ImSet::clone(&output.references.locals);
|
||||||
|
|
||||||
// Start with the return expression's referenced locals. They're the only ones that count!
|
// Start with the return expression's referenced locals. They're the only ones that count!
|
||||||
//
|
//
|
||||||
// If I have two defs which reference each other, but neither of them is referenced
|
// If I have two defs which reference each other, but neither of them is referenced
|
||||||
|
@ -367,7 +369,7 @@ fn canonicalize_def<'a>(
|
||||||
// Make types for the body expr, even if we won't end up having a body.
|
// Make types for the body expr, even if we won't end up having a body.
|
||||||
let expr_var = var_store.fresh();
|
let expr_var = var_store.fresh();
|
||||||
let expr_type = Type::Variable(expr_var);
|
let expr_type = Type::Variable(expr_var);
|
||||||
let mut variables_by_symbol = SendMap::default();
|
let mut vars_by_symbol = SendMap::default();
|
||||||
|
|
||||||
// Each def gets to have all the idents in scope that are defined in this
|
// Each def gets to have all the idents in scope that are defined in this
|
||||||
// block. Order of defs doesn't matter, thanks to referential transparency!
|
// block. Order of defs doesn't matter, thanks to referential transparency!
|
||||||
|
@ -474,7 +476,7 @@ fn canonicalize_def<'a>(
|
||||||
// TODO try to remove this .clone()!
|
// TODO try to remove this .clone()!
|
||||||
value: loc_can_expr.value.clone(),
|
value: loc_can_expr.value.clone(),
|
||||||
},
|
},
|
||||||
variables_by_symbol: im::HashMap::clone(&variables_by_symbol),
|
vars_by_symbol: im::HashMap::clone(&vars_by_symbol),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -496,7 +498,7 @@ fn canonicalize_def<'a>(
|
||||||
(&loc_pattern.value, &loc_can_pattern.value)
|
(&loc_pattern.value, &loc_can_pattern.value)
|
||||||
{
|
{
|
||||||
env.tailcallable_symbol = Some(defined_symbol.clone());
|
env.tailcallable_symbol = Some(defined_symbol.clone());
|
||||||
variables_by_symbol.insert(defined_symbol.clone(), expr_var);
|
vars_by_symbol.insert(defined_symbol.clone(), expr_var);
|
||||||
};
|
};
|
||||||
|
|
||||||
let (seen_rigids, can_annotation) =
|
let (seen_rigids, can_annotation) =
|
||||||
|
@ -651,7 +653,7 @@ fn canonicalize_def<'a>(
|
||||||
// TODO try to remove this .clone()!
|
// TODO try to remove this .clone()!
|
||||||
value: loc_can_expr.value.clone(),
|
value: loc_can_expr.value.clone(),
|
||||||
},
|
},
|
||||||
variables_by_symbol: im::HashMap::clone(&variables_by_symbol),
|
vars_by_symbol: im::HashMap::clone(&vars_by_symbol),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -676,7 +678,9 @@ fn canonicalize_def<'a>(
|
||||||
) = (&loc_pattern.value, &loc_can_pattern.value)
|
) = (&loc_pattern.value, &loc_can_pattern.value)
|
||||||
{
|
{
|
||||||
env.tailcallable_symbol = Some(defined_symbol.clone());
|
env.tailcallable_symbol = Some(defined_symbol.clone());
|
||||||
variables_by_symbol.insert(defined_symbol.clone(), expr_var);
|
|
||||||
|
// TODO isn't types_by_symbol enough? Do we need vars_by_symbol too?
|
||||||
|
vars_by_symbol.insert(defined_symbol.clone(), expr_var);
|
||||||
};
|
};
|
||||||
|
|
||||||
let (mut loc_can_expr, can_output, ret_constraint) = canonicalize_expr(
|
let (mut loc_can_expr, can_output, ret_constraint) = canonicalize_expr(
|
||||||
|
@ -800,13 +804,14 @@ fn canonicalize_def<'a>(
|
||||||
// TODO try to remove this .clone()!
|
// TODO try to remove this .clone()!
|
||||||
value: loc_can_expr.value.clone(),
|
value: loc_can_expr.value.clone(),
|
||||||
},
|
},
|
||||||
variables_by_symbol: im::HashMap::clone(&variables_by_symbol),
|
vars_by_symbol: im::HashMap::clone(&vars_by_symbol),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Nested(value) => {
|
Nested(value) => {
|
||||||
return canonicalize_def(
|
canonicalize_def(
|
||||||
rigids,
|
rigids,
|
||||||
found_rigids,
|
found_rigids,
|
||||||
env,
|
env,
|
||||||
|
|
|
@ -372,7 +372,7 @@ pub fn solve_loaded(
|
||||||
|
|
||||||
// All the top-level defs should also be available in vars_by_symbol
|
// All the top-level defs should also be available in vars_by_symbol
|
||||||
for def in module.defs.iter() {
|
for def in module.defs.iter() {
|
||||||
for (symbol, var) in def.variables_by_symbol.iter() {
|
for (symbol, var) in def.vars_by_symbol.iter() {
|
||||||
vars_by_symbol.insert(symbol.clone(), var.clone());
|
vars_by_symbol.insert(symbol.clone(), var.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,7 @@ pub fn solve_loaded(
|
||||||
|
|
||||||
// All its top-level defs should also be available in vars_by_symbol
|
// All its top-level defs should also be available in vars_by_symbol
|
||||||
for def in valid_dep.defs {
|
for def in valid_dep.defs {
|
||||||
for (symbol, var) in def.variables_by_symbol {
|
for (symbol, var) in def.vars_by_symbol {
|
||||||
vars_by_symbol.insert(symbol, var);
|
vars_by_symbol.insert(symbol, var);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
20
src/solve.rs
20
src/solve.rs
|
@ -200,13 +200,14 @@ fn solve(
|
||||||
subs,
|
subs,
|
||||||
&let_con.defs_constraint,
|
&let_con.defs_constraint,
|
||||||
);
|
);
|
||||||
// Add a variable for each assignment to the vars_by_symbol.
|
|
||||||
let mut locals = ImMap::default();
|
// Add a variable for each def to new_vars_by_env.
|
||||||
|
let mut local_def_vars = ImMap::default();
|
||||||
|
|
||||||
for (symbol, loc_type) in let_con.def_types.iter() {
|
for (symbol, loc_type) in let_con.def_types.iter() {
|
||||||
let var = type_to_var(subs, rank, pools, &loc_type.value);
|
let var = type_to_var(subs, rank, pools, &loc_type.value);
|
||||||
|
|
||||||
locals.insert(
|
local_def_vars.insert(
|
||||||
symbol.clone(),
|
symbol.clone(),
|
||||||
Located {
|
Located {
|
||||||
value: var,
|
value: var,
|
||||||
|
@ -214,9 +215,10 @@ fn solve(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut new_vars_by_symbol = vars_by_symbol.clone();
|
let mut new_vars_by_symbol = vars_by_symbol.clone();
|
||||||
|
|
||||||
for (symbol, loc_var) in locals.iter() {
|
for (symbol, loc_var) in local_def_vars.iter() {
|
||||||
if !new_vars_by_symbol.contains_key(&symbol) {
|
if !new_vars_by_symbol.contains_key(&symbol) {
|
||||||
new_vars_by_symbol.insert(symbol.clone(), loc_var.value);
|
new_vars_by_symbol.insert(symbol.clone(), loc_var.value);
|
||||||
}
|
}
|
||||||
|
@ -232,7 +234,7 @@ fn solve(
|
||||||
ret_con,
|
ret_con,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (symbol, loc_var) in locals {
|
for (symbol, loc_var) in local_def_vars {
|
||||||
check_for_infinite_type(subs, problems, symbol, loc_var);
|
check_for_infinite_type(subs, problems, symbol, loc_var);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,13 +266,13 @@ fn solve(
|
||||||
pool.extend(flex_vars.iter());
|
pool.extend(flex_vars.iter());
|
||||||
|
|
||||||
// Add a variable for each assignment to the vars_by_symbol.
|
// Add a variable for each assignment to the vars_by_symbol.
|
||||||
let mut locals = ImMap::default();
|
let mut local_def_vars = ImMap::default();
|
||||||
|
|
||||||
for (symbol, loc_type) in let_con.def_types.iter() {
|
for (symbol, loc_type) in let_con.def_types.iter() {
|
||||||
let def_type = loc_type.value.clone();
|
let def_type = loc_type.value.clone();
|
||||||
let var = type_to_var(subs, next_rank, next_pools, &def_type);
|
let var = type_to_var(subs, next_rank, next_pools, &def_type);
|
||||||
|
|
||||||
locals.insert(
|
local_def_vars.insert(
|
||||||
symbol.clone(),
|
symbol.clone(),
|
||||||
Located {
|
Located {
|
||||||
value: var,
|
value: var,
|
||||||
|
@ -307,7 +309,7 @@ fn solve(
|
||||||
|
|
||||||
let mut new_vars_by_symbol = vars_by_symbol.clone();
|
let mut new_vars_by_symbol = vars_by_symbol.clone();
|
||||||
|
|
||||||
for (symbol, loc_var) in locals.iter() {
|
for (symbol, loc_var) in local_def_vars.iter() {
|
||||||
if !new_vars_by_symbol.contains_key(&symbol) {
|
if !new_vars_by_symbol.contains_key(&symbol) {
|
||||||
new_vars_by_symbol.insert(symbol.clone(), loc_var.value);
|
new_vars_by_symbol.insert(symbol.clone(), loc_var.value);
|
||||||
}
|
}
|
||||||
|
@ -332,7 +334,7 @@ fn solve(
|
||||||
&ret_con,
|
&ret_con,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (symbol, loc_var) in locals {
|
for (symbol, loc_var) in local_def_vars {
|
||||||
check_for_infinite_type(subs, problems, symbol, loc_var);
|
check_for_infinite_type(subs, problems, symbol, loc_var);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,10 +171,10 @@ mod test_load {
|
||||||
assert_eq!(expected_types.len(), module.defs.len());
|
assert_eq!(expected_types.len(), module.defs.len());
|
||||||
|
|
||||||
for def in module.defs {
|
for def in module.defs {
|
||||||
for (symbol, var) in def.variables_by_symbol {
|
for (symbol, expr_var) in def.vars_by_symbol {
|
||||||
let content = subs.get(var).content;
|
let content = subs.get(expr_var).content;
|
||||||
|
|
||||||
name_all_type_vars(var, &mut subs);
|
name_all_type_vars(expr_var, &mut subs);
|
||||||
|
|
||||||
let actual_str = content_to_string(content, &mut subs);
|
let actual_str = content_to_string(content, &mut subs);
|
||||||
let expected_type = expected_types
|
let expected_type = expected_types
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue