Discussion:
@safe pure nothrow compiler inference
Atila Neves via Digitalmars-d
2014-09-29 14:32:13 UTC
Permalink
So somehow I missed that for template functions the attributes
can be inferred. From what I can tell it has to do with having
the body available. But when not using .di files, why can't it be
done for regular functions?

Atila
Daniel N via Digitalmars-d
2014-09-29 14:40:33 UTC
Permalink
Post by Atila Neves via Digitalmars-d
So somehow I missed that for template functions the attributes
can be inferred. From what I can tell it has to do with having
the body available. But when not using .di files, why can't it
be done for regular functions?
Atila
It can be done, Walter wanted to do it, but there was large
resistance, mainly because library APIs would become unstable,
possibly changing between every release.

IMHO it would be safe to use inference for private functions...

Daniel N
Walter Bright via Digitalmars-d
2014-10-01 08:50:29 UTC
Permalink
So somehow I missed that for template functions the attributes can be
inferred. From what I can tell it has to do with having the body
available. But when not using .di files, why can't it be done for
regular functions?
Atila
It can be done, Walter wanted to do it, but there was large resistance,
mainly because library APIs would become unstable, possibly changing
between every release.
I wanted to do it for "auto" returning functions, since they require a
function body.
IMHO it would be safe to use inference for private functions...
Not a bad idea. Please file as an enhancement request.

The more attribute inference we can do, the better.
Atila Neves via Digitalmars-d
2014-10-01 13:59:26 UTC
Permalink
Post by Walter Bright via Digitalmars-d
I wanted to do it for "auto" returning functions, since they
require a function body.
Is there any good reason to _not_ do it for auto return functions?

Atila
Kagamin via Digitalmars-d
2014-10-01 15:12:40 UTC
Permalink
Post by Daniel N via Digitalmars-d
It can be done, Walter wanted to do it, but there was large
resistance, mainly because library APIs would become unstable,
possibly changing between every release.
Huh? Templates are part of library API too, see std.algorithm. So
what's the difference if the API consists of templated or
non-templated functions? Why for one part of API it's ok to
change with every release and for the other not ok?
monarch_dodra via Digitalmars-d
2014-10-01 19:31:40 UTC
Permalink
Post by Kagamin via Digitalmars-d
Post by Daniel N via Digitalmars-d
It can be done, Walter wanted to do it, but there was large
resistance, mainly because library APIs would become unstable,
possibly changing between every release.
Huh? Templates are part of library API too, see std.algorithm.
So what's the difference if the API consists of templated or
non-templated functions? Why for one part of API it's ok to
change with every release and for the other not ok?
It's not that "it's OK for templates", it's that you *must* have
inference.

This was not an argument against having inference for normal
functions.

Steven Schveighoffer via Digitalmars-d
2014-09-29 15:00:48 UTC
Permalink
So somehow I missed that for template functions the attributes can be
inferred. From what I can tell it has to do with having the body
available. But when not using .di files, why can't it be done for
regular functions?
There was a push to do it for ctors, and require them to be available. I
think this was actually discussed by Walter at one conference talk
(maybe you missed it).

I think we should have an @infer property that would infer the
properties and require the function body in .di (compiler would output
it for .di generation also).

For various reasons, this all fell through.

-Steve
Loading...