dalley has joined #hpy
dalley has quit [Client Quit]
DuToit has quit [Ping timeout: 248 seconds]
DuToit has joined #hpy
DuToit has quit [Read error: No route to host]
DuToit has joined #hpy
DuToit has quit [Ping timeout: 244 seconds]
DuToit has joined #hpy
<antocuni> this is an interesting post, it contains a lot of stuff that pybind11 needs to be able to query on a type object. We should probably think how to offer the same functionality in HPy
<phlebas> antocuni: we have added something like this for the numpy port already, as a kind of "preliminary api"
<phlebas> only for checking the slot function pointer so far, but if we allow that, we might as well allow retrieving the pointer
<phlebas> since that was originally provided by the user anyway
<antocuni> "the slot function pointer"? What do you mean?
<phlebas> i thought you're talking about that they want to use `PyType_GetSlot`?
<antocuni> ah ok, yes
<antocuni> I just didn't understand what you meant
DuToit has quit [Read error: Connection reset by peer]
DuToit has joined #hpy
DuToit has quit [Ping timeout: 276 seconds]
DuToit has joined #hpy
DuToit has quit [Ping timeout: 246 seconds]
DuToit has joined #hpy
DuToit has quit [Ping timeout: 244 seconds]
DuToit has joined #hpy
DuToit has quit [Read error: Connection reset by peer]
DuToit has joined #hpy
<antocuni> pff, calling tp_traverse from the PyPy's GC custom tracer is a mess
<antocuni> I think I want something like this: https://paste.openstack.org/show/b5lFYk8FsLtDbKybEkmo/
<antocuni> i.e., the pypy GC calls hpy_customtrace, which calls tp_traverse, which calls _trace_one_field, which finally calls gc._trace_callback
<antocuni> the hard part is to make RPython happy
<antocuni> I think there are at least 2 problems:
<antocuni> 1. hpy_customtrace is @specialized on the callback, so I need to create many instances of ll_trace_one_field, one per each callback. I suppose I can somehow do it by adding this feature to get_llhelper()
<antocuni> 2. how do I pass "gc" and "arg" from hpy_customtrace to _trace_one_field? I cannot use an RPython tuple because I cannot allocate anything using the GC; if I were in C, I would allocate a custom struct on the stack, but in RPython it's not so easy
<antocuni> I don't think we have any RPython support for calling alloca(), do we?
<antocuni> what a mess
<antocuni> cfbolz, arigato, ronan, fijal, mattip: do you have any idea?
<antocuni> for reference, this is the branch I'm playing with: https://foss.heptapod.net/pypy/pypy/-/tree/branch/hpy-0.0.4-hpyfields
<cfbolz> antocuni: store it into fields on the GC?
<antocuni> and this is the tentative diff which I have for the customtracer (in this diff, it always assume there are to HPyFields at offsets 0 and 8): https://paste.openstack.org/show/bdmlRua7zw9GbAwDXbt3/
<antocuni> cfbolz: so basically, I would pass "gc" as the arg of trace_one_field, and fish gc.original_arg from there?
<antocuni> it looks hacky but it might work
<antocuni> there is one more problem. Inside trace_one_field, I receive "arg" which is a void*, and I need to cast it to the correct RPython type of "gc" before calling gc._trace_callback
<antocuni> uhm, I might have to use annlowlevel.cast_object_to_ptr and cast_base_ptr_to_instance & friends?
<antocuni> I also don't understand whether 'gc' is a real object or a prebuilt constant similar to space
<antocuni> (hoorray for RPython clarity)
<antocuni> I'd expect that gc is a prebuilt, but looking at the generated C code I see that there is an actual object of type "struct pypy_rpython_memory_gc_incminimark_IncrementalMiniMarkG0*" which is passed around
<cfbolz> antocuni: it's an instance
<cfbolz> Can't be pre-built because it has mutable attributes
<antocuni> uhm, I think that prebuilt instances can still be mutable, cannot them?
<antocuni> e.g., hpy's handlemanager is a prebuilt and it owns the list of handles
<cfbolz> antocuni: ah, I might be mixing up prebuilt and frozen
<cfbolz> but anyway, it's not like the space, which is frozen
<antocuni> right
<antocuni> anyway, not so important for my problem at hand, but I was curious
<cfbolz> antocuni: why do you need a concrete instance?
<cfbolz> Isn't a gcref enough for the GC?
<antocuni> I need a concrete instance of the 'gc' object
<cfbolz> Ah
<antocuni> to call gc._trace_callback
<cfbolz> That is very difficult 😅
<antocuni> I know
<antocuni> things which are trivial in C are very difficult in RPython 😤
<cfbolz> might even be not supported atm
<cfbolz> because so far we only cast GC instances
<cfbolz> to gcref
<antocuni> can't I use annlowlevel.cast_instance_to_base_ptr() and back?
<cfbolz> antocuni: maybe it works, just saying that you would be the first to try this
<antocuni> "hooray"
<antocuni> and everything is made much more difficult because it's hard to unit test
<antocuni> I don't even know where to start to write a test which can be run before translation
<cfbolz> antocuni: hmmm, maybe you could do this differently
<cfbolz> You could have a new rpython op gc_get_instance that the GC transformer turns into the constant
<antocuni> uhm right
<antocuni> this could be simpler
<antocuni> this way I don't even need to hack to pass two arguments to the callback, because one will be sufficient
* antocuni afk
<cfbolz> Me too
DuToit has quit [Read error: No route to host]
DuToit has joined #hpy
DuToit has quit [Ping timeout: 260 seconds]
DuToit has joined #hpy
DuToit has quit [Read error: Connection reset by peer]
DuToit has joined #hpy
DuToit has quit [Ping timeout: 260 seconds]
DuToit has joined #hpy
DuToit has quit [Remote host closed the connection]
DuToit has joined #hpy