Skip to content

Hashability of non-primitive types used as a user-defined-property value. #292

@eblankenberg-trt

Description

@eblankenberg-trt

Attempting to create a user-defined property that references a non-primitive (hashable) value causes the tool to fail. For example, a reference to another field. The current workaround is to describe the reference via a string that is a path which is not ideal. See the example below:

property view_pointer {
    type = field;
    component = field; // TODO field is not hashable so breaks peakrdl-python but for now we do relative directories
};

addrmap test {
    reg {
        field {
            hw = rw;
            sw = rw;
        } value [32-1:0];
    } view;

    reg {
        field {
            hw = rw;
            sw = rw;
        } value [32-1:0];
    } pointer;

    view.value->view_pointer = pointer.value;
};

Calling python -m peakrdl python test.rdl --udp view_pointer -o out yields:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\peakrdl\__main__.py", line 3, in <module>
    main()
    ~~~~^^
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\peakrdl\main.py", line 146, in main
    options.subcommand.main(importers, options)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\peakrdl\subcommand.py", line 158, in main
    self.do_export(root.top, options)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\peakrdl_python\__peakrdl__.py", line 179, in do_export    
    peakrdl_exporter.export(
    ~~~~~~~~~~~~~~~~~~~~~~~^
        node=top_node,
        ^^^^^^^^^^^^^^
    ...<19 lines>...
        hashing_method=NodeHashingMethod[options.hashing_mode]
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\peakrdl_python\exporter.py", line 1094, in export
    self.__export_reg_model(
    ~~~~~~~~~~~~~~~~~~~~~~~^
        top_block=top_block, package=package, asyncoutput=asyncoutput,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<11 lines>...
        hashing_method=hashing_method
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\peakrdl_python\exporter.py", line 222, in __export_reg_model
    RDLWalker(unroll=True).walk(top_block.parent, unique_component_walker,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                skip_top=False)
                                ^^^^^^^^^^^^^^^
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\systemrdl\walker.py", line 218, in walk
    self._walk(child, listeners)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\systemrdl\walker.py", line 227, in _walk
    self.current_action = self.do_enter(node, listener)
                          ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\systemrdl\walker.py", line 271, in do_enter
    new_action = listener.enter_Addrmap(node) or WalkerAction.Continue
                 ~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\peakrdl_python\unique_component_iterator.py", line 466, in enter_Addrmap
    return self.__enter_non_field_node(node)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\peakrdl_python\unique_component_iterator.py", line 430, in __enter_non_field_node
    potential_unique_node = self.__build_peak_rdl_unique_component(node)
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\peakrdl_python\unique_component_iterator.py", line 378, in __build_peak_rdl_unique_component
    nodal_hash_result = self.calculate_or_lookup_hash(node)
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\peakrdl_python\unique_component_iterator.py", line 508, in calculate_or_lookup_hash
    nodal_hash_result = node_hash(node=node, udp_include_func=self.udp_include_func,
                                  hide_node_callback=self.hide_node_callback,
                                  include_name_and_desc=self.include_name_and_desc,
                                  method=self.hashing_method)
  File "C:\BLANew\quick_gain\release_test\trt-gain-fpga\.pixi\envs\default\Lib\site-packages\peakrdl_python\systemrdl_node_hashes.py", line 549, in node_hash
    return hash(tuple(hash_content))
TypeError: unhashable type: 'FieldNode'

I think it may be ok for many use-cases if references to objects that don't exist in the Python HAL (ex. signals) exist just as reference objects with the SystemRDL metadata (inst name, properties, etc.).

See #291 for a use case (view register with underlying pointer) for when this may be helpful.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions