Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
May 22, 2014 What's the issue(s) with scope vars? | ||||
---|---|---|---|---|
| ||||
I know there's been a lot of chatter about scope vars needing work, what exactly is the deal with that? Isn't there a lib version of scoped? Are there current problems with that? |
May 22, 2014 Re: What's the issue(s) with scope vars? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On Thursday, 22 May 2014 at 19:08:53 UTC, Nick Sabalausky wrote: > I know there's been a lot of chatter about scope vars needing work, what exactly is the deal with that? Isn't there a lib version of scoped? Are there current problems with that? Example nastiness of scoped!(): https://issues.dlang.org/show_bug.cgi?id=10921 |
May 22, 2014 Re: What's the issue(s) with scope vars? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On Thursday, 22 May 2014 at 19:08:53 UTC, Nick Sabalausky wrote:
> I know there's been a lot of chatter about scope vars needing work, what exactly is the deal with that? Isn't there a lib version of scoped? Are there current problems with that?
You speak about scope storage class (aka scope classes as in D1). It has been deprecated and replaced by Phobos scoped.
Recent chatter is about scope type qualifier which is supposed to prohibit escaping references to variable making it only available in current and nested scopes. There are many possible applications for that - safe casting away for shared, safe rvalue references, efficient reference counting and so on. It is currently present in the language but has no actual implementation, being effectively a NO-OP.
|
May 22, 2014 Re: What's the issue(s) with scope vars? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | On 5/22/2014 3:31 PM, Dicebot wrote:
> On Thursday, 22 May 2014 at 19:08:53 UTC, Nick Sabalausky wrote:
>> I know there's been a lot of chatter about scope vars needing work,
>> what exactly is the deal with that? Isn't there a lib version of
>> scoped? Are there current problems with that?
>
> You speak about scope storage class (aka scope classes as in D1). It has
> been deprecated and replaced by Phobos scoped.
>
> Recent chatter is about scope type qualifier which is supposed to
> prohibit escaping references to variable making it only available in
> current and nested scopes. There are many possible applications for that
> - safe casting away for shared, safe rvalue references, efficient
> reference counting and so on. It is currently present in the language
> but has no actual implementation, being effectively a NO-OP.
Is phobos scoped at least good enough for real-world use in the meantime?
Also, is this unimplemented scope type qualifier you speak of going to basically replace phobos scoped?
|
May 22, 2014 Re: What's the issue(s) with scope vars? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On Thursday, 22 May 2014 at 19:36:06 UTC, Nick Sabalausky wrote:
> On 5/22/2014 3:31 PM, Dicebot wrote:
>> On Thursday, 22 May 2014 at 19:08:53 UTC, Nick Sabalausky wrote:
>>> I know there's been a lot of chatter about scope vars needing work,
>>> what exactly is the deal with that? Isn't there a lib version of
>>> scoped? Are there current problems with that?
>>
>> You speak about scope storage class (aka scope classes as in D1). It has
>> been deprecated and replaced by Phobos scoped.
>>
>> Recent chatter is about scope type qualifier which is supposed to
>> prohibit escaping references to variable making it only available in
>> current and nested scopes. There are many possible applications for that
>> - safe casting away for shared, safe rvalue references, efficient
>> reference counting and so on. It is currently present in the language
>> but has no actual implementation, being effectively a NO-OP.
>
> Is phobos scoped at least good enough for real-world use in the meantime?
>
> Also, is this unimplemented scope type qualifier you speak of going to basically replace phobos scoped?
First question - don't now for sure. It worked for me few times I have used it but there several bug reports in bugzilla with some nastiness.
Second question - that is something yet to investigate. Natural relation between those is that value captured by `scoped` should be qualified as `scope` to be reliably memory safe. Does that also mean that you can skip `scoped` altogether and release all scope variables at the end of scope automatically? Something yet to investigate.
|
May 22, 2014 Re: What's the issue(s) with scope vars? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | On 5/22/2014 3:39 PM, Dicebot wrote:
>
> Second question - that is something yet to investigate. Natural relation
> between those is that value captured by `scoped` should be qualified as
> `scope` to be reliably memory safe. Does that also mean that you can
> skip `scoped` altogether and release all scope variables at the end of
> scope automatically? Something yet to investigate.
Ooh, looking at the docs for phobos scoped now, I see it's mainly just for emplacing a class on the stack, and doesn't prevent escaping at all. I'm understanding it better now.
I had thought there was something in phobos that worked for structs, preventing escaping by disabling postblit and then guaranteeing destruction at the end of the defining scope - or something vaguely like that anyway. But I think I was confusing several different things such as scoped, emplace and RefCOunted.
|
May 22, 2014 Re: What's the issue(s) with scope vars? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | On Thu, 22 May 2014 19:39:58 +0000
Dicebot via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> On Thursday, 22 May 2014 at 19:36:06 UTC, Nick Sabalausky wrote:
> > On 5/22/2014 3:31 PM, Dicebot wrote:
> >> On Thursday, 22 May 2014 at 19:08:53 UTC, Nick Sabalausky wrote:
> >>> I know there's been a lot of chatter about scope vars needing
> >>> work,
> >>> what exactly is the deal with that? Isn't there a lib version
> >>> of
> >>> scoped? Are there current problems with that?
> >>
> >> You speak about scope storage class (aka scope classes as in
> >> D1). It has
> >> been deprecated and replaced by Phobos scoped.
> >>
> >> Recent chatter is about scope type qualifier which is supposed
> >> to
> >> prohibit escaping references to variable making it only
> >> available in
> >> current and nested scopes. There are many possible
> >> applications for that
> >> - safe casting away for shared, safe rvalue references,
> >> efficient
> >> reference counting and so on. It is currently present in the
> >> language
> >> but has no actual implementation, being effectively a NO-OP.
> >
> > Is phobos scoped at least good enough for real-world use in the meantime?
> >
> > Also, is this unimplemented scope type qualifier you speak of going to basically replace phobos scoped?
>
> First question - don't now for sure. It worked for me few times I have used it but there several bug reports in bugzilla with some nastiness.
>
> Second question - that is something yet to investigate. Natural relation between those is that value captured by `scoped` should be qualified as `scope` to be reliably memory safe. Does that also mean that you can skip `scoped` altogether and release all scope variables at the end of scope automatically? Something yet to investigate.
AFAIK, scope is only implemented for delegates (and I'm not even sure that that fully works). For all other types, it does nothing (which is part of why using in makes no sense). So, on the whole, scope is currently ill-defined and mostly unimplemented.
- Jonathan M Davis
- Jonathan M Davis
|
Copyright © 1999-2021 by the D Language Foundation