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

js codegen bug for case statement with just else branch #24031

Closed
choltreppe opened this issue Aug 29, 2024 · 4 comments · Fixed by #24047
Closed

js codegen bug for case statement with just else branch #24031

choltreppe opened this issue Aug 29, 2024 · 4 comments · Fixed by #24047

Comments

@choltreppe
Copy link

Description

case 0
else: discard

generates

else {}

whithout preceding if

Nim Version

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

git hash: 5935c3b
active boot switches: -d:release

Current Output

No response

Expected Output

No response

Known Workarounds

No response

Additional Information

No response

@juancarlospaco
Copy link
Collaborator

!nim js

case 0
else: discard

Copy link
Contributor

🐧 Linux bisect by @juancarlospaco (collaborator)
devel 👎 FAIL

Output


IR

Compiled filesize 401 bytes (401 bytes)
var framePtr = null;
var excHandler = 0;
var lastJSError = null;
var F = {procname: "module temp", prev: framePtr, filename: "/home/runner/work/Nim/Nim/temp.nim", line: 0};
framePtr = F;
else{
}
framePtr = F.prev;
var F = {procname: "module temp", prev: framePtr, filename: "/home/runner/work/Nim/Nim/temp.nim", line: 0};
framePtr = F;
framePtr = F.prev;

Stats

  • Started 2024-08-29T20:36:32
  • Finished 2024-08-29T20:36:33
  • Duration

AST

nnkStmtList.newTree(
  nnkCaseStmt.newTree(
    newLit(0),
    nnkElse.newTree(
      nnkStmtList.newTree(
        nnkDiscardStmt.newTree(
          newEmptyNode()
        )
      )
    )
  )
)
stable 👎 FAIL

Output


IR

Compiled filesize 400 bytes (400 bytes)
var framePtr = null;
var excHandler = 0;
var lastJSError = null;
var F = {procname: "module temp", prev: framePtr, filename: "/home/runner/work/Nim/Nim/temp.nim", line: 0};
framePtr = F;
else{
}
framePtr = F.prev;
var F = {procname: "module temp", prev: framePtr, filename: "/home/runner/work/Nim/Nim/temp.nim", line: 0};
framePtr = F;
framePtr = F.prev;

Stats

  • Started 2024-08-29T20:36:36
  • Finished 2024-08-29T20:36:37
  • Duration

AST

nnkStmtList.newTree(
  nnkCaseStmt.newTree(
    newLit(0),
    nnkElse.newTree(
      nnkStmtList.newTree(
        nnkDiscardStmt.newTree(
          newEmptyNode()
        )
      )
    )
  )
)
2.0.8 👎 FAIL

Output


IR

Compiled filesize 400 bytes (400 bytes)
var framePtr = null;
var excHandler = 0;
var lastJSError = null;
var F = {procname: "module temp", prev: framePtr, filename: "/home/runner/work/Nim/Nim/temp.nim", line: 0};
framePtr = F;
else{
}
framePtr = F.prev;
var F = {procname: "module temp", prev: framePtr, filename: "/home/runner/work/Nim/Nim/temp.nim", line: 0};
framePtr = F;
framePtr = F.prev;

Stats

  • Started 2024-08-29T20:36:37
  • Finished 2024-08-29T20:36:37
  • Duration

AST

nnkStmtList.newTree(
  nnkCaseStmt.newTree(
    newLit(0),
    nnkElse.newTree(
      nnkStmtList.newTree(
        nnkDiscardStmt.newTree(
          newEmptyNode()
        )
      )
    )
  )
)
2.0.0 👎 FAIL

Output


IR

Compiled filesize 400 bytes (400 bytes)
var framePtr = null;
var excHandler = 0;
var lastJSError = null;
var F = {procname: "module temp", prev: framePtr, filename: "/home/runner/work/Nim/Nim/temp.nim", line: 0};
framePtr = F;
else{
}
framePtr = F.prev;
var F = {procname: "module temp", prev: framePtr, filename: "/home/runner/work/Nim/Nim/temp.nim", line: 0};
framePtr = F;
framePtr = F.prev;

Stats

  • Started 2024-08-29T20:36:40
  • Finished 2024-08-29T20:36:41
  • Duration

AST

nnkStmtList.newTree(
  nnkCaseStmt.newTree(
    newLit(0),
    nnkElse.newTree(
      nnkStmtList.newTree(
        nnkDiscardStmt.newTree(
          newEmptyNode()
        )
      )
    )
  )
)
1.6.20 👍 OK

Output


IR

