Skip to content

Introduce OMR_FINAL attribute for extensible classes - #7964

Merged
hzongaro merged 2 commits into
eclipse-omr:masterfrom
0xdaryl:omrfinal
Oct 6, 2025
Merged

Introduce OMR_FINAL attribute for extensible classes#7964
hzongaro merged 2 commits into
eclipse-omr:masterfrom
0xdaryl:omrfinal

Conversation

@0xdaryl

@0xdaryl 0xdaryl commented Oct 1, 2025

Copy link
Copy Markdown
Contributor

This PR introduces an OMR_FINAL attribute that can be used in the compiler component to decorate member functions in C++ extensible classes to indicate they will not be overridden by a subclass. This attribute is not enforced by the compiler at build time and serves primarily as documentation. However, its intended semantics in the code can be verified using third-party linting tools, such as those built with Clang.

The introduction of this attribute is motivated by the desire to improve code readability by eliminating the requirement for self() calls when dispatching trivial member functions (such as getters and setters) in extensible classes.

This PR includes a commit that demonstrates how and where OMR_FINAL can be used in a number of extensible classes. This is not an exhaustive application of OMR_FINAL, only a demonstrative set. Eliminating the unnecessary self() calls will occur in future PRs in OMR and downstream projects.

An alternative approach to achieve the same result is to introduce an attribute to decorate the member functions that could be extended by sub-classes in an extensible class hierarchy. This is more in line with the way C++ allows methods to be extended via virtual functions and dynamic polymorphism. However, taking such an approach would require scrutiny of every member function in an extensible class to determine which are acceptable extension points and which are not. This is a far larger undertaking than is necessary to achieve the end goal (more readable code). In addition, the number of OMR_FINAL functions is expected to be much less than the number of extension points allowed.

@0xdaryl

0xdaryl commented Oct 1, 2025

Copy link
Copy Markdown
Contributor Author

@mstoodle @vijaysun-omr @hzongaro @jdmpapin @dsouzai @kevindean12 : FYI for any opinions

Comment thread compiler/infra/Annotations.hpp Outdated
Comment thread doc/compiler/extensible_classes/Extensible_Classes.md
Comment thread compiler/infra/Annotations.hpp
Comment thread doc/compiler/extensible_classes/Extensible_Classes.md Outdated
The `OMR_FINAL` attribute is used to decorate member functions of an extensible
class to indicate the implementation will not be overridden by a subclass.

Member functions designated `OMR_FINAL` need not be referenced with `self()`,
which improves readability of the code.

Signed-off-by: Daryl Maier <maier@ca.ibm.com>
@kevindean12

Copy link
Copy Markdown
Contributor

@0xdaryl Looks good from my perspective. Thanks for the heads up!

@hzongaro hzongaro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. Thanks!

@vijaysun-omr

Copy link
Copy Markdown
Contributor

LGTM, thanks

@hzongaro hzongaro self-assigned this Oct 3, 2025
@hzongaro

hzongaro commented Oct 3, 2025

Copy link
Copy Markdown
Contributor

Jenkins build all

@hzongaro

hzongaro commented Oct 3, 2025

Copy link
Copy Markdown
Contributor

The failure running compunittest in linux_ppc-64_le_gcc testing has occurre frequently of late - it is unrelated to this change.

I will hold off merging until @dsouzai and @mstoodle have had a chance to express an opinion.

@mstoodle

mstoodle commented Oct 4, 2025

Copy link
Copy Markdown
Contributor

looks ok to me

@dsouzai

dsouzai commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

No concerns from my end.

@0xdaryl

0xdaryl commented Oct 6, 2025

Copy link
Copy Markdown
Contributor Author

Jenkins build riscv

For the record, RISC-V testing was successful for this PR. Launching it again in this PR to test the RV build pipeline for a different issue.

@vijaysun-omr

Copy link
Copy Markdown
Contributor

It did fail riscv testing

@0xdaryl

0xdaryl commented Oct 6, 2025

Copy link
Copy Markdown
Contributor Author

@hzongaro : since we have broad consensus on this, could you merge please? Thanks.

@hzongaro
hzongaro merged commit 17895ec into eclipse-omr:master Oct 6, 2025
12 of 14 checks passed
thallium pushed a commit to thallium/omr that referenced this pull request Oct 7, 2025
Introduce OMR_FINAL attribute for extensible classes

new jfr mem category

Signed-off-by: Gengchen Tuo <gengchen.tuo@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants