Skip to content

Conversation

@datokrat
Copy link
Contributor

@datokrat datokrat commented Oct 30, 2025

This PR introduces slices of lists that are available via slice notation (e.g., xs[1...5]).

  • Moved the take combinator and the List iterator producer to Init.
  • Introduced a toTake combinator: it.toTake behaves like it, but it has the same type as it.take n. There is a constant cost per iteration compared to it itself.
  • Introduced List slices. Their iterators are defined as suffixList.iter.take n for upper-bounded slices and suffixList.iter.toTake for unbounded ones.

Performance characteristics of using the slice list[a...b]:

  • when creating it: O(a)
  • every iterator step: O(1)
  • toList: O(b - a + 1) (given that a <= b)

Because the slice only stores a suffix of xs internally, two slices can be equal even though the underlying lists differ in an irrelevant prefix. Because the stop field is allowed to be beyond the list's upper bound, the slices [1][0...1] and [1][0...2] are not equal, even though they effectively cover the same range of the same list. Improving this would require us to call List.length when building the slice, which would iterate through the whole list.

@datokrat datokrat added the changelog-library Library label Oct 30, 2025
@datokrat datokrat changed the base branch from master to paul/base/iterators/listslice October 30, 2025 13:19
@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 Oct 30, 2025
@leanprover-bot
Copy link
Collaborator

leanprover-bot commented Oct 30, 2025

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2025-10-21 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-10-30 14:26:59)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2025-11-13 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-13 09:55:18)
  • 🟡 Reference manual branch lean-pr-testing-11019 build against this PR didn't complete normally. (2025-11-13 13:50:53) View Log
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2025-11-14 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-14 11:17:14)

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Oct 30, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Oct 30, 2025
@leanprover-community-bot leanprover-community-bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Oct 30, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Oct 30, 2025

Mathlib CI status (docs):

  • ❌ Mathlib branch lean-pr-testing-11019 built against this PR, but testing failed. (2025-10-30 15:51:55) View Log
  • ❌ Mathlib branch lean-pr-testing-11019 built against this PR, but testing failed. (2025-10-31 16:44:44) View Log
  • ✅ Mathlib branch lean-pr-testing-11019 has successfully built against this PR. (2025-11-01 12:04:41) View Log
  • ✅ Mathlib branch lean-pr-testing-11019 has successfully built against this PR. (2025-11-11 09:48:16) View Log
  • ❗ Batteries CI can not be attempted yet, as the nightly-testing-2025-11-13 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Batteries CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2025-11-13 09:55:17)
  • ✅ Mathlib branch lean-pr-testing-11019 has successfully built against this PR. (2025-11-13 15:07:41) View Log
  • ❗ Batteries CI can not be attempted yet, as the nightly-testing-2025-11-14 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Batteries CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2025-11-14 11:17:13)

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Oct 31, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Oct 31, 2025
@leanprover-community-bot leanprover-community-bot 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 1, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Nov 11, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Nov 11, 2025
@datokrat datokrat marked this pull request as ready for review November 11, 2025 09:48
@datokrat datokrat requested a review from kim-em as a code owner November 11, 2025 09:48
@datokrat
Copy link
Contributor Author

!radar

@leanprover-radar
Copy link

leanprover-radar commented Nov 11, 2025

Benchmark results for 7cba2da against ed73cdd are in! @datokrat

Runs (1)
  • other exited with code 1 (🟥)
Major changes (1)
  • stdlib//number of imported bytes changed by +1.5% (🟥).
Minor changes (3)
  • stdlib//instructions changed by +0.2% (🟥).
  • stdlib//number of imported consts changed by +1.2% (🟥).
  • stdlib//number of imported entries changed by +0.9% (🟥).

@datokrat datokrat force-pushed the paul/base/iterators/listslice branch from ed73cdd to 2b85e29 Compare November 13, 2025 09:05
@datokrat datokrat force-pushed the paul/iterators/listslice branch from 7cba2da to 10bb408 Compare November 13, 2025 09:05
@datokrat
Copy link
Contributor Author

!radar

@leanprover-radar
Copy link

leanprover-radar commented Nov 13, 2025

Benchmark results for 10bb408 against 2b85e29 are in! @datokrat

Runs (1)
  • other exited with code 1 (🟥)
Major changes (1)
  • stdlib//number of imported bytes changed by +1.6% (🟥).
Minor changes (3)
  • stdlib//instructions changed by +0.2% (🟥).
  • stdlib//number of imported consts changed by +1.3% (🟥).
  • stdlib//number of imported entries changed by +0.9% (🟥).

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Nov 13, 2025
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Nov 13, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Nov 13, 2025
@leanprover-bot leanprover-bot added the breaks-manual This is not necessarily a blocker for merging, but there needs to be a plan. label Nov 13, 2025
@datokrat datokrat force-pushed the paul/iterators/listslice branch from 20dc6d3 to ac54c21 Compare November 14, 2025 10:27
@datokrat datokrat changed the base branch from paul/base/iterators/listslice to master November 14, 2025 11:16
@datokrat datokrat added this pull request to the merge queue Nov 14, 2025
@datokrat datokrat removed this pull request from the merge queue due to a manual request Nov 14, 2025
@datokrat datokrat added this pull request to the merge queue Nov 14, 2025
Merged via the queue into master with commit b5b34ee Nov 14, 2025
27 of 31 checks passed
@datokrat
Copy link
Contributor Author

!radar

@leanprover-radar
Copy link

leanprover-radar commented Nov 15, 2025

Benchmark results for ac54c21 against de07370 are in! @datokrat

Minor changes (7)
  • iterators (elab)//instructions changed by +0.7% (🟥).
  • lake build clean//instructions changed by +0.8% (🟥).
  • language server startup//instructions changed by +0.7% (🟥).
  • stdlib//instructions changed by +0.2% (🟥).
  • stdlib//number of imported bytes changed by +0.9% (🟥).
  • stdlib//number of imported consts changed by +0.5% (🟥).
  • workspaceSymbols with new ranges//instructions changed by -3.0% (✅).

@datokrat
Copy link
Contributor Author

!radar

@leanprover-radar
Copy link

Benchmark results for ac54c21 against de07370 are in! @datokrat

Minor changes (7)
  • iterators (elab)//instructions changed by +0.7% (🟥).
  • lake build clean//instructions changed by +0.8% (🟥).
  • language server startup//instructions changed by +0.7% (🟥).
  • stdlib//instructions changed by +0.2% (🟥).
  • stdlib//number of imported bytes changed by +0.9% (🟥).
  • stdlib//number of imported consts changed by +0.5% (🟥).
  • workspaceSymbols with new ranges//instructions changed by -3.0% (✅).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaks-manual This is not necessarily a blocker for merging, but there needs to be a plan. 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.

7 participants