mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Add List.set_in_place test to test_opt
This commit is contained in:
parent
99359221ab
commit
d878ef86aa
1 changed files with 43 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
|||
#[macro_use]
|
||||
extern crate pretty_assertions;
|
||||
#[macro_use]
|
||||
extern crate indoc;
|
||||
// #[macro_use]
|
||||
// extern crate indoc;
|
||||
|
||||
extern crate bumpalo;
|
||||
extern crate roc_mono;
|
||||
|
@ -11,16 +11,22 @@ mod helpers;
|
|||
// Test optimizations
|
||||
#[cfg(test)]
|
||||
mod test_opt {
|
||||
use crate::helpers::uniq_expr;
|
||||
use crate::helpers::{infer_expr, uniq_expr};
|
||||
use bumpalo::Bump;
|
||||
use roc_collections::all::MutMap;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::expr::Expr::{self, *};
|
||||
use roc_mono::layout::{Builtin, Layout};
|
||||
|
||||
// HELPERS
|
||||
|
||||
fn compiles_to(src: &str, expected: Expr<'_>) {
|
||||
let arena = Bump::new();
|
||||
let (loc_expr, _, _problems, subs, _, _, home, mut interns) = uniq_expr(src);
|
||||
let (loc_expr, _, _problems, subs, var, constraint, home, mut interns) = uniq_expr(src);
|
||||
|
||||
let mut unify_problems = Vec::new();
|
||||
let (_content, subs) = infer_expr(subs, &mut unify_problems, &constraint, var);
|
||||
|
||||
// Compile and add all the Procs before adding main
|
||||
let mut procs = MutMap::default();
|
||||
let mut ident_ids = interns.all_ident_ids.remove(&home).unwrap();
|
||||
|
@ -47,4 +53,37 @@ mod test_opt {
|
|||
fn float_literal() {
|
||||
compiles_to("0.5", Float(0.5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_unique_int_list() {
|
||||
// This should optimize List.set to List.set_in_place
|
||||
compiles_to(
|
||||
"List.getUnsafe (List.set [ 12, 9, 7, 3 ] 1 42) 1",
|
||||
CallByName(
|
||||
Symbol::LIST_GET_UNSAFE,
|
||||
&vec![
|
||||
(
|
||||
CallByName(
|
||||
Symbol::LIST_SET_IN_PLACE,
|
||||
&vec![
|
||||
(
|
||||
Array {
|
||||
elem_layout: Layout::Builtin(Builtin::Int64),
|
||||
elems: &vec![Int(12), Int(9), Int(7), Int(3)],
|
||||
},
|
||||
Layout::Builtin(Builtin::List(&Layout::Builtin(
|
||||
Builtin::Int64,
|
||||
))),
|
||||
),
|
||||
(Int(1), Layout::Builtin(Builtin::Int64)),
|
||||
(Int(42), Layout::Builtin(Builtin::Int64)),
|
||||
],
|
||||
),
|
||||
Layout::Builtin(Builtin::List(&Layout::Builtin(Builtin::Int64))),
|
||||
),
|
||||
(Int(1), Layout::Builtin(Builtin::Int64)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue