PRL-PRG / UFOs

User Fault Objects: making vectors lazy and forgetful.
12 stars 3 forks source link

1-length vectors are not allocated using our custom allocator #18

Closed kondziu closed 3 years ago

kondziu commented 4 years ago
library(ufoseq)
x <- ufo_seq(1,2,2)

x should contain 1, but

> x[1]
[1] 1
> .Internal(inspect(x))
@555557db2198 13 INTSXP g0c1 [NAM(1)] (len=1, tl=0) 0

On further investigation I noticed that my population function was not called. I put a breakpoint in readHandleUfEvent which should call by populate function, but that breakpoint was not reached either. handler was not reached either.

I kept looking and I saw that the allocator for UFO vectors was never actually triggered. That seems to be because in allocVector3 even if you specify a custom allocator, R interpreter just ignores it when length == 1 to do it's scalar vector short circuit.

Is this a bug in R?

kondziu commented 4 years ago

Trying to contact someone from R to see if this is a bug or not.

kondziu commented 3 years ago

This is intended behavior in R. We have a workaround in place.