Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 17, 2025

Problem

The ILVerify baseline comparison was generating spurious diffs due to auto-generated numeric suffixes in F# method names that change between builds. These patterns include:

  • Closure suffixes: +clo@924-516
  • Pipe expressions: Pipe #1 stage #1 at line 1782@1782
  • Function suffixes: parseOption@269
  • Line references: at line 1234

When the F# compiler generates different numbers for these constructs, the ILVerify output differs even though the actual verification results are semantically identical, causing CI failures.

Solution

Added a Normalize-IlverifyOutputLine function to tests/ILVerify/ilverify.ps1 that removes these auto-generated numeric suffixes before baseline comparison. The function:

  1. Strips closure suffixes: +clo@924-516+clo
  2. Removes pipe patterns: Pipe #1 stage #1 at line 1782@1782(removed)
  3. Normalizes function suffixes: parseOption@269parseOption
  4. Removes line references: at line 1234(removed)
  5. Cleans up extra whitespace

The normalization is applied to both the ILVerify output and baseline content during comparison, ensuring that functionally equivalent outputs match regardless of auto-generated numbering.

Example

Before normalization:

[IL]: Error [StackUnexpected]: : <StartupCode$FSharp-Compiler-Service>.$ServiceLexing+clo@924-516::Invoke(...)
[IL]: Error [StackUnexpected]: : FSharp.Compiler.ParseAndCheckInputs+Pipe #1 stage #1 at line 1782@1782::Invoke(...)

After normalization:

[IL]: Error [StackUnexpected]: : <StartupCode$FSharp-Compiler-Service>.$ServiceLexing+clo::Invoke(...)
[IL]: Error [StackUnexpected]: : FSharp.Compiler.ParseAndCheckInputs+::Invoke(...)

Now different builds with different auto-generated numbers will normalize to identical baseline comparisons, eliminating false positive CI failures while maintaining full verification integrity.

Impact

  • ✅ Eliminates spurious ILVerify diffs caused by F# compiler internal numbering changes
  • ✅ Improves CI stability for F# compiler development
  • ✅ Maintains full verification accuracy - only comparison logic is affected
  • ✅ Backward compatible with existing baseline files

This pull request was created as a result of the following prompt from Copilot chat.

Problem Statement

The current tests/ILVerify/ilverify.ps1 script compares the output of ILVerify directly to the contents of baseline .bsl files. However, these outputs contain method names with auto-generated numeric suffixes (e.g., F# 'clo@123-456', 'at line 789', etc.) that are not robust to source changes and cause spurious diffs.

Solution

Normalize the method names in the ILVerify output before performing comparison and writing to baseline files. This normalization should:

Add a function in PowerShell to handle this normalization. Apply this function to all lines of ILVerify output before comparison and file writes, so that only normalized lines are ever compared or stored.

Implementation Details

A new PowerShell function Normalize-IlverifyOutputLine should be added to the script, with the following logic:

function Normalize-IlverifyOutputLine {
    param(
        [string]$line
    )
    # Remove F# closure suffixes: +clo@NNN-NNN, +clo@NNN, +NAME@NNN-NNN, +NAME@NNN
    $line = $line -replace '(\+\w+)@\d+(-\d+)?', '$1'
    # Remove patterns like "Pipe #1 stage #1 at line 1782@1782"
    $line = $line -replace 'Pipe #\d+ stage #\d+ at line \d+@\d+', ''
    # Remove function suffixes like NAME@NNN or NAME@NNN-NNN in method names
    $line = $line -replace '(\w+)@\d+(-\d+)?', '$1'
    # Remove 'at line NNNN'
    $line = $line -replace 'at line \d+', ''
    # Remove leftover double spaces, stray "+" etc.
    $line = $line -replace '\s+', ' '
    $line = $line.Trim()
    return $line
}

The function should be used on ILVerify output before comparison and writing baselines.


Markdown summary table of patterns being normalized

| Pattern Example                                                      | Regex Pattern                          | Replacement                  |
|---------------------------------------------------------------------|----------------------------------------|------------------------------|
| `+clo@924-516`, `+parseOption@269`                                  | `\+\w+@\d+(-\d+)?`                    | `+clo`, `+parseOption`       |
| `Pipe #1 stage #1 at line 1782@1782`                                | `Pipe #\d+ stage #\d+ at line \d+@\d+` | *(remove)*                   |
| `pointerToNativeInt@106`, `pushShadowedLocals@959`                  | `(\w+)@\d+(-\d+)?`                    | `pointerToNativeInt`, ...     |
| `<StartupCode$FSharp-Compiler-Service>.$ServiceLexing+clo@924-516`  | handled by above                       |                              |

This change will make the ILVerify output comparison robust to changes in auto-generated function numbering and improve CI stability.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Normalize ilverify output for robust baseline comparison Normalize ILVerify output to remove auto-generated numeric suffixes Sep 17, 2025
Copilot AI requested a review from T-Gro September 17, 2025 12:29
@auduchinok
Copy link
Member

I'm wondering what are we trying to achieve with these baselines? Do we need them for FCS, especially for all the compiler-generated implementation details, as opposed to FSharp.Core? Does anyone analyze them in some PRs? I tend to think these baselines add more friction than actual help, at least for FCS.

@T-Gro
Copy link
Member

T-Gro commented Sep 17, 2025

Absolute majority of PRs do not affect codegen, so I agree with you.
This check is mainly for the ones that do, often at low-level which is not detected elsewhere (think state machines, byref types, escape analysis)

@github-actions
Copy link
Contributor

✅ No release notes required

@T-Gro
Copy link
Member

T-Gro commented Sep 17, 2025

/run ilverify

@dotnet dotnet deleted a comment from github-actions bot Sep 17, 2025
@github-actions
Copy link
Contributor

🔧 CLI Command Report

  • Command: /run ilverify
  • Outcome: success

✅ Patch applied:
- Files changed: 8
- Lines changed: 455

@T-Gro T-Gro marked this pull request as ready for review September 17, 2025 16:59
@T-Gro T-Gro requested a review from a team as a code owner September 17, 2025 16:59
@T-Gro T-Gro requested review from a team, auduchinok, Copilot and edgarfgp September 17, 2025 17:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds normalization to ILVerify output comparison to eliminate spurious test failures caused by auto-generated numeric suffixes in F# method names. The normalization removes closure suffixes, pipe patterns, function suffixes, and line references that change between builds but don't affect actual verification results.

Key changes:

  • Added Normalize-IlverifyOutputLine function to remove auto-generated F# compiler numbering patterns
  • Applied normalization to ILVerify output during comparison processing
  • Updated baseline files to reflect normalized method names without numeric suffixes

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/ILVerify/ilverify.ps1 Added normalization function and applied it to ILVerify output processing
tests/ILVerify/ilverify_FSharp.Core_Release_netstandard2.1.bsl Updated baseline with normalized method names
tests/ILVerify/ilverify_FSharp.Core_Release_netstandard2.0.bsl Updated baseline with normalized method names
tests/ILVerify/ilverify_FSharp.Core_Debug_netstandard2.1.bsl Updated baseline with normalized method names
tests/ILVerify/ilverify_FSharp.Core_Debug_netstandard2.0.bsl Updated baseline with normalized method names
tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl Updated baseline with normalized method names
tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net10.0.bsl Updated baseline with normalized method names
tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl Updated baseline with normalized method names
tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net10.0.bsl Updated baseline with normalized method names

Copy link
Member

@auduchinok auduchinok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@T-Gro Thanks a lot!

@T-Gro T-Gro enabled auto-merge (squash) September 18, 2025 08:20
@T-Gro T-Gro merged commit 0dbd3cd into main Sep 18, 2025
36 checks passed
@T-Gro T-Gro deleted the copilot/fix-1a4fc82b-1990-4310-9da5-6127bf9aa564 branch September 29, 2025 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants