mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Thread LayoutInterner trait through
This commit is contained in:
parent
b1424afefd
commit
fdbc0ebdad
5 changed files with 53 additions and 54 deletions
|
@ -7,8 +7,7 @@ The user needs to analyse the Wasm module's memory to decode the result.
|
|||
use bumpalo::{collections::Vec, Bump};
|
||||
|
||||
use roc_builtins::bitcode::{FloatWidth, IntWidth};
|
||||
use roc_intern::Interner;
|
||||
use roc_mono::layout::{Builtin, Layout, UnionLayout};
|
||||
use roc_mono::layout::{Builtin, Layout, LayoutInterner, UnionLayout};
|
||||
use roc_std::{RocDec, RocList, RocOrder, RocResult, RocStr, I128, U128};
|
||||
use roc_target::TargetInfo;
|
||||
use roc_wasm_module::{
|
||||
|
@ -39,7 +38,7 @@ pub trait Wasm32Result {
|
|||
/// Layout-driven wrapper generation
|
||||
pub fn insert_wrapper_for_layout<'a>(
|
||||
arena: &'a Bump,
|
||||
interner: &impl Interner<'a, Layout<'a>>,
|
||||
interner: &impl LayoutInterner<'a>,
|
||||
module: &mut WasmModule<'a>,
|
||||
wrapper_name: &'static str,
|
||||
main_fn_index: u32,
|
||||
|
|
|
@ -11,7 +11,9 @@ use crate::code_gen_help::let_lowlevel;
|
|||
use crate::ir::{
|
||||
BranchInfo, Call, CallType, Expr, JoinPointId, Literal, ModifyRc, Param, Stmt, UpdateModeId,
|
||||
};
|
||||
use crate::layout::{Builtin, InLayout, Layout, STLayoutInterner, TagIdIntType, UnionLayout};
|
||||
use crate::layout::{
|
||||
Builtin, InLayout, Layout, LayoutInterner, STLayoutInterner, TagIdIntType, UnionLayout,
|
||||
};
|
||||
|
||||
use super::{CodeGenHelp, Context, HelperOp};
|
||||
|
||||
|
@ -420,7 +422,7 @@ pub fn refcount_reset_proc_body<'a>(
|
|||
// progress incrementally. Kept in sync with generate_procs using assertions.
|
||||
pub fn is_rc_implemented_yet<'a, I>(interner: &I, layout: &Layout<'a>) -> bool
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
use UnionLayout::*;
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
use std::fmt::Display;
|
||||
|
||||
use roc_intern::Interner;
|
||||
use roc_module::symbol::{Interns, Symbol};
|
||||
use ven_pretty::{Arena, DocAllocator, DocBuilder};
|
||||
|
||||
use crate::{
|
||||
ir::{Parens, ProcLayout},
|
||||
layout::Layout,
|
||||
layout::{Layout, LayoutInterner},
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
@ -20,7 +19,7 @@ pub fn format_problems<'a, I>(
|
|||
problems: Problems<'a>,
|
||||
) -> impl Display
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let Problems(problems) = problems;
|
||||
let f = Arena::new();
|
||||
|
@ -44,7 +43,7 @@ fn format_problem<'a, 'd, I>(
|
|||
) -> Doc<'d>
|
||||
where
|
||||
'a: 'd,
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let Problem {
|
||||
proc,
|
||||
|
@ -118,7 +117,7 @@ fn format_kind<'a, 'd, I>(
|
|||
kind: ProblemKind<'a>,
|
||||
) -> (&'static str, Vec<(usize, Doc<'d>)>, Doc<'d>)
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let title;
|
||||
let docs_before;
|
||||
|
@ -445,7 +444,7 @@ fn format_proc_spec<'a, 'd, I>(
|
|||
proc_layout: ProcLayout<'a>,
|
||||
) -> Doc<'d>
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
f.concat([
|
||||
f.as_string(symbol.as_str(interns)),
|
||||
|
@ -460,7 +459,7 @@ fn format_proc_layout<'a, 'd, I>(
|
|||
proc_layout: ProcLayout<'a>,
|
||||
) -> Doc<'d>
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let ProcLayout {
|
||||
arguments,
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
use crate::layout::{
|
||||
self, Builtin, ClosureCallOptions, ClosureRepresentation, EnumDispatch, LambdaName, LambdaSet,
|
||||
Layout, LayoutCache, LayoutProblem, Niche, RawFunctionLayout, STLayoutInterner, TagIdIntType,
|
||||
UnionLayout, WrappedVariant,
|
||||
Layout, LayoutCache, LayoutInterner, LayoutProblem, Niche, RawFunctionLayout, STLayoutInterner,
|
||||
TagIdIntType, UnionLayout, WrappedVariant,
|
||||
};
|
||||
use bumpalo::collections::{CollectIn, Vec};
|
||||
use bumpalo::Bump;
|
||||
|
@ -22,7 +22,6 @@ use roc_debug_flags::{
|
|||
use roc_derive::SharedDerivedModule;
|
||||
use roc_error_macros::{internal_error, todo_abilities};
|
||||
use roc_exhaustive::{Ctor, CtorName, ListArity, RenderAs, TagId};
|
||||
use roc_intern::Interner;
|
||||
use roc_late_solve::storage::{ExternalModuleStorage, ExternalModuleStorageSnapshot};
|
||||
use roc_late_solve::{resolve_ability_specialization, AbilitiesView, Resolved, UnificationFailed};
|
||||
use roc_module::ident::{ForeignSymbol, Lowercase, TagName};
|
||||
|
@ -339,7 +338,7 @@ impl<'a> Proc<'a> {
|
|||
D: DocAllocator<'b, A>,
|
||||
D::Doc: Clone,
|
||||
A: Clone,
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let args_doc = self.args.iter().map(|(layout, symbol)| {
|
||||
let arg_doc = symbol_to_doc(alloc, *symbol, pretty);
|
||||
|
@ -382,7 +381,7 @@ impl<'a> Proc<'a> {
|
|||
|
||||
pub fn to_pretty<I>(&self, interner: &I, width: usize, pretty: bool) -> String
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let allocator = BoxAllocator;
|
||||
let mut w = std::vec::Vec::new();
|
||||
|
@ -2173,7 +2172,7 @@ impl<'a> Stmt<'a> {
|
|||
D: DocAllocator<'b, A>,
|
||||
D::Doc: Clone,
|
||||
A: Clone,
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
use Stmt::*;
|
||||
|
||||
|
@ -2329,7 +2328,7 @@ impl<'a> Stmt<'a> {
|
|||
|
||||
pub fn to_pretty<I>(&self, interner: &I, width: usize, pretty: bool) -> String
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let allocator = BoxAllocator;
|
||||
let mut w = std::vec::Vec::new();
|
||||
|
|
|
@ -743,7 +743,7 @@ impl<'a> UnionLayout<'a> {
|
|||
D: DocAllocator<'b, A>,
|
||||
D::Doc: Clone,
|
||||
A: Clone,
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
use UnionLayout::*;
|
||||
|
||||
|
@ -982,7 +982,7 @@ impl<'a> UnionLayout<'a> {
|
|||
target_info: TargetInfo,
|
||||
) -> u32
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
tags.iter()
|
||||
.map(|field_layouts| {
|
||||
|
@ -994,7 +994,7 @@ impl<'a> UnionLayout<'a> {
|
|||
|
||||
pub fn allocation_alignment_bytes<I>(&self, interner: &I, target_info: TargetInfo) -> u32
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let allocation = match self {
|
||||
UnionLayout::NonRecursive(tags) => {
|
||||
|
@ -1019,7 +1019,7 @@ impl<'a> UnionLayout<'a> {
|
|||
/// Size of the data in memory, whether it's stack or heap (for non-null tag ids)
|
||||
pub fn data_size_and_alignment<I>(&self, interner: &I, target_info: TargetInfo) -> (u32, u32)
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let (data_width, data_align) =
|
||||
self.data_size_and_alignment_help_match(interner, target_info);
|
||||
|
@ -1052,7 +1052,7 @@ impl<'a> UnionLayout<'a> {
|
|||
/// Returns None if the tag_id is not stored as data in the layout.
|
||||
pub fn data_size_without_tag_id<I>(&self, interner: &I, target_info: TargetInfo) -> Option<u32>
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
if !self.stores_tag_id_as_data(target_info) {
|
||||
return None;
|
||||
|
@ -1070,7 +1070,7 @@ impl<'a> UnionLayout<'a> {
|
|||
target_info: TargetInfo,
|
||||
) -> (u32, u32)
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
match self {
|
||||
Self::NonRecursive(tags) => {
|
||||
|
@ -1093,7 +1093,7 @@ impl<'a> UnionLayout<'a> {
|
|||
|
||||
pub fn tag_id_offset<I>(&self, interner: &I, target_info: TargetInfo) -> Option<u32>
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
match self {
|
||||
UnionLayout::NonRecursive(tags)
|
||||
|
@ -1111,7 +1111,7 @@ impl<'a> UnionLayout<'a> {
|
|||
target_info: TargetInfo,
|
||||
) -> u32
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let (data_width, data_align) =
|
||||
Layout::stack_size_and_alignment_slices(interner, layouts, target_info);
|
||||
|
@ -1122,7 +1122,7 @@ impl<'a> UnionLayout<'a> {
|
|||
/// Very important to use this when doing a memcpy!
|
||||
fn stack_size_without_alignment<I>(&self, interner: &I, target_info: TargetInfo) -> u32
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
match self {
|
||||
UnionLayout::NonRecursive(_) => {
|
||||
|
@ -1281,7 +1281,7 @@ impl<'a> Niche<'a> {
|
|||
D: DocAllocator<'b, A>,
|
||||
D::Doc: Clone,
|
||||
A: Clone,
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
match self.0 {
|
||||
NichePriv::Captures(captures) => alloc.concat([
|
||||
|
@ -1394,7 +1394,7 @@ pub enum ClosureCallOptions<'a> {
|
|||
impl<'a> LambdaSet<'a> {
|
||||
pub fn runtime_representation<I>(&self, interner: &I) -> Layout<'a>
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
*interner.get(self.representation)
|
||||
}
|
||||
|
@ -1406,7 +1406,7 @@ impl<'a> LambdaSet<'a> {
|
|||
|
||||
pub fn is_represented<I>(&self, interner: &I) -> Option<Layout<'a>>
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
if self.has_unwrapped_capture_repr() {
|
||||
let repr = interner.get(self.representation);
|
||||
|
@ -1450,7 +1450,7 @@ impl<'a> LambdaSet<'a> {
|
|||
lambda_name: LambdaName,
|
||||
) -> ClosureRepresentation<'a>
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
debug_assert!(self.contains(lambda_name.name));
|
||||
|
||||
|
@ -1475,7 +1475,7 @@ impl<'a> LambdaSet<'a> {
|
|||
captures_layouts: &[Layout],
|
||||
) -> LambdaName<'a>
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
debug_assert!(
|
||||
self.contains(function_symbol),
|
||||
|
@ -1516,7 +1516,7 @@ impl<'a> LambdaSet<'a> {
|
|||
/// Resolves recursive pointers to the layout of the lambda set.
|
||||
fn capture_layouts_eq<I>(&self, interner: &I, left: &InLayout<'a>, right: &Layout) -> bool
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let left = interner.get(*left);
|
||||
if left == right {
|
||||
|
@ -1550,7 +1550,7 @@ impl<'a> LambdaSet<'a> {
|
|||
|
||||
fn layout_for_member<I, F>(&self, interner: &I, comparator: F) -> ClosureRepresentation<'a>
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
F: Fn(Symbol, &[InLayout]) -> bool,
|
||||
{
|
||||
if self.has_unwrapped_capture_repr() {
|
||||
|
@ -1663,7 +1663,7 @@ impl<'a> LambdaSet<'a> {
|
|||
|
||||
pub fn call_by_name_options<I>(&self, interner: &I) -> ClosureCallOptions<'a>
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let repr = interner.get(self.representation);
|
||||
|
||||
|
@ -1907,7 +1907,7 @@ impl<'a> LambdaSet<'a> {
|
|||
|
||||
pub fn stack_size<I>(&self, interner: &I, target_info: TargetInfo) -> u32
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
interner
|
||||
.get(self.representation)
|
||||
|
@ -1915,7 +1915,7 @@ impl<'a> LambdaSet<'a> {
|
|||
}
|
||||
pub fn contains_refcounted<I>(&self, interner: &I) -> bool
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
interner
|
||||
.get(self.representation)
|
||||
|
@ -1923,14 +1923,14 @@ impl<'a> LambdaSet<'a> {
|
|||
}
|
||||
pub fn safe_to_memcpy<I>(&self, interner: &I) -> bool
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
interner.get(self.representation).safe_to_memcpy(interner)
|
||||
}
|
||||
|
||||
pub fn alignment_bytes<I>(&self, interner: &I, target_info: TargetInfo) -> u32
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
interner
|
||||
.get(self.representation)
|
||||
|
@ -2399,7 +2399,7 @@ impl<'a> Layout<'a> {
|
|||
|
||||
pub fn safe_to_memcpy<I>(&self, interner: &I) -> bool
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
use Layout::*;
|
||||
|
||||
|
@ -2445,7 +2445,7 @@ impl<'a> Layout<'a> {
|
|||
|
||||
pub fn is_passed_by_reference<I>(&self, interner: &I, target_info: TargetInfo) -> bool
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
match self {
|
||||
Layout::Builtin(builtin) => {
|
||||
|
@ -2472,7 +2472,7 @@ impl<'a> Layout<'a> {
|
|||
|
||||
pub fn stack_size<I>(&self, interner: &I, target_info: TargetInfo) -> u32
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let width = self.stack_size_without_alignment(interner, target_info);
|
||||
let alignment = self.alignment_bytes(interner, target_info);
|
||||
|
@ -2482,7 +2482,7 @@ impl<'a> Layout<'a> {
|
|||
|
||||
pub fn stack_size_and_alignment<I>(&self, interner: &I, target_info: TargetInfo) -> (u32, u32)
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let width = self.stack_size_without_alignment(interner, target_info);
|
||||
let alignment = self.alignment_bytes(interner, target_info);
|
||||
|
@ -2494,7 +2494,7 @@ impl<'a> Layout<'a> {
|
|||
/// Very important to use this when doing a memcpy!
|
||||
pub fn stack_size_without_alignment<I>(&self, interner: &I, target_info: TargetInfo) -> u32
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
use Layout::*;
|
||||
|
||||
|
@ -2520,7 +2520,7 @@ impl<'a> Layout<'a> {
|
|||
|
||||
pub fn alignment_bytes<I>(&self, interner: &I, target_info: TargetInfo) -> u32
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
match self {
|
||||
Layout::Struct { field_layouts, .. } => field_layouts
|
||||
|
@ -2572,7 +2572,7 @@ impl<'a> Layout<'a> {
|
|||
|
||||
pub fn allocation_alignment_bytes<I>(&self, interner: &I, target_info: TargetInfo) -> u32
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let ptr_width = target_info.ptr_width() as u32;
|
||||
|
||||
|
@ -2598,7 +2598,7 @@ impl<'a> Layout<'a> {
|
|||
target_info: TargetInfo,
|
||||
) -> (u32, u32)
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let mut data_align = 1;
|
||||
let mut data_width = 0;
|
||||
|
@ -2642,7 +2642,7 @@ impl<'a> Layout<'a> {
|
|||
/// goes out of scope, the refcount on those values/fields must be decremented.
|
||||
pub fn contains_refcounted<I>(&self, interner: &I) -> bool
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
use Layout::*;
|
||||
|
||||
|
@ -2683,7 +2683,7 @@ impl<'a> Layout<'a> {
|
|||
D: DocAllocator<'b, A>,
|
||||
D::Doc: Clone,
|
||||
A: Clone,
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
use Layout::*;
|
||||
|
||||
|
@ -2725,7 +2725,7 @@ impl<'a> Layout<'a> {
|
|||
|
||||
pub fn runtime_representation<I>(&self, interner: &I) -> Self
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
match self {
|
||||
Layout::LambdaSet(lambda_set) => lambda_set.runtime_representation(interner),
|
||||
|
@ -2927,7 +2927,7 @@ impl<'a> Builtin<'a> {
|
|||
D: DocAllocator<'b, A>,
|
||||
D::Doc: Clone,
|
||||
A: Clone,
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
use Builtin::*;
|
||||
|
||||
|
@ -2973,7 +2973,7 @@ impl<'a> Builtin<'a> {
|
|||
|
||||
pub fn allocation_alignment_bytes<I>(&self, interner: &I, target_info: TargetInfo) -> u32
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let ptr_width = target_info.ptr_width() as u32;
|
||||
|
||||
|
@ -4377,7 +4377,7 @@ pub fn cmp_fields<'a, L: Ord, I>(
|
|||
target_info: TargetInfo,
|
||||
) -> Ordering
|
||||
where
|
||||
I: Interner<'a, Layout<'a>>,
|
||||
I: LayoutInterner<'a>,
|
||||
{
|
||||
let size1 = layout1.alignment_bytes(interner, target_info);
|
||||
let size2 = layout2.alignment_bytes(interner, target_info);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue