eclipse / omr

Eclipse OMR™ Cross platform components for building reliable, high performance language runtimes
http://www.eclipse.org/omr
Other
933 stars 392 forks source link

Extensible classes: how to be protected from inter-project name clashes for re-declared concrete classes #7390

Open samolisov opened 1 week ago

samolisov commented 1 week ago

Hello everyone, actually this is not and issue (yet?), just a question.

In the amazing documentation about the concept of extensible classes, we can found the following wording (not cited, just meaning): concrete classes should be put in the common (TR:: in our case) namespace and the file name for the header with the class definition should be after the class' name. Also, we can (and do!) re-declare a concrete class between projects.

For example, omr containas the compiler/codegen/CodeGenerator.hpp header and the TR::CodeGenerator class is defined there. Also, openj9 contains the same header where the same class in defined. Unfortunately, I wasn't able to find an example of not header-only concrete class what would be re-declared between the projects, but I believe this example is enough: both CodeGenerator.hpp headers are included in many, many extensible classes in both projects and those classes have a corresponding .cpp implementation part.

So, the question is, whether there is an ODR violation and if so, how the omr and openj9 projects are protected? Because openj9 has omr as a dependency, omr should be built first and will have the compiler library with the corresponding object modules that contain the first definition of the TR::CodeGenerator class. When we build the openj9 project, it gets the its own compiler library, which will contain the second definition of the TR::CodeGenerator class. Then we link both projects and an ODR violation should be there. This is how I get the things.

What protect openj9 from the ODR violation with the upstream project? I believe this is the correct linking ordering for object modules and dependencies, but maybe I'm missing something?

Thank your very much for any help. I think the extensible classes concept is a great invention and would be glad to understand it deeply.