Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Deprecations #697

Merged
merged 12 commits into from over 1 year ago

9 participants

Daniel Murphy Don Clugston David Nadlinger Brad Roberts Marco Leise Andrei Alexandrescu Alex Rønne Petersen Andrej Mitrovic Hara Kenji
Daniel Murphy
Collaborator

The first wave of deprecations for language features.

The following were errors, and will now be removed compeltely:

  • 'l' suffix (long)

  • .size

The following were already deprecated, and are now errors

  • Implicitly declared length variable for array indexing.

  • Local variable shadowing

  • delete aa[key]

  • Escape string literals

  • 'l' suffix (real)

  • 'I' suffix (imaginary)

  • .typeinfo

  • .offset

  • if (v; e)

And one was scheduled to be deprecated, and is now a warning:

  • .min for floating point types

Depends on druntime pull 144 and phobos pull 418

Don Clugston
Collaborator

C function pointers shouldn't be included here, I think. The original (vague) plan was to make them deprecated permanently. (OTOH C aliases of function and array type are really awful, and they interfere with template lookup, so those do need to become errors).
All of the other things on the list only exist only in D code, so they disappear quickly. But C function pointers will always keep coming in from C. Maybe we should still make it an error, but would be better not to include it in the same pull request as the less controversial stuff.

David Nadlinger
Collaborator

Still seems to break druntime, see the auto tester.

Daniel Murphy
Collaborator

Thanks, I have no idea how I missed that.

Brad Roberts
Owner

You missed another failure in the phobos unittests.. you really need to remember to run all the tests.. more so when doing this sort of almost certainly intrusive type of changes. I fixed that one for you and ran the tests for all three packages on linux/64. There's a chance there's a platform specific issue somewhere, but at least it now passes fully on at least one.

Daniel Murphy
Collaborator

Thanks, I knew about that one but hadn't gotten around to fixing it yet. It wasn't accidental, I don't run the phobos unittests when making a pull request, I just build it. My computer is not exactly top of the line and they take quite a while, so I've been relying on the autotester to show me where the bugs are - I check each of my pull requests on there to ensure they're passing. If this workflow is a problem I'll stop doing it, but it is incredibly convenient for me.

Marco Leise

IIRC you also cannot use a variable named 'length' inside [], because the compiler thinks it is the deprecated version of '$'.

Daniel Murphy
Collaborator

IIRC you also cannot use a variable named 'length' inside [], because the compiler thinks it is the deprecated version of '$'.

Huh? That's this... Once it's been an error for a while we can remove it completely, and then it will be legal code.

Daniel Murphy
Collaborator

Rebased without the C-style function pointers change.

David Nadlinger klickverbot commented on the diff July 14, 2012
src/mtype.c
... ...
@@ -2854,8 +2846,8 @@ Expression *TypeBasic::getProperty(Loc loc, Identifier *ident)
2854 2846
             case Tcomplex80:
2855 2847
             case Timaginary80:
2856 2848
             case Tfloat80:
2857  
-                                // For backwards compatibility - eventually, deprecate
2858  
-                                goto Lmin_normal;
  2849
+                warning(loc, "min property is deprecated, use min_normal instead");
2
David Nadlinger Collaborator
klickverbot added a note July 14, 2012

Just a warning?

Daniel Murphy Collaborator
yebblies added a note July 14, 2012

Language features are supposed to go through valid -> spec change -> warning -> deprecated -> error -> removed. That was the idea, anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Daniel Murphy
Collaborator

Removed the html source stuff.

Andrei Alexandrescu
Owner

I approve of these changes. One question I'd have is about if (decl; expr) stmt. The Go programming language uses it, so it seems to have some use. Should we consider keeping it?

Alex Rønne Petersen

I think I'd have to do a double take if I ever saw that in actual code. That seems very obscure to me...

Daniel Murphy
Collaborator

@andralex
if (decl; expr) stmt has been deprecated since 0.149 (over six years!), and does not provide any functionality over if (auto decl = expr) stmt.

Andrei Alexandrescu
Owner

@yebblies actually it's better because the latter syntax only works if the tested thing is nonzero. If you want to test if some number is -1 or not, the auto thing won't work. But I guess that's fine.

Andrej Mitrovic
Collaborator

@andralex can you elaborate how that example is used? if (decl; expr == -1) decl here becomes a bool. I've never used if (decl; expr) before.

Andrei Alexandrescu
Owner
if (auto printed = printf("stuff"); printed == -1)
{
    writeln("Something sux.");
}
else
{
    writeln("Printed ", printed, " characters. Something rox.");
}
Andrej Mitrovic
Collaborator

@andralex: That won't compile, lol.

Andrei Alexandrescu
Owner

ehm

Andrej Mitrovic
Collaborator

auto lets you store the result, I don't see how if(decl; exp) does the same:

    static auto f() { return -2; }
    if (asdf; f() == -2)
    {
        writeln(asdf);  // writes true, not -2
        writeln("func() returned -2");
    }

So what's the secret that makes if (decl; expr) useful?

Daniel Murphy
Collaborator

@andralex I really think we should just get rid of it. It has been deprecated so long it isn't really a part of D any more. If we want it back with the same or a different semantic meaning we should go through the normal process of discussing and approving a language feature. Does this seem reasonable?

David Nadlinger
Collaborator

@yebblies: Very reasonable, at least to me… ;)

Andrei Alexandrescu
Owner

OK. Let me look at the dependee pulls in druntime and phobos.

Andrei Alexandrescu
Owner

Oh, those were already merged and there are errors related to use of .min. Could you please fix so this can be merged. Thanks!

Daniel Murphy
Collaborator

@andralex This should do it.

Daniel Murphy
Collaborator

Rebased

Brad Roberts braddr referenced this pull request from a commit October 21, 2012
Commit has since been removed from the repository and is no longer available.
Daniel Murphy
Collaborator

@andralex @9rnsr @dawgfoto @donc @braddr @WalterBright
Could somebody please merge this while it's green?

Hara Kenji
Collaborator

LGTM. Let's merge.

Hara Kenji 9rnsr merged commit d89fa73 into from October 28, 2012
Hara Kenji 9rnsr closed this October 28, 2012
Daniel Murphy
Collaborator

Thankyou!

Daniel Murphy yebblies deleted the branch November 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  src/dsymbol.c
@@ -1266,7 +1266,7 @@ Dsymbol *ArrayScopeSymbol::search(Loc loc, Identifier *ident, int flags)
1266 1266
         Expression *ce;
1267 1267
 
1268 1268
         if (ident == Id::length)
1269  
-            deprecation("using 'length' inside [ ] is deprecated, use '$' instead");
  1269
+            ::error(loc, "using 'length' inside [ ] is deprecated, use '$' instead");
1270 1270
 
1271 1271
     L1:
1272 1272
 
21  src/e2ir.c
@@ -3726,26 +3726,7 @@ elem *DeleteExp::toElem(IRState *irs)
3726 3726
     {
3727 3727
         IndexExp *ae = (IndexExp *)(e1);
3728 3728
         tb = ae->e1->type->toBasetype();
3729  
-        if (tb->ty == Taarray)
3730  
-        {
3731  
-            TypeAArray *taa = (TypeAArray *)tb;
3732  
-            elem *ea = ae->e1->toElem(irs);
3733  
-            elem *ekey = ae->e2->toElem(irs);
3734  
-            elem *ep;
3735  
-            elem *keyti;
3736  
-
3737  
-            if (tybasic(ekey->Ety) == TYstruct || tybasic(ekey->Ety) == TYarray)
3738  
-            {
3739  
-                ekey = el_una(OPstrpar, TYstruct, ekey);
3740  
-                ekey->ET = ekey->E1->ET;
3741  
-            }
3742  
-
3743  
-            Symbol *s = taa->aaGetSymbol("Del", 0);
3744  
-            keyti = taa->index->getInternalTypeInfo(NULL)->toElem(irs);
3745  
-            ep = el_params(ekey, keyti, ea, NULL);
3746  
-            e = el_bin(OPcall, TYnptr, el_var(s), ep);
3747  
-            goto Lret;
3748  
-        }
  3729
+        assert(tb->ty != Taarray);
3749 3730
     }
3750 3731
     //e1->type->print();
3751 3732
     e = e1->toElem(irs);
6  src/expression.c
@@ -5521,7 +5521,7 @@ Expression *DeclarationExp::semantic(Scope *sc)
5521 5521
                     s->toPrettyChars(), sc->func->toChars());
5522 5522
                 return new ErrorExp();
5523 5523
             }
5524  
-            else if (!global.params.useDeprecated)
  5524
+            else
5525 5525
             {   // Disallow shadowing
5526 5526
 
5527 5527
                 for (Scope *scx = sc->enclosing; scx && scx->func == sc->func; scx = scx->enclosing)
@@ -5531,7 +5531,7 @@ Expression *DeclarationExp::semantic(Scope *sc)
5531 5531
                         (s2 = scx->scopesym->symtab->lookup(s->ident)) != NULL &&
5532 5532
                         s != s2)
5533 5533
                     {
5534  
-                        deprecation("shadowing declaration %s is deprecated", s->toPrettyChars());
  5534
+                        error("is shadowing declaration %s", s->toPrettyChars());
5535 5535
                         return new ErrorExp();
5536 5536
                     }
5537 5537
                 }
@@ -8985,7 +8985,7 @@ Expression *DeleteExp::semantic(Scope *sc)
8985 8985
         IndexExp *ae = (IndexExp *)(e1);
8986 8986
         Type *tb1 = ae->e1->type->toBasetype();
8987 8987
         if (tb1->ty == Taarray)
8988  
-            deprecation("delete aa[key] deprecated, use aa.remove(key)");
  8988
+            error("delete aa[key] deprecated, use aa.remove(key)");
8989 8989
     }
8990 8990
 
8991 8991
     return this;
8  src/lexer.c
@@ -578,7 +578,7 @@ void Lexer::scan(Token *t)
578 578
                 t->postfix = 0;
579 579
                 t->value = TOKstring;
580 580
 #if DMDV2
581  
-                deprecation("Escape String literal %.*s is deprecated, use double quoted string literal \"%.*s\" instead", p - pstart, pstart, p - pstart, pstart);
  581
+                error("Escape String literal %.*s is deprecated, use double quoted string literal \"%.*s\" instead", p - pstart, pstart, p - pstart, pstart);
582 582
 #endif
583 583
                 return;
584 584
             }
@@ -2147,8 +2147,6 @@ TOK Lexer::number(Token *t)
2147 2147
                 f = FLAGS_unsigned;
2148 2148
                 goto L1;
2149 2149
 
2150  
-            case 'l':
2151  
-                error("'l' is not a valid suffix, did you mean 'L'?");
2152 2150
             case 'L':
2153 2151
                 f = FLAGS_long;
2154 2152
             L1:
@@ -2399,7 +2397,7 @@ __body
2399 2397
             break;
2400 2398
 
2401 2399
         case 'l':
2402  
-            deprecation("'l' suffix is deprecated, use 'L' instead");
  2400
+            error("'l' suffix is deprecated, use 'L' instead");
2403 2401
         case 'L':
2404 2402
             result = TOKfloat80v;
2405 2403
             p++;
@@ -2408,7 +2406,7 @@ __body
2408 2406
     if (*p == 'i' || *p == 'I')
2409 2407
     {
2410 2408
         if (*p == 'I')
2411  
-            deprecation("'I' suffix is deprecated, use 'i' instead");
  2409
+            error("'I' suffix is deprecated, use 'i' instead");
2412 2410
         p++;
2413 2411
         switch (result)
2414 2412
         {
17  src/mtype.c
@@ -1939,18 +1939,13 @@ Expression *Type::getProperty(Loc loc, Identifier *ident)
1939 1939
     {
1940 1940
         e = new IntegerExp(loc, size(loc), Type::tsize_t);
1941 1941
     }
1942  
-    else if (ident == Id::size)
1943  
-    {
1944  
-        error(loc, ".size property should be replaced with .sizeof");
1945  
-        e = new ErrorExp();
1946  
-    }
1947 1942
     else if (ident == Id::__xalignof)
1948 1943
     {
1949 1944
         e = new IntegerExp(loc, alignsize(), Type::tsize_t);
1950 1945
     }
1951 1946
     else if (ident == Id::typeinfo)
1952 1947
     {
1953  
-        deprecation(loc, ".typeinfo deprecated, use typeid(type)");
  1948
+        error(loc, ".typeinfo deprecated, use typeid(type)");
1954 1949
         e = getTypeInfo(NULL);
1955 1950
     }
1956 1951
     else if (ident == Id::init)
@@ -2020,7 +2015,7 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident)
2020 2015
     {
2021 2016
         if (ident == Id::offset)
2022 2017
         {
2023  
-            deprecation(e->loc, ".offset deprecated, use .offsetof");
  2018
+            error(e->loc, ".offset deprecated, use .offsetof");
2024 2019
             goto Loffset;
2025 2020
         }
2026 2021
         else if (ident == Id::offsetof)
@@ -2046,7 +2041,7 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident)
2046 2041
     }
2047 2042
     if (ident == Id::typeinfo)
2048 2043
     {
2049  
-        deprecation(e->loc, ".typeinfo deprecated, use typeid(type)");
  2044
+        error(e->loc, ".typeinfo deprecated, use typeid(type)");
2050 2045
         e = getTypeInfo(sc);
2051 2046
     }
2052 2047
     else if (ident == Id::stringof)
@@ -2851,8 +2846,8 @@ Expression *TypeBasic::getProperty(Loc loc, Identifier *ident)
2851 2846
             case Tcomplex80:
2852 2847
             case Timaginary80:
2853 2848
             case Tfloat80:
2854  
-                                // For backwards compatibility - eventually, deprecate
2855  
-                                goto Lmin_normal;
  2849
+                warning(loc, "min property is deprecated, use min_normal instead");
  2850
+                goto Lmin_normal;
2856 2851
         }
2857 2852
     }
2858 2853
     else if (ident == Id::min_normal)
@@ -8411,7 +8406,7 @@ Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident)
8411 8406
 
8412 8407
         if (ident == Id::typeinfo)
8413 8408
         {
8414  
-            deprecation(e->loc, ".typeinfo deprecated, use typeid(type)");
  8409
+            error(e->loc, ".typeinfo deprecated, use typeid(type)");
8415 8410
             return getTypeInfo(sc);
8416 8411
         }
8417 8412
         if (ident == Id::outer && sym->vthis)
2  src/parse.c
@@ -4010,7 +4010,7 @@ Statement *Parser::parseStatement(int flags)
4010 4010
                     arg = new Parameter(0, NULL, token.ident, NULL);
4011 4011
                     nextToken();
4012 4012
                     nextToken();
4013  
-                    deprecation("if (v%s e) is deprecated, use if (auto v = e)", t->toChars());
  4013
+                    error("if (v; e) is deprecated, use if (auto v = e)");
4014 4014
                 }
4015 4015
             }
4016 4016
 
12  test/runnable/deprecate1.d
@@ -56,17 +56,6 @@ void test10()
56 56
 }
57 57
 
58 58
 /**************************************
59  
-        backslash literals
60  
-**************************************/
61  
-
62  
-// from lexer.d
63  
-void lexerTest7()
64  
-{
65  
-    auto str = \xDB;
66  
-    assert(str.length == 1);
67  
-}
68  
-
69  
-/**************************************
70 59
             typedef
71 60
 **************************************/
72 61
 
@@ -1268,7 +1257,6 @@ int main()
1268 1257
 {
1269 1258
     test2();
1270 1259
     test5();
1271  
-    lexerTest7();
1272 1260
     test10();
1273 1261
     test19();
1274 1262
     test33();
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.