RFC: scope and borrowing

Ivan Timokhin via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 11 09:32:52 PDT 2014


I am in no way a language guru, but here are a few things that bother me 
in your proposal. Thought I'd share.

1. AFAIK, all current D type modifiers can be safely removed from the 
topmost level (i.e. it is OK to assign immutable(int[]) to 
immutable(int)[]), because they currently apply to particular variable, 
so there's no good reason to impose same restrictions on its copy. 
Situation seems different with scope: it is absolutely not safe to cast 
away and it applies to a *value*, not a variable holding it.

This is not only inconsistent, but may also cause trouble with 
interaction with existing features. For example, what should be 
std.traits.Unqual!(scope(int*)) ?

2. Consider findSubstring from your examples. What should be 
typeof(findSubstring("", ""))? Is the following code legal?

	scope(string) a = ..., b = ...;
	...
	typeof(findSubstring("", "")) c = findSubstring(a, b);

This is a bit troublesome, because this is how things like 
std.range.ElementType work currently, so they may break. For example,
what would be ElementType!ByLineImpl (from the "scope(const...)" section)?

This troubles me the most, because currently return type of a function 
may depend only on types of its arguments, and there is a lot of 
templated code written in that assumption. With the current proposal it 
ALL could break. Maybe there's no way around it if we want a solid 
lifetime management system, but I think this is definitely a problem to 
be aware of.

3. I believe it was mentioned before, but shouldn't scope propagate 
*outwards*? This would not only make perfect sense, since the aggregate 
obviously "holds the reference" just as well as its member does, it 
would also make various range-wrappers and alike automatically 
scope-aware, in that the wrapper would automatically become scoped if 
the wrapped range is scoped.

11.09.2014 15:58, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm at gmx.net>" пишет:
> PING
>
> Now that there are again several GC related topics being discussed, I
> thought I'd bump this thread.
>
> Would be nice if Walter and/or Andrei could have a look and share there
> opinions. Is this something worth pursuing further? Are there
> fundamental objections against it?
>
> On Sunday, 24 August 2014 at 13:14:45 UTC, Marc Schütz wrote:
>> In the "Opportunities for D" thread, Walter again mentioned the topics
>> ref counting, GC, uniqueness, and borrowing, from which a lively
>> discussion developed [1]. I took this thread as an opportunity to
>> write down some ideas about these topics. The result is a rather
>> extensive proposal for the implementation of borrowing, and its
>> implementations:
>>
>> http://wiki.dlang.org/User:Schuetzm/scope
>>
>> This is not a real DIP, but before I put more work into formalizing
>> it, I'd like to hear some thoughts from the languages gurus here:
>>
>> * Is this the general direction we want to go? Is it acceptable in
>> general?
>> * Is the proposal internally consistent?
>> * How big would the effort to implement it be? (I suspect it's a large
>> amount of work, but relatively straightforward.)
>>
>> [1] http://forum.dlang.org/thread/lphnen$1ml7$1@digitalmars.com
>



More information about the Digitalmars-d mailing list