Skip to content

Commit

Permalink
Poison "quantized int" specializations of std::is_signed, as a first …
Browse files Browse the repository at this point in the history
…step towards removing them.

This specialization is not permitted per the C++ standard, and thus:
- MSVC silently ignores specializations of `std::is_signed`, since VS2019 16.4.
- Clang emits `error: 'is_signed' cannot be specialized: Users are not allowed to specialize this standard library entity [-Winvalid-specialization]` by default, as of Clang 20.

Also, modify all relevant callers of `std::is_signed<T>` for which the change triggered a compilation failure to instead call `std::numeric_limits<T>::is_signed`.

Note that `std::numeric_limits` _is_ permitted to be specialized for user types.

PiperOrigin-RevId: 719339288
  • Loading branch information
Google-ML-Automation committed Jan 27, 2025
1 parent ea9d7ba commit 3efae36
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions xla/tsl/framework/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,22 @@ class numeric_limits<tsl::quint16> : public numeric_limits<tsl::uint16> {};
template <>
class numeric_limits<tsl::qint32> : public numeric_limits<tsl::int32> {};

// Specialize is_signed for quantized types.
// Templates from <type_traits> are not permitted to be specialized by users,
// and doing so may be ignored or cause an error. As a transitional measure,
// since tensorflow was specializing is_signed for some time, poison uses by
// specializing with an empty struct (missing the `value` member).
//
// TODO(b/392034954): Delete these invalid specializations.
template <>
struct is_signed<tsl::qint8> : public is_signed<tsl::int8> {};
struct is_signed<tsl::qint8> {};
template <>
struct is_signed<tsl::quint8> : public is_signed<tsl::uint8> {};
struct is_signed<tsl::quint8> {};
template <>
struct is_signed<tsl::qint16> : public is_signed<tsl::int16> {};
struct is_signed<tsl::qint16> {};
template <>
struct is_signed<tsl::quint16> : public is_signed<tsl::uint16> {};
struct is_signed<tsl::quint16> {};
template <>
struct is_signed<tsl::qint32> : public is_signed<tsl::int32> {};
struct is_signed<tsl::qint32> {};

} // namespace std

Expand Down

0 comments on commit 3efae36

Please sign in to comment.