Skip to content

Conversation

@jdmpapin
Copy link
Contributor

@jdmpapin jdmpapin commented Aug 9, 2022

TR_Uncopyable provides highly general functionality that should be available without including FrontEnd.hpp. This commit moves it into its own header, where it will be more widely available.

Additionally:

  • It is moved into the TR namespace.

  • The constructor and destructor are declared protected rather than public. Only subclasses need access to those.

  • The only existing point of use (TR_FrontEnd) is changed to use private rather than public inheritance, since the fact that inheritance is used to get the desired effect is an implementation detail.

  • A couple of types are changed to use TR::Uncopyable.

#define OMR_UNCOPYABLE_INCL

namespace TR {

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be useful to have a brief comment here for what and why this class is useful and how it is expected to be used (i.e., subclassing). Would you mind adding a brief comment here please?

*******************************************************************************/

#ifndef OMR_UNCOPYABLE_INCL
#define OMR_UNCOPYABLE_INCL
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically this should be TR_UNCOPYABLE_INCL per existing conventions.

@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2022, 2022 IBM Corp. and others
Copy link
Contributor

Choose a reason for hiding this comment

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

As this was lifted from FrontEnd.hpp, I think the first copyright date should be 2000.

@0xdaryl 0xdaryl self-assigned this Aug 10, 2022
TR_Uncopyable provides highly general functionality that should be
available without including FrontEnd.hpp. This commit moves it into its
own header, where it will be more widely available.

Additionally:

- It is moved into the TR namespace.

- A doc comment is added to the class, and another comment explains the
  mechanism by which it works.

- The constructor and destructor are declared protected rather than
  public. Only subclasses need access to those.

- The only existing point of use (TR_FrontEnd) is changed to use private
  rather than public inheritance, since the fact that inheritance is
  used to get the desired effect is an implementation detail.

- A couple of types are changed to use TR::Uncopyable.
@jdmpapin
Copy link
Contributor Author

Updated to fix the copyright start date and include guard name, and to document the class. I also added another comment to explain how it works.

While documenting this, I realized that it additionally happens to prevent the implicit default definition of the move constructor and move assignment operator (in both Uncopyable itself and then therefore in its subtypes). I think moves usually make sense for a type even if copies don't. This could easily be made movable and therefore allow its subtypes to implicitly define move operations like so:

Uncopyable(Uncopyable&&) {}
Uncopyable &operator=(Uncopyable&&) { return *this; }

However, it isn't clear that we have a reasonable level of support for move semantics in all of our build compilers (even though the list of supported C++ features claims that we can use it). For example, cppreference.com says that no version of XLC++ supports "defaulted move special member functions." From a bit of experimentation, it seems that this includes implicitly-defined move operations, which means that we couldn't portably rely on the implicit definitions allowed by the snippet above.

But it seems we don't use move semantics regardless. At least, I don't recall seeing any explicit rvalue references or moves in the codebase, and in my experimentation I hit a number of surprising road blocks beyond just the lack of defaulted move methods, e.g. lack of move constructors for STL types. So for now I've left the move constructor and assignment operator undeclared without so much as commenting about them in the code, just as though move semantics don't even exist.

@0xdaryl
Copy link
Contributor

0xdaryl commented Aug 11, 2022

Jenkins build all

@0xdaryl 0xdaryl merged commit e26f652 into eclipse-omr:master Aug 11, 2022
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.

2 participants