Skip to content

Conversation

nicolasnoble
Copy link
Member

No description provided.

Copy link
Contributor

coderabbitai bot commented Jun 8, 2025

Walkthrough

The event type hashing mechanism in the EventBus system is refactored to support both RTTI-enabled and RTTI-disabled environments. A macro abstracts hash retrieval, and type definitions are updated to use a new HashType alias. Method signatures and hash table key types are modified to accommodate this abstraction.

Changes

File(s) Change Summary
src/support/eventbus.h Refactored event type hashing to support RTTI and non-RTTI modes; introduced HashType alias, macro for hash retrieval, updated method signatures and hash table key types.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant EventBus
    participant Listener

    Client->>EventBus: listen(PCSX_HASH_TYPE(Event), Listener)
    EventBus->>EventBus: Register listener with hash key

    Client->>EventBus: signal(PCSX_HASH_TYPE(Event), event)
    EventBus->>Listener: Notify listener(s) for hash key
Loading

Poem

In the meadow of code, a hash hops anew,
RTTI or not, the events still flow through.
A macro now leads, with type info in tow,
Listeners gather where hashed breezes blow.
Whether runtime or compile, the signals still chime—
A rabbit’s delight, in refactor sublime!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nicolasnoble nicolasnoble requested a review from Copilot June 8, 2025 02:37
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces an alternative mechanism to retrieve event type hashes for the event bus without relying solely on RTTI.

  • Implements conditional inclusion to use standard RTTI when available and a fallback (ctti) when not.
  • Updates hashtable key types and listener registrations to use the PCSX_HASH_TYPE macro.
Comments suppressed due to low confidence (2)

src/support/eventbus.h:41

  • Consider adding a brief comment above the PCSX_HASH_TYPE macro to describe its purpose and how it differentiates between using RTTI and the ctti library, for improved clarity and maintainability.
#define PCSX_HASH_TYPE(type) typeid(type).hash_code()

src/support/eventbus.h:55

  • A comment clarifying why HashType is typedef’d differently based on the availability of RTTI (i.e., std::size_t vs. std::uint64_t) would be helpful to future maintainers.
typedef std::size_t HashType;

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a067701 and 27e9e1c.

📒 Files selected for processing (1)
  • src/support/eventbus.h (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: pcsx-redux (x86_64-linux)
  • GitHub Check: pcsx-redux (aarch64-linux)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: toolchain
  • GitHub Check: coverage
  • GitHub Check: aur-build
  • GitHub Check: asan
  • GitHub Check: build-openbios
  • GitHub Check: build
  • GitHub Check: cross-arm64
  • GitHub Check: macos-build-and-test-toolchain
  • GitHub Check: pcsx-redux (x86_64-linux)
  • GitHub Check: pcsx-redux (aarch64-linux)
🔇 Additional comments (3)
src/support/eventbus.h (3)

37-48: RTTI detection and macro definition looks solid.

The conditional compilation logic correctly detects RTTI support using standard compiler macros and provides appropriate fallbacks. The macro abstraction cleanly handles the different hashing mechanisms.


54-58: HashType abstraction is well-designed.

The conditional typedef correctly matches the return types of the respective hashing mechanisms - std::size_t for RTTI's typeid().hash_code() and std::uint64_t for CTTI's hash method.


90-90: Hash table key type update is consistent.

The typedef correctly uses the new HashType instead of the hardcoded std::size_t, maintaining consistency with the abstraction.

void signal(const Event& event) {
using Functor = typename ListenerElement<Event>::Functor;
auto list = m_table.find(typeid(Event).hash_code());
auto list = m_table.find(PCSX_HASH_TYPE(Event));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Consider potential ABI compatibility implications.

The macro usage is correct and maintains a clean interface. However, switching between RTTI and non-RTTI modes could break ABI compatibility since the hash types and algorithms differ.

Consider documenting the ABI implications of this change and ensure that:

  1. All translation units use the same RTTI mode
  2. The build system enforces consistent RTTI settings
  3. Different hash algorithms don't introduce subtle behavioral differences

Also applies to: 112-112, 127-127


🏁 Script executed:

#!/bin/bash
# Description: Check for potential mixed RTTI usage patterns in the codebase

# Look for direct typeid usage that might bypass the macro
rg "typeid\(" --type cpp --type cc --type cxx | grep -v "PCSX_HASH_TYPE"

# Check for existing RTTI-dependent code that might conflict
rg -i "rtti" --type cpp --type cc --type cxx --type cmake | head -10

# Look for build configuration that might affect RTTI settings
rg -i "frtti\|fno-rtti" --type cmake --type make

Length of output: 246


The previous ripgrep invocation failed to detect “.cc” files, so let’s retry with explicit glob patterns:


🏁 Script executed:

#!/bin/bash
# 1) Find any direct typeid() usages not wrapped in PCSX_HASH_TYPE
rg "typeid\\(" -g '*.cpp' -g '*.cc' -g '*.cxx' --no-heading | grep -v "PCSX_HASH_TYPE"

# 2) Scan for any RTTI mentions in source, headers, and CMake
rg -i rtti -g '*.cpp' -g '*.cc' -g '*.cxx' -g '*.h' -g '*.hpp' -g '*.cmake' -g 'CMakeLists.txt' | head -20

# 3) Look for RTTI-related compiler flags in CMakeLists
rg -i 'fno-rtti|frtti' -g '*.cmake' -g 'CMakeLists.txt' --no-heading

Length of output: 2188


Document ABI implications and enforce RTTI consistency

No direct typeid() calls bypassing PCSX_HASH_TYPE were found in your sources (only in third_party/EABase tests). However, the build system doesn’t currently lock down RTTI settings, which risks mixing RTTI modes and breaking ABI. To address this:

  • In src/support/eventbus.h, expand the comment around PCSX_RTTI to explain that it switches hash algorithms and impacts the ABI.
  • In your top‐level CMakeLists.txt (and any per‐module CMake files), add compiler flags (-frtti or -fno-rtti) uniformly so all targets share the same RTTI mode.
  • Consider a CMake configuration check that errors out if different targets compile with mismatched RTTI settings.
🤖 Prompt for AI Agents
In src/support/eventbus.h at line 102, update the comment near the
PCSX_HASH_TYPE(Event) macro usage to explicitly document that switching between
RTTI and non-RTTI modes changes the hash algorithm and affects ABI
compatibility. Additionally, ensure the top-level CMakeLists.txt and any
module-specific CMake files enforce consistent RTTI compiler flags (-frtti or
-fno-rtti) across all targets, and implement a CMake configuration check that
fails the build if RTTI settings differ between targets to prevent ABI breakage.

Comment on lines +44 to +47
#define CTTI_HAS_ENUM_AWARE_PRETTY_FUNCTION 1
#define CTTI_HAS_VARIABLE_TEMPLATES 1
#include "ctti/type_id.hpp"
#define PCSX_HASH_TYPE(type) ctti::unnamed_type_id<type>().hash()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify CTTI library configuration and compatibility.

The CTTI library configuration defines are hardcoded. Ensure these settings are compatible with your target environments and the version of CTTI being used.


🏁 Script executed:

#!/bin/bash
# Description: Check if CTTI library is properly integrated and verify the hash return type

# Check if CTTI headers exist in the project
fd -t f -e hpp -e h "type_id" | head -10

# Look for CTTI-related build configuration
rg -i "ctti" --type cmake --type make | head -5

# Verify the hash method return type in CTTI documentation or source
rg -A 5 -B 5 "hash.*uint64" | head -10

Length of output: 18316


CTTI Library Integration and Compatibility Needs Attention

  • No ctti/type_id.hpp (or other CTTI headers) were found in the repository; confirm the CTTI library is added as a dependency (e.g. submodule or external package) and that your build system (CMake/Makefiles) includes its header directory.
  • There are no CTTI-related entries in CMakeLists.txt or Makefiles—add the necessary find_package or include-path settings so the compiler can locate the headers.
  • The hardcoded macros
    #define CTTI_HAS_ENUM_AWARE_PRETTY_FUNCTION 1
    #define CTTI_HAS_VARIABLE_TEMPLATES 1
    must match the actual CTTI version you’re using. Verify your version supports these features before defining them.
  • Ensure that ctti::unnamed_type_id<type>().hash() returns the intended width (e.g., std::size_t or uint64_t) on all target platforms. If you depend on a 64-bit hash, guard or static-assert accordingly.
🤖 Prompt for AI Agents
In src/support/eventbus.h around lines 44 to 47, verify that the CTTI library is
properly integrated by ensuring its headers are present in the project and that
your build system (CMake or Makefiles) includes the correct include paths or
find_package directives for CTTI. Confirm the hardcoded macros
CTTI_HAS_ENUM_AWARE_PRETTY_FUNCTION and CTTI_HAS_VARIABLE_TEMPLATES match the
actual CTTI version used, adjusting or removing them if incompatible.
Additionally, check that ctti::unnamed_type_id<type>().hash() returns the
expected hash width on all target platforms, adding static assertions or guards
if a specific size like 64-bit is required.

@nicolasnoble nicolasnoble merged commit 675f7e7 into main Jun 8, 2025
25 checks passed
@nicolasnoble nicolasnoble deleted the eventbus-no-rtti branch June 8, 2025 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant