Skip to content

Loading…

Deprecations #697

Merged
merged 12 commits into from

8 participants

@yebblies
D Programming Language member

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

@donc
D Programming Language member

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.

@klickverbot
D Programming Language member

Still seems to break druntime, see the auto tester.

@yebblies
D Programming Language member

Thanks, I have no idea how I missed that.

@braddr
D Programming Language member

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.

@yebblies
D Programming Language member

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.

@mleise

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

@yebblies
D Programming Language member

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.

@yebblies
D Programming Language member

Rebased without the C-style function pointers change.

@klickverbot klickverbot commented on the diff
src/mtype.c
@@ -2854,8 +2846,8 @@ Expression *TypeBasic::getProperty(Loc loc, Identifier *ident)
case Tcomplex80:
case Timaginary80:
case Tfloat80:
- // For backwards compatibility - eventually, deprecate
- goto Lmin_normal;
+ warning(loc, "min property is deprecated, use min_normal instead");
@klickverbot D Programming Language member

Just a warning?

@yebblies D Programming Language member

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
@yebblies
D Programming Language member

Removed the html source stuff.

@andralex
D Programming Language member

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?

@alexrp
D Programming Language member

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

@yebblies
D Programming Language member

@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.

@andralex
D Programming Language member

@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.

@ghost

@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.

@andralex
D Programming Language member
if (auto printed = printf("stuff"); printed == -1)
{
    writeln("Something sux.");
}
else
{
    writeln("Printed ", printed, " characters. Something rox.");
}
@ghost

@andralex: That won't compile, lol.

@andralex
D Programming Language member

ehm

@ghost

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?

@yebblies
D Programming Language member

@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?

@klickverbot
D Programming Language member

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

@andralex
D Programming Language member

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

@andralex
D Programming Language member

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

@yebblies
D Programming Language member

@andralex This should do it.

@yebblies
D Programming Language member

Rebased

@yebblies
D Programming Language member

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

@9rnsr
D Programming Language member

LGTM. Let's merge.

@9rnsr 9rnsr merged commit d89fa73 into D-Programming-Language:master

1 check was pending

Details default Pass: 8, Pending: 1
@yebblies
D Programming Language member

Thankyou!

@yebblies yebblies deleted the yebblies:deprecations branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 28, 2012
  1. @yebblies

    Deprecation: array[length] - (deprecated -> error)

    yebblies committed
    This has been deprecated for 23 months (2.041), that should be enough.
  2. @yebblies

    Deprecation: Shadowing local variables (deprecated -> error)

    yebblies committed
    This has been deprecated since version 0.061, it is time it went away.
  3. @yebblies

    Deprecation: Delete on AA element (deprecated -> error)

    yebblies committed
    This has been deprecated since 0.127.
  4. @yebblies

    Deprecation: .offsetof (deprecated -> error)

    yebblies committed
    This has been deprecated since 0.107
  5. @yebblies

    Deprecation: Escape string literals (deprecated -> error)

    yebblies committed
    This has been deprecated since 2.026 (35 months)
  6. @yebblies

    Deprecation: 'l' suffix for long integer literals (error -> gone)

    yebblies committed
    This has been an error since 0.174.
  7. @yebblies
  8. @yebblies

    Deprecation: 'I' suffix for imaginary literal (deprecation -> error)

    yebblies committed
    This has been deprecated since 0.154
  9. @yebblies

    Deprecation: if (v; e) - (deprecated -> error)

    yebblies committed
    This has been deprecated since 0.194
  10. @yebblies

    Deprecation: .typeinfo (deprecated -> error)

    yebblies committed
    This has been deprecated since 0.093
  11. @yebblies
  12. @yebblies

    Deprecation: .size property - (error -> gone)

    yebblies committed
    This has been an error since 0.107.
Showing with 15 additions and 53 deletions.
  1. +1 −1 src/dsymbol.c
  2. +1 −20 src/e2ir.c
  3. +3 −3 src/expression.c
  4. +3 −5 src/lexer.c
  5. +6 −11 src/mtype.c
  6. +1 −1 src/parse.c
  7. +0 −12 test/runnable/deprecate1.d
View
2 src/dsymbol.c
@@ -1266,7 +1266,7 @@ Dsymbol *ArrayScopeSymbol::search(Loc loc, Identifier *ident, int flags)
Expression *ce;
if (ident == Id::length)
- deprecation("using 'length' inside [ ] is deprecated, use '$' instead");
+ ::error(loc, "using 'length' inside [ ] is deprecated, use '$' instead");
L1:
View
21 src/e2ir.c
@@ -3726,26 +3726,7 @@ elem *DeleteExp::toElem(IRState *irs)
{
IndexExp *ae = (IndexExp *)(e1);
tb = ae->e1->type->toBasetype();
- if (tb->ty == Taarray)
- {
- TypeAArray *taa = (TypeAArray *)tb;
- elem *ea = ae->e1->toElem(irs);
- elem *ekey = ae->e2->toElem(irs);
- elem *ep;
- elem *keyti;
-
- if (tybasic(ekey->Ety) == TYstruct || tybasic(ekey->Ety) == TYarray)
- {
- ekey = el_una(OPstrpar, TYstruct, ekey);
- ekey->ET = ekey->E1->ET;
- }
-
- Symbol *s = taa->aaGetSymbol("Del", 0);
- keyti = taa->index->getInternalTypeInfo(NULL)->toElem(irs);
- ep = el_params(ekey, keyti, ea, NULL);
- e = el_bin(OPcall, TYnptr, el_var(s), ep);
- goto Lret;
- }
+ assert(tb->ty != Taarray);
}
//e1->type->print();
e = e1->toElem(irs);
View
6 src/expression.c
@@ -5521,7 +5521,7 @@ Expression *DeclarationExp::semantic(Scope *sc)
s->toPrettyChars(), sc->func->toChars());
return new ErrorExp();
}
- else if (!global.params.useDeprecated)
+ else
{ // Disallow shadowing
for (Scope *scx = sc->enclosing; scx && scx->func == sc->func; scx = scx->enclosing)
@@ -5531,7 +5531,7 @@ Expression *DeclarationExp::semantic(Scope *sc)
(s2 = scx->scopesym->symtab->lookup(s->ident)) != NULL &&
s != s2)
{
- deprecation("shadowing declaration %s is deprecated", s->toPrettyChars());
+ error("is shadowing declaration %s", s->toPrettyChars());
return new ErrorExp();
}
}
@@ -8985,7 +8985,7 @@ Expression *DeleteExp::semantic(Scope *sc)
IndexExp *ae = (IndexExp *)(e1);
Type *tb1 = ae->e1->type->toBasetype();
if (tb1->ty == Taarray)
- deprecation("delete aa[key] deprecated, use aa.remove(key)");
+ error("delete aa[key] deprecated, use aa.remove(key)");
}
return this;
View
8 src/lexer.c
@@ -578,7 +578,7 @@ void Lexer::scan(Token *t)
t->postfix = 0;
t->value = TOKstring;
#if DMDV2
- deprecation("Escape String literal %.*s is deprecated, use double quoted string literal \"%.*s\" instead", p - pstart, pstart, p - pstart, pstart);
+ error("Escape String literal %.*s is deprecated, use double quoted string literal \"%.*s\" instead", p - pstart, pstart, p - pstart, pstart);
#endif
return;
}
@@ -2147,8 +2147,6 @@ TOK Lexer::number(Token *t)
f = FLAGS_unsigned;
goto L1;
- case 'l':
- error("'l' is not a valid suffix, did you mean 'L'?");
case 'L':
f = FLAGS_long;
L1:
@@ -2399,7 +2397,7 @@ __body
break;
case 'l':
- deprecation("'l' suffix is deprecated, use 'L' instead");
+ error("'l' suffix is deprecated, use 'L' instead");
case 'L':
result = TOKfloat80v;
p++;
@@ -2408,7 +2406,7 @@ __body
if (*p == 'i' || *p == 'I')
{
if (*p == 'I')
- deprecation("'I' suffix is deprecated, use 'i' instead");
+ error("'I' suffix is deprecated, use 'i' instead");
p++;
switch (result)
{
View
17 src/mtype.c
@@ -1939,18 +1939,13 @@ Expression *Type::getProperty(Loc loc, Identifier *ident)
{
e = new IntegerExp(loc, size(loc), Type::tsize_t);
}
- else if (ident == Id::size)
- {
- error(loc, ".size property should be replaced with .sizeof");
- e = new ErrorExp();
- }
else if (ident == Id::__xalignof)
{
e = new IntegerExp(loc, alignsize(), Type::tsize_t);
}
else if (ident == Id::typeinfo)
{
- deprecation(loc, ".typeinfo deprecated, use typeid(type)");
+ error(loc, ".typeinfo deprecated, use typeid(type)");
e = getTypeInfo(NULL);
}
else if (ident == Id::init)
@@ -2020,7 +2015,7 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident)
{
if (ident == Id::offset)
{
- deprecation(e->loc, ".offset deprecated, use .offsetof");
+ error(e->loc, ".offset deprecated, use .offsetof");
goto Loffset;
}
else if (ident == Id::offsetof)
@@ -2046,7 +2041,7 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident)
}
if (ident == Id::typeinfo)
{
- deprecation(e->loc, ".typeinfo deprecated, use typeid(type)");
+ error(e->loc, ".typeinfo deprecated, use typeid(type)");
e = getTypeInfo(sc);
}
else if (ident == Id::stringof)
@@ -2851,8 +2846,8 @@ Expression *TypeBasic::getProperty(Loc loc, Identifier *ident)
case Tcomplex80:
case Timaginary80:
case Tfloat80:
- // For backwards compatibility - eventually, deprecate
- goto Lmin_normal;
+ warning(loc, "min property is deprecated, use min_normal instead");
@klickverbot D Programming Language member

Just a warning?

@yebblies D Programming Language member

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
+ goto Lmin_normal;
}
}
else if (ident == Id::min_normal)
@@ -8411,7 +8406,7 @@ Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident)
if (ident == Id::typeinfo)
{
- deprecation(e->loc, ".typeinfo deprecated, use typeid(type)");
+ error(e->loc, ".typeinfo deprecated, use typeid(type)");
return getTypeInfo(sc);
}
if (ident == Id::outer && sym->vthis)
View
2 src/parse.c
@@ -4010,7 +4010,7 @@ Statement *Parser::parseStatement(int flags)
arg = new Parameter(0, NULL, token.ident, NULL);
nextToken();
nextToken();
- deprecation("if (v%s e) is deprecated, use if (auto v = e)", t->toChars());
+ error("if (v; e) is deprecated, use if (auto v = e)");
}
}
View
12 test/runnable/deprecate1.d
@@ -56,17 +56,6 @@ void test10()
}
/**************************************
- backslash literals
-**************************************/
-
-// from lexer.d
-void lexerTest7()
-{
- auto str = \xDB;
- assert(str.length == 1);
-}
-
-/**************************************
typedef
**************************************/
@@ -1268,7 +1257,6 @@ int main()
{
test2();
test5();
- lexerTest7();
test10();
test19();
test33();
Something went wrong with that request. Please try again.