Skip to content

Cleanup: use printn/print instead of printfn/printf for interpolated strings - #20542

Open
charlesroddie wants to merge 5 commits into
dotnet:mainfrom
charlesroddie:use-printn
Open

charlesroddie wants to merge 5 commits into
dotnet:mainfrom
charlesroddie:use-printn

Conversation

@charlesroddie

@charlesroddie charlesroddie commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Prior to print(n), we could not print interpolated strings directly using FSharp syntax, and had to go through a formatted string path (printf(n) $"..."). This PR starts to use print(n) for these cases.

The advantages are simpler types and reduced cognitive complexity, improved performance, and being able to benefit from the new changes in interpolated strings (fsharp/fslang-suggestions#1468 (comment)).

Moreover, the less printf there is in public code, including the FSharp repo, the less AIs will use it.

Details

This PR replaces printfn $"..." with printn $"..." and printf $"..." with print $"..." (FS-1125) where the referenced FSharp.Core has them, and removes the one redundant sprintf before an interpolated string.

Changed

  • FSharp.Core XML doc examples (set, async, eventmodule, observable, array2, array3)
  • Commented-out code in FSharp.Core, the compiler, FSharp.Editor and coroutines.fsx
  • FSharp.Core.UnitTests (always references the FSharp.Core project)
  • eng/tests/TestSplit.fsx (runs on the SDK's FSharp.Core)
  • TheBigFileOfDebugStepping.fsx (manual walkthrough compiled with the repo's fsc)
  • RemoveUnnecessaryParenthesesTests (syntax-only inputs; continuation lines align with the function name, so layout is unchanged)
  • TransparentCompiler.fs: sprintf $"F%03d{i}"$"F%03d{i}"

Not changed

  • Code in projects in FSharp.Compiler.Service.slnx (including tests/scripts/scriptlib.fsx): with FSHARPCORE_USE_PACKAGE=true they build against the shipped FSharp.Core 10.0.101, which lacks print/printn.
  • Test source compiled at test time: breaks when tests run against the package FSharp.Core, and some snippets have IL baselines. Tests about printf itself (TypedInterpolatedStringsTests, StringFormatAndInterpolation) stay regardless.
  • Other sprintf $ uses: they test sprintf $ itself (printf-interpolated/test.fsx, StringInterpolation.fs, EditorTests.fs) or describe that code path (printf.fs).
  • Benchmarks, .github diagnostics server, docs/fcs: FSharp.Core 10 or own tooling.
  • printf.fsi: those examples document printf/printfn.

The remainder can follow once the shipped FSharp.Core pin moves to 11.

🤖 Generated with Claude Code

…vailable

Replace printfn $"..." with printn $"..." in FSharp.Core doc examples,
commented-out code, FSharp.Core.UnitTests and SDK-run scripts.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

❗ Release notes required

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

@charlesroddie,

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:

`* . (PR #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.

Change path Release notes path Description
`src/FSharp.Core` docs/release-notes/.FSharp.Core/11.0.100.md No release notes found or release notes format is not correct
`src/Compiler` docs/release-notes/.FSharp.Compiler.Service/11.0.100.md No release notes found or release notes format is not correct
`vsintegration/src` docs/release-notes/.VisualStudio/18.vNext.md No release notes found or release notes format is not correct

charlesroddie and others added 3 commits September 14, 2026 07:34
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@charlesroddie charlesroddie changed the title Use printn instead of printfn for interpolated strings Use printn/print instead of printfn/printf for interpolated strings Sep 14, 2026
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@charlesroddie
charlesroddie marked this pull request as ready for review September 14, 2026 07:00
@charlesroddie
charlesroddie requested a review from a team as a code owner September 14, 2026 07:00
@charlesroddie charlesroddie changed the title Use printn/print instead of printfn/printf for interpolated strings Cleanup: use printn/print instead of printfn/printf for interpolated strings Sep 14, 2026
@github-actions github-actions Bot added ⚠️ Affects-Test-Tooling Tooling check: PR touches test framework infrastructure ⚠️ Affects-Build-Infra Tooling check: PR touches build infrastructure labels Sep 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Tooling Safety Check — Affects-Build-Infra, Affects-Test-Tooling
Affects-Build-Infra: TestSplit script executes within build and CI workflows.
Affects-Test-Tooling: TestSplit controls generated test execution commands.

Generated by PR Tooling Safety Check · gpt56 1.1M ·

@Happypig375

Copy link
Copy Markdown
Member

Should also implement a warning against using printf with $.

@T-Gro T-Gro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 🕵️ LGTM

@github-project-automation github-project-automation Bot moved this from New to In Progress in F# Compiler and Tooling Sep 14, 2026
@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label Sep 14, 2026
@T-Gro
T-Gro self-requested a review September 14, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚠️ Affects-Build-Infra Tooling check: PR touches build infrastructure ⚠️ Affects-Test-Tooling Tooling check: PR touches test framework infrastructure AI-reviewed PR reviewed by AI review council

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants