Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove final on template derived classes #3923

Merged
merged 3 commits into from
Nov 29, 2024

Conversation

paulgessinger
Copy link
Member

@paulgessinger paulgessinger commented Nov 29, 2024

This seems to cause issues when using dynamic_cast on AppleClang 16 and llvm 18 on macOS 15 (at least).

Reproducer:
https://gist.github.com/paulgessinger/2c1d2abdeb322072c507878ab5833728

Summary by CodeRabbit

  • New Features

    • Enhanced extensibility of the GridPortalLinkT, Axis, Affine3Transformed, GlobalSubspace, and LocalSubspace classes by allowing subclassing.
    • Updated constructors and methods in GridPortalLinkT to improve error handling and functionality.
  • Bug Fixes

    • Improved validation in the resolveVolume method to ensure positions are within valid bounds.
  • Documentation

    • Clarified class hierarchies and relationships due to changes in access specifiers.

This seems to cause issued when using `dynamic_cast` on AppleClang 16
and llvm 17 on macOS 15 (at least).

Reproducer:
https://gist.github.com/paulgessinger/2c1d2abdeb322072c507878ab5833728
@paulgessinger paulgessinger changed the title fix: Remove final on teplate derived classes fix: Remove final on template derived classes Nov 29, 2024
Copy link

coderabbitai bot commented Nov 29, 2024

Walkthrough

Changes made, significant they are. The GridPortalLinkT class no longer marked as final, subclassing allowed it is. Constructor updated, surface type checks added, and member variable initialized. Methods like resolveVolume modified, overload introduced for position validation. Similar alterations in Axis and grid access helper classes, final specifier removed, inheritance extended. Flexibility increased, potential for future development enhanced.

Changes

File Path Change Summary
Core/include/Acts/Geometry/GridPortalLink.hpp GridPortalLinkT class no longer final, constructor updated with surface type checks, resolveVolume method overloaded, and several methods updated for type-erased access.
Core/include/Acts/Utilities/Axis.hpp Axis<AxisType::Equidistant, bdt> and Axis<AxisType::Variable, bdt> classes no longer final, allowing inheritance.
Core/include/Acts/Utilities/GridAccessHelpers.hpp Affine3Transformed, GlobalSubspace, and LocalSubspace classes no longer final, template parameters removed for flexibility.

Poem

In the realm of code, changes unfold,
Classes unshackled, new tales to be told.
From final to free, inheritance blooms,
In the dance of design, creativity looms.
With checks and balances, the structure refined,
A brighter future for all, intertwined. 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

@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: 0

🧹 Outside diff range and nitpick comments (5)
Core/include/Acts/Utilities/GridAccessHelpers.hpp (2)

145-145: Good, this change is! Documentation, enhance we should.

Remove final specifier, we must, for dynamic_cast to function properly. Yet, document the inheritance capabilities in class documentation, we should. Help future Padawans understand the design intentions, it will.

Consider adding this documentation above the class:

/// @brief A global subspace transformation class that can be inherited from
/// to customize the transformation behavior

Line range hint 113-182: Architectural wisdom, share I must.

Template inheritance, a powerful tool it is, but use it wisely we must. Consider these aspects, you should:

  • Template instantiation overhead, watch for it
  • Binary size impact, measure you must
  • Consistent inheritance patterns across codebase, maintain we should
Core/include/Acts/Utilities/Axis.hpp (1)

Line range hint 100-420: Virtual destructor, consider adding you must.

When inheritance allowed becomes, virtual destructor crucial it is. Through base pointer when derived object deleted is, undefined behavior without virtual destructor occurs.

Add virtual destructor to IAxis base class or protected non-virtual destructor if public inheritance not intended:

class IAxis {
+    virtual ~IAxis() = default;
     // ... existing members ...
};
Core/include/Acts/Geometry/GridPortalLink.hpp (2)

Line range hint 412-445: More descriptive error messages, suggest I do!

Improve error handling clarity, we must. When invalid surface type or direction encountered is, more context in error messages, helpful would be.

Consider this improvement:

-      throw std::invalid_argument{"Invalid binning direction"};
+      throw std::invalid_argument{
+        "Invalid binning direction for CylinderSurface. Expected binRPhi or binZ, got " + 
+        std::to_string(static_cast<int>(direction))};

Similar improvements for other error messages, apply you should.


Line range hint 551-558: Safer bounds checking, implement we must!

Assert statement in production code, dangerous it can be. Replace with proper error handling, we should.

Consider this improvement:

-    assert(surface().insideBounds(position, BoundaryTolerance::None()));
+    if (!surface().insideBounds(position, BoundaryTolerance::None())) {
+      return Result<const TrackingVolume*>::failure(
+          std::runtime_error("Position not within surface bounds"));
+    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between eb6a5f1 and 62ebd04.

📒 Files selected for processing (3)
  • Core/include/Acts/Geometry/GridPortalLink.hpp (1 hunks)
  • Core/include/Acts/Utilities/Axis.hpp (2 hunks)
  • Core/include/Acts/Utilities/GridAccessHelpers.hpp (3 hunks)
🔇 Additional comments (6)
Core/include/Acts/Utilities/GridAccessHelpers.hpp (3)

113-113: Wise decision, removing final is! Hmmmm.

Align with the PR objectives, this change does. Allow dynamic_cast to work correctly on AppleClang 16 and LLVM 17, it will. Inheritance hierarchy, preserved it is.


182-182: Approve this change, I do! Yet verify consistency, we must.

Remove final specifier, wise it is. With the Force of dynamic_cast, align it does.


Line range hint 224-224: Consistency in the Force, sense I do not. Hmmmm.

Still marked as final, the BoundCylinderToZPhi class is. Verify we must, if same treatment it needs.

✅ Verification successful

Remove 'final' keyword, we must not!

Correct the marking as 'final' is, young padawan! Through the Force, I see that BoundCylinderToZPhi used only through dynamic casting and factory methods it is. No inheritance from it exists, and proper it is to prevent it. Base class IBoundToGridLocal serves as the interface, it does, while BoundCylinderToZPhi remains a concrete leaf class, hmmmm.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of BoundCylinderToZPhi with dynamic_cast
rg "dynamic_cast.*BoundCylinderToZPhi" 

# Check if BoundCylinderToZPhi is used as a base class
ast-grep --pattern 'class $_ : public BoundCylinderToZPhi'

Length of output: 341


Script:

#!/bin/bash
# Search for the BoundCylinderToZPhi class definition
ast-grep --pattern 'class BoundCylinderToZPhi {
  $$$
}'

# Check if there are any virtual methods in BoundCylinderToZPhi
rg -A 5 "virtual.*BoundCylinderToZPhi"

# Look for inheritance from BoundCylinderToZPhi
rg "BoundCylinderToZPhi" -A 2 -B 2

Length of output: 4102


Script:

#!/bin/bash
# Search for the base class IBoundToGridLocal definition and usage
ast-grep --pattern 'class IBoundToGridLocal {
  $$$
}'

# Check if there are any other classes inheriting from IBoundToGridLocal
rg "public IBoundToGridLocal" -B 2 -A 2

Length of output: 862

Core/include/Acts/Utilities/Axis.hpp (2)

100-100: Approve removal of final specifier from Equidistant axis class, I do.

Wise decision this is, allowing inheritance from template class and fixing dynamic_cast issues on AppleClang it does. Maintain functionality while extending flexibility, it does.


420-420: Approve removal of final specifier from Variable axis class, I do.

Similar to Equidistant axis, wise change this is. Dynamic casting issues on macOS platform, resolve it does.

Core/include/Acts/Geometry/GridPortalLink.hpp (1)

399-399: Approve the removal of final specifier, I do!

Wise decision this is, allowing proper inheritance and fixing dynamic_cast issues on AppleClang 16 and LLVM 17, it does. Safe and necessary change, this appears to be.

Copy link
Contributor

@andiwand andiwand left a comment

Choose a reason for hiding this comment

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

seems like the best solution for now 👍

@github-actions github-actions bot added this to the next milestone Nov 29, 2024
@github-actions github-actions bot added the Component - Core Affects the Core module label Nov 29, 2024
Copy link

github-actions bot commented Nov 29, 2024

📊: Physics performance monitoring for cf7db32

Full contents

physmon summary

@kodiakhq kodiakhq bot merged commit 8895da1 into acts-project:main Nov 29, 2024
48 checks passed
kodiakhq bot pushed a commit that referenced this pull request Dec 3, 2024
- I missed a `final` in one location (see #3923)
- Adding an exception to `GridAccessJsonConverter::toJson`. This was previously silently returning an empty json object if none of the downcasts worked. Since the downcast chain is not exhaustive, I think it's better to throw if there's an unhandled case.
@paulgessinger paulgessinger modified the milestones: next, v38.1.0 Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Core Affects the Core module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants