Skip to content

refactor: use String.Slice in String.take and variants#11180

Merged
TwoFX merged 7 commits intoleanprover:masterfrom
TwoFX:markus/return-substring-raw
Nov 18, 2025
Merged

refactor: use String.Slice in String.take and variants#11180
TwoFX merged 7 commits intoleanprover:masterfrom
TwoFX:markus/return-substring-raw

Conversation

@TwoFX
Copy link
Copy Markdown
Member

@TwoFX TwoFX commented Nov 14, 2025

This PR redefines String.take and variants to operate on String.Slice. While previously functions returning a substring of the input sometimes returned String and sometimes returned Substring.Raw, they now uniformly return String.Slice.

This is a BREAKING change, because many functions now have a different return type. So for example, if s is a string and f is a function accepting a string, f (s.drop 1) will no longer compile because s.drop 1 is a String.Slice. To fix this, insert a call to copy to restore the old behavior: f (s.drop 1).copy.

Of course, in many cases, there will be more efficient options. For example, don't write f <| s.drop 1 |>.copy |>.dropEnd 1 |>.copy, write f <| s.drop 1 |>.dropEnd 1 |>.copy instead. Also, instead of (s.drop 1).copy = "Hello", write s.drop 1 == "Hello".toSlice instead.

@TwoFX TwoFX added WIP This is work in progress, and only a PR for the sake of CI or sharing. No review yet. changelog-library Library labels Nov 14, 2025
@TwoFX TwoFX force-pushed the markus/return-substring-raw branch from 29bf6bb to 46a0a74 Compare November 17, 2025 15:22
@TwoFX
Copy link
Copy Markdown
Member Author

TwoFX commented Nov 17, 2025

!radar

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Nov 17, 2025

Benchmark results for bda0362 against 5ce1f67 are in! @TwoFX

Major changes (12)
  • Init.Data.BitVec.Lemmas//instructions changed by -1.3% (✅).
  • Init.Data.List.Sublist async//instructions changed by -1.3% (✅).
  • Init.Prelude async//instructions changed by -1.0% (✅).
  • Std.Data.Internal.List.Associative//instructions changed by -1.7% (✅).
  • bv_decide_rewriter.lean//instructions changed by -2.1% (✅).
  • grind_bitvec2.lean//instructions changed by -1.6% (✅).
  • grind_list2.lean//instructions changed by -1.9% (✅).
  • identifier auto-completion//instructions changed by -1.3% (✅).
  • simp_bubblesort_256//instructions changed by -3.3% (✅).
  • simp_local//instructions changed by -2.5% (✅).
  • simp_subexpr//instructions changed by -3.2% (✅).
  • stdlib//instructions changed by -1.0% (✅).
Minor changes (10)
  • Std.Data.DHashMap.Internal.RawLemmas//instructions changed by -1.0% (✅).
  • big_match_partial//instructions changed by -0.6% (✅).
  • big_omega.lean MT//instructions changed by -0.9% (✅).
  • big_omega.lean//instructions changed by -0.9% (✅).
  • lake config elab//instructions changed by -0.6% (✅).
  • mut_rec_wf//instructions changed by -0.5% (✅).
  • omega_stress.lean async//instructions changed by -0.7% (✅).
  • reduceMatch//instructions changed by -0.9% (✅).
  • riscv-ast.lean//instructions changed by -1.0% (✅).
  • stdlib size//bytes .olean.server changed by +0.3% (🟥).

@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Nov 17, 2025
@ghost
Copy link
Copy Markdown

ghost commented Nov 17, 2025

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 5ce1f67261a3393bbe97e365b8ab595b8971fe70 --onto 8b575dcbf2a3b907044df2233a61b61003eeeb45. You can force Mathlib CI using the force-mathlib-ci label. (2025-11-17 17:33:58)
  • 💥 Mathlib branch lean-pr-testing-11180 build failed against this PR. (2025-11-18 12:48:17) View Log
  • 🟡 Mathlib branch lean-pr-testing-11180 build this PR didn't complete normally. (2025-11-18 14:31:03) View Log
  • ❌ Mathlib branch lean-pr-testing-11180 built against this PR, but testing failed. (2025-11-18 15:34:04) View Log
  • ✅ Mathlib branch lean-pr-testing-11180 has successfully built against this PR. (2025-11-18 15:52:48) View Log

@leanprover-bot
Copy link
Copy Markdown
Collaborator

leanprover-bot commented Nov 17, 2025

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 5ce1f67261a3393bbe97e365b8ab595b8971fe70 --onto d3dda9f6d4428a906c096067ecb75e432afc4615. You can force reference manual CI using the force-manual-ci label. (2025-11-17 17:33:59)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2025-11-18 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2025-11-18 12:44:38)

@TwoFX TwoFX force-pushed the markus/return-substring-raw branch from bda0362 to fd4047c Compare November 18, 2025 11:32
ghost pushed a commit to leanprover-community/batteries that referenced this pull request Nov 18, 2025
ghost pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Nov 18, 2025
@ghost ghost added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Nov 18, 2025
@TwoFX TwoFX removed the WIP This is work in progress, and only a PR for the sake of CI or sharing. No review yet. label Nov 18, 2025
@ghost ghost added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Nov 18, 2025
@TwoFX TwoFX marked this pull request as ready for review November 18, 2025 16:13
@TwoFX TwoFX requested a review from tydeu as a code owner November 18, 2025 16:13
@TwoFX TwoFX enabled auto-merge November 18, 2025 16:13
@TwoFX TwoFX added this pull request to the merge queue Nov 18, 2025
Merged via the queue into leanprover:master with commit fa5d08b Nov 18, 2025
36 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Nov 20, 2025
This PR adds a few deprecations for functions that never existed but
that are still helpful for people migrating their code post-#11180.
kim-em added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Nov 23, 2025
* Update lean-toolchain for testing leanprover/lean4#11232

* A few fixes

* Update lean-toolchain for leanprover/lean4#11232

* Update lean-toolchain for testing leanprover/lean4#11180

* lake update

* Fix

* Fixed Cli

* Fix cache and tests

* chore: bump to nightly-2025-11-19

* lake update

* deprecations

* fix merge

* lake update proofwidgets

* lake update aesop

* some `grind +revert`

* chore: bump to nightly-2025-11-20

* lake update batteries

* grind +revert

* chore: adaptations for nightly-2025-11-20

* add grind regression test

* chore: bump to nightly-2025-11-21

* chore: adaptations for nightly-2025-11-21

* lake update

---------

Co-authored-by: leanprover-community-mathlib4-bot <leanprover-community-mathlib4-bot@users.noreply.github.com>
Co-authored-by: Markus Himmel <markus@lean-fro.org>
Co-authored-by: Kim Morrison <kim@tqft.net>
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: mathlib4-bot <github-mathlib4-bot@leanprover.zulipchat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR changelog-library Library toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants