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

regression that std/json seq[JsonNode] == operator raises exception only in Nim 2.0+ #22254

Closed
tersec opened this issue Jul 11, 2023 · 3 comments · Fixed by #22294
Closed

regression that std/json seq[JsonNode] == operator raises exception only in Nim 2.0+ #22254

tersec opened this issue Jul 11, 2023 · 3 comments · Fixed by #22294
Assignees

Comments

@tersec
Copy link
Contributor

tersec commented Jul 11, 2023

Description

import std/json
proc f(a, b: seq[JsonNode]) {.raises: [].} = discard a == b

Nim Version

Nim Compiler Version 1.6.14 [Linux: amd64]
Compiled at 2023-06-29
Copyright (c) 2006-2023 by Andreas Rumpf

active boot switches: -d:release

version-2-0:

Nim Compiler Version 1.9.5 [Linux: amd64]
Compiled at 2023-07-11
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 9ddd768cce291e5c562cde23baeeefb47aa79c86
active boot switches: -d:release

devel:

Nim Compiler Version 1.9.5 [Linux: amd64]
Compiled at 2023-07-11
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 9ddd768cce291e5c562cde23baeeefb47aa79c86
active boot switches: -d:release

Current Output

1.6.14: compiles
2.0/devel: Error: a == b can raise an unlisted exception: Exception

Expected Output

Compiles

Possible Solution

No response

Additional Information

Related to #22253 but distinct in that this behaves differently in 1.6.14 and 2.0/devel, while that one behaves consistently across all of 1.6.14, 2.0, and devel, so some additional distinct mechanism is presumably operating in this case.

@juancarlospaco
Copy link
Collaborator

!nim c

import std/json
proc f(a, b: seq[JsonNode]) {.raises: [].} = discard a == b

@github-actions
Copy link
Contributor

@juancarlospaco (contributor)

devel :-1: FAIL

Output

Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off  --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(2, 56) Error: a == b can raise an unlisted exception: Exception

Stats

  • Created 2023-07-11T13:37:14Z
  • Started 2023-07-11T13:37:40
  • Finished 2023-07-11T13:37:41
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

IR

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("json")
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("f"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("b"),
        nnkBracketExpr.newTree(
          newIdentNode("seq"),
          newIdentNode("JsonNode")
        ),
        newEmptyNode()
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        nnkInfix.newTree(
          newIdentNode("=="),
          newIdentNode("a"),
          newIdentNode("b")
        )
      )
    )
  )
)
stable :+1: OK

Output


Stats

  • Created 2023-07-11T13:37:14Z
  • Started 2023-07-11T13:37:42
  • Finished 2023-07-11T13:37:43
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
1.6.0 :+1: OK

Output


Stats

  • Created 2023-07-11T13:37:14Z
  • Started 2023-07-11T13:37:45
  • Finished 2023-07-11T13:37:46
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
1.4.0 :+1: OK

Output


Stats

  • Created 2023-07-11T13:37:14Z
  • Started 2023-07-11T13:37:48
  • Finished 2023-07-11T13:37:49
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
1.2.0 :+1: OK

Output


Stats

  • Created 2023-07-11T13:37:14Z
  • Started 2023-07-11T13:38:05
  • Finished 2023-07-11T13:38:05
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
1.0.0 :+1: OK

Output


Stats

  • Created 2023-07-11T13:37:14Z
  • Started 2023-07-11T13:38:19
  • Finished 2023-07-11T13:38:20
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
0.20.2 :+1: OK

Output


Stats

  • Created 2023-07-11T13:37:14Z
  • Started 2023-07-11T13:38:31
  • Finished 2023-07-11T13:38:32
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
#1e15f975b ➡️ 🐛

Diagnostics

ringabout introduced a bug at 2022-10-15 20:07:40 +0800 on commit #1e15f975b with message:

fixes #19162; enable `strictEffects` for v2 (#19380)

* enable stricteffects
* add gcsafe
* fix tests
* use func
* fixes pegs tests
* explicitly mark repr related procs with noSideEffect
* add nimLegacyEffects
* change URL
* fixes docopt
* add `raises: []` to repr
* fixes weave
* fixes nimyaml
* fixes glob
* fixes parsetoml
* Apply suggestions from code review
* Update testament/important_packages.nim
* add legacy:laxEffects

The bug is in the files:

changelog.md
compiler/nim.cfg
compiler/options.nim
compiler/sempass2.nim
config/config.nims
doc/manual.md
lib/pure/pegs.nim
lib/system.nim
lib/system/repr_v2.nim
nimsuggest/sexp.nim
testament/important_packages.nim
tests/closure/tnested.nim
tests/effects/teffects6.nim
tests/effects/tgcsafe.nim
tests/effects/tnosideeffect.nim
tests/stdlib/tpegs.nim

The bug can be in the commits:

(Diagnostics sometimes off-by-one).

🤖 Bug found in 1 minute bisecting 1580 commits at 1336 commits per second.

@tersec
Copy link
Contributor Author

tersec commented Jul 12, 2023

My guess is that it's equivalent to

type
  G = object
    case kind: bool
    of false: discard
    of true:  elems: seq[G]

func `==`(a, b: G): bool =
  case a.kind
  of false: true
  of true: a.elems == b.elems

proc f*(a, b: G) {.raises: [].} = discard a == b

which is a simplified case -- but has the same properties where it regresses from 1.6 to 2.0/devel.

Somewhat to my surprise, it didn't have anything to do with the Table lookup KeyError.

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

Successfully merging a pull request may close this issue.

3 participants