nim-lang / RFCs

A repository for your Nim proposals.
135 stars 26 forks source link

remove `deprecated` statement #521

Closed metagn closed 1 year ago

metagn commented 1 year ago

Abstract

Get rid of the deprecated pragma statement syntax.

type New = object
{.deprecated: [Old: New].}

Motivation

This feature is redundant over the deprecated pragma next to definitions. It was added a very long time ago but never documented in the language spec (or its documentation was removed). It still had use cases for a while because 1. some kinds of symbols (like const) used to not support the pragma, which they now do, and 2. the nimfix tool can automatically replace the old name with the new name (see description below for how to deal with this).

The biggest reason to remove it though is the fact that it is the sole remaining user of the internal skAlias symbol kind which requires skipAlias calls everywhere in the compiler, and when some parts of the compiler forget to call it, it causes issues: https://github.com/nim-lang/Nim/issues/14819.

Description

How to make nimfix still work:

  1. don't
  2. make nimfix parse stuff like "nimfixReplace:xyz" or "use xyz instead" (could give wrong code) in the deprecated message in markUsed
  3. define a custom pragma template deprecatedReplace(newName: untyped) {.pragma.} which then nimfix would look for in markUsed

I vote 1 because 2 and 3 are way too opt-in and tedious to implement and I've never heard of anyone using nimfix.

Code Examples

type
  New = object
  Old {.deprecated: "use New instead".} = New # https://www.youtube.com/watch?v=BnTdfA5aTpY

type Foo = enum fooX
# this works since 2.0 (specifically PR #20115)
const fooA {.deprecated: "use fooX instead".} = fooX

Backwards Compatibility

Backwards incompatible for people who used this, but can use when and version check to work around.

Only use I could find in the old Nim standard library was db_connector/mysql (used regex deprecated\s*:\s*\[). I don't think many people used this but it's still worth checking if they did.

Araq commented 1 year ago

It was meant for a transition period and it was used during this period successfully. Now it's time to let it die and make the compiler a tiny bit simpler (and faster) internally.

mratsim commented 1 year ago

what's nimfix?

Araq commented 1 year ago

A tool that can do the "rename" refactoring feature automatically. It was used successfully back in the days and could be revived, but this doesn't require this pragma.

metagn commented 1 year ago

Packages caught in Nim CI that use the deprecated statement along with db_connector as mentioned above:

Since these are versioned, it may be fine to make PRs just removing these, since they've been there for a long time and it's not likely anyone uses the deprecated names.