rescript-lang / rescript-lang/rescript-vscode

Stack overflow when showing a type involving recursive polymorphic variants

Open
#1,034 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
ReScript
Stars
354
Forks
63
Avg merge
11h 29m
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the hover and formatting failure with the minimal recursive polymorphic-variant example in the issue, using the reported ReScript and VS Code extension versions. Trace the hover and formatting commands in the language-server extension and confirm that the type display no longer freezes or reports a stack overflow.

Written by the indexing model from the issue text.

Assessment

Tech stack
vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.