Escape analysis (full scope analysis proposal)
Michel Fortin
michel.fortin at michelf.com
Sun Nov 2 18:47:50 PST 2008
On 2008-11-02 19:04:37 -0500, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> said:
>> Personally, I'd have liked to have a language where you can be
>> completely scope safe, where you could document interfaces so they know
>> the scope they're evolving in. This concept of something in between is
>> a nice attempt at a compromize, but I find it somewhat limitting.
>
> I agree. Again, something like this was on the table:
>
> void wyda(scope T* a, scope U* b)
> if (scope(a) <= scope(b)
> {
> a.field = b;
> }
>
> I think it's not hard to appreciate the toll this kind of user-written
> function summary exacts on the user of the language.
First, I think it's a pretty good idea to have this. Second, I think
it's possible to improve the syntax; there should be a way to not have
to worry about the scope rules when you don't want them to bother you.
Here's something we could do about it...
Add a special keyword (lets call it "autoscope" for now) that you can
put at the start of the function making the compiler create
automatically the less restrictive scope constrains from the function
body and apply them to the signature. The restriction is that the
source must be available for the compiler to see and there must not be
any override based solely on scope constrains.
So basically, you could write:
autoscope void wyda(T* a, U* b)
{
a.field = b;
}
and the compiler would make the signature like your example above.
And it'd be a good idea if the compiler could generate correct scoping
constrains (without using "autoscope") in an eventual generated .di
file to make things faster and not reliant on the code itself.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list