Skip to content

Fix duplicate SV struct typedefs when multiple Python APIs share the same struct type#50

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/fix-duplicate-typedefs-sv-package
Draft

Fix duplicate SV struct typedefs when multiple Python APIs share the same struct type#50
Copilot wants to merge 6 commits intomainfrom
copilot/fix-duplicate-typedefs-sv-package

Conversation

Copy link

Copilot AI commented Feb 28, 2026

  • Add unit test to confirm duplicate struct typedef issue when multiple Python APIs share the same struct type
  • Fix _collect_struct_types in gen_sv_class.py to track already-emitted struct types across multiple gen() calls via _emitted_struct_types set
  • Clear _struct_types after each gen() call to avoid memory growth
  • Fix CI: install pcpp cxxheaderparser without -U to avoid upgrading setuptools to a version incompatible with ivpm's build_ext.py (copy_file() got an unexpected keyword argument 'dry_run')
  • Verify fix with unit tests (23 passed)
Original prompt

This section details on the original issue you should resolve

<issue_title>Duplicate SV structure typedefs are created when referenced by multiple Python APs</issue_title>
<issue_description>When multiple Python APIs reference a structure type in their method arguments, the structure typedef is replicated in the generated SV package:

class Point(ct.Structure):
    _fields_ = [
        ("x", ct.c_int32),
        ("y", ct.c_int32),
    ]

@hif.api
class FirstAPI(object):
    @hif.imp
    async def func1(self, pt: Point):
        pass

@hif.api
class SecondAPI(object):
    @hif.exp
   def func2(self, pt: Point):
        print(pt)

The above code results in two Point_t structure typedefs in the generated SV package, resulting in the following VCS error:

Error-[IPD] Identifier previously declared
  Identifier 'Point_t' previously declared as typedef

A workaround is to split these APIs into separate files and generate them separately, but it would be convenient to add memory when a structure was generated to prevent duplicate definitions.</issue_description>

<agent_instructions>Create a test for this situation and confirm the presence of duplicate struct/class definitions. Investigate and correct the duplication</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

… type

Co-authored-by: mballance <1340805+mballance@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix duplicate SV structure typedefs in generated package Fix duplicate SV struct typedefs when multiple Python APIs share the same struct type Feb 28, 2026
@mballance
Copy link
Member

@copilot, seems something broke. Review failures and correct

…setup.py build_ext

Co-authored-by: mballance <1340805+mballance@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 28, 2026

@copilot, seems something broke. Review failures and correct

The CI failure was caused by a newer version of ivpm no longer installing pcpp and cxxheaderparser via ivpm update -a (these are in the default-ci dep-set but were not making it into packages/python). My code changes (gen_sv_class.py and test file) were unrelated to this failure.

Fixed in commit 211d527 by explicitly installing pcpp cxxheaderparser in the CI workflow's pip install step before running setup.py build_ext --inplace.

@mballance
Copy link
Member

@copilot still not quite right. Check and correct

…pgrade incompatibility

Co-authored-by: mballance <1340805+mballance@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 28, 2026

@copilot still not quite right. Check and correct

The previous fix used pip install -U ... pcpp cxxheaderparser which upgraded setuptools as a side effect, making it incompatible with ivpm's build_ext.py (copy_file() got an unexpected keyword argument 'dry_run').

Fixed in commit 538bf14 by installing pcpp cxxheaderparser in a separate pip install line without -U, so that setuptools is not upgraded.

mballance and others added 2 commits March 2, 2026 03:41
Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
…automatic in initial blocks

- In pyhdl_if_macros.svh, conditionally define STACKTRACE macro to use
  a display placeholder when XILINX_SIMULATOR is defined, since Vivado
  xsim does not support $stacktrace
- In pyhdl_if.sv, switch the inline $stacktrace call to use the
  STACKTRACE macro for consistency
- In struct_bfm.sv and struct_comprehensive_bfm.sv, declare class
  variables in initial blocks as 'automatic' to satisfy xelab's
  requirement for explicit lifetime

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Duplicate SV structure typedefs are created when referenced by multiple Python APs

2 participants