Stack overflow despite tail call position but only in 64-bit

后端 未结 1 1348
谎友^
谎友^ 2021-01-18 07:35

Originated from this question, I have this little F# code (github) to generate random values according to a normal distribution:

// val nextSingle : (unit -&         


        
1条回答
  •  北恋
    北恋 (楼主)
    2021-01-18 08:24

    Looks like a bug in the compiler's sequence expression compilation mechanism. Here's a simplified repro:

    let rec loop r = seq {
        if r > 0 then
            let rec unused() = unused()
            yield r
            yield! loop r
    }
    
    printfn "%i" (Seq.nth 10000000 (loop 1))
    

    Obviously the presence of the unused recursive definition shouldn't affect whether this generates a stack overflow, but it does.

    0 讨论(0)
提交回复
热议问题