mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
fix oversights
This commit is contained in:
parent
74e94869e3
commit
55eff1dba1
10 changed files with 87 additions and 128 deletions
|
@ -156,9 +156,6 @@ impl<'a> ParamMap<'a> {
|
|||
Let(_, _, _, cont) => {
|
||||
stack.push(cont);
|
||||
}
|
||||
Info(_, cont) => {
|
||||
stack.push(cont);
|
||||
}
|
||||
Invoke { pass, fail, .. } => {
|
||||
stack.push(pass);
|
||||
stack.push(fail);
|
||||
|
@ -465,10 +462,6 @@ impl<'a> BorrowInfState<'a> {
|
|||
self.collect_stmt(b);
|
||||
}
|
||||
|
||||
Info(_, cont) => {
|
||||
self.collect_stmt(cont);
|
||||
}
|
||||
|
||||
Let(x, Expr::FunctionPointer(fsymbol, layout), _, b) => {
|
||||
// ensure that the function pointed to is in the param map
|
||||
if let Some(params) = self.param_map.get_symbol(*fsymbol) {
|
||||
|
|
|
@ -178,6 +178,7 @@ fn layout_for_constructor<'a>(
|
|||
layout: &Layout<'a>,
|
||||
constructor: u64,
|
||||
) -> ConstructorLayout<&'a [Layout<'a>]> {
|
||||
use ConstructorLayout::*;
|
||||
use Layout::*;
|
||||
|
||||
match layout {
|
||||
|
@ -194,7 +195,21 @@ fn layout_for_constructor<'a>(
|
|||
ConstructorLayout::HasFields(other_fields)
|
||||
}
|
||||
}
|
||||
_ => todo!(),
|
||||
NullableWrapped {
|
||||
nullable_id,
|
||||
other_tags,
|
||||
} => {
|
||||
if constructor as i64 == *nullable_id {
|
||||
ConstructorLayout::IsNull
|
||||
} else {
|
||||
ConstructorLayout::HasFields(other_tags[constructor as usize])
|
||||
}
|
||||
}
|
||||
NonRecursive(fields) | Recursive(fields) => HasFields(fields[constructor as usize]),
|
||||
NonNullableUnwrapped(fields) => {
|
||||
debug_assert_eq!(constructor, 0);
|
||||
HasFields(fields)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
@ -404,22 +419,6 @@ pub fn expand_and_cancel<'a>(env: &mut Env<'a, '_>, stmt: &'a Stmt<'a>) -> &'a S
|
|||
expand_and_cancel(env, cont)
|
||||
}
|
||||
|
||||
Info(info, cont) => {
|
||||
env.constructor_map
|
||||
.insert(info.scrutinee, info.tag_id as u64);
|
||||
|
||||
env.layout_map.insert(info.scrutinee, info.layout.clone());
|
||||
|
||||
let cont = expand_and_cancel(env, cont);
|
||||
|
||||
env.constructor_map.remove(&info.scrutinee);
|
||||
env.layout_map.remove(&info.scrutinee);
|
||||
|
||||
let stmt = Info(info.clone(), cont);
|
||||
|
||||
env.arena.alloc(stmt)
|
||||
}
|
||||
|
||||
Invoke {
|
||||
symbol,
|
||||
call,
|
||||
|
@ -469,6 +468,27 @@ pub fn expand_and_cancel<'a>(env: &mut Env<'a, '_>, stmt: &'a Stmt<'a>) -> &'a S
|
|||
result = env.arena.alloc(stmt);
|
||||
}
|
||||
|
||||
// do all decrements
|
||||
for (symbol, amount) in deferred.inc_dec_map.iter().rev() {
|
||||
use std::cmp::Ordering;
|
||||
match amount.cmp(&0) {
|
||||
Ordering::Equal => {
|
||||
// do nothing else
|
||||
}
|
||||
Ordering::Greater => {
|
||||
// do nothing yet
|
||||
}
|
||||
Ordering::Less => {
|
||||
// the RC insertion should not double decrement in a block
|
||||
debug_assert_eq!(*amount, -1);
|
||||
|
||||
// insert missing decrements
|
||||
let stmt = Refcounting(ModifyRc::Dec(*symbol), result);
|
||||
result = env.arena.alloc(stmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (symbol, amount) in deferred.inc_dec_map.into_iter().rev() {
|
||||
use std::cmp::Ordering;
|
||||
match amount.cmp(&0) {
|
||||
|
@ -481,12 +501,7 @@ pub fn expand_and_cancel<'a>(env: &mut Env<'a, '_>, stmt: &'a Stmt<'a>) -> &'a S
|
|||
result = env.arena.alloc(stmt);
|
||||
}
|
||||
Ordering::Less => {
|
||||
// the RC insertion should not double decrement in a block
|
||||
debug_assert_eq!(amount, -1);
|
||||
|
||||
// insert missing decrements
|
||||
let stmt = Refcounting(ModifyRc::Dec(symbol), result);
|
||||
result = env.arena.alloc(stmt);
|
||||
// already done
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,10 +32,6 @@ pub fn occuring_variables(stmt: &Stmt<'_>) -> (MutSet<Symbol>, MutSet<Symbol>) {
|
|||
stack.push(cont);
|
||||
}
|
||||
|
||||
Info(_, cont) => {
|
||||
stack.push(cont);
|
||||
}
|
||||
|
||||
Invoke {
|
||||
symbol,
|
||||
call,
|
||||
|
@ -712,16 +708,6 @@ impl<'a> Context<'a> {
|
|||
)
|
||||
}
|
||||
|
||||
Info(info, cont) => {
|
||||
let (cont, live_vars) = self.visit_stmt(cont);
|
||||
|
||||
let stmt = Info(info.clone(), cont);
|
||||
|
||||
let stmt = self.arena.alloc(stmt);
|
||||
|
||||
(stmt, live_vars)
|
||||
}
|
||||
|
||||
Invoke {
|
||||
symbol,
|
||||
call,
|
||||
|
@ -928,20 +914,6 @@ pub fn collect_stmt(
|
|||
collect_stmt(cont, jp_live_vars, vars)
|
||||
}
|
||||
|
||||
Info(_, cont) => collect_stmt(cont, jp_live_vars, vars),
|
||||
|
||||
Jump(id, arguments) => {
|
||||
vars.extend(arguments.iter().copied());
|
||||
|
||||
// NOTE deviation from Lean
|
||||
// we fall through when no join point is available
|
||||
if let Some(jvars) = jp_live_vars.get(id) {
|
||||
vars.extend(jvars);
|
||||
}
|
||||
|
||||
vars
|
||||
}
|
||||
|
||||
Join {
|
||||
id: j,
|
||||
parameters,
|
||||
|
@ -959,6 +931,18 @@ pub fn collect_stmt(
|
|||
collect_stmt(b, &jp_live_vars, vars)
|
||||
}
|
||||
|
||||
Jump(id, arguments) => {
|
||||
vars.extend(arguments.iter().copied());
|
||||
|
||||
// NOTE deviation from Lean
|
||||
// we fall through when no join point is available
|
||||
if let Some(jvars) = jp_live_vars.get(id) {
|
||||
vars.extend(jvars);
|
||||
}
|
||||
|
||||
vars
|
||||
}
|
||||
|
||||
Switch {
|
||||
cond_symbol,
|
||||
branches,
|
||||
|
|
|
@ -17,7 +17,7 @@ use roc_types::subs::{Content, FlatType, Subs, Variable};
|
|||
use std::collections::HashMap;
|
||||
use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder};
|
||||
|
||||
pub const PRETTY_PRINT_IR_SYMBOLS: bool = true;
|
||||
pub const PRETTY_PRINT_IR_SYMBOLS: bool = false;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum MonoProblem {
|
||||
|
@ -796,7 +796,6 @@ pub enum Stmt<'a> {
|
|||
},
|
||||
Ret(Symbol),
|
||||
Rethrow,
|
||||
Info(ConstructorInfo<'a>, &'a Stmt<'a>),
|
||||
Refcounting(ModifyRc, &'a Stmt<'a>),
|
||||
Join {
|
||||
id: JoinPointId,
|
||||
|
@ -895,14 +894,6 @@ impl ModifyRc {
|
|||
}
|
||||
}
|
||||
|
||||
/// in the block below, symbol `scrutinee` is assumed be be of shape `tag_id`
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ConstructorInfo<'a> {
|
||||
pub scrutinee: Symbol,
|
||||
pub layout: Layout<'a>,
|
||||
pub tag_id: u8,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Literal<'a> {
|
||||
// Literals
|
||||
|
@ -1256,28 +1247,13 @@ impl<'a> Stmt<'a> {
|
|||
.text("let ")
|
||||
.append(symbol_to_doc(alloc, *symbol))
|
||||
//.append(" : ")
|
||||
//.append(alloc.text(format!("{:?}", layout)))
|
||||
//.append(alloc.text(format!("{:?}", _layout)))
|
||||
.append(" = ")
|
||||
.append(expr.to_doc(alloc))
|
||||
.append(";")
|
||||
.append(alloc.hardline())
|
||||
.append(cont.to_doc(alloc)),
|
||||
|
||||
Info(info, cont) => alloc
|
||||
.text("info:")
|
||||
.append(alloc.hardline())
|
||||
.append(alloc.text(" scrutinee: "))
|
||||
.append(symbol_to_doc(alloc, info.scrutinee))
|
||||
.append(alloc.hardline())
|
||||
.append(alloc.text(" tag_id: "))
|
||||
.append(format!("{:?}", info.tag_id))
|
||||
.append(alloc.hardline())
|
||||
.append(alloc.text(" layout: "))
|
||||
.append(format!("{:?}", info.layout))
|
||||
.append(";")
|
||||
.append(alloc.hardline())
|
||||
.append(cont.to_doc(alloc)),
|
||||
|
||||
Refcounting(modify, cont) => modify
|
||||
.to_doc(alloc)
|
||||
.append(alloc.hardline())
|
||||
|
@ -4844,10 +4820,6 @@ fn substitute_in_stmt_help<'a>(
|
|||
None => None,
|
||||
}
|
||||
}
|
||||
Info(info, cont) => match substitute_in_stmt_help(arena, cont, subs) {
|
||||
Some(cont) => Some(arena.alloc(Info(info.clone(), cont))),
|
||||
None => None,
|
||||
},
|
||||
|
||||
Jump(id, args) => {
|
||||
let mut did_change = false;
|
||||
|
|
|
@ -235,10 +235,6 @@ fn insert_jumps<'a>(
|
|||
Some(cont) => Some(arena.alloc(Refcounting(*modify, cont))),
|
||||
None => None,
|
||||
},
|
||||
Info(info, cont) => match insert_jumps(arena, cont, goal_id, needle) {
|
||||
Some(cont) => Some(arena.alloc(Info(info.clone(), cont))),
|
||||
None => None,
|
||||
},
|
||||
|
||||
Rethrow => None,
|
||||
Ret(_) => None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue