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 overflow when showing a type involving recursive polymorphic variants #1034

Open
interphx opened this issue Sep 1, 2024 · 1 comment

Comments

@interphx
Copy link

interphx commented Sep 1, 2024

Thanks for all the work on ReScript!

I'm running into an issue with the VS Code extension freezing when trying to view the type of fold in the following code (simplified from an actual language AST):

type ast<'a> = [
  | #Num(int)
  | #Add('a, 'a)
]

type rec expression = ast<expression>

// Hovering over "fold" freezes the language server, even with explicit signature
let rec fold = (expr: ast<'a>, transform: 'a => 'b): 'b =>
  switch expr {
  | #Num(_) as num => transform(num)
  | #Add(lhs, rhs) => transform(#Add(fold(lhs, transform), fold(rhs, transform)))
  }

The tooltip gets stuck at "Loading...", formatting the file also becomes unresponsive. After about a minute, the following error gets logged in the extension output:

Fatal error: exception Stack overflow

Fatal error: exception Stack overflow
Error: Command failed: c:\Users\___\.vscode\extensions\chenglou92.rescript-vscode-1.54.0\server\analysis_binaries\win32\rescript-editor-analysis.exe hover c:\___\rescript-stackoverflow-minimal-repro\src\Demo.res 13 12 C:\Users\___\AppData\Local\Temp\rescript_format_file_7676_27 true
Fatal error: exception Stack overflow

    at genericNodeError (node:internal/errors:984:15)
    at wrappedFn (node:internal/errors:538:14)
    at checkExecSyncError (node:child_process:928:11)
    at Object.execFileSync (node:child_process:964:15)
    at Object.func (node:electron/js2c/node_init:2:2214)
    at Lt (c:\Users\___\.vscode\extensions\chenglou92.rescript-vscode-1.54.0\server\out\cli.js:36:5435)
    at Ct (c:\Users\___\.vscode\extensions\chenglou92.rescript-vscode-1.54.0\server\out\cli.js:36:5637)
    at aw (c:\Users\___\.vscode\extensions\chenglou92.rescript-vscode-1.54.0\server\out\cli.js:42:5564)
    at process.Ph (c:\Users\___\.vscode\extensions\chenglou92.rescript-vscode-1.54.0\server\out\cli.js:42:15178)
    at process.emit (node:events:519:28) {
  status: 2,
  signal: null,
  output: [
    null,
    <Buffer >,
    <Buffer 46 61 74 61 6c 20 65 72 72 6f 72 3a 20 65 78 63 65 70 74 69 6f 6e 20 53 74 61 63 6b 20 6f 76 65 72 66 6c 6f 77 0d 0a>
  ],
  pid: 1788,
  stdout: <Buffer >,
  stderr: <Buffer 46 61 74 61 6c 20 65 72 72 6f 72 3a 20 65 78 63 65 70 74 69 6f 6e 20 53 74 61 63 6b 20 6f 76 65 72 66 6c 6f 77 0d 0a>
}
Original response:  
Args:  [
  'hover',
  'c:\\Dev\\rescript-stackoverflow-minimal-repro\\src\\Demo.res',
  13,
  12,
  'C:\\Users\\___\\AppData\\Local\\Temp\\rescript_format_file_7676_27',
  true
]

This is purely an extension issue, the code compiles and runs just fine. The issue persists after restarting VS Code without also restarting the build process, which makes me think that it may be related to formatting, and not actual type inference.

ReScript version: 11.1.3
Extension version: v1.55.5 (pre-release, but this also happens on stable)
OS: Windows 10

@zth
Copy link
Collaborator

zth commented Sep 2, 2024

Thank you @interphx, will look into it. We squashed a bug like this a while back, hopefully we can just extend that fix to cover this case as well.

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