sweet-js / sweet-core

Sweeten your JavaScript.
https://www.sweetjs.org
BSD 2-Clause "Simplified" License
4.58k stars 208 forks source link

bug: Unicode character causes v8 timeout. #702

Closed egriff38 closed 7 years ago

egriff38 commented 7 years ago

I was trying to create a new operator using the nabla (∇) character, and the compiler timed out:

$ sjs operators.js

<--- Last few GCs --->

[69027:0x102802000]    89813 ms: Mark-sweep 1400.3 (1460.0) -> 1400.3 (1460.0) MB, 745.5 / 0.0 ms  allocation failure GC in old space requested
[69027:0x102802000]    90595 ms: Mark-sweep 1400.3 (1460.0) -> 1400.2 (1430.0) MB, 782.0 / 0.0 ms  last resort gc
[69027:0x102802000]    91459 ms: Mark-sweep 1400.2 (1430.0) -> 1400.2 (1430.0) MB, 864.0 / 0.0 ms  last resort gc

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0xfa41bcc0d39 <JS Object>
    1: readToken [/usr/local/lib/node_modules/@sweet-js/cli/node_modules/sweet-core/dist/reader/token-reader.js:~75] [pc=0xeea59659f36](this=0x24757670b1b1 <a Reader with map 0x258b8f83ad89>,/* anonymous */=0x24757670b149 <a CharStream with map 0x258b8f83ab21>)
    2: arguments adaptor frame: 3->1
    3: readUntil [/usr/local/lib/node_modules/@sweet-js/cli/node_modules/sweet-core/dist/reader/tok...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/usr/local/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
 4: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/bin/node]
 5: v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
 6: 0xeea593063a7
[1]    69027 abort      sjs operators.js

Here was the code I was trying to use:

operator ∇ left 1 = (left,right) => {
  return #`${right}(${left})`;
}
gabejohnson commented 7 years ago

This is probably an issue in the reader. I try to take a look this weekend.

gabejohnson commented 7 years ago

@xepher0coded I think I found the issue and should have a fix in tonight. In the meantime, I should mention that even after the fix you won't be able to make a operator. It's not a valid JS identifier. Only valid JS identifiers can be bound to macros ATM. Once #687 is resolved that will change.