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

fixes #20219; ignore comment/empty node in stmtListExpr #20249

Merged
merged 1 commit into from
Aug 24, 2022
Merged

Conversation

ringabout
Copy link
Member

@ringabout ringabout commented Aug 20, 2022

fixes #20219

@Varriount
Copy link
Contributor

Varriount commented Aug 21, 2022

What happens in the following scenario?

var a = 1

proc incrementSideEffect: bool =
  inc(a)
  return true

proc main =
  if incrementSideEffect():
    discard

  echo a

@ringabout
Copy link
Member Author

What happens in the following scenario?

It works as expected and prints 2

function main_452984840() {
  if (incrementSideEffect_452984834()) {
  }
  rawEcho(HEX24_318767107(a_452984833[0]));
}

incrementSideEffect is not a simple expression because it contains two statements.

@AmjadHD
Copy link
Contributor

AmjadHD commented Aug 23, 2022

A case statement seems more suitable:

proc isSimpleExpr(p: PProc; n: PNode): bool =
  # calls all the way down --> can stay expression based
  case n.kind
  of nkCallKinds, nkBracketExpr, nkDotExpr, nkPar, nkTupleConstr, nkObjConstr, nkBracket, nkCurly:
    for c in n:
      if not p.isSimpleExpr(c): return false
    result = true
  of nkStmtListExpr:
    for i in 0..<n.len-1:
      if n[i].kind notin {nkCommentStmt, nkEmpty}: return false
    result = isSimpleExpr(p, n.lastSon)
  elif n.isAtom:
    result = true
  else: discard

@Varriount Varriount added the Requires Araq To Merge PR should only be merged by Araq label Aug 24, 2022
@Varriount Varriount requested a review from Araq August 24, 2022 03:07
@ringabout
Copy link
Member Author

A case statement seems more suitable:

A following up PR is welcome! First we make it correct, then we can make it even faster.

@ringabout ringabout added the TODO: followup needed remove tag once fixed or tracked elsewhere label Aug 24, 2022
@Araq Araq merged commit 9d9ecc3 into devel Aug 24, 2022
@Araq Araq deleted the pr_js_simpleexpr branch August 24, 2022 07:28
@github-actions
Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 9d9ecc3

Hint: mm: orc; threads: on; opt: speed; options: -d:release
163802 lines; 12.029s; 841.582MiB peakmem

@ringabout ringabout removed the TODO: followup needed remove tag once fixed or tracked elsewhere label Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Requires Araq To Merge PR should only be merged by Araq
Projects
None yet
Development

Successfully merging this pull request may close these issues.

x < 1 (and|or) b generates temp variables in js output
4 participants