mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
special-case properly
This commit is contained in:
parent
0d1cc3844e
commit
bdd07b0968
1 changed files with 45 additions and 13 deletions
|
@ -3739,6 +3739,36 @@ pub fn with_hole<'a>(
|
||||||
debug_assert_eq!(field_layouts.len(), symbols.len());
|
debug_assert_eq!(field_layouts.len(), symbols.len());
|
||||||
debug_assert_eq!(fields.len(), symbols.len());
|
debug_assert_eq!(fields.len(), symbols.len());
|
||||||
|
|
||||||
|
if symbols.len() == 1 {
|
||||||
|
// TODO we can probably special-case this more, skippiing the generation of
|
||||||
|
// UpdateExisting
|
||||||
|
let mut stmt = hole.clone();
|
||||||
|
|
||||||
|
let what_to_do = &fields[0];
|
||||||
|
|
||||||
|
match what_to_do {
|
||||||
|
UpdateExisting(field) => {
|
||||||
|
substitute_in_exprs(env.arena, &mut stmt, assigned, symbols[0]);
|
||||||
|
|
||||||
|
stmt = assign_to_symbol(
|
||||||
|
env,
|
||||||
|
procs,
|
||||||
|
layout_cache,
|
||||||
|
field.var,
|
||||||
|
*field.loc_expr.clone(),
|
||||||
|
symbols[0],
|
||||||
|
stmt,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
CopyExisting(_) => {
|
||||||
|
unreachable!(
|
||||||
|
r"when a record has just one field and is updated, it must update that one field"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt
|
||||||
|
} else {
|
||||||
let expr = Expr::Struct(symbols);
|
let expr = Expr::Struct(symbols);
|
||||||
let mut stmt = Stmt::Let(assigned, expr, record_layout, hole);
|
let mut stmt = Stmt::Let(assigned, expr, record_layout, hole);
|
||||||
|
|
||||||
|
@ -3763,12 +3793,14 @@ pub fn with_hole<'a>(
|
||||||
index,
|
index,
|
||||||
field_layouts,
|
field_layouts,
|
||||||
};
|
};
|
||||||
stmt = Stmt::Let(*symbol, access_expr, *field_layout, arena.alloc(stmt));
|
stmt =
|
||||||
|
Stmt::Let(*symbol, access_expr, *field_layout, arena.alloc(stmt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stmt
|
stmt
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Closure {
|
Closure {
|
||||||
function_type,
|
function_type,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue