Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DecRefError related to closures for non heap based mutable values. #2197

Open
spotandjake opened this issue Nov 17, 2024 · 1 comment
Open

Comments

@spotandjake
Copy link
Member

I ran into a wierd decRef error with the below code:

let test = () => {
  let mut dependencyExists = false
  (() => {
    print(dependencyExists)
  })()
  (() => {
    print(dependencyExists)
  })()
  return dependencyExists
}
print(test())

This also happens if dependencyExists is a char or really any stack type. However if it is a Number, or heap type this error does not occur. Some cases that do work are below:

let test = () => {
  let dependencyExists = box(void)
  (() => {
    print(dependencyExists)
  })()
  (() => {
    print(dependencyExists)
  })()
  return dependencyExists
}
print("Test1")
print(test())

let test = () => {
  let mut dependencyExists = 1
  (() => {
    print(dependencyExists)
  })()
  (() => {
    print(dependencyExists)
  })()
  return dependencyExists
}
print("Test2")
print(test())
@spotandjake
Copy link
Member Author

I stumbled upon some more cases where this is occurring:

module Main
from "set" include Set
use Set.{ module Immutable as Set }
from "array" include Array
Array.reduce((argResult, arg) => {
  Set.empty
}, Set.empty, [> 1, 1, 1, 1])
print("me")

Which also fails when refactored as below as if the reduce was inlined (to verify the behaviour):

module Main

from "set" include Set
use Set.{ module Immutable as Set }
from "array" include Array
let test = () => {
  let mut acc = Set.empty
  Array.forEach(el => acc = ((_, _) => {
    Set.empty
  })(acc, el), [>1, 1, 1, 1])
}
test()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant