RFR: 8264707: HotSpot Style Guide should permit use of lambda

Kim Barrett kbarrett at openjdk.java.net
Sat Aug 21 07:10:29 UTC 2021


On Fri, 20 Aug 2021 17:29:12 GMT, Xin Liu <xliu at openjdk.org> wrote:

>> Please review this proposal to permit the use of lambda expressions in
>> HotSpot code, with some restrictions and suggestions for good usage within
>> HotSpot code.  Lambda expressions were added in C++11, and provide a more
>> expressive syntax for local functions, with a number of use-cases where they
>> can improve readability by eliminating a lot of uninteresting boilerplate.
>> 
>> Some example uses are included, but are not part of the proposed change.
>> They will be removed from the PR before it is pushed.  (In particular, the
>> ScopeGuard utility uses move semantics, the use of which hasn't been
>> approved or even discussed.)  They are given to show some of the benefits
>> that might accrue from permitting the use of lambdas. In particular, they
>> highlight some of the code reduction that is possible. Some of these code
>> changes might be proposed in the future, using the normal PR process.
>> 
>> This is a modification of the Style Guide, so rough consensus among the
>> HotSpot Group members is required to make this change.  Only Group members
>> should vote for approval (via the github PR), though reasoned objections or
>> comments from anyone will be considered.  A decision on this proposal will
>> not be made before Wednesday 1-Sep-2021 at 12h00 UTC.
>> 
>> Since we're piggybacking on github PRs here, please use the PR review
>> process to approve (click on Review Changes > Approve), rather than sending
>> a "vote: yes" email reply that would be normal for a CFV.
>
> doc/hotspot-style.md line 708:
> 
>> 706: * Local function objects, including lambda expressions, may be used.
>> 707: * Lambda expressions must only be used as a downward value.
>> 708: * Prefer `[&]` as the capture list of a lambda expression.
> 
> hi, @kimbarrett , 
> Why does it sound like a suggestion instead of a mandate? 
> You explain why we should use [&] and all your examples are implicit capture reference.

That's intentional. Capture lists were by far the single most contentious part
of the Oracle-internal discussions about lambda usage. Making this a
suggestion rather than a mandate, along with the rationale, leaves open the
possibility of using other forms *with good reason*, and preferably after a
period of folks getting used to the "usual" form. There are HotSpot developers
who aren't familiar with lambda-like constructs, or are not comfortable with
the introduction of yet more non-alphanumeric syntax that resembles line
noise; limiting the capture list features being used helps them. On the other
hand, there have been proponents of nearly every capture list feature for some
use case or another.

-------------

PR: https://git.openjdk.java.net/jdk/pull/5144


More information about the hotspot-dev mailing list