Skip to content

Conversation

@donn
Copy link
Contributor

@donn donn commented Oct 21, 2025

What are the reasons/motivation for this change?

  • IdString was not being copied by value and thus not incrementing IdStrings' refcounts.
  • AttrObject methods were not available for Cell

Explain how this is achieved.

  • class properties are now always bridged by reference if they're pointers or containers, and by value otherwise
    • resolves an issue with python copies of .name not incrementing the IdString's refcount
  • add new overload of RTLIL::Module::addMemory that does not require a "donor" object
    • the idea is Module, Memory, Wire, Cell and Process cannot be directly constructed in Python and can only be added to the existing memory hierarchy in Design using the add methods - Memory requiring a donor object was the odd one out here
  • fix superclass member wrapping only looking at direct superclass for inheritance instead of recursively checking superclasses
  • fix superclass member wrapping not using superclass's denylists
  • fix Design's __str__ function not returning a string
  • fix the generator crashing if there's any std::function in a header
  • misc: add a crude __repr__ based on __str__

Make sure your change comes with tests. If not possible, share how a reviewer might evaluate it.

With a Yosys compiled with ENABLE_PYTHON, python3 ./tests/pyosys/run_tests.py yosys

- class properties are now always bridged as references if they're pointers or containers, and by value otherwise
  - resolves an issue with python copies of `.name` not incrementing the IdString's refcount
- add new overload of RTLIL::Module: addMemory that does not require a "donor" object
  - the idea is `Module`, `Memory`, `Wire`, `Cell` and `Process` cannot be directly constructed in Python and can only be added to the existing memory hierarchy in `Design` using the `add` methods - `Memory` requiring a donor object was the odd one out here
- fix superclass member wrapping only looking at direct superclass for inheritance instead of recursively checking superclasses
- fix superclass member wrapping not using superclass's denylists
- fix Design's `__str__` function not returning a string
- fix the generator crashing if there's any `std::function` in a header
- misc: add a crude `__repr__` based on `__str__`
@donn donn changed the title fix: select bugs and object lifecycle issues fix: select pyosys bugs and object lifecycle issues Oct 21, 2025
@donn donn requested a review from mmicko October 22, 2025 16:52
@mmicko
Copy link
Member

mmicko commented Oct 23, 2025

Would like to ping @jix and @georgerennie on this one as well

@donn
Copy link
Contributor Author

donn commented Oct 23, 2025

I should mention for the record there's another lifecycle issue left which is dangling references behave a lot like C++. The way the boost bindings handled that is by keeping the entire design in memory if any references to even like, an IdString key in cells_ was left. I will replicate that behavior in another PR, but this fixes a more immediate issue.

@donn donn marked this pull request as draft October 24, 2025 08:13
@donn
Copy link
Contributor Author

donn commented Oct 24, 2025

Actually, let me think about this one a bit more. The copy by value solution is also kind of a hack — because if A and B are classes and A has a non-pointer member of type B, a.b.x = 0 would mutate a copy. This will confuse people.

The current semantics are consistent despite the memory issues. I just need to fix the memory issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants