Skip to content

Optimizer: don't inline named functions in debug builds#19548

Open
auduchinok wants to merge 6 commits intodotnet:mainfrom
auduchinok:inlineNamedFunctions
Open

Optimizer: don't inline named functions in debug builds#19548
auduchinok wants to merge 6 commits intodotnet:mainfrom
auduchinok:inlineNamedFunctions

Conversation

@auduchinok
Copy link
Copy Markdown
Member

@auduchinok auduchinok commented Apr 3, 2026

inline functions are fully inlined on the call sites by F# compiler. This means the source information and actual calls are lost, so it's very hard to reliably debug code using such functions.

This PR prevents inlining inline functions in debug builds. This improves debugging experience by allowing setting breakpoints inside such functions and allowing stepping into them and checking the function arguments. It also allows IDEs to analyze the produced IL more reliably during debug.

The implementation handles two distinct cases. When possible, a normal call to the existing method is emitted. When a function contains SRTPs and no callable method is produced, a specialized method is created for each type instantiation.

An example inline function that can be called directly:

let inline add a =
    a + 1

[<EntryPoint>]
let main _ =
    let i = add 1
    0
Screenshot 2026-04-03 at 21 18 51

The existing method is called:
Screenshot 2026-04-03 at 21 18 43

An inline function with SRTPs:

let inline add a b =
    a + b

[<EntryPoint>]
let main _ =
    let i = add 1 2
    0
Screenshot 2026-04-03 at 20 57 08

A specialized method is produced and called:
Screenshot 2026-04-03 at 20 57 22

Open questions:

  • Should we annotate specialized functions from other assemblies somehow? DebuggerNonUserCode?
  • Should we whitelist something from FSharp.Core, like built-in operators?

Implements fsharp/fslang-suggestions#824 for debug builds.
Fixes #9555.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/11.0.100.md

@auduchinok auduchinok force-pushed the inlineNamedFunctions branch from ed866e5 to d607132 Compare April 7, 2026 13:09
@auduchinok auduchinok force-pushed the inlineNamedFunctions branch from bb4fe70 to 9377496 Compare April 7, 2026 13:25
@auduchinok auduchinok force-pushed the inlineNamedFunctions branch from 9377496 to 257c702 Compare April 7, 2026 13:27
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.

F# .net core debugger: Inline functions don't work as expected in debugger even in Debug builds

1 participant