Skip to content

Conversation

RobertLeahy
Copy link
Contributor

The get_env implementation for stdexec::write_env is supplied via a lambda. Prior to this commit that lambda relied on automatic return type deduction. When a function relies on automatic return type deduction the compiler must evaluate the body thereof to determine the type returned thereby. A consequence of the aforegoing formulation is that if any statement in the body of the lambda directly or transitively relied on the completeness of an incomplete type compilation would fail.

The above might seem normal and non-problematic until one considers that it is fairly normal in C++ code to compute (and rely upon) types and other properties of functions long before any bona fide evaluation of that function occurs. This motivates the distinction between evaluated and unevaluated contexts. However as a consequence of the preceding paragraph the previous implementation of get_env meant that when code relied upon the return type thereof in an unevaluated context the context became an evaluated context in the body of get_env (and transitively through all statements therein).

The newly-added unit test highlights this. With the previous implementation of get_env (which uses automatic return type deduction) compilation fails. With the new implementation of get_env (which provides an explicit return type) compilation succeeds.

The get_env implementation for stdexec::write_env is supplied via a
lambda. Prior to this commit that lambda relied on automatic return type
deduction. When a function relies on automatic return type deduction the
compiler must evaluate the body thereof to determine the type returned
thereby. A consequence of the aforegoing formulation is that if any
statement in the body of the lambda directly or transitively relied on
the completeness of an incomplete type compilation would fail.

The above might seem normal and non-problematic until one considers that
it is fairly normal in C++ code to compute (and rely upon) types and
other properties of functions long before any bona fide evaluation of
that function occurs. This motivates the distinction between evaluated
and unevaluated contexts. However as a consequence of the preceding
paragraph the previous implementation of get_env meant that when code
relied upon the return type thereof in an unevaluated context the
context became an evaluated context in the body of get_env (and
transitively through all statements therein).

The newly-added unit test highlights this. With the previous
implementation of get_env (which uses automatic return type deduction)
compilation fails. With the new implementation of get_env (which
provides an explicit return type) compilation succeeds.
Copy link

copy-pr-bot bot commented Sep 27, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@RobertLeahy
Copy link
Contributor Author

I noticed on further investigation that this change disagrees with the wording.

Copy link
Collaborator

@ericniebler ericniebler left a comment

Choose a reason for hiding this comment

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

thanks! i guess we should file a LWG issue.

@ericniebler
Copy link
Collaborator

/ok to test 6613b75

@ericniebler ericniebler merged commit 6380044 into NVIDIA:main Sep 27, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants