Skip to content

Maximum call stack size exceeded for getTypeAtFlowNode in Large File #14314

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

Closed
mattbierner opened this issue Feb 26, 2017 · 5 comments
Closed
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@mattbierner
Copy link

TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)

Code
Discovered while trying to work around facebook/react-native#12590

For a large TS file that looks like:

const data = {} as any

data["a"] = "AH0";
data["a(1)"] = "EY1";
data["a's"] = "EY1 Z";
data["a."] = "EY1";
data["a.'s"] = "EY1 Z";
data["a.s"] = "EY1 Z";
... 100,000 + lines

Compile the file on its own with tsc

Here's the complete file: https://gist.githubusercontent.com/mattbierner/34dbc249be0ebddedcc275d0ff40281b/raw/985dbbfba9a5db89f9cea618ce3c885ccc46ef8b/cmu.js

Bug

/XXX/node_modules/typescript/lib/tsc.js:51296
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at isMatchingReference (/XXX/node_modules/typescript/lib/tsc.js:27613:37)
    at getTypeAtFlowAssignment (/XXX/node_modules/typescript/lib/tsc.js:28150:21)
    at getTypeAtFlowNode (/XXX/node_modules/typescript/lib/tsc.js:28101:32)
    at getTypeAtFlowArrayMutation (/XXX/node_modules/typescript/lib/tsc.js:28178:36)
    at getTypeAtFlowNode (/XXX/node_modules/typescript/lib/tsc.js:28123:32)
    at getTypeAtFlowArrayMutation (/XXX/node_modules/typescript/lib/tsc.js:28178:36)
    at getTypeAtFlowNode (/XXX/node_modules/typescript/lib/tsc.js:28123:32)
    at getTypeAtFlowArrayMutation (/XXX/node_modules/typescript/lib/tsc.js:28178:36)
    at getTypeAtFlowNode (/XXX/node_modules/typescript/lib/tsc.js:28123:32)
    at getTypeAtFlowArrayMutation (/XXX/node_modules/typescript/lib/tsc.js:28178:36)
@mhegazy
Copy link
Contributor

mhegazy commented Feb 27, 2017

Every statement is considered a "narrowing" expression, and that triggers more analysis, if the compiler goes far enough in the statement list, it runs out of stack space.

have you considered writing it as an object literal?

const data = {
    "a": "AH0",
    "a(1)": "EY1",
    "a's": "EY1 Z",
    "a.": "EY1",
    "a.'s": "EY1 Z",
    "a.s": "EY1 Z",
    ...
}

or adding a type annotation with an index signature, e.g. : { [x:string}: string }

@mjbvz
Copy link
Contributor

mjbvz commented Feb 28, 2017

Thanks @mhegazy. I actually started with a json object but ran into some problems with react-native, which is why I tried to convert it to this format. Obviously the code is not terribly practical, but I also wasn't trying to break typescript or anything when doing this.

Adding an index signiture like so:

const data: { [index: string]: string} = {}
...

Does not fix things. I still see exceptions such as:

Error - 8:57:45 PM] 'quickinfo' request failed with error.
Error processing request. Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
    at Object.isBindingPattern (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:8117:30)
    at walkUpBindingElementsAndPatterns (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:8700:49)
    at Object.getCombinedNodeFlags (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:8722:16)
    at Object.isBlockOrCatchScoped (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:5394:20)
    at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:21992:88
    at Object.forEach (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:1220:30)
    at checkResolvedBlockScopedVariable (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:21992:34)
    at resolveName (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:21909:25)
    at getResolvedSymbol (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:28697:67)
    at isMatchingReference (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:28743:80)

and

[Error - 8:58:14 PM] 'completions' request failed with error.
Error processing request. Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
    at Object.isBindingPattern (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:8117:30)
    at walkUpBindingElementsAndPatterns (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:8700:49)
    at Object.getCombinedNodeFlags (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:8722:16)
    at Object.isBlockOrCatchScoped (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:5394:20)
    at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:21992:88
    at Object.forEach (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:1220:30)
    at checkResolvedBlockScopedVariable (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:21992:34)
    at resolveName (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:21909:25)
    at getResolvedSymbol (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:28697:67)
    at isMatchingReference (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/tsserver.js:28743:80)

@mhegazy mhegazy added the Bug A bug in TypeScript label Feb 28, 2017
@mhegazy mhegazy added this to the TypeScript 2.3 milestone Feb 28, 2017
@mhegazy mhegazy assigned sandersn and unassigned sandersn Mar 24, 2017
@mhegazy mhegazy added Bug A bug in TypeScript and removed Bug A bug in TypeScript labels Mar 24, 2017
@mhegazy mhegazy removed this from the TypeScript 2.3 milestone Mar 24, 2017
@atifsyedali
Copy link

This is particularly problematic because it tends to break long locale files in large projects.

@endel
Copy link

endel commented Aug 4, 2017

Still occurring on [email protected].

As @atifsyedali said, this is quite problematic. I'm working with legacy code that has +5000 lines of assignments to a dictionary.

/XXX/node_modules/typescript/lib/tsc.js:55776
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at isMatchingReference (/XXX/node_modules/typescript/lib/tsc.js:30445:37)
    at isMatchingReference (/XXX/node_modules/typescript/lib/tsc.js:30458:25)
    at getTypeAtFlowArrayMutation (/XXX/node_modules/typescript/lib/tsc.js:31030:21)
    at getTypeAtFlowNode (/XXX/node_modules/typescript/lib/tsc.js:30976:32)
    at getTypeAtFlowArrayMutation (/XXX/node_modules/typescript/lib/tsc.js:31031:36)
    at getTypeAtFlowNode (/XXX/node_modules/typescript/lib/tsc.js:30976:32)
    at getTypeAtFlowArrayMutation (/XXX/node_modules/typescript/lib/tsc.js:31031:36)
    at getTypeAtFlowNode (/XXX/node_modules/typescript/lib/tsc.js:30976:32)
    at getTypeAtFlowArrayMutation (/XXX/node_modules/typescript/lib/tsc.js:31031:36)
    at getTypeAtFlowNode (/XXX/node_modules/typescript/lib/tsc.js:30976:32)

@endel
Copy link

endel commented Aug 4, 2017

As a workaround, I'm using arrays and assigning later to the dictionary:

let dict: any = {};

let values = [
  ["key", "value"],
  ["key", "value"],
  // ... 5000+ entries
];

for (let i=0; i<values.length; i++) {
  dict[ values[i][0] ] = values[i][1];
}

@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.5.1 milestone Aug 4, 2017
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed Fixed A PR has been merged for this issue labels Aug 16, 2017
@mhegazy mhegazy modified the milestones: TypeScript 2.6, TypeScript 2.5.1 Aug 16, 2017
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Sep 5, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

8 participants