Compiled filesize 566 bytes (566 bytes)
var framePtr = null;
var excHandler = 0;
var lastJSError = null;
var F = {procname: "module temp", prev: framePtr, filename: "/home/runner/work/Nim/Nim/temp.nim", line: 0};
framePtr = F;
switch (0) {
default: 
break;
}
framePtr = F.prev;
var F = {procname: "module temp", prev: framePtr, filename: "/home/runner/work/Nim/Nim/temp.nim", line: 0};
framePtr = F;
framePtr = F.prev;
var F = {procname: "module temp", prev: framePtr, filename: "/home/runner/work/Nim/Nim/temp.nim", line: 0};
framePtr = F;
framePtr = F.prev;

Stats

  • Started 2024-08-29T20:36:43
  • Finished 2024-08-29T20:36:44
  • Duration
1.4.8 👍 OK

Output


IR

Compiled filesize 538 bytes (538 bytes)
var framePtr = null;
var excHandler = 0;
var lastJSError = null;
var F={procname:"module temp",prev:framePtr,filename:"/home/runner/work/Nim/Nim/temp.nim",line:0};
framePtr = F;
switch (0) {
default: 
break;
}
framePtr = F.prev;
var F={procname:"module temp",prev:framePtr,filename:"/home/runner/work/Nim/Nim/temp.nim",line:0};
framePtr = F;
framePtr = F.prev;
var F={procname:"module temp",prev:framePtr,filename:"/home/runner/work/Nim/Nim/temp.nim",line:0};
framePtr = F;
framePtr = F.prev;

Stats

  • Started 2024-08-29T20:36:46
  • Finished 2024-08-29T20:36:46
  • Duration
1.2.18 👍 OK

Output


IR

Compiled filesize 807 bytes (807 bytes)
var framePtr = null;
var excHandler = 0;
var lastJSError = null;
if (typeof Int8Array === 'undefined') Int8Array = Array;
if (typeof Int16Array === 'undefined') Int16Array = Array;
if (typeof Int32Array === 'undefined') Int32Array = Array;
if (typeof Uint8Array === 'undefined') Uint8Array = Array;
if (typeof Uint16Array === 'undefined') Uint16Array = Array;
if (typeof Uint32Array === 'undefined') Uint32Array = Array;
if (typeof Float32Array === 'undefined') Float32Array = Array;
if (typeof Float64Array === 'undefined') Float64Array = Array;
process.exitCode = 0;
var global_raise_hook_142018 = [null];
var local_raise_hook_142023 = [null];
var out_of_mem_hook_142026 = [null];
var unhandled_exception_hook_142031 = [null];
switch (0) {
default: 
break;
}

Stats

  • Started 2024-08-29T20:36:48
  • Finished 2024-08-29T20:36:48
  • Duration
1.0.10 👍 OK

Output


IR

Compiled filesize 789 bytes (789 bytes)
var framePtr = null;
var excHandler = 0;
var lastJSError = null;
if (typeof Int8Array === 'undefined') Int8Array = Array;
if (typeof Int16Array === 'undefined') Int16Array = Array;
if (typeof Int32Array === 'undefined') Int32Array = Array;
if (typeof Uint8Array === 'undefined') Uint8Array = Array;
if (typeof Uint16Array === 'undefined') Uint16Array = Array;
if (typeof Uint32Array === 'undefined') Uint32Array = Array;
if (typeof Float32Array === 'undefined') Float32Array = Array;
if (typeof Float64Array === 'undefined') Float64Array = Array;
process.exitCode = 0;
var global_raise_hook_18618 = [null];
var local_raise_hook_18623 = [null];
var out_of_mem_hook_18626 = [null];
switch (0) {
default: 
 break;
}

Stats

  • Started 2024-08-29T20:36:50
  • Finished 2024-08-29T20:36:50
  • Duration
??? ➡️ 🐛

Diagnostics

The commit that introduced the bug can not be found, but the bug is in the commits:

(Can not find the commit because Nim can not be re-built commit-by-commit to bisect).

Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 20.4
  • Created 2024-08-29T20:36:06Z
  • Comments 1
  • Commands nim js -d:nodejs -d:nimExperimentalAsyncjsThen -d:nimExperimentalJsfetch --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

🤖 Bug found in 22 mins bisecting 2431 commits at 110 commits per second

@juancarlospaco
Copy link
Collaborator

@bung87 See #24031 (comment) looks like your PR introduced a bug #20548

@ringabout ringabout self-assigned this Aug 30, 2024
@metagn
Copy link
Collaborator

metagn commented Aug 30, 2024

Could also just disallow this, not a critical regression

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.

4 participants