moved Ownership to borrow

This commit is contained in:
J.Teeuwissen 2023-01-09 18:15:34 +01:00
parent a11d94aee2
commit b28b32cdc4
No known key found for this signature in database
GPG key ID: DB5F7A1ED8D478AD
8 changed files with 23 additions and 19 deletions

View file

@ -9,7 +9,8 @@ use roc_collections::all::{MutMap, MutSet};
use roc_error_macros::internal_error; use roc_error_macros::internal_error;
use roc_module::symbol::Symbol; use roc_module::symbol::Symbol;
use roc_mono::{ use roc_mono::{
ir::{JoinPointId, Ownership, Param}, borrow::Ownership,
ir::{JoinPointId, Param},
layout::{Builtin, Layout, STLayoutInterner, TagIdIntType, UnionLayout}, layout::{Builtin, Layout, STLayoutInterner, TagIdIntType, UnionLayout},
}; };
use roc_target::TargetInfo; use roc_target::TargetInfo;

View file

@ -2,8 +2,7 @@ use std::collections::HashMap;
use std::hash::Hash; use std::hash::Hash;
use crate::ir::{ use crate::ir::{
Expr, HigherOrderLowLevel, JoinPointId, Ownership, Param, PassedFunction, Proc, ProcLayout, Expr, HigherOrderLowLevel, JoinPointId, Param, PassedFunction, Proc, ProcLayout, Stmt,
Stmt,
}; };
use crate::layout::Layout; use crate::layout::Layout;
use bumpalo::collections::Vec; use bumpalo::collections::Vec;
@ -16,6 +15,12 @@ use roc_module::symbol::Symbol;
pub(crate) const OWNED: bool = false; pub(crate) const OWNED: bool = false;
pub(crate) const BORROWED: bool = true; pub(crate) const BORROWED: bool = true;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Ownership {
Owned,
Borrowed,
}
/// For reference-counted types (lists, (big) strings, recursive tags), owning a value /// For reference-counted types (lists, (big) strings, recursive tags), owning a value
/// means incrementing its reference count. Hence, we prefer borrowing for these types /// means incrementing its reference count. Hence, we prefer borrowing for these types
fn should_borrow_layout(layout: &Layout) -> bool { fn should_borrow_layout(layout: &Layout) -> bool {
@ -107,7 +112,7 @@ pub struct ParamOffset(usize);
impl From<ParamOffset> for usize { impl From<ParamOffset> for usize {
fn from(id: ParamOffset) -> Self { fn from(id: ParamOffset) -> Self {
id.0 as usize id.0
} }
} }
@ -421,7 +426,7 @@ impl<'a> BorrowInfState<'a> {
start: ParamOffset, start: ParamOffset,
length: usize, length: usize,
) { ) {
let index: usize = start.into(); let ParamOffset(index) = start;
let ps = &mut param_map.declarations[index..][..length]; let ps = &mut param_map.declarations[index..][..length];
for p in ps.iter_mut() { for p in ps.iter_mut() {

View file

@ -3,8 +3,9 @@ use roc_intern::Interner;
use roc_module::low_level::LowLevel; use roc_module::low_level::LowLevel;
use roc_module::symbol::{IdentIds, Symbol}; use roc_module::symbol::{IdentIds, Symbol};
use crate::borrow::Ownership;
use crate::ir::{ use crate::ir::{
BranchInfo, Call, CallType, Expr, JoinPointId, Literal, Ownership, Param, Stmt, UpdateModeId, BranchInfo, Call, CallType, Expr, JoinPointId, Literal, Param, Stmt, UpdateModeId,
}; };
use crate::layout::{Builtin, InLayout, Layout, STLayoutInterner, TagIdIntType, UnionLayout}; use crate::layout::{Builtin, InLayout, Layout, STLayoutInterner, TagIdIntType, UnionLayout};

View file

@ -7,10 +7,10 @@ use roc_module::low_level::{LowLevel, LowLevel::*};
use roc_module::symbol::{IdentIds, Symbol}; use roc_module::symbol::{IdentIds, Symbol};
use roc_target::PtrWidth; use roc_target::PtrWidth;
use crate::borrow::Ownership;
use crate::code_gen_help::let_lowlevel; use crate::code_gen_help::let_lowlevel;
use crate::ir::{ use crate::ir::{
BranchInfo, Call, CallType, Expr, JoinPointId, Literal, ModifyRc, Ownership, Param, Stmt, BranchInfo, Call, CallType, Expr, JoinPointId, Literal, ModifyRc, Param, Stmt, UpdateModeId,
UpdateModeId,
}; };
use crate::layout::{Builtin, InLayout, Layout, STLayoutInterner, TagIdIntType, UnionLayout}; use crate::layout::{Builtin, InLayout, Layout, STLayoutInterner, TagIdIntType, UnionLayout};

View file

@ -1,6 +1,7 @@
use crate::borrow::Ownership;
use crate::ir::{ use crate::ir::{
build_list_index_probe, BranchInfo, Call, CallType, DestructType, Env, Expr, JoinPointId, build_list_index_probe, BranchInfo, Call, CallType, DestructType, Env, Expr, JoinPointId,
ListIndex, Literal, Ownership, Param, Pattern, Procs, Stmt, ListIndex, Literal, Param, Pattern, Procs, Stmt,
}; };
use crate::layout::{Builtin, Layout, LayoutCache, LayoutInterner, TagIdIntType, UnionLayout}; use crate::layout::{Builtin, Layout, LayoutCache, LayoutInterner, TagIdIntType, UnionLayout};
use roc_builtins::bitcode::{FloatWidth, IntWidth}; use roc_builtins::bitcode::{FloatWidth, IntWidth};

View file

@ -1,7 +1,7 @@
use crate::borrow::{ParamMap, BORROWED, OWNED}; use crate::borrow::{Ownership, ParamMap, BORROWED, OWNED};
use crate::ir::{ use crate::ir::{
CallType, Expr, HigherOrderLowLevel, JoinPointId, ModifyRc, Ownership, Param, Proc, ProcLayout, CallType, Expr, HigherOrderLowLevel, JoinPointId, ModifyRc, Param, Proc, ProcLayout, Stmt,
Stmt, UpdateModeIds, UpdateModeIds,
}; };
use crate::layout::{Layout, STLayoutInterner}; use crate::layout::{Layout, STLayoutInterner};
use bumpalo::collections::Vec; use bumpalo::collections::Vec;

View file

@ -1,5 +1,6 @@
#![allow(clippy::manual_map)] #![allow(clippy::manual_map)]
use crate::borrow::Ownership;
use crate::layout::{ use crate::layout::{
self, Builtin, ClosureCallOptions, ClosureRepresentation, EnumDispatch, LambdaName, LambdaSet, self, Builtin, ClosureCallOptions, ClosureRepresentation, EnumDispatch, LambdaName, LambdaSet,
Layout, LayoutCache, LayoutProblem, Niche, RawFunctionLayout, STLayoutInterner, TagIdIntType, Layout, LayoutCache, LayoutProblem, Niche, RawFunctionLayout, STLayoutInterner, TagIdIntType,
@ -1523,12 +1524,6 @@ impl<'a, 'i> Env<'a, 'i> {
#[derive(Clone, Debug, PartialEq, Copy, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Copy, Eq, Hash)]
pub struct JoinPointId(pub Symbol); pub struct JoinPointId(pub Symbol);
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Ownership {
Owned,
Borrowed,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Param<'a> { pub struct Param<'a> {
pub symbol: Symbol, pub symbol: Symbol,

View file

@ -1,6 +1,7 @@
#![allow(clippy::manual_map)] #![allow(clippy::manual_map)]
use crate::ir::{CallType, Expr, JoinPointId, Ownership, Param, Stmt}; use crate::borrow::Ownership;
use crate::ir::{CallType, Expr, JoinPointId, Param, Stmt};
use crate::layout::{LambdaName, Layout}; use crate::layout::{LambdaName, Layout};
use bumpalo::collections::Vec; use bumpalo::collections::Vec;
use bumpalo::Bump; use bumpalo::Bump;