mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Change RocRefcounted to have argumentless inc function
Just inc by 1. No need for inc by n.
This commit is contained in:
parent
f87c32ca7d
commit
c79febb52d
4 changed files with 91 additions and 95 deletions
|
@ -35,9 +35,9 @@ pub struct File {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for File {
|
impl RocRefcounted for File {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.content.inc(n);
|
self.content.inc();
|
||||||
self.name.inc(n);
|
self.name.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -70,14 +70,14 @@ pub struct Types {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for Types {
|
impl RocRefcounted for Types {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.aligns.inc(n);
|
self.aligns.inc();
|
||||||
self.deps.inc(n);
|
self.deps.inc();
|
||||||
self.entrypoints.inc(n);
|
self.entrypoints.inc();
|
||||||
self.sizes.inc(n);
|
self.sizes.inc();
|
||||||
self.types.inc(n);
|
self.types.inc();
|
||||||
self.typesByName.inc(n);
|
self.typesByName.inc();
|
||||||
self.target.inc(n);
|
self.target.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -193,8 +193,8 @@ pub struct R8 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for R8 {
|
impl RocRefcounted for R8 {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.name.inc(n);
|
self.name.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -368,10 +368,10 @@ pub struct R14 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for R14 {
|
impl RocRefcounted for R14 {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.name.inc(n);
|
self.name.inc();
|
||||||
self.payload.inc(n);
|
self.payload.inc();
|
||||||
self.tagName.inc(n);
|
self.tagName.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -423,12 +423,12 @@ pub union RocSingleTagPayload {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for RocSingleTagPayload {
|
impl RocRefcounted for RocSingleTagPayload {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
match self.discriminant() {
|
match self.discriminant() {
|
||||||
discriminant_RocSingleTagPayload::HasClosure => self.HasClosure.deref_mut().inc(n),
|
discriminant_RocSingleTagPayload::HasClosure => self.HasClosure.deref_mut().inc(),
|
||||||
discriminant_RocSingleTagPayload::HasNoClosure => {
|
discriminant_RocSingleTagPayload::HasNoClosure => {
|
||||||
self.HasNoClosure.deref_mut().inc(n)
|
self.HasNoClosure.deref_mut().inc()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -568,9 +568,9 @@ pub struct R1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for R1 {
|
impl RocRefcounted for R1 {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.fields.inc(n);
|
self.fields.inc();
|
||||||
self.name.inc(n);
|
self.name.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -621,11 +621,11 @@ pub union RocStructFields {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for RocStructFields {
|
impl RocRefcounted for RocStructFields {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
match self.discriminant() {
|
match self.discriminant() {
|
||||||
discriminant_RocStructFields::HasClosure => self.HasClosure.deref_mut().inc(n),
|
discriminant_RocStructFields::HasClosure => self.HasClosure.deref_mut().inc(),
|
||||||
discriminant_RocStructFields::HasNoClosure => self.HasNoClosure.deref_mut().inc(n),
|
discriminant_RocStructFields::HasNoClosure => self.HasNoClosure.deref_mut().inc(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -658,8 +658,8 @@ pub struct R3 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for R3 {
|
impl RocRefcounted for R3 {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.getter.inc(n);
|
self.getter.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -746,8 +746,8 @@ pub struct Tuple1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for Tuple1 {
|
impl RocRefcounted for Tuple1 {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.f0.inc(n);
|
self.f0.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -777,23 +777,23 @@ pub union RocType {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for RocType {
|
impl RocRefcounted for RocType {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
match self.discriminant() {
|
match self.discriminant() {
|
||||||
discriminant_RocType::Bool => {}
|
discriminant_RocType::Bool => {}
|
||||||
discriminant_RocType::EmptyTagUnion => {}
|
discriminant_RocType::EmptyTagUnion => {}
|
||||||
discriminant_RocType::Function => self.Function.deref_mut().inc(n),
|
discriminant_RocType::Function => self.Function.deref_mut().inc(),
|
||||||
discriminant_RocType::Num => self.Num.inc(n),
|
discriminant_RocType::Num => self.Num.inc(),
|
||||||
discriminant_RocType::RecursivePointer => self.RecursivePointer.inc(n),
|
discriminant_RocType::RecursivePointer => self.RecursivePointer.inc(),
|
||||||
discriminant_RocType::RocBox => self.RocBox.inc(n),
|
discriminant_RocType::RocBox => self.RocBox.inc(),
|
||||||
discriminant_RocType::RocDict => self.RocDict.inc(n),
|
discriminant_RocType::RocDict => self.RocDict.inc(),
|
||||||
discriminant_RocType::RocList => self.RocList.inc(n),
|
discriminant_RocType::RocList => self.RocList.inc(),
|
||||||
discriminant_RocType::RocResult => self.RocResult.inc(n),
|
discriminant_RocType::RocResult => self.RocResult.inc(),
|
||||||
discriminant_RocType::RocSet => self.RocSet.inc(n),
|
discriminant_RocType::RocSet => self.RocSet.inc(),
|
||||||
discriminant_RocType::RocStr => {}
|
discriminant_RocType::RocStr => {}
|
||||||
discriminant_RocType::Struct => self.Struct.deref_mut().inc(n),
|
discriminant_RocType::Struct => self.Struct.deref_mut().inc(),
|
||||||
discriminant_RocType::TagUnion => self.TagUnion.deref_mut().inc(n),
|
discriminant_RocType::TagUnion => self.TagUnion.deref_mut().inc(),
|
||||||
discriminant_RocType::TagUnionPayload => self.TagUnionPayload.deref_mut().inc(n),
|
discriminant_RocType::TagUnionPayload => self.TagUnionPayload.deref_mut().inc(),
|
||||||
discriminant_RocType::Unit => {}
|
discriminant_RocType::Unit => {}
|
||||||
discriminant_RocType::Unsized => {}
|
discriminant_RocType::Unsized => {}
|
||||||
}
|
}
|
||||||
|
@ -846,8 +846,8 @@ pub struct R4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for R4 {
|
impl RocRefcounted for R4 {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.name.inc(n);
|
self.name.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -869,9 +869,9 @@ pub struct R2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for R2 {
|
impl RocRefcounted for R2 {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.accessors.inc(n);
|
self.accessors.inc();
|
||||||
self.name.inc(n);
|
self.name.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -893,8 +893,8 @@ pub struct Tuple2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for Tuple2 {
|
impl RocRefcounted for Tuple2 {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.f1.inc(n);
|
self.f1.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -920,24 +920,20 @@ pub union RocTagUnion {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for RocTagUnion {
|
impl RocRefcounted for RocTagUnion {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
match self.discriminant() {
|
match self.discriminant() {
|
||||||
discriminant_RocTagUnion::Enumeration => self.Enumeration.deref_mut().inc(n),
|
discriminant_RocTagUnion::Enumeration => self.Enumeration.deref_mut().inc(),
|
||||||
discriminant_RocTagUnion::NonNullableUnwrapped => {
|
discriminant_RocTagUnion::NonNullableUnwrapped => {
|
||||||
self.NonNullableUnwrapped.deref_mut().inc(n)
|
self.NonNullableUnwrapped.deref_mut().inc()
|
||||||
}
|
}
|
||||||
discriminant_RocTagUnion::NonRecursive => self.NonRecursive.deref_mut().inc(n),
|
discriminant_RocTagUnion::NonRecursive => self.NonRecursive.deref_mut().inc(),
|
||||||
discriminant_RocTagUnion::NullableUnwrapped => {
|
discriminant_RocTagUnion::NullableUnwrapped => {
|
||||||
self.NullableUnwrapped.deref_mut().inc(n)
|
self.NullableUnwrapped.deref_mut().inc()
|
||||||
}
|
|
||||||
discriminant_RocTagUnion::NullableWrapped => {
|
|
||||||
self.NullableWrapped.deref_mut().inc(n)
|
|
||||||
}
|
|
||||||
discriminant_RocTagUnion::Recursive => self.Recursive.deref_mut().inc(n),
|
|
||||||
discriminant_RocTagUnion::SingleTagStruct => {
|
|
||||||
self.SingleTagStruct.deref_mut().inc(n)
|
|
||||||
}
|
}
|
||||||
|
discriminant_RocTagUnion::NullableWrapped => self.NullableWrapped.deref_mut().inc(),
|
||||||
|
discriminant_RocTagUnion::Recursive => self.Recursive.deref_mut().inc(),
|
||||||
|
discriminant_RocTagUnion::SingleTagStruct => self.SingleTagStruct.deref_mut().inc(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -977,9 +973,9 @@ pub struct R10 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for R10 {
|
impl RocRefcounted for R10 {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.name.inc(n);
|
self.name.inc();
|
||||||
self.tags.inc(n);
|
self.tags.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -1004,10 +1000,10 @@ pub struct R9 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for R9 {
|
impl RocRefcounted for R9 {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.name.inc(n);
|
self.name.inc();
|
||||||
self.nonNullTag.inc(n);
|
self.nonNullTag.inc();
|
||||||
self.nullTag.inc(n);
|
self.nullTag.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -1032,9 +1028,9 @@ pub struct R7 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for R7 {
|
impl RocRefcounted for R7 {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.name.inc(n);
|
self.name.inc();
|
||||||
self.tags.inc(n);
|
self.tags.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -1064,9 +1060,9 @@ pub struct R6 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for R6 {
|
impl RocRefcounted for R6 {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.name.inc(n);
|
self.name.inc();
|
||||||
self.tagName.inc(n);
|
self.tagName.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -1089,9 +1085,9 @@ pub struct R5 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for R5 {
|
impl RocRefcounted for R5 {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.name.inc(n);
|
self.name.inc();
|
||||||
self.tags.inc(n);
|
self.tags.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
@ -1126,10 +1122,10 @@ pub struct RocFn {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for RocFn {
|
impl RocRefcounted for RocFn {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.args.inc(n);
|
self.args.inc();
|
||||||
self.externName.inc(n);
|
self.externName.inc();
|
||||||
self.functionName.inc(n);
|
self.functionName.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
|
|
@ -559,8 +559,8 @@ impl Hash for U128 {
|
||||||
///
|
///
|
||||||
/// For aggregate types, this must recurse down the structure.
|
/// For aggregate types, this must recurse down the structure.
|
||||||
pub trait RocRefcounted {
|
pub trait RocRefcounted {
|
||||||
/// Increments the refcount n times.
|
/// Increments the refcount.
|
||||||
fn inc(&mut self, n: usize);
|
fn inc(&mut self);
|
||||||
|
|
||||||
/// Decrements the refcount potentially freeing the underlying allocation.
|
/// Decrements the refcount potentially freeing the underlying allocation.
|
||||||
fn dec(&mut self);
|
fn dec(&mut self);
|
||||||
|
@ -574,7 +574,7 @@ macro_rules! roc_refcounted_noop_impl {
|
||||||
( $( $T:tt),+ ) => {
|
( $( $T:tt),+ ) => {
|
||||||
$(
|
$(
|
||||||
impl RocRefcounted for $T {
|
impl RocRefcounted for $T {
|
||||||
fn inc(&mut self, _: usize) {}
|
fn inc(&mut self) {}
|
||||||
fn dec(&mut self) {}
|
fn dec(&mut self) {}
|
||||||
fn is_refcounted() -> bool {
|
fn is_refcounted() -> bool {
|
||||||
false
|
false
|
||||||
|
@ -596,8 +596,8 @@ macro_rules! roc_refcounted_arr_impl {
|
||||||
where
|
where
|
||||||
T: RocRefcounted,
|
T: RocRefcounted,
|
||||||
{
|
{
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
self.iter_mut().for_each(|x| x.inc(n));
|
self.iter_mut().for_each(|x| x.inc());
|
||||||
}
|
}
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
self.iter_mut().for_each(|x| x.dec());
|
self.iter_mut().for_each(|x| x.dec());
|
||||||
|
@ -625,9 +625,9 @@ macro_rules! roc_refcounted_tuple_impl {
|
||||||
where
|
where
|
||||||
$($T : RocRefcounted, )*
|
$($T : RocRefcounted, )*
|
||||||
{
|
{
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
$(
|
$(
|
||||||
self.$idx.inc(n);
|
self.$idx.inc();
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
fn dec(&mut self) {
|
fn dec(&mut self) {
|
||||||
|
|
|
@ -667,7 +667,7 @@ impl<T> RocRefcounted for RocList<T>
|
||||||
where
|
where
|
||||||
T: RocRefcounted,
|
T: RocRefcounted,
|
||||||
{
|
{
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
if self.elements.is_none() {
|
if self.elements.is_none() {
|
||||||
// Empty, non-allocated list, no refcounting to do.
|
// Empty, non-allocated list, no refcounting to do.
|
||||||
return;
|
return;
|
||||||
|
@ -676,7 +676,7 @@ where
|
||||||
let ptr = self.ptr_to_refcount();
|
let ptr = self.ptr_to_refcount();
|
||||||
unsafe {
|
unsafe {
|
||||||
let value = std::ptr::read(ptr);
|
let value = std::ptr::read(ptr);
|
||||||
std::ptr::write(ptr, Ord::max(0, ((value as isize) + n as isize) as usize));
|
std::ptr::write(ptr, Ord::max(0, ((value as isize) + 1) as usize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -793,9 +793,9 @@ impl From<SendSafeRocStr> for RocStr {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RocRefcounted for RocStr {
|
impl RocRefcounted for RocStr {
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
if !self.is_small_str() {
|
if !self.is_small_str() {
|
||||||
unsafe { self.0.heap_allocated.deref_mut().inc(n) }
|
unsafe { self.0.heap_allocated.deref_mut().inc() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -890,11 +890,11 @@ impl BigString {
|
||||||
unsafe { std::ptr::write(ptr, 0) }
|
unsafe { std::ptr::write(ptr, 0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inc(&mut self, n: usize) {
|
fn inc(&mut self) {
|
||||||
let ptr = self.ptr_to_refcount();
|
let ptr = self.ptr_to_refcount();
|
||||||
unsafe {
|
unsafe {
|
||||||
let value = std::ptr::read(ptr);
|
let value = std::ptr::read(ptr);
|
||||||
std::ptr::write(ptr, Ord::max(0, ((value as isize) + n as isize) as usize));
|
std::ptr::write(ptr, Ord::max(0, ((value as isize) + 1) as usize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -995,7 +995,7 @@ impl Clone for BigString {
|
||||||
capacity_or_alloc_ptr: self.capacity_or_alloc_ptr,
|
capacity_or_alloc_ptr: self.capacity_or_alloc_ptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.inc(1);
|
this.inc();
|
||||||
|
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue