mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
Make defs use "let rec" style; drop Variable
This commit is contained in:
parent
760de2f328
commit
302b03cb20
6 changed files with 32 additions and 33 deletions
|
@ -918,37 +918,32 @@ pub fn can_defs_with_return<'a>(
|
|||
|
||||
output.rigids = output.rigids.union(found_rigids);
|
||||
|
||||
// Rigid constraint for the def expr as a whole
|
||||
// Rigid constraint for the def expr as a whole.
|
||||
// This is a "LetRec" constraint; it supports recursion.
|
||||
// (The only advantage of "Let" over "LetRec" is if you want to
|
||||
// shadow things, and Roc disallows shadowing anyway.)
|
||||
let constraint = Let(Box::new(LetConstraint {
|
||||
rigid_vars: rigid_info.vars,
|
||||
flex_vars: Vec::new(),
|
||||
def_types: rigid_info.def_types,
|
||||
defs_constraint:
|
||||
// Flex constraint
|
||||
Let(Box::new(LetConstraint {
|
||||
defs_constraint: True,
|
||||
ret_constraint: Let(Box::new(LetConstraint {
|
||||
rigid_vars: Vec::new(),
|
||||
flex_vars: flex_info.vars,
|
||||
def_types: flex_info.def_types.clone(),
|
||||
defs_constraint:
|
||||
// Final flex constraints
|
||||
Let(Box::new(LetConstraint {
|
||||
rigid_vars: Vec::new(),
|
||||
defs_constraint: Let(Box::new(LetConstraint {
|
||||
flex_vars: Vec::new(),
|
||||
rigid_vars: Vec::new(),
|
||||
def_types: flex_info.def_types,
|
||||
defs_constraint: True,
|
||||
ret_constraint: And(flex_info.constraints)
|
||||
ret_constraint: And(flex_info.constraints),
|
||||
})),
|
||||
ret_constraint: And(vec![And(rigid_info.constraints), ret_con])
|
||||
ret_constraint: And(vec![And(rigid_info.constraints), ret_con]),
|
||||
})),
|
||||
ret_constraint: True,
|
||||
}));
|
||||
|
||||
match can_defs {
|
||||
Ok(defs) => (
|
||||
Defs(var_store.fresh(), defs, Box::new(ret_expr)),
|
||||
output,
|
||||
constraint,
|
||||
),
|
||||
Ok(defs) => (Defs(defs, Box::new(ret_expr)), output, constraint),
|
||||
Err(err) => (RuntimeError(err), output, constraint),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ pub enum Expr {
|
|||
Box<Located<Expr>>,
|
||||
Vec<(Located<Pattern>, Located<Expr>)>,
|
||||
),
|
||||
Defs(Variable, Vec<Def>, Box<Located<Expr>>),
|
||||
Defs(Vec<Def>, Box<Located<Expr>>),
|
||||
|
||||
/// This is *only* for calling functions, not for tag application.
|
||||
/// The Tag variant contains any applied values inside it.
|
||||
|
|
|
@ -565,7 +565,7 @@ fn adjust_rank(
|
|||
} else if mark == visit_mark {
|
||||
desc.rank
|
||||
} else {
|
||||
let min_rank = desc.rank.min(group_rank);
|
||||
let min_rank = group_rank.min(desc.rank);
|
||||
|
||||
// TODO from elm-compiler: how can min_rank ever be group_rank?
|
||||
desc.rank = min_rank;
|
||||
|
|
|
@ -45,6 +45,8 @@ impl fmt::Debug for Type {
|
|||
match self {
|
||||
Type::EmptyRec => write!(f, "{{}}"),
|
||||
Type::Function(args, ret) => {
|
||||
write!(f, "Fn(")?;
|
||||
|
||||
for (index, arg) in args.iter().enumerate() {
|
||||
if index > 0 {
|
||||
", ".fmt(f)?;
|
||||
|
@ -55,7 +57,9 @@ impl fmt::Debug for Type {
|
|||
|
||||
write!(f, " -> ")?;
|
||||
|
||||
ret.fmt(f)
|
||||
ret.fmt(f)?;
|
||||
|
||||
write!(f, ")")
|
||||
}
|
||||
Type::Variable(var) => write!(f, "<{:?}>", var),
|
||||
|
||||
|
|
|
@ -385,7 +385,7 @@ pub fn canonicalize_expr(
|
|||
)
|
||||
}
|
||||
|
||||
Defs(_, defs, loc_ret) => {
|
||||
Defs(defs, loc_ret) => {
|
||||
// The body expression gets a new scope for canonicalization,
|
||||
// so clone it.
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ mod test_canonicalize {
|
|||
|
||||
fn get_closure(expr: &Expr, i: usize) -> roc::can::expr::Recursive {
|
||||
match expr {
|
||||
Defs(_, assignments, _) => match &assignments.get(i).map(|def| &def.expr.value) {
|
||||
Defs(assignments, _) => match &assignments.get(i).map(|def| &def.expr.value) {
|
||||
Some(Closure(_, recursion, _, _)) => recursion.clone(),
|
||||
Some(other @ _) => {
|
||||
panic!("assignment at {} is not a closure, but a {:?}", i, other)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue