mitsuba-renderer / drjit

Dr.Jit — A Just-In-Time-Compiler for Differentiable Rendering
BSD 3-Clause "New" or "Revised" License
603 stars 45 forks source link

Fix potential cyclic dependencies with `dr.alloc_local` #248

Closed njroussel closed 4 months ago

njroussel commented 4 months ago

This PR fixes a potential cyclic dependency when using dataclasses in dr.alloc_local.

The following code snippet would leak

from dataclasses import dataclass
import drjit as dr

if __name__ == "__main__":
    @dataclass
    class SampleData:
        data: dr.llvm.ad.Float

    some_float = dr.llvm.ad.Float([1, 2, 3])
    default = SampleData(some_float)

    sample_data = dr.alloc_local(SampleData, 10, default)

The default value and dtype information are sources of cyclic dependencies.