[Issue 23664] New: Infer `const` for lambdas/closures
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Feb 2 14:20:45 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23664
Issue ID: 23664
Summary: Infer `const` for lambdas/closures
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: qs.il.paperinik at gmail.com
Attributes (`@safe`, `pure`, etc.) are inferred for lambdas, but a delegate can
also specify a type constructor (or a combination such as `inout const`).
Because the implementation of the lambda is always known, the compiler can
figure out if the delegate is in fact
* `immutable`, i.e. all data it accesses through its context (if any) is
`immutable`.
* `const`, i.e. all the accessed data in its context (if any) is not changed by
the delegate (think of: the delegate only calls free functions and `const`
member functions on things it accesses).
Note that type constructors in this case are purely additional information, the
same way `@safe`, `pure`, `nothrow`, or `@nogc`. This means that forgetting
them won’t make using the delegate invalid; only the context it’s used in might
require them. (This requires that the implicit conversion of `immutable` to
`const` and `immutable`/`const` to mutable for delegate context type
constructors is implemented.
--
More information about the Digitalmars-d-bugs
mailing list