My Reference Safety System (DIP???)

via Digitalmars-d digitalmars-d at puremagic.com
Fri Feb 27 15:18:23 PST 2015


I think I have an inference algorithm that works. It can infer 
the required scope levels for local variables given the 
constraints of function parameters, and it can even infer the 
annotations for the parameters (in template functions). It can 
also cope with local variables that are explicitly declared as 
`scope`, though these are mostly unnecessary.

Interestingly, the rvalue/lvalue problem deadalnix found is only 
relevant during assignment checking, but not during inference. 
That's because we are free to widen the scope of variables that 
are to be inferred as needed.

It's based on two principles:

* We start with the minimum possible scope a variable may have, 
which is empty for local variables, and its own lifetime for 
parameters.
* When a scoped value is stored somewhere, it is then reachable 
through the destination. Therefore, assuming the source's scope 
is fixed, the destination's scope must be widened to accommodate 
the source's scope.
* From the opposite viewpoint, a value that is to be stored 
somewhere must have at least the destination's scope. Therefore, 
assuming the destination's scope is fixed, the source's scope 
needs to be widened accordingly.

I haven't formalized it yet, but I posted a very detailed 
step-by-step demonstration on my wiki talk page (nicer to read 
because it has syntax highlighting):
http://wiki.dlang.org/User_talk:Schuetzm/scope2

I will also add examples how return and static annotations are 
handled.


More information about the Digitalmars-d mailing list