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

{.since.} doesn't work for bootstrap nim, nor 1.0.0, breaking valid code #16646

Closed
timotheecour opened this issue Jan 8, 2021 · 0 comments · Fixed by #17895
Closed

{.since.} doesn't work for bootstrap nim, nor 1.0.0, breaking valid code #16646

timotheecour opened this issue Jan 8, 2021 · 0 comments · Fixed by #17895

Comments

@timotheecour
Copy link
Member

timotheecour commented Jan 8, 2021

Example

when true:
  import std/private/since
  static: echo (NimMajor, NimMinor, NimPatch)
  echo (NimMajor, NimMinor, NimPatch)
  since (0,19,0): echo "ok1"
  since (1,5,1): echo "ok2"
  since (2,0,0): echo "ok3"

  proc isNaN2*() {.since: (1,5,1).} = discard
  isNaN2() #  Error: undeclared identifier: 'isNaN1'

Current Output

0.20: Error: undeclared identifier: 'isNaN2'
1.0.0: ditto
1.0.2: ditto
1.0.4: works

XDG_CONFIG_HOME= nim c --lib:lib -r --skipparentcfg main

Expected Output

this should work with the nim binary that's used to bootstrap nim

Possible Solution

update the bootstrap version of nim (csources2) to be at least 1.0.4 (1.0.0 doesn't work)
(and in fact latest stable as I argued here #16282 (comment) but this can be debated elsewhere)
note that https://github.com/nim-lang/csources_v1.git is apparently at version 1.0.11 (which is >= 1.0.4 ie would fix this issue), but this isn't documented; it should be documented via a machine-readable text file containing the hash or preferably git tag for which csources were generated from, currently at 1.0.11.

Additional Information

1.5.1 d34d023
found this while investigating CI failure in https://github.com/nim-lang/Nim/pull/16627/files with this seemingly correct code:

  if (result.n[0].kind in {nkFloatLit..nkFloat64Lit} and isNaN(result.n[0].floatVal)) or
      (result.n[1].kind in {nkFloatLit..nkFloat64Lit} and isNaN(result.n[1].floatVal)):
    localError(c.config, n.info, "NaN is not a valid start or end for a range")

which should've worked because compiler is built with --lib:lib so {.since: (1,5,1).} should've been enabled even with nim bootstrap, but wasn't, because of this bug affecting 0.20.0 (current nim bootstrap version).

note that this also didn't work:

  when not declared(isNaN):
    static: doAssert (NimMajor, NimMinor, NimPatch) < (1, 5, 1) # sanity check to ensure this workaround isn't taken in recent nim
    template isNaN(a): untyped = classify(a) == fcNan

because (NimMajor, NimMinor, NimPatch) = (1,5,1) holds, so the static doAssert fails.

workaround

# replace:
  proc isNaN2*() {.since: (1,5,1).} = discard

# with:
  since (1,5,1):
    proc isNaN2*() = discard

related

nimVersionCT (#14648 which was closed) would in future allow distingushing the version nim binary was compiled at from the version of the stdlib, which is useful in cases like this where we rely on a compiler fix/feature (in this case what matters is that the nim binary was >= 1.0.4, in addition to stdlib >= (1,5,1))

Araq pushed a commit that referenced this issue Apr 30, 2021
…17895)

* revive #16627 now that csources_v1 was merged

* use dedent in rst.nim, refs #17257 (comment)

* fix test and improve rendering of a rst warning
PMunch pushed a commit to PMunch/Nim that referenced this issue Mar 28, 2022
…ces_v1 (nim-lang#17895)

* revive nim-lang#16627 now that csources_v1 was merged

* use dedent in rst.nim, refs nim-lang#17257 (comment)

* fix test and improve rendering of a rst warning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant