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

stack size exceeded error on js target #268

Closed
chancyk opened this issue Sep 3, 2023 · 1 comment
Closed

stack size exceeded error on js target #268

chancyk opened this issue Sep 3, 2023 · 1 comment

Comments

@chancyk
Copy link
Contributor

chancyk commented Sep 3, 2023

Using Nim 2.0.0 on Windows 11

The following code is a minimal example that produces a Maximum call stack size exceeded error when compiled to JS and run from Node 16.15.1 or Chromium 116:

import karax / [kbase, karaxdsl, vdom]

proc render*(): kstring =
  let vnode = buildHtml(html()):
    body:
      section(id = "section1"):
        text "Section 1 content..."

  result = $vnode

echo render()

and here's the offending recursive function that's produced:

function len_738198497(a_738198498) {
    var Temporary1;

  var result_738198499 = 0;

  var F = {procname: "vdom.len", prev: framePtr, filename: "C:\\Users\\username\\.nimble\\pkgs2\\karax-1.3.0-481742b3d0c0e3c92174b1bdd08a4a94853250af\\karax\\vdom.nim", line: 0};
  framePtr = F;
    F.line = 352;
    F.filename = "vdom.nim";
    if ((a_738198498 == null)) {
      Temporary1 = 0;
    }
    else {
      Temporary1 = len_738198497(a_738198498);
    }
    
    result_738198499 = Temporary1;
  framePtr = F.prev;

  return result_738198499;
}

by this Nim code that was introduced in pull request #159:

when kstring is cstring:
  proc len(a: kstring): int =
    # xxx: maybe move where kstring is defined
    # without this, `n.field.len` fails on js (non web) platform
    if a == nil: 0 else: a.len

It seems like a.len should be calling a version of length without the guard instead of it being recursive? Is that possible?

@chancyk
Copy link
Contributor Author

chancyk commented Sep 3, 2023

Created a pull request (#269) which fixes the issue for me. Is this an acceptable approach?

@Araq Araq closed this as completed Sep 3, 2023
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