www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dual-context deprecation

reply jmh530 <john.michael.hall gmail.com> writes:
The code below (simplified from my actual problem) generates a 
warning that member function b "requires a dual-context, which is 
deprecated".

However when I look at the list of deprecated features [1], I'm 
not seeing which one this is referring to. Is it a valid 
deprecation?

I could only find this [2] reference to dual-contexts, which 
suggests that the problem relates to passing aliases into member 
functions. Moving it to a member function fixes the problem. 
Alternately, I could make the alias part of Foo's type. My use 
case it is just a little easier structured like this, but I get 
that there are workarounds.

My bigger question is about why it isn't listed more than 
anything. I.e., should I file something in bugzilla.

```d
struct Foo
{
     double a;

     this(double x)
     {
         this.a = x;
     }

     double b(alias inverse)()
     {
         return inverse(a);
     }
}

void main()
{
     auto foo = Foo(2.0);
     auto x = foo.b!(a => (10.0 ^^ a))();
}
```

[1] https://dlang.org/deprecate.html
[2] 
https://forum.dlang.org/thread/mkeumwltwiimkrelgqrr forum.dlang.org
May 17 2021
next sibling parent reply Paul Backus <snarwin gmail.com> writes:
On Monday, 17 May 2021 at 13:47:28 UTC, jmh530 wrote:
 The code below (simplified from my actual problem) generates a 
 warning that member function b "requires a dual-context, which 
 is deprecated".

 However when I look at the list of deprecated features [1], I'm 
 not seeing which one this is referring to. Is it a valid 
 deprecation?
See this issue for context: https://issues.dlang.org/show_bug.cgi?id=5710
May 17 2021
parent jmh530 <john.michael.hall gmail.com> writes:
On Monday, 17 May 2021 at 13:51:32 UTC, Paul Backus wrote:
 [snip]

 See this issue for context:

 https://issues.dlang.org/show_bug.cgi?id=5710
Thanks. Lots of details there that I don't follow all of. I mentioned in the deprecation PR [1] that it was not listed in the list of deprecated features. [1] https://github.com/dlang/dmd/pull/9702
May 17 2021
prev sibling parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 5/17/21 9:47 AM, jmh530 wrote:
 The code below (simplified from my actual problem) generates a warning 
 that member function b "requires a dual-context, which is deprecated".
 
 However when I look at the list of deprecated features [1], I'm not 
 seeing which one this is referring to. Is it a valid deprecation?
 
 I could only find this [2] reference to dual-contexts, which suggests 
 that the problem relates to passing aliases into member functions. 
 Moving it to a member function fixes the problem. Alternately, I could 
 make the alias part of Foo's type. My use case it is just a little 
 easier structured like this, but I get that there are workarounds.
 
 My bigger question is about why it isn't listed more than anything. 
 I.e., should I file something in bugzilla.
 
 ```d
 struct Foo
 {
      double a;
 
      this(double x)
      {
          this.a = x;
      }
 
      double b(alias inverse)()
      {
          return inverse(a);
      }
 }
 
 void main()
 {
      auto foo = Foo(2.0);
      auto x = foo.b!(a => (10.0 ^^ a))();
 }
 ```
The feature is deprecated in its current form. The issue as I understand it (i.e. very little) is that compilers other than DMD could not use this same way to implement dual contexts, and so they could not have the feature. This means that valid code in DMD would not compile on GDC or LDC. The way forward was to deprecate the mechanism used to implement it for DMD, and at some point tackle it in a backend-agnostic way. Personally, I don't know why we can't fix it so that it's portable, but I understand so little about compilers that I've pretty much stayed out of it. The feature is very much needed. -Steve
May 17 2021
next sibling parent jmh530 <john.michael.hall gmail.com> writes:
On Monday, 17 May 2021 at 14:35:51 UTC, Steven Schveighoffer 
wrote:
 [snip]
 The feature is deprecated in its current form. The issue as I 
 understand it (i.e. very little) is that compilers other than 
 DMD could not use this same way to implement dual contexts, and 
 so they could not have the feature. This means that valid code 
 in DMD would not compile on GDC or LDC.

 The way forward was to deprecate the mechanism used to 
 implement it for DMD, and at some point tackle it in a 
 backend-agnostic way.

 Personally, I don't know why we can't fix it so that it's 
 portable, but I understand so little about compilers that I've 
 pretty much stayed out of it. The feature is very much needed.

 -Steve
That's a good summary. Thanks.
May 17 2021
prev sibling parent 12345swordy <alexanderheistermann gmail.com> writes:
On Monday, 17 May 2021 at 14:35:51 UTC, Steven Schveighoffer 
wrote:
 On 5/17/21 9:47 AM, jmh530 wrote:
 The code below (simplified from my actual problem) generates a 
 warning that member function b "requires a dual-context, which 
 is deprecated".
 
 However when I look at the list of deprecated features [1], 
 I'm not seeing which one this is referring to. Is it a valid 
 deprecation?
 
 I could only find this [2] reference to dual-contexts, which 
 suggests that the problem relates to passing aliases into 
 member functions. Moving it to a member function fixes the 
 problem. Alternately, I could make the alias part of Foo's 
 type. My use case it is just a little easier structured like 
 this, but I get that there are workarounds.
 
 My bigger question is about why it isn't listed more than 
 anything. I.e., should I file something in bugzilla.
 
 ```d
 struct Foo
 {
      double a;
 
      this(double x)
      {
          this.a = x;
      }
 
      double b(alias inverse)()
      {
          return inverse(a);
      }
 }
 
 void main()
 {
      auto foo = Foo(2.0);
      auto x = foo.b!(a => (10.0 ^^ a))();
 }
 ```
The feature is deprecated in its current form. The issue as I understand it (i.e. very little) is that compilers other than DMD could not use this same way to implement dual contexts, and so they could not have the feature. This means that valid code in DMD would not compile on GDC or LDC. The way forward was to deprecate the mechanism used to implement it for DMD, and at some point tackle it in a backend-agnostic way. Personally, I don't know why we can't fix it so that it's portable, but I understand so little about compilers that I've pretty much stayed out of it. The feature is very much needed. -Steve
The dual context that warning is referring to is vthis2, which the gdc maintainer struggle to implemented for the gdc compiler. A correct fix involves templates having their own context. -Alex
May 17 2021