nim-lang / RFCs

A repository for your Nim proposals.
137 stars 23 forks source link

Move `$` and `==` for objects out of system #475

Open metagn opened 2 years ago

metagn commented 2 years ago

Abstract

Move the overloads for the symbols $ and == for generic object types out of system into a new module.

Motivation

Objects are nominal types that often overload these procs. This can cause problems with uses of them in generic/template code that don't mix them in, and statically use the system module overload of them for objects. There were some open issues of this but it's hard to find them.

== for objects also has a limitation where, since it's defined in system, it can't use complex macro code, which means it can't support case objects easily since fieldPairs is unavailable for case objects (https://github.com/nim-lang/Nim/issues/6676).

Also in general people might not want their object types to have a default $/== overload like this. But sometimes they will, and they can have this by just importing the new module these would be in.

Description

$ implementation, == implementation

Notice the implementation is the same for tuples and objects. One option is to move these implementations to a private module, then export specialized versions for tuples and objects in separate modules.

Inspired by https://github.com/nim-lang/Nim/pull/20185.

Code Examples

No response

Backwards Compatibility

This would be part of -d:nimPreviewSlimSystem. Any backwards compatibility issues are the same as the rest of the umbrella of that flag.

juancarlospaco commented 2 years ago

But should be added to prelude.