digitalmars.D.learn - Auto attributes for functions
- uri (13/13) Aug 19 2014 Hi all,
- Meta (11/24) Aug 19 2014 Only if they're template functions.
- Jonathan M Davis via Digitalmars-d-learn (13/24) Aug 20 2014 Currently, just templated functions get their attributes inferred. The b...
- ed (4/43) Aug 20 2014 Thanks guys for the info.
Hi all, Bit new to D so this might be a very naive question... Can the compiler auto infer function attributes? I am often adding as many attributes as possible and use the compiler to show me where they're not applicable and take them away. It would be great if this could be achieved like so: auto function() auto {} instead of manually writing: auto function() pure safe nothrow nogc const {} cheers, uri
Aug 19 2014
On Wednesday, 20 August 2014 at 01:38:53 UTC, uri wrote:Hi all, Bit new to D so this might be a very naive question... Can the compiler auto infer function attributes? I am often adding as many attributes as possible and use the compiler to show me where they're not applicable and take them away. It would be great if this could be achieved like so: auto function() auto {} instead of manually writing: auto function() pure safe nothrow nogc const {} cheers, uriOnly if they're template functions. //inferred as safe pure nothrow nogc auto fun()() {} //Compiler treats this is system impure throwing gc //(if the latter three existed) auto fun() {} I think Andrei suggested in the past that functions with a return type of "auto" have attributes inferred for them as well, but some people were against it, and nobody's tried implementing it yet.
Aug 19 2014
On Wed, 20 Aug 2014 01:38:52 +0000 uri via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:Hi all, Bit new to D so this might be a very naive question... Can the compiler auto infer function attributes? I am often adding as many attributes as possible and use the compiler to show me where they're not applicable and take them away. It would be great if this could be achieved like so: auto function() auto {} instead of manually writing: auto function() pure safe nothrow nogc const {}Currently, just templated functions get their attributes inferred. The biggest problem with inferring them for all functions is that you can declare a function without defining it in the same place (e.g. if you're using .di files), in which case the compiler has no function body to use for attribute inferrence. There have been discussions on ways to reasonably infer attributes under more circumstances, but nothing has come of them yet. However, I'd expect that there will be at least some improvements to the situation at some point given that there is a general consensus that while the attributes are quite useful, it's also rather annoying to have to keep typing them all. - Jonathan M Davis
Aug 20 2014
On Wednesday, 20 August 2014 at 09:13:15 UTC, Jonathan M Davis via Digitalmars-d-learn wrote:On Wed, 20 Aug 2014 01:38:52 +0000 uri via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:Thanks guys for the info. /uriHi all, Bit new to D so this might be a very naive question... Can the compiler auto infer function attributes? I am often adding as many attributes as possible and use the compiler to show me where they're not applicable and take them away. It would be great if this could be achieved like so: auto function() auto {} instead of manually writing: auto function() pure safe nothrow nogc const {}Currently, just templated functions get their attributes inferred. The biggest problem with inferring them for all functions is that you can declare a function without defining it in the same place (e.g. if you're using .di files), in which case the compiler has no function body to use for attribute inferrence. There have been discussions on ways to reasonably infer attributes under more circumstances, but nothing has come of them yet. However, I'd expect that there will be at least some improvements to the situation at some point given that there is a general consensus that while the attributes are quite useful, it's also rather annoying to have to keep typing them all. - Jonathan M Davis
Aug 20 2014