Skip to content

Simplify some enable_ifs in ivalue_inl.h - #194977

Closed
lakshayg wants to merge 1 commit into
pytorch:mainfrom
lakshayg:simplify-enable-if-ivalue
Closed

lakshayg wants to merge 1 commit into
pytorch:mainfrom
lakshayg:simplify-enable-if-ivalue

Conversation

@lakshayg

Copy link
Copy Markdown
Collaborator

No description provided.

@pytorch-bot

pytorch-bot Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/194977

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit cd95cc8 with merge base 4380f31 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@lakshayg
lakshayg requested review from Skylion007 and cyyever August 27, 2026 03:25
@lakshayg lakshayg self-assigned this Aug 27, 2026
@lakshayg lakshayg added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category labels Aug 27, 2026
@Skylion007

Copy link
Copy Markdown
Collaborator

I think some older MacOS builds are using an older version of Apple Clang that is missing concepts support

@Skylion007 Skylion007 added the ciflow/mps Run MPS tests (subset of trunk) label Aug 27, 2026
@Skylion007

Copy link
Copy Markdown
Collaborator

Is executorch updated to support cpp20 properly yet?

@lakshayg

Copy link
Copy Markdown
Collaborator Author

@Skylion007 I am not sure if executorch supports this properly but I see an open issue and a PR so probably not

@lakshayg
lakshayg force-pushed the simplify-enable-if-ivalue branch from 4f0d33f to 979b6c1 Compare August 27, 2026 21:44
@lakshayg

Copy link
Copy Markdown
Collaborator Author

@Skylion007 I reverted the concept based approach to be safe

@lakshayg
lakshayg force-pushed the simplify-enable-if-ivalue branch from 979b6c1 to 52b4414 Compare August 27, 2026 22:26
@lakshayg
lakshayg force-pushed the simplify-enable-if-ivalue branch from 52b4414 to cd95cc8 Compare August 27, 2026 22:50
Comment on lines +508 to +512
template <typename... Ts>
using enable_if_ivalue_compatible =
std::enable_if<std::conjunction<
std::negation<std::is_lvalue_reference<Ts>>...,
std::is_constructible<IValue, Ts>...>::value>;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Note for reviewers: This pattern of using enable_if_BLABLA = ...; is pretty common in the IValue class.

@lakshayg

Copy link
Copy Markdown
Collaborator Author

@pytorchmergebot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

