gleam-lang/gleam

Long case statements kill Javascript stack

Open

#4,737 创建于 2025年6月29日

在 GitHub 查看
 (3 评论) (2 反应) (0 负责人)Rust (960 fork)batch import
help wanted

仓库指标

Star
 (21,417 star)
PR 合并指标
 (平均合并 10天 19小时) (30 天内合并 69 个 PR)

描述

After the Javascript case statement optimizations in 1.11.0, a case statement with too many patterns will overwhelm the stack on the Javascript target. The same code worked in 1.10.0.

Reproducing

Calling

pub fn main() -> Nil {
  derived_property(0x00A1)
  |> string.inspect
  |> io.println
}

on https://github.com/NineFX/precious/blob/main/src/precious/derived.gleam on the Javascript target

λ ~/stack/ main* asdf current gleam
Name            Version         Source                               Installed
gleam           1.10.0          /Users/sdfsdf9/stack/.tool-versions true
λ ~/stack/ main* gleam run -m stack --target javascript
  Compiling stack
   Compiled in 0.06s
    Running stack.main
FreePVal(Punctuation)
λ ~/stack/ main* asdf set gleam 1.11.1 ;gleam clean ; gleam run -m stack --target javascript
Downloading packages
 Downloaded 2 packages in 0.04s
  Compiling gleam_stdlib
  Compiling gleeunit
  Compiling stack
   Compiled in 0.16s
    Running stack.main
file:///Users/sdfsdf9/stack/build/dev/javascript/stack/stack.mjs:14309
  let _pipe = derived_property(0xA1);
              ^

RangeError: Maximum call stack size exceeded
    at main (file:///Users/sdfsdf9/stack/build/dev/javascript/stack/stack.mjs:14309:15)
    at file:///Users/sdfsdf9/stack/build/dev/javascript/stack/gleam.main.mjs:2:1
    at ModuleJob.run (node:internal/modules/esm/module_job:365:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:99:5)

Node.js v24.3.0

贡献者指南