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

Editor freezes when using long variable names #7

Closed
manokara opened this issue Oct 7, 2023 · 2 comments
Closed

Editor freezes when using long variable names #7

manokara opened this issue Oct 7, 2023 · 2 comments

Comments

@manokara
Copy link

manokara commented Oct 7, 2023

Hey, I've been using CalcTape on my phone for a while and was looking for something similar to use on my desktop, and stumbled upon QwikTape. Seeing that CalcTape was one of the inspirations, it's exactly what I was looking for! The variable assigning in results is quite handy. So here's a brief story of my first experience:

Today I went grocery shopping with my mom and sister and I was paying, but we're splitting the bill, so I used a couple variables to see the total of stuff for each of us and also check it against my bank balance to see if I'll still make ends meet. In this process, I was using descriptive variable names like sister_total, mom_total, house_total, and also doing compound calculations (e.g. foo / bar = baz / qux = foobar), until suddently QwikTape froze on me.

Here is a small snippet that triggers it (but doesn't freeze completely):

fee_fo_fum_fam_foo_bar_baz_qux_leeroy_jenkins = 100

Do any operation with the variable below to trigger a freeze:

fee_fo_fum_fam_foo_bar_baz_qux_leeroy_jenkins

This is an exaggeration of course, the variables I was using weren't that long, but using them together had the same effect as using a single long one, and the more calculations you have the longer it freezes. It seems that long variables break the document evaluation to such a degree that changing the variable value doesn't even update the calculation anymore. This happens in the latest release and also in the latest commit. A workround is just to use small/single character variables, but that makes things less readable.

Here's the stack trace (from the latest commit):

InternalError: stack overflow
    at tg (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at cg (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at pT (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at Mb (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at dM (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at s (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at apply (native)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at ALT (file:///home/manokara/Downloads/QwikTape/src/parser/tape-embedded.js)
    at call (native)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/parser/tape-embedded.js:742)
    at apply (native)
    at s (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at apply (native)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at ALT (file:///home/manokara/Downloads/QwikTape/src/parser/tape-embedded.js)
    at call (native)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/parser/tape-embedded.js:655)
    at apply (native)
    at s (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at apply (native)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/parser/tape-embedded.js:639)
    at apply (native)
    at s (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at apply (native)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/parser/tape-embedded.js:614)
    at apply (native)
    at s (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at apply (native)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/parser/tape-embedded.js:601)
    at apply (native)
    at s (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at apply (native)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/parser/tape-embedded.js:594)
    at apply (native)
    at s (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at apply (native)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/parser/tape-embedded.js:576)
    at apply (native)
    at s (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at apply (native)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at ALT (file:///home/manokara/Downloads/QwikTape/src/parser/tape-embedded.js)
    at call (native)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/parser/tape-embedded.js:247)
    at apply (native)
    at s (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at apply (native)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/parser/tape-embedded.js:232)
    at call (native)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at <anonymous> (file:///home/manokara/Downloads/QwikTape/src/parser/tape-embedded.js:234)
    at apply (native)
    at s (file:///home/manokara/Downloads/QwikTape/src/chevrotain/chevrotain.min.js)
    at parseTape (file:///home/manokara/Downloads/QwikTape/src/components/editor.js:153)
    at evalTokens (file:///home/manokara/Downloads/QwikTape/src/components/editor.js:186)
// The line above repeats around 380 times!
    at on ^change at :root (file:///home/manokara/Downloads/QwikTape/src/components/editor.js:454)

Looking at the stack trace and with my limited understarding of the source code, it's almost as if it's considering each character in the editor as a token, causing a stack overflow.

@4silvertooth
Copy link
Owner

Must be related to regexp, looking.

@4silvertooth
Copy link
Owner

4silvertooth commented Oct 8, 2023

The issue was long variable names wouldn't fit in the given padding. The padding being calculated using the decimal place of any number

     100.00
   10000.00
═══════════
   10100.00

so even not so very long variable name that would not fit would hang/loop to fit it in place

not_very_long_varialble = 100

not_very_long_varialble 
+ 100.00
══════════════

it's fixed now with variable name length being considered to calculate paddings for variables

   not_very_long_varialble 
+                   100.00
══════════════════════════

Edit: Will show up in next build.

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