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

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

✅ Release-note check exempted

The NO_RELEASE_NOTES label exempts this pull request.

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
@T-Gro

T-Gro commented Sep 18, 2026

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

1 similar comment
@T-Gro

T-Gro commented Sep 18, 2026

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

@T-Gro T-Gro added the NO_RELEASE_NOTES Label for pull requests which signals, that user opted-out of providing release notes label Sep 18, 2026
@Happypig375

Copy link
Copy Markdown
Member

No warning against using printf with $?

@T-Gro

T-Gro commented Sep 19, 2026

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

@T-Gro

T-Gro commented Sep 19, 2026

Copy link
Copy Markdown
Member

@Happypig375 :

I don't wan't to introduce a lot of warnings for existing codebases - at least not without a centralized analyzer+fixer story.

(There are environments where people maintain working codebases without motivation to touch the code much, but still we want them to update their SDK and not receive a flood of new warnings for code that was OK)

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 NO_RELEASE_NOTES Label for pull requests which signals, that user opted-out of providing release notes

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants