Skip to content

StackGuard when DotNetBuildUseMonoRuntime #19360

Draft
T-Gro wants to merge 1 commit intomainfrom
feature/mono-filemapping-stackguard
Draft

StackGuard when DotNetBuildUseMonoRuntime #19360
T-Gro wants to merge 1 commit intomainfrom
feature/mono-filemapping-stackguard

Conversation

@T-Gro
Copy link
Member

@T-Gro T-Gro commented Feb 25, 2026

Add StackGuard for visitSynExpr under Mono runtime + source-build CI for Mono configuration

Problem

The visitSynExpr function in FileContentMapping.fs uses deep recursion through a continuation-passing style visit function. On Mono-based .NET runtimes (used in certain VMR source-build configurations), the default stack size is smaller, which can lead to StackOverflowException when processing deeply nested syntax trees.

Changes

Compiler: StackGuard for Mono runtime (FileContentMapping.fs)

When building with DotNetBuildUseMonoRuntime=true, the recursive visit function in visitSynExpr is replaced with a visitGuarded variant that uses StackGuard to check remaining stack space and spill to a new thread when needed. This is gated behind #if BUILD_USING_MONO so the CoreCLR path remains unchanged.

  • Added open FSharp.Compiler.DiagnosticsLogger for StackGuard access.
  • Under BUILD_USING_MONO: visitGuarded takes a StackGuard parameter; each recursive visit call goes through sg.Guard(...).
  • Under CoreCLR (default): the existing visit function is kept as-is with no overhead.

Project: conditional BUILD_USING_MONO define (FSharp.Compiler.Service.fsproj)

Added <DefineConstants> that sets BUILD_USING_MONO when DotNetBuildUseMonoRuntime is true, matching the convention used by the VMR (dotnet/dotnet) for Mono source-build scenarios.

CI: second source-build platform for Mono configuration (azure-pipelines-PR.yml)

Added a Managed_MonoRuntime source-build platform that passes /p:DotNetBuildUseMonoRuntime=true alongside --source-build. This exercises the Mono code paths in PR CI. The property flows through build.sh -> eng/build.sh -> MSBuild via the existing /p:* pass-through mechanism.

Note: This does not run the build on the Mono runtime itself -- the CI container still uses a CoreCLR-based SDK. The DotNetBuildUseMonoRuntime property enables Mono-specific adaptations (disable R2R, enable StackGuard, set BUILD_USING_MONO define). Actual Mono-runtime execution happens when F# is built inside the VMR with a Mono-based SDK.

@github-actions
Copy link
Contributor

❗ Release notes required

@T-Gro,

Caution

No release notes found for the changed paths (see table below).

Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format.

The following format is recommended for this repository:

* <Informative description>. ([PR #XXXXX](https://github.com/dotnet/fsharp/pull/XXXXX))

See examples in the files, listed in the table below or in th full documentation at https://fsharp.github.io/fsharp-compiler-docs/release-notes/About.html.

If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request.

You can open this PR in browser to add release notes: open in github.dev

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/10.0.300.md No release notes found or release notes format is not correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

1 participant