Skip to content

StackGuard when DotNetBuildUseMonoRuntime #19360

Merged
T-Gro merged 2 commits intomainfrom
feature/mono-filemapping-stackguard
Feb 26, 2026
Merged

StackGuard when DotNetBuildUseMonoRuntime #19360
T-Gro merged 2 commits 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

github-actions bot commented Feb 25, 2026

⚠️ Release notes required, but author opted out

Warning

Author opted out of release notes, check is disabled for this pull request.
cc @dotnet/fsharp-team-msft

@T-Gro T-Gro marked this pull request as ready for review February 26, 2026 10:12
@T-Gro T-Gro requested a review from a team as a code owner February 26, 2026 10:12
@T-Gro T-Gro added the NO_RELEASE_NOTES Label for pull requests which signals, that user opted-out of providing release notes label Feb 26, 2026
@T-Gro T-Gro requested a review from abonie February 26, 2026 10:13
@T-Gro T-Gro enabled auto-merge (squash) February 26, 2026 10:13
@github-project-automation github-project-automation bot moved this from New to In Progress in F# Compiler and Tooling Feb 26, 2026
@T-Gro T-Gro merged commit 7584c7f into main Feb 26, 2026
45 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in F# Compiler and Tooling Feb 26, 2026
@T-Gro T-Gro deleted the feature/mono-filemapping-stackguard branch February 26, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NO_RELEASE_NOTES Label for pull requests which signals, that user opted-out of providing release notes

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants