Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

namespaced defines: -d:myproj.mykey to avoid clashes #181

Open
timotheecour opened this issue Jan 15, 2020 · 1 comment
Open

namespaced defines: -d:myproj.mykey to avoid clashes #181

timotheecour opened this issue Jan 15, 2020 · 1 comment

Comments

@timotheecour
Copy link
Member

timotheecour commented Jan 15, 2020

defines have global scope and can cause clashes.
nim itself defines 363 unique defines, many of which are not prefixed by nim, see the list here: https://gist.github.com/timotheecour/8b2286478083a6068731a63114ee9dd0

The current scheme (which is rarely followed) is to prefix by nimble package name, eg: -d:nimHasLibFFI
However this scheme is brittle because of style and case insensitivity of defines, so you can still have clashes, eg:
-d:fooBarBaz # could be interpreted as (package foo, var barBaz) or (package fooBar, var baz) or any other variation

This is a problem because many nimble packages are prefixes of each other, eg see https://gist.github.com/timotheecour/182fce669ff217c6b0bc87d918303c3e which shows 233 (package1, package2) pairs such that package1 is a prefix of package2.
Furthermore, plenty of packages start with nim so that further causes chances of define clashes.

There is a simple solution to that:

proposal

allow using a namespace for defines, eg:

nim c -d:myproj.mykey1 main.nim
nim c -d:myproj.mykey2:foo main.nim

# main.nim
when defined(myproj.mykey1): discard
const bar {.strdefine:"myproj.mykey2".} = "foo2"

we can just restrict (for simplicity) to at most a single dot, so that foo.bar is valid but not foo.bar.baz

this allows a nimble package foo to prefix all its defines by foo., eg -d:foo.bar

implementation difficulty

easy, I can do it if this RFC is accepted

note

see also #269 for a proposal that enforces ODR (one definition rule), that is complimentary to this RFC.

@metagn
Copy link
Contributor

metagn commented Dec 1, 2021

Seems to be accepted?

@metagn metagn mentioned this issue Jan 16, 2022
33 tasks
metagn added a commit to metagn/Nim that referenced this issue Jul 12, 2022
Araq pushed a commit to nim-lang/Nim that referenced this issue Jul 12, 2022
* allow dots in defined()

refs nim-lang/RFCs#181

* mention accents in older versions
FedericoCeratto pushed a commit to FedericoCeratto/Nim that referenced this issue Jul 30, 2022
* allow dots in defined()

refs nim-lang/RFCs#181

* mention accents in older versions
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
* allow dots in defined()

refs nim-lang/RFCs#181

* mention accents in older versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants