This commit is contained in:
Folkert 2022-01-26 14:37:32 +01:00
parent 74932a4cab
commit 0ed259a80d
5 changed files with 34 additions and 23 deletions

View file

@ -590,7 +590,9 @@ fn eq_list<'a>(
// let size = literal int // let size = literal int
let size = root.create_symbol(ident_ids, "size"); let size = root.create_symbol(ident_ids, "size");
let size_expr = Expr::Literal(Literal::Int(elem_layout.stack_size(root.ptr_size) as i128)); let size_expr = Expr::Literal(Literal::Int(
elem_layout.stack_size(root.target_info) as i128
));
let size_stmt = |next| Stmt::Let(size, size_expr, layout_isize, next); let size_stmt = |next| Stmt::Let(size, size_expr, layout_isize, next);
// let list_size = len_1 * size // let list_size = len_1 * size

View file

@ -1,9 +1,9 @@
use bumpalo::collections::vec::Vec; use bumpalo::collections::vec::Vec;
use bumpalo::Bump; use bumpalo::Bump;
use roc_builtins::bitcode::IntWidth;
use roc_module::ident::Ident; use roc_module::ident::Ident;
use roc_module::low_level::LowLevel; use roc_module::low_level::LowLevel;
use roc_module::symbol::{IdentIds, ModuleId, Symbol}; use roc_module::symbol::{IdentIds, ModuleId, Symbol};
use roc_target::TargetInfo;
use crate::ir::{ use crate::ir::{
Call, CallSpecId, CallType, Expr, HostExposedLayouts, JoinPointId, ModifyRc, Proc, ProcLayout, Call, CallSpecId, CallType, Expr, HostExposedLayouts, JoinPointId, ModifyRc, Proc, ProcLayout,
@ -74,19 +74,19 @@ pub struct Context<'a> {
pub struct CodeGenHelp<'a> { pub struct CodeGenHelp<'a> {
arena: &'a Bump, arena: &'a Bump,
home: ModuleId, home: ModuleId,
ptr_size: u32, target_info: TargetInfo,
layout_isize: Layout<'a>, layout_isize: Layout<'a>,
specializations: Vec<'a, Specialization<'a>>, specializations: Vec<'a, Specialization<'a>>,
debug_recursion_depth: usize, debug_recursion_depth: usize,
} }
impl<'a> CodeGenHelp<'a> { impl<'a> CodeGenHelp<'a> {
pub fn new(arena: &'a Bump, intwidth_isize: IntWidth, home: ModuleId) -> Self { pub fn new(arena: &'a Bump, target_info: TargetInfo, home: ModuleId) -> Self {
CodeGenHelp { CodeGenHelp {
arena, arena,
home, home,
ptr_size: intwidth_isize.stack_size(), target_info,
layout_isize: Layout::Builtin(Builtin::Int(intwidth_isize)), layout_isize: Layout::usize(target_info),
specializations: Vec::with_capacity_in(16, arena), specializations: Vec::with_capacity_in(16, arena),
debug_recursion_depth: 0, debug_recursion_depth: 0,
} }

View file

@ -207,7 +207,7 @@ pub fn rc_ptr_from_data_ptr<'a>(
// Mask for lower bits (for tag union id) // Mask for lower bits (for tag union id)
let mask_sym = root.create_symbol(ident_ids, "mask"); let mask_sym = root.create_symbol(ident_ids, "mask");
let mask_expr = Expr::Literal(Literal::Int(-(root.ptr_size as i128))); let mask_expr = Expr::Literal(Literal::Int(-(root.target_info.ptr_width() as i128)));
let mask_stmt = |next| Stmt::Let(mask_sym, mask_expr, root.layout_isize, next); let mask_stmt = |next| Stmt::Let(mask_sym, mask_expr, root.layout_isize, next);
let masked_sym = root.create_symbol(ident_ids, "masked"); let masked_sym = root.create_symbol(ident_ids, "masked");
@ -222,7 +222,7 @@ pub fn rc_ptr_from_data_ptr<'a>(
// Pointer size constant // Pointer size constant
let ptr_size_sym = root.create_symbol(ident_ids, "ptr_size"); let ptr_size_sym = root.create_symbol(ident_ids, "ptr_size");
let ptr_size_expr = Expr::Literal(Literal::Int(root.ptr_size as i128)); let ptr_size_expr = Expr::Literal(Literal::Int(root.target_info.ptr_width() as i128));
let ptr_size_stmt = |next| Stmt::Let(ptr_size_sym, ptr_size_expr, root.layout_isize, next); let ptr_size_stmt = |next| Stmt::Let(ptr_size_sym, ptr_size_expr, root.layout_isize, next);
// Refcount address // Refcount address
@ -382,7 +382,7 @@ fn refcount_str<'a>(
// A pointer to the refcount value itself // A pointer to the refcount value itself
let rc_ptr = root.create_symbol(ident_ids, "rc_ptr"); let rc_ptr = root.create_symbol(ident_ids, "rc_ptr");
let alignment = root.ptr_size; let alignment = root.target_info.ptr_width() as u32;
let ret_unit_stmt = rc_return_stmt(root, ident_ids, ctx); let ret_unit_stmt = rc_return_stmt(root, ident_ids, ctx);
let mod_rc_stmt = modify_refcount( let mod_rc_stmt = modify_refcount(
@ -487,7 +487,7 @@ fn refcount_list<'a>(
// //
let rc_ptr = root.create_symbol(ident_ids, "rc_ptr"); let rc_ptr = root.create_symbol(ident_ids, "rc_ptr");
let alignment = layout.alignment_bytes(root.ptr_size); let alignment = layout.alignment_bytes(root.target_info);
let ret_stmt = rc_return_stmt(root, ident_ids, ctx); let ret_stmt = rc_return_stmt(root, ident_ids, ctx);
let modify_list = modify_refcount( let modify_list = modify_refcount(
@ -584,7 +584,9 @@ fn refcount_list_elems<'a>(
// let size = literal int // let size = literal int
let elem_size = root.create_symbol(ident_ids, "elem_size"); let elem_size = root.create_symbol(ident_ids, "elem_size");
let elem_size_expr = Expr::Literal(Literal::Int(elem_layout.stack_size(root.ptr_size) as i128)); let elem_size_expr = Expr::Literal(Literal::Int(
elem_layout.stack_size(root.target_info) as i128
));
let elem_size_stmt = |next| Stmt::Let(elem_size, elem_size_expr, layout_isize, next); let elem_size_stmt = |next| Stmt::Let(elem_size, elem_size_expr, layout_isize, next);
// let list_size = len * size // let list_size = len * size
@ -972,7 +974,7 @@ fn refcount_union_rec<'a>(
let rc_structure_stmt = { let rc_structure_stmt = {
let rc_ptr = root.create_symbol(ident_ids, "rc_ptr"); let rc_ptr = root.create_symbol(ident_ids, "rc_ptr");
let alignment = Layout::Union(union_layout).alignment_bytes(root.ptr_size); let alignment = Layout::Union(union_layout).alignment_bytes(root.target_info);
let ret_stmt = rc_return_stmt(root, ident_ids, ctx); let ret_stmt = rc_return_stmt(root, ident_ids, ctx);
let modify_structure_stmt = modify_refcount( let modify_structure_stmt = modify_refcount(
root, root,
@ -988,7 +990,7 @@ fn refcount_union_rec<'a>(
ident_ids, ident_ids,
structure, structure,
rc_ptr, rc_ptr,
union_layout.stores_tag_id_in_pointer(root.ptr_size), union_layout.stores_tag_id_in_pointer(root.target_info),
root.arena.alloc(modify_structure_stmt), root.arena.alloc(modify_structure_stmt),
) )
}; };
@ -1080,7 +1082,7 @@ fn refcount_union_tailrec<'a>(
) )
}; };
let alignment = layout.alignment_bytes(root.ptr_size); let alignment = layout.alignment_bytes(root.target_info);
let modify_structure_stmt = modify_refcount( let modify_structure_stmt = modify_refcount(
root, root,
ident_ids, ident_ids,
@ -1095,7 +1097,7 @@ fn refcount_union_tailrec<'a>(
ident_ids, ident_ids,
current, current,
rc_ptr, rc_ptr,
union_layout.stores_tag_id_in_pointer(root.ptr_size), union_layout.stores_tag_id_in_pointer(root.target_info),
root.arena.alloc(modify_structure_stmt), root.arena.alloc(modify_structure_stmt),
) )
}; };

View file

@ -16,6 +16,7 @@ use roc_module::symbol::{IdentIds, ModuleId, Symbol};
use roc_problem::can::RuntimeError; use roc_problem::can::RuntimeError;
use roc_region::all::{Loc, Region}; use roc_region::all::{Loc, Region};
use roc_std::RocDec; use roc_std::RocDec;
use roc_target::TargetInfo;
use roc_types::subs::{Content, FlatType, StorageSubs, Subs, Variable, VariableSubsSlice}; use roc_types::subs::{Content, FlatType, StorageSubs, Subs, Variable, VariableSubsSlice};
use std::collections::HashMap; use std::collections::HashMap;
use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder}; use ven_pretty::{BoxAllocator, DocAllocator, DocBuilder};
@ -1071,7 +1072,7 @@ pub struct Env<'a, 'i> {
pub problems: &'i mut std::vec::Vec<MonoProblem>, pub problems: &'i mut std::vec::Vec<MonoProblem>,
pub home: ModuleId, pub home: ModuleId,
pub ident_ids: &'i mut IdentIds, pub ident_ids: &'i mut IdentIds,
pub target_info: u32, pub target_info: TargetInfo,
pub update_mode_ids: &'i mut UpdateModeIds, pub update_mode_ids: &'i mut UpdateModeIds,
pub call_specialization_counter: u32, pub call_specialization_counter: u32,
} }
@ -8259,7 +8260,7 @@ pub enum IntOrFloat {
/// Given the `a` in `Num a`, determines whether it's an int or a float /// Given the `a` in `Num a`, determines whether it's an int or a float
pub fn num_argument_to_int_or_float( pub fn num_argument_to_int_or_float(
subs: &Subs, subs: &Subs,
ptr_bytes: u32, target_info: TargetInfo,
var: Variable, var: Variable,
known_to_be_float: bool, known_to_be_float: bool,
) -> IntOrFloat { ) -> IntOrFloat {
@ -8274,7 +8275,7 @@ pub fn num_argument_to_int_or_float(
// Recurse on the second argument // Recurse on the second argument
let var = subs[args.variables().into_iter().next().unwrap()]; let var = subs[args.variables().into_iter().next().unwrap()];
num_argument_to_int_or_float(subs, ptr_bytes, var, false) num_argument_to_int_or_float(subs, target_info, var, false)
} }
other @ Content::Alias(symbol, args, _) => { other @ Content::Alias(symbol, args, _) => {
@ -8292,16 +8293,15 @@ pub fn num_argument_to_int_or_float(
// Recurse on the second argument // Recurse on the second argument
let var = subs[args.variables().into_iter().next().unwrap()]; let var = subs[args.variables().into_iter().next().unwrap()];
num_argument_to_int_or_float(subs, ptr_bytes, var, true) num_argument_to_int_or_float(subs, target_info, var, true)
} }
Symbol::NUM_DECIMAL | Symbol::NUM_AT_DECIMAL => IntOrFloat::DecimalFloatType, Symbol::NUM_DECIMAL | Symbol::NUM_AT_DECIMAL => IntOrFloat::DecimalFloatType,
Symbol::NUM_NAT | Symbol::NUM_NATURAL | Symbol::NUM_AT_NATURAL => { Symbol::NUM_NAT | Symbol::NUM_NATURAL | Symbol::NUM_AT_NATURAL => {
let int_width = match ptr_bytes { let int_width = match target_info.ptr_width() {
4 => IntWidth::U32, roc_target::PtrWidth::Bytes4 => IntWidth::U32,
8 => IntWidth::U64, roc_target::PtrWidth::Bytes8 => IntWidth::U64,
_ => panic!("unsupported word size"),
}; };
IntOrFloat::Int(int_width) IntOrFloat::Int(int_width)

View file

@ -1237,6 +1237,13 @@ impl<'a> Layout<'a> {
} }
} }
pub fn isize(target_info: TargetInfo) -> Layout<'a> {
match target_info.ptr_width() {
roc_target::PtrWidth::Bytes4 => Self::i32(),
roc_target::PtrWidth::Bytes8 => Self::i64(),
}
}
pub fn bool() -> Layout<'a> { pub fn bool() -> Layout<'a> {
Layout::Builtin(Builtin::Bool) Layout::Builtin(Builtin::Bool)
} }