r-hedgehog icon indicating copy to clipboard operation
r-hedgehog copied to clipboard

c stack usage

Open blset opened this issue 3 years ago • 9 comments

this smple gen gen.element(1:100) |> gen.c(of = 1400)

produces the error Erreur : C stack usage 7972516 is too close to the limit

with

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=fr_FR.UTF-8       LC_NUMERIC=C               LC_TIME=fr_FR.UTF-8        LC_COLLATE=fr_FR.UTF-8    
 [5] LC_MONETARY=fr_FR.UTF-8    LC_MESSAGES=fr_FR.UTF-8    LC_PAPER=fr_FR.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] hedgehog_0.1   testthat_3.0.2

loaded via a namespace (and not attached):
[1] compiler_4.1.0 magrittr_2.0.1 R6_2.5.0       tools_4.1.0    rlang_0.4.11  
 

blset avatar Jul 01 '21 04:07 blset

Thanks for the report. IIRC, the implentation of gen.c was implented based on a early version of the haskell library.

Obviously, they're different languages, and Haskell's stack is on the heap and not the c stack, and is a bit lazier, so this wasn't the best choice.

Fortunately, there's been a bit on this front in our other implementations, so I think we should be able to relook at that, even if not everything applies.

You can also use a generator which doesn't shrink individual elements like this one.

HuwCampbell avatar Jul 01 '21 04:07 HuwCampbell

Try this: https://github.com/hedgehogqa/r-hedgehog/pull/18

HuwCampbell avatar Jul 01 '21 06:07 HuwCampbell

@HuwCampbell I had this issue with more (overly?) complex gens and #18 fixed the issue! There is a workaround with unix::rlimit_stack(cur = Inf) but it is good to have it solved in the "backend"

assignUser avatar Oct 30 '21 18:10 assignUser

Cool. I will endevour to make a release with these changes this week.

HuwCampbell avatar Oct 31 '21 10:10 HuwCampbell

Correction, fixed it most of the time, in some sessions it still happens (there is some randomness in input size for my generators so that might be the reason why) but that is most likely more an issue with my gens and can be optimized.

assignUser avatar Oct 31 '21 13:10 assignUser

If you can give an example showing where the stack is being blown I can have a look.

HuwCampbell avatar Oct 31 '21 22:10 HuwCampbell

It happens somewhere in here https://github.com/kgoldfeld/simstudy/blob/main/tests/testthat/test-define_data.R but I'll have to take a closer look where exactly in the coming days.

assignUser avatar Nov 01 '21 00:11 assignUser

I ran into the same problem, but using the current master (which includes #18) seems to fix the problem. (Installed with devtools::install_github("hedgehogqa/r-hedgehog")

Is that fix already part of the 0.1 release on CRAN?

gregmuellegger avatar Feb 16 '24 10:02 gregmuellegger

Looks like it's not.

I will have a go at getting a release up, I haven't touched this project for a while, so it's likely I'll need to kick a few dependencies; we'll see how I go.

HuwCampbell avatar Feb 19 '24 00:02 HuwCampbell