Have Stmt::new accept LayoutCache

This commit is contained in:
Richard Feldman 2020-08-12 23:14:06 -04:00
parent 8751e4bd00
commit 3f0b08a992
4 changed files with 21 additions and 13 deletions

View file

@ -257,7 +257,9 @@ pub fn gen(src: &[u8], target: Triple, opt_level: OptLevel) -> Result<(String, S
ident_ids: &mut ident_ids,
};
let main_body = roc_mono::ir::Stmt::new(&mut mono_env, loc_expr.value, &mut procs);
let mut layout_cache = LayoutCache::default();
let main_body =
roc_mono::ir::Stmt::new(&mut mono_env, loc_expr.value, &mut procs, &mut layout_cache);
let main_body =
roc_mono::inc_dec::visit_declaration(mono_env.arena, mono_env.arena.alloc(main_body));
let mut headers = {

View file

@ -13,7 +13,7 @@ pub fn helper_without_uniqueness<'a>(
use roc_gen::llvm::build::Scope;
use roc_gen::llvm::build::{build_proc, build_proc_header};
use roc_gen::llvm::convert::basic_type_from_layout;
use roc_mono::layout::Layout;
use roc_mono::layout::{Layout, LayoutCache};
let target = target_lexicon::Triple::host();
let ptr_bytes = target.pointer_width().unwrap().bytes() as u32;
@ -105,7 +105,9 @@ pub fn helper_without_uniqueness<'a>(
ident_ids: &mut ident_ids,
};
let main_body = roc_mono::ir::Stmt::new(&mut mono_env, loc_expr.value, &mut procs);
let mut layout_cache = LayoutCache::default();
let main_body =
roc_mono::ir::Stmt::new(&mut mono_env, loc_expr.value, &mut procs, &mut layout_cache);
let main_body =
roc_mono::inc_dec::visit_declaration(mono_env.arena, mono_env.arena.alloc(main_body));
@ -214,7 +216,7 @@ pub fn helper_with_uniqueness<'a>(
use roc_gen::llvm::build::Scope;
use roc_gen::llvm::build::{build_proc, build_proc_header};
use roc_gen::llvm::convert::basic_type_from_layout;
use roc_mono::layout::Layout;
use roc_mono::layout::{Layout, LayoutCache};
let target = target_lexicon::Triple::host();
let ptr_bytes = target.pointer_width().unwrap().bytes() as u32;
@ -296,7 +298,9 @@ pub fn helper_with_uniqueness<'a>(
ident_ids: &mut ident_ids,
};
let main_body = roc_mono::ir::Stmt::new(&mut mono_env, loc_expr.value, &mut procs);
let mut layout_cache = LayoutCache::default();
let main_body =
roc_mono::ir::Stmt::new(&mut mono_env, loc_expr.value, &mut procs, &mut layout_cache);
let main_body =
roc_mono::inc_dec::visit_declaration(mono_env.arena, mono_env.arena.alloc(main_body));
let mut headers = {

View file

@ -625,11 +625,11 @@ impl<'a> Stmt<'a> {
env: &mut Env<'a, '_>,
can_expr: roc_can::expr::Expr,
procs: &mut Procs<'a>,
layout_cache: &mut LayoutCache<'a>,
) -> Self {
let mut layout_cache = LayoutCache::default();
from_can(env, can_expr, procs, &mut layout_cache)
from_can(env, can_expr, procs, layout_cache)
}
pub fn to_doc<'b, D, A>(&'b self, alloc: &'b D) -> DocBuilder<'b, D, A>
where
D: DocAllocator<'b, A>,

View file

@ -10,21 +10,21 @@ mod helpers;
#[cfg(test)]
mod test_reporting {
use crate::helpers::test_home;
use crate::helpers::{can_expr, infer_expr, CanExprOut, ParseErrOut};
use bumpalo::Bump;
use roc_module::symbol::{Interns, ModuleId};
use roc_mono::ir::{Procs, Stmt};
use roc_mono::layout::LayoutCache;
use roc_reporting::report::{
can_problem, mono_problem, parse_problem, type_problem, Report, BLUE_CODE, BOLD_CODE,
CYAN_CODE, DEFAULT_PALETTE, GREEN_CODE, MAGENTA_CODE, RED_CODE, RESET_CODE, UNDERLINE_CODE,
WHITE_CODE, YELLOW_CODE,
};
use roc_reporting::report::{RocDocAllocator, RocDocBuilder};
use roc_solve::solve;
use roc_types::pretty_print::name_all_type_vars;
use roc_types::subs::Subs;
use std::path::PathBuf;
// use roc_region::all;
use crate::helpers::{can_expr, infer_expr, CanExprOut, ParseErrOut};
use roc_reporting::report::{RocDocAllocator, RocDocBuilder};
use roc_solve::solve;
fn filename_from_string(str: &str) -> PathBuf {
let mut filename = PathBuf::new();
@ -87,6 +87,7 @@ mod test_reporting {
let mut ident_ids = interns.all_ident_ids.remove(&home).unwrap();
// Populate Procs and Subs, and get the low-level Expr from the canonical Expr
let mut layout_cache = LayoutCache::default();
let mut mono_env = roc_mono::ir::Env {
arena: &arena,
subs: &mut subs,
@ -94,7 +95,8 @@ mod test_reporting {
home,
ident_ids: &mut ident_ids,
};
let _mono_expr = Stmt::new(&mut mono_env, loc_expr.value, &mut procs);
let _mono_expr =
Stmt::new(&mut mono_env, loc_expr.value, &mut procs, &mut layout_cache);
}
Ok((unify_problems, can_problems, mono_problems, home, interns))