RFR: JDK-8299386: Refactor metaprogramming to use <type_traits>

Kim Barrett kbarrett at openjdk.org
Wed Dec 28 08:04:53 UTC 2022


On Wed, 28 Dec 2022 06:00:59 GMT, Justin King <jcking at openjdk.org> wrote:

> Cleanup `metaprogramming/` to just use implementations from `<type_traits>` that are available in C++11 and onward.

I started out intending to suggest replacing some of these changes by instead
updating the uses of a couple that are rarely used, and getting rid of the
associated pre-C++11 synonyms entirely. But it turns out most are rarely used,
leading me to question this change almost in its entirety.

I think better would be a series of changes to replace uses of the synonyms
with the corresponding element from <type_traits> and delete the synonyms.  I
say "a series of changes" because I would prefer it not be done all in one
changeset, for easier reviewing.

I suggest making an exception for EnableIf, because of the number of uses and
because I'm hoping we'll be able to revise them in a better way in the not too
distant future. Many of the uses are for function SFINAE, where the syntax is
pretty horrible. We have the newer form of function SFINAE available (see
ENABLE_IF), but I think in many/most cases even better would be to use C++17
constexpr if. That's why I haven't proposed rewriting any of them using
ENABLE_IF. I'm hopeful that using C++17 isn't too far away, now that there
seems to be a compiler available for the aix-ppc port.

src/hotspot/share/metaprogramming/integralConstant.hpp line 50:

> 48: 
> 49: // A bool valued IntegralConstant whose value is true.
> 50: using TrueType = std::true_type;

Outside of the implementation of our pre-C++11 metaprogramming tools, there are only a very small number of uses of this type.  It would be better to update those uses.

src/hotspot/share/metaprogramming/integralConstant.hpp line 53:

> 51: 
> 52: // A bool valued IntegralConstant whose value is false.
> 53: using FalseType = std::false_type;

I think there are no uses of FalseType outside of the implementation of our pre-C++11 metaprogramming tools.  Since I'm proposing we update uses of those and eliminate our synonyms, that will likely render this type unused.

src/hotspot/share/metaprogramming/isArray.hpp line 33:

> 31: 
> 32: template <typename T>
> 33: using IsArray = std::is_array<T>;

There is only one use of IsArray (in zSafeDelete.inline.hpp).  It would be better to update that use and delete this file.

src/hotspot/share/metaprogramming/isConst.hpp line 33:

> 31: 
> 32: template <typename T>
> 33: using IsConst = std::is_const<T>;

There is only one use of IsConst (in oopStorage.inline.hpp).  It would be better to update that use and delete this file.

src/hotspot/share/metaprogramming/isFloatingPoint.hpp line 36:

> 34: 
> 35: template <typename T>
> 36: using IsFloatingPoint = std::is_floating_point<T>;

There are only two uses of IsFloatingPoint (in accessBackend.hpp).  It would be better to update those uses and delete this file.

src/hotspot/share/metaprogramming/isIntegral.hpp line 41:

> 39: 
> 40: // This metafunction returns true iff the type T (irrespective of CV qualifiers)
> 41: // is a signed integral type. Note that this is false for enums.

IsSignedIntegral and IsUnsignedIntegral don't seem to be used anymore.

src/hotspot/share/metaprogramming/isVolatile.hpp line 33:

> 31: 
> 32: template <typename T>
> 33: using IsVolatile = std::is_volatile<T>;

There are only two uses if IsVolatile (in accessBackend.hpp).  It would be better to update those uses and delete this file.

src/hotspot/share/metaprogramming/removeCV.hpp line 31:

> 29: 
> 30: template <typename T>
> 31: using RemoveCV = std::remove_cv<T>;

After some of the changes proposed here there are only a couple of uses of RemoveCV remaining (in atomic.hpp).  It would be better to update those uses and delete this file.

src/hotspot/share/metaprogramming/removeExtent.hpp line 31:

> 29: 
> 30: template <typename T>
> 31: using RemoveExtent = std::remove_extent<T>;

There is only one use of RemoveExtent.  It would be better to update that use and delete this file.

src/hotspot/share/metaprogramming/removePointer.hpp line 35:

> 33: 
> 34: template <typename T>
> 35: using RemovePointer = std::remove_pointer<T>;

RemovePointer is no longer used, and this file can be deleted.

src/hotspot/share/metaprogramming/removeReference.hpp line 35:

> 33: 
> 34: template <typename T>
> 35: using RemoveReference = std::remove_reference<T>;

After the change to define Decay in terms of std::decay, RemoveReference is no longer used and this file can be deleted.

-------------

PR: https://git.openjdk.org/jdk/pull/11794


More information about the hotspot-dev mailing list