DIP1000: Scoped Pointers (Discussion)

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 22 11:03:40 PDT 2016

On Mon, Aug 22, 2016 at 06:02:20PM +0000, Meta via Digitalmars-d wrote:
> On Monday, 22 August 2016 at 17:22:28 UTC, H. S. Teoh wrote:
> > I think it should be possible even with recursion, at least if there
> > is a non-recursive branch in the function(s). Of course, it may not
> > necessarily be *feasible* to implement the required analysis in the
> > compiler. But maybe for the simplest cases, e.g.:
> > 
> > 	auto func(...) {
> > 		if (condition)
> > 			return finalResult;
> > 		else
> > 			return func(...);
> > 	}
> > 
> > 
> > T
> I must be missing something here, but isn't it trivial to infer
> attributes for a recursive function? By definition you either have a
> call to the current function, which is idempotent in regards to
> attributes, or some non-recursive work that is done, in which case you
> follow the normal inference algorithm. I know this is exactly the
> basic case that you have shown, but even for more complex cases such
> as mutually-recursive functions I can't see this being unmanageable.

Yeah, this can probably be extended to more complex cases. But you may
start running into limitations with the current compiler design once the
recursion involves multiple functions, since AFAIK the compiler
separately compiles each function, so the inference may not be able to
resolve two mutually-recursive functions at the same time.  But maybe
there's a way around it that I haven't thought of.

In any case, making inference work with recursive functions is an
important step in making inroads to maximizing attribute inference
throughout the language.


Lottery: tax on the stupid. -- Slashdotter

More information about the Digitalmars-d mailing list