pytorchmergebot pushed a commit that referenced this pull request Sep 2, 2026
Forward fix for D117882908 (#194977), which broke every
arvr/ovrsource build that depends on `xplat/caffe2:ATen_lib_ovrsource`:

```
xplat/caffe2/aten/src/ATen/core/ivalue.h:516:18: error: missing 'typename' prior to
  dependent type name 'enable_if_ivalue_compatible<Args...>::type'
xplat/caffe2/aten/src/ATen/core/ivalue_inl.h:1959:16: error: missing 'typename' prior to
  dependent type name 'IValue::enable_if_ivalue_compatible<Args...>::type'
3 errors generated.
```

That diff factored the tuple-constructor SFINAE into a new alias member:

```
template <typename... Ts>
using enable_if_ivalue_compatible = std::enable_if<...>;   // enable_if, not enable_if_t
```

and uses it as `typename = enable_if_ivalue_compatible<Args...>::type`. Since
the alias expands to `std::enable_if<...>`, `::type` is a dependent name and
needs the `typename` disambiguator.

C++20's P0634R3 ("Down with typename!") makes `typename` optional in exactly
this position -- the default argument of a type template parameter -- which is
why this compiled everywhere the change was tested. This is not a language
version difference: both fbcode and arvr build caffe2 at `-std=gnu++20`. It is
a compiler version difference. fbcode uses clang-21, while `ATen_lib_ovrsource`
under `arvr/mode/platform010/*` pins clang-15 (see the
`x86_64-clang-dev-platform010` platform in
`arvr/tools/build_defs/config/platform/linux/generated.bzl`), and clang did not
implement P0634R3 until 16.

Add the `typename` disambiguator at the three use sites. It is well formed in
every standard from C++11 on, so it is also accepted by the newer compilers
that already build the current form.

The SFINAE predicate itself is left alone. Rewriting
`!disjunction_v<is_lvalue_reference<Args>..., negation<is_constructible<IValue, Args>>...>`
as `conjunction<negation<is_lvalue_reference<Ts>>..., is_constructible<IValue, Ts>...>`
is a correct De Morgan transform and preserves the short-circuit ordering that
keeps `is_constructible<IValue, T>` from being instantiated on reference types.

`xplat/caffe2` is updated to keep it in sync with `fbcode/caffe2`.

This should also go upstream to #194977, since OSS CI will hit
the same error on any clang-15 build.

Differential Revision: [D118389865](https://our.internmc.facebook.com/intern/diff/D118389865/)
Pull Request resolved: #195671
Approved by: https://github.com/pytorchgreenlight, https://github.com/Skylion007
Sanskaaar1 pushed a commit to Sanskaaar1/pytorch that referenced this pull request Sep 8, 2026
)

Forward fix for D117882908 (pytorch#194977), which broke every
arvr/ovrsource build that depends on `xplat/caffe2:ATen_lib_ovrsource`:

```
xplat/caffe2/aten/src/ATen/core/ivalue.h:516:18: error: missing 'typename' prior to
  dependent type name 'enable_if_ivalue_compatible<Args...>::type'
xplat/caffe2/aten/src/ATen/core/ivalue_inl.h:1959:16: error: missing 'typename' prior to
  dependent type name 'IValue::enable_if_ivalue_compatible<Args...>::type'
3 errors generated.
```

That diff factored the tuple-constructor SFINAE into a new alias member:

```
template <typename... Ts>
using enable_if_ivalue_compatible = std::enable_if<...>;   // enable_if, not enable_if_t
```

and uses it as `typename = enable_if_ivalue_compatible<Args...>::type`. Since
the alias expands to `std::enable_if<...>`, `::type` is a dependent name and
needs the `typename` disambiguator.

C++20's P0634R3 ("Down with typename!") makes `typename` optional in exactly
this position -- the default argument of a type template parameter -- which is
why this compiled everywhere the change was tested. This is not a language
version difference: both fbcode and arvr build caffe2 at `-std=gnu++20`. It is
a compiler version difference. fbcode uses clang-21, while `ATen_lib_ovrsource`
under `arvr/mode/platform010/*` pins clang-15 (see the
`x86_64-clang-dev-platform010` platform in
`arvr/tools/build_defs/config/platform/linux/generated.bzl`), and clang did not
implement P0634R3 until 16.

Add the `typename` disambiguator at the three use sites. It is well formed in
every standard from C++11 on, so it is also accepted by the newer compilers
that already build the current form.

The SFINAE predicate itself is left alone. Rewriting
`!disjunction_v<is_lvalue_reference<Args>..., negation<is_constructible<IValue, Args>>...>`
as `conjunction<negation<is_lvalue_reference<Ts>>..., is_constructible<IValue, Ts>...>`
is a correct De Morgan transform and preserves the short-circuit ordering that
keeps `is_constructible<IValue, T>` from being instantiated on reference types.

`xplat/caffe2` is updated to keep it in sync with `fbcode/caffe2`.

This should also go upstream to pytorch#194977, since OSS CI will hit
the same error on any clang-15 build.

Differential Revision: [D118389865](https://our.internmc.facebook.com/intern/diff/D118389865/)
Pull Request resolved: pytorch#195671
Approved by: https://github.com/pytorchgreenlight, https://github.com/Skylion007
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mps Run MPS tests (subset of trunk) ciflow/trunk Trigger trunk jobs on your pull request Merged open source topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants