Skip to content

Stack overflow on ppc64le #19988

Description

@tmds

Since #6884 was merged, Mono ppc64le builds are crashing during compilation of fsharp repo.

The StackGuard added in #19286 under #if BUILD_USING_MONO checks whether there is room for the next frame. It does not know how many frames will actually come until the next check. The large stack frames on ppc64le cause the stack to deplete much faster.

The following diff, which flattens the Sequential chains, causes the stack overflows to no longer occur. This pattern is already used for the IfThenElse in the same file.

--- a/src/fsharp/src/Compiler/Driver/GraphChecking/FileContentMapping.fs
+++ b/src/fsharp/src/Compiler/Driver/GraphChecking/FileContentMapping.fs
@@ -454,8 +454,13 @@ let visitSynExpr (e: SynExpr) : FileContentEntry list =
             | SynExpr.TryFinally(tryExpr = tryExpr; finallyExpr = finallyExpr) ->
                 visit tryExpr (fun tNodes -> visit finallyExpr (fun fNodes -> tNodes @ fNodes |> continuation))
             | SynExpr.Lazy(expr, _) -> visit expr continuation
-            | SynExpr.Sequential(expr1 = expr1; expr2 = expr2) ->
-                visit expr1 (fun nodes1 -> visit expr2 (fun nodes2 -> nodes1 @ nodes2 |> continuation))
+            | SynExpr.Sequential _ ->
+                let rec flattenSequential acc e =
+                    match e with
+                    | SynExpr.Sequential(expr1 = e1; expr2 = e2) -> flattenSequential (e1 :: acc) e2
+                    | other -> List.rev (other :: acc)
+
+                Continuation.concatenate (List.map visit (flattenSequential [] e)) continuation
             | SynExpr.IfThenElse(ifExpr = ifExpr; thenExpr = thenExpr; elseExpr = elseExpr) ->
                 let continuations = List.map visit (ifExpr :: thenExpr :: Option.toList elseExpr)
                 Continuation.concatenate continuations continuation

Note: above code was written by an llm.

@T-Gro @majocha @dotnet/fsharp ptal.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions