Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Stack overflow when a quotation contains a list literal of about a thousand elements

Đang mở
#20,788 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
fsharp
Lĩnh vực
compilers

Hướng nghiên cứu

The crash is in QuotationTranslator.fs, where ConvExprCore and ConvExpr recurse once per list element; the repro in the issue (a quotation with a 1500-element list literal, run with dotnet fsi) reproduces it. Compare with how StackGuard is applied in the type checker and PostInferenceChecks, which the issue notes this file lacks. Done means the repro script prints done and the existing quotation tests still pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Bug Needs-Triage

QuotationTranslator recurses once per element of a list literal and has no stack guard, so a quotation that contains a long list literal crashes the compiler with a stack overflow.

Repro steps

  1. Generate a script with a list literal of 1500 elements inside a quotation:
// gen.fsx
let elements = String.concat "; " [ for i in 1..1500 -> string i ]
System.IO.File.WriteAllText("repro.fsx", "let q = <@ [ " + elements + " ] @>\nprintfn \"done\"")
  1. Run dotnet fsi gen.fsx, then dotnet fsi repro.fsx.

Expected behavior

The script prints done. The same list literal outside a quotation compiles (tried 5000 elements), and so does [| ... |] inside a quotation (tried 10000).

Actual behavior

The process crashes:

Stack overflow.
   at FSharp.Compiler.TypedTreeOps.TupleCompilation.|Let|_|(Expr)
   at FSharp.Compiler.TypedTreeOps.TupleCompilation.|CompiledForEachExpr|_|(TcGlobals, Expr)
   at FSharp.Compiler.TypedTreeOps.TupleCompilation.|CompiledInt32RangeForEachExpr|_|(TcGlobals, Expr)
   at FSharp.Compiler.TypedTreeOps.TupleCompilation.DetectAndOptimizeForEachExpression(TcGlobals, OptimizeForExpressionOptions, Expr)
Repeated 1165 times:
--------------------------------
   at FSharp.Compiler.QuotationTranslator.ConvExprCore(QuotationGenerationScope, QuotationTranslationEnv, Expr)
   at FSharp.Compiler.QuotationTranslator.ConvExpr(QuotationGenerationScope, QuotationTranslationEnv, Expr)
   at Microsoft.FSharp.Primitives.Basics.List.mapToFreshConsTail[...]
   at Microsoft.FSharp.Primitives.Basics.List.map[...]
--------------------------------
   at FSharp.Compiler.QuotationTranslator.ConvExprCore(QuotationGenerationScope, QuotationTranslationEnv, Expr)
   at FSharp.Compiler.QuotationTranslator.ConvExpr(QuotationGenerationScope, QuotationTranslationEnv, Expr)
   at FSharp.Compiler.QuotationTranslator.ConvExprPublic(QuotationGenerationScope, Boolean, Expr)
   at FSharp.Compiler.PostTypeCheckSemanticChecks.doData@1416(...)

The threshold in dotnet fsi is between 800 and 1000 elements on SDK 10.0.402 and between 1000 and 1250 on SDK 11.0.100-rc.2. QuotationTranslator.fs does not use StackGuard, unlike the type checker and PostInferenceChecks.

It was found while compiling tests/fsharp/typeProviders/helloWorld/provider.fsx in the FSharp.Compiler.ComponentTests host: a quotation there with a list of a few dozen elements overflowed with a Debug build of the compiler on a thread-pool thread.

Known workarounds

Use an array literal.

Related information

  • Windows 11, x64
  • .NET Core (SDK 10.0.402 and 11.0.100-rc.2.26504.105, dotnet fsi)
Ngôn ngữ chính
F#
Star
4.3k
Fork
881
Merge trung bình
3 ngày 23 giờ
Pull request đã merge (30 ngày)
110

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dotnet/fsharp

Tất cả issue của dotnet/fsharp

Issue tương tự

Thêm issue về Compilers

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.