fix bug in decision_tree

This commit is contained in:
Folkert 2020-11-13 01:39:39 +01:00
parent ed26b07916
commit 70cba33fe4
4 changed files with 16 additions and 8 deletions

View file

@ -1369,7 +1369,10 @@ pub fn load_symbol<'a, 'ctx, 'env>(
Some((_, ptr)) => env
.builder
.build_load(*ptr, symbol.ident_string(&env.interns)),
None => panic!("There was no entry for {:?} in scope {:?}", symbol, scope),
None => panic!(
"There was no entry for {:?} {} in scope {:?}",
symbol, symbol, scope
),
}
}

View file

@ -979,7 +979,7 @@ fn path_to_expr_help<'a>(
break;
}
Some(wrapped) => {
let field_layouts = match layout {
let field_layouts = match &layout {
Layout::Union(layouts) | Layout::RecursiveUnion(layouts) => {
layouts[*tag_id as usize].to_vec()
}
@ -987,9 +987,10 @@ fn path_to_expr_help<'a>(
other => vec![other.clone()],
};
debug_assert!(*index < field_layouts.len() as u64);
let inner_layout = field_layouts[*index as usize].clone();
let inner_layout = match &field_layouts[*index as usize] {
Layout::RecursivePointer => layout.clone(),
other => other.clone(),
};
let inner_expr = Expr::AccessAtIndex {
index: *index,
@ -1057,7 +1058,7 @@ fn test_to_equality<'a>(
let rhs_symbol = env.unique_symbol();
stores.push((lhs_symbol, Layout::Builtin(Builtin::Int64), lhs));
stores.insert(0, (rhs_symbol, Layout::Builtin(Builtin::Int64), rhs));
stores.push((rhs_symbol, Layout::Builtin(Builtin::Int64), rhs));
(
stores,
@ -1324,7 +1325,8 @@ fn decide_to_branching<'a>(
arena.alloc(cond),
);
for (symbol, layout, expr) in new_stores.into_iter() {
// stores are in top-to-bottom order, so we have to add them in reverse
for (symbol, layout, expr) in new_stores.into_iter().rev() {
cond = Stmt::Let(symbol, expr, layout, arena.alloc(cond));
}

View file

@ -1827,7 +1827,9 @@ mod test_mono {
let Test.8 = true;
let Test.10 = 0i64;
let Test.9 = Index 1 Test.2;
inc Test.9;
let Test.11 = Index 0 Test.9;
dec Test.9;
let Test.12 = lowlevel Eq Test.10 Test.11;
let Test.7 = lowlevel And Test.12 Test.8;
if Test.7 then

View file

@ -2,10 +2,11 @@ app Main provides [ main ] imports [ Effect, RBTree ]
toAndFro : Int
toAndFro =
empty : RBTree.Dict Int Int
empty : RBTree.Dict Int {}
empty = RBTree.empty
empty
|> (\d -> RBTree.insert 1 {} d)
|> RBTree.toList
|> List.len