[PATCH] D130867: WORK-IN-PROGRESS [clang] adds builtin `std::invoke` and `std::invoke_r`

Christopher Di Bella via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 31 22:06:35 PDT 2022


cjdb created this revision.
cjdb added reviewers: aaron.ballman, rsmith.
Herald added a reviewer: NoQ.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`std::invoke` and `std::invoke_r` are fairly easy to implement as
library functions using overloads, but this is an expensive
implementation. They can also be implemented using `if constexpr`, but
this requires duplicating the logic for the _noexcept-specifier_, which
makes the implementation brittle.

This commit lifts these functions into the compiler to avoid these
problems. It also adds the associated type-traits:

- `__invoke_result`
- `__is_invocable`
- `__is_invocable_r`
- `__is_nothrow_invocable`
- `__is_nothrow_invocable_r`

-------

THIS IS A WORK IS PROGRESS

The following things need to be done:

- add all of the type traits
- fix up diagnostics
- benchmark against the aforementioned library implementaitons

I'm putting this up for an early review as I'd like to see if this is
headed down the right path, if there's anything I'm missing from the
function's side of things, and because I'd appreciate input on the
diagnostics (while I'm happy with the diags themselves, I'm less than
happy about how I'm handling them, and am wondering if the process
should be more invasive).

On diagnostics: it might be undesirable for the error to say the
expression, because expressions might be long. In this case, it would be
replaced with the entity kind (e.g. "can't invoke function", etc.), but
I feel this loses a lot of the diagnostic's expressability, and I'm
unhappy about that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130867

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/builtin-std-invoke.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130867.448917.patch
Type: text/x-patch
Size: 43372 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220801/2722cf77/attachment-0001.bin>


More information about the cfe-commits mailing list