<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56943>56943</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Empty function name with PyCapsule in mlir
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          gaogaotiantian
      </td>
    </tr>
</table>

<pre>
    Hi,

I recently found an issue of `mlir` on the usage of PyCapsule. I used the pre-built version from jaxlib, but it should be reproducible with pure mlir as well.

```sh
pip install jaxlib
``` 

If you run the following code, which basically imports a module from mlir and print the function calls to C functions that use PyCapsule:

```python
import sys

def profile_func(frame, event, arg):
    if event == "c_call":
        if "PyCapsule" in str(arg):
            print(arg)

sys.setprofile(profile_func)

import jaxlib.mlir.dialects.builtin
```

You'll find a `<built-in method  of PyCapsule object at 0x7fbd516941b0>` after each `register_operation` call.

I don't know if this empty name function is intentional, but it seems a bit weird to me.

On C level, a `PyCFunctionObject` needs a `PyMethodDef` for the function names and to store the actual C function. In common cases, the `PyMethodDef` is defined statically so all the data in it, including the function name, is accessible all the time. However, is the `PyMethodDef` for this "anonymous" function allocated dynamically so the function name will be freed when it's done?

Thank you in advance for your time.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxtVU2TmzgQ_TX40jUUBn8eOGRn4koOW9nDXvY0JVBjlAiJksQ4_vf7JOyxnRkXNqBuqd_rft1urDzX31RWPmfFS1Z8mX-_k-OWTdBn6uxkJAlDyvuJyXaUbYpBK4cbWUOhZ5q8OCbTP-dnMfpJc07fscoymUfHT82kdKA3dl5hU-fsQD_Fb60aRKZmCqQC-d5OWlLDiD46K6dWNZrppEJP4-SYYlgSnk6sdX6PF1jmy_fzwqhGUsYHofU1zqMjPdDt6GwnctNMp7Na25MyR2qt5Ajw1Ku2p0Z41eLEM6lhtC54EjQAJjAmQ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