Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for function references (free and static member) in bind_back #605

Merged
merged 3 commits into from
Apr 12, 2024

Conversation

denizevrenci
Copy link
Contributor

The following program does not compile: https://godbolt.org/z/WfhEc51dY But if we replace the function reference with a lambda, it does: https://godbolt.org/z/jrhTY4nse Constructing a std::tuple with a function type fails but function pointers are allowed. We instantiate _result with std::decay_t... which maps function references to function pointers and then the corresponding std::tuple instantiation does not fail to compile. The problem with the existing code is that, in order to instantiate std::tuple<std::decay_t...>, we first constructed a std::tuple and passed it over. If instead we construct a std::tuple<std::decay_t...> with the function arguments, they will be converted to function pointers and the std::tuple instantiation will compile.

@facebook-github-bot
Copy link

Hi @denizevrenci!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 11, 2024
Copy link
Contributor

@ispeters ispeters left a comment

Choose a reason for hiding this comment

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

A couple of nits regarding the tests, but I think we should chat about the new callable specialization.

test/let_done_test.cpp Outdated Show resolved Hide resolved
test/let_done_test.cpp Outdated Show resolved Hide resolved
test/let_done_test.cpp Outdated Show resolved Hide resolved
test/let_done_test.cpp Outdated Show resolved Hide resolved
include/unifex/detail/concept_macros.hpp Outdated Show resolved Hide resolved
@denizevrenci denizevrenci force-pushed the function_ref branch 2 times, most recently from cecc1ec to 628964c Compare April 12, 2024 00:54
Copy link
Contributor

@ispeters ispeters left a comment

Choose a reason for hiding this comment

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

Looking good!

include/unifex/bind_back.hpp Outdated Show resolved Hide resolved
include/unifex/bind_back.hpp Outdated Show resolved Hide resolved
include/unifex/bind_back.hpp Outdated Show resolved Hide resolved
include/unifex/bind_back.hpp Outdated Show resolved Hide resolved
include/unifex/continuations.hpp Outdated Show resolved Hide resolved
include/unifex/v1/debug_async_scope.hpp Outdated Show resolved Hide resolved
include/unifex/v1/debug_async_scope.hpp Outdated Show resolved Hide resolved
include/unifex/v1/debug_async_scope.hpp Outdated Show resolved Hide resolved
include/unifex/with_query_value.hpp Outdated Show resolved Hide resolved
test/any_object_test.cpp Outdated Show resolved Hide resolved
These are drop in replacements of is_callable variants and we can
replace our concept shim with them as well.
These assertions are usually followed by other expressions
assuming that they are passing and in case a change breaks them
they potentially trigger undefined behavior with `EXCEPT_TRUE`.
…back

The following program does not compile: https://godbolt.org/z/WfhEc51dY
But if we replace the function reference with a lambda, it does: https://godbolt.org/z/jrhTY4nse
Constructing a std::tuple with a function type fails but function pointers are allowed.
We instantiate _result with std::decay_t<ArgN>... which maps function references to function pointers
and then the corresponding std::tuple instantiation does not fail to compile. The problem with the
existing code is that, in order to instantiate std::tuple<std::decay_t<ArgN>...>, we first constructed a
std::tuple<ArgN> and passed it over. If instead we construct a std::tuple<std::decay_t<ArgN>...>
with the function arguments, they will be converted to function pointers and the std::tuple instantiation
will compile.
Copy link
Contributor

@ispeters ispeters left a comment

Choose a reason for hiding this comment

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

LGTM

@ispeters ispeters merged commit 1b66205 into facebookexperimental:main Apr 12, 2024
47 checks passed
@denizevrenci denizevrenci deleted the function_ref branch April 12, 2024 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants