Skip to content

Commit 3b211be

Browse files
committed
move Std.Range to Std.Legacy.Range
1 parent dd28f00 commit 3b211be

File tree

7 files changed

+43
-41
lines changed

7 files changed

+43
-41
lines changed

src/Init/Data/Range/Basic.lean

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public import Init.Omega
1010

1111
public section
1212

13-
namespace Std
13+
namespace Std.Legacy
1414
-- We put `Range` in `Init` because we want the notation `[i:j]` without importing `Std`
1515
-- We don't put `Range` in the top-level namespace to avoid collisions with user defined types
1616
structure Range where
@@ -74,15 +74,17 @@ macro_rules
7474
| `([ : $stop : $step ]) => `({ stop := $stop, step := $step, step_pos := by decide : Range })
7575

7676
end Range
77-
end Std
77+
end Std.Legacy
7878

79-
theorem Membership.mem.upper {i : Nat} {r : Std.Range} (h : i ∈ r) : i < r.stop := h.2.1
79+
@[deprecated "use the new range notation `a...b` instead of `[a:b]` and `Std.Rco.lt_upper_of_mem`" (since := "2025-12-01")]
80+
theorem Membership.mem.upper {i : Nat} {r : Std.Legacy.Range} (h : i ∈ r) : i < r.stop := h.2.1
8081

81-
theorem Membership.mem.lower {i : Nat} {r : Std.Range} (h : i ∈ r) : r.start ≤ i := h.1
82+
@[deprecated "use the new range notation `a...b` instead of `[a:b]` and `Std.Rco.lower_le_of_mem`" (since := "2025-12-01")]
83+
theorem Membership.mem.lower {i : Nat} {r : Std.Legacy.Range} (h : i ∈ r) : r.start ≤ i := h.1
8284

83-
theorem Membership.mem.step {i : Nat} {r : Std.Range} (h : i ∈ r) : (i - r.start) % r.step = 0 := h.2.2
85+
theorem Membership.mem.step {i : Nat} {r : Std.Legacy.Range} (h : i ∈ r) : (i - r.start) % r.step = 0 := h.2.2
8486

85-
theorem Membership.get_elem_helper {i n : Nat} {r : Std.Range} (h₁ : i ∈ r) (h₂ : r.stop = n) :
87+
theorem Membership.get_elem_helper {i n : Nat} {r : Std.Legacy.Range} (h₁ : i ∈ r) (h₂ : r.stop = n) :
8688
i < n := h₂ ▸ h₁.2.1
8789

8890
macro_rules

src/Init/Data/Range/Lemmas.lean

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public import Init.Data.Nat.Div.Lemmas
1515
public section
1616

1717
/-!
18-
# Lemmas about `Std.Range`
18+
# Lemmas about `Std.Legacy.Range`
1919
20-
We provide lemmas rewriting for loops over `Std.Range` in terms of `List.range'`.
20+
We provide lemmas rewriting for loops over `Std.Legacy.Range` in terms of `List.range'`.
2121
-/
2222

23-
namespace Std.Range
23+
namespace Std.Legacy.Range
2424

2525
/-- Generalization of `mem_of_mem_range'` used in `forIn'_loop_eq_forIn'_range'` below. -/
2626
private theorem mem_of_mem_range'_aux {r : Range} {a : Nat} (w₁ : (i - r.start) % r.step = 0)
@@ -37,7 +37,7 @@ theorem mem_of_mem_range' {r : Range} (h : x ∈ List.range' r.start r.size r.st
3737
unfold size at h
3838
apply mem_of_mem_range'_aux (by simp) (by simp) h
3939

40-
private theorem size_eq (r : Std.Range) (h : i < r.stop) :
40+
private theorem size_eq (r : Range) (h : i < r.stop) :
4141
(r.stop - i + r.step - 1) / r.step =
4242
(r.stop - (i + r.step) + r.step - 1) / r.step + 1 := by
4343
have w := r.step_pos
@@ -57,7 +57,7 @@ private theorem size_eq (r : Std.Range) (h : i < r.stop) :
5757
rw [Nat.div_eq_iff] <;> omega
5858
omega
5959

60-
private theorem forIn'_loop_eq_forIn'_range' [Monad m] (r : Std.Range)
60+
private theorem forIn'_loop_eq_forIn'_range' [Monad m] (r : Range)
6161
(init : β) (f : (a : Nat) → a ∈ r → β → m (ForInStep β)) (i) (w₁) (w₂) :
6262
forIn'.loop r f init i w₁ w₂ =
6363
forIn' (List.range' i ((r.stop - i + r.step - 1) / r.step) r.step) init
@@ -75,20 +75,20 @@ private theorem forIn'_loop_eq_forIn'_range' [Monad m] (r : Std.Range)
7575
rw [Nat.div_eq_iff] <;> omega
7676
simp [this]
7777

78-
@[simp] theorem forIn'_eq_forIn'_range' [Monad m] (r : Std.Range)
78+
@[simp] theorem forIn'_eq_forIn'_range' [Monad m] (r : Range)
7979
(init : β) (f : (a : Nat) → a ∈ r → β → m (ForInStep β)) :
8080
forIn' r init f =
8181
forIn' (List.range' r.start r.size r.step) init (fun a h => f a (mem_of_mem_range' h)) := by
8282
conv => lhs; simp only [forIn', Range.forIn']
8383
simp only [size]
8484
rw [forIn'_loop_eq_forIn'_range']
8585

86-
@[simp] theorem forIn_eq_forIn_range' [Monad m] (r : Std.Range)
86+
@[simp] theorem forIn_eq_forIn_range' [Monad m] (r : Range)
8787
(init : β) (f : Nat → β → m (ForInStep β)) :
8888
forIn r init f = forIn (List.range' r.start r.size r.step) init f := by
8989
simp only [forIn, forIn'_eq_forIn'_range']
9090

91-
private theorem forM_loop_eq_forM_range' [Monad m] (r : Std.Range) (f : Nat → m PUnit) :
91+
private theorem forM_loop_eq_forM_range' [Monad m] (r : Range) (f : Nat → m PUnit) :
9292
forM.loop r f i = forM (List.range' i ((r.stop - i + r.step - 1) / r.step) r.step) f := by
9393
have w := r.step_pos
9494
rw [forM.loop]
@@ -101,8 +101,8 @@ private theorem forM_loop_eq_forM_range' [Monad m] (r : Std.Range) (f : Nat →
101101
rw [Nat.div_eq_iff] <;> omega
102102
simp [this]
103103

104-
@[simp] theorem forM_eq_forM_range' [Monad m] (r : Std.Range) (f : Nat → m PUnit) :
104+
@[simp] theorem forM_eq_forM_range' [Monad m] (r : Range) (f : Nat → m PUnit) :
105105
forM r f = forM (List.range' r.start r.size r.step) f := by
106106
simp only [forM, Range.forM, forM_loop_eq_forM_range', size]
107107

108-
end Std.Range
108+
end Std.Legacy.Range

src/Init/Data/Stream.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ instance : ToStream (Subarray α) (Subarray α) where
8282
instance : ToStream String Substring.Raw where
8383
toStream s := s.toRawSubstring
8484

85-
instance : ToStream Std.Range Std.Range where
85+
instance : ToStream Std.Legacy.Range Std.Legacy.Range where
8686
toStream r := r
8787

8888
instance [Stream ρ α] [Stream γ β] : Stream (ρ × γ) (α × β) where
@@ -108,7 +108,7 @@ instance : Stream (Subarray α) α where
108108
else
109109
none
110110

111-
instance : Stream Std.Range Nat where
111+
instance : Stream Std.Legacy.Range Nat where
112112
next? r :=
113113
if r.start < r.stop then
114114
some (r.start, { r with start := r.start + r.step })

src/Lean/PrettyPrinter/Delaborator/Builtins.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,9 +1291,9 @@ def delabPProdMk : Delab := delabPProdMkCore ``PProd.mk
12911291
@[builtin_delab app.MProd.mk]
12921292
def delabMProdMk : Delab := delabPProdMkCore ``MProd.mk
12931293

1294-
@[builtin_delab app.Std.Range.mk]
1294+
@[builtin_delab app.Std.Legacy.Range.mk]
12951295
def delabRange : Delab := whenPPOption getPPNotation do
1296-
-- Std.Range.mk : (start : Nat) → (stop : Nat) → (step : Nat) → 0 < step → Std.Range
1296+
-- Std.Legacy.Range.mk : (start : Nat) → (stop : Nat) → (step : Nat) → 0 < step → Std.Legacy.Range
12971297
guard <| (← getExpr).getAppNumArgs == 4
12981298
-- `none` if the start is `0`
12991299
let start? ← withNaryArg 0 do

src/Std/Do/Triple/SpecLemmas.lean

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public import Init.Data.Iterators.Lemmas.Combinators.FilterMap
2424
This module contains Hoare triple specifications for some functions in Core.
2525
-/
2626

27-
namespace Std.Range
27+
namespace Std.Legacy.Range
2828

29-
abbrev toList (r : Std.Range) : List Nat :=
29+
abbrev toList (r : Std.Legacy.Range) : List Nat :=
3030
List.range' r.start ((r.stop - r.start + r.step - 1) / r.step) r.step
3131

32-
end Std.Range
32+
end Std.Legacy.Range
3333

3434
namespace List
3535

@@ -718,23 +718,23 @@ theorem Spec.foldlM_list_const_inv
718718
@[spec]
719719
theorem Spec.forIn'_range {β : Type u} {m : Type u → Type v} {ps : PostShape}
720720
[Monad m] [WPMonad m ps]
721-
{xs : Std.Range} {init : β} {f : (a : Nat) → a ∈ xs → β → m (ForInStep β)}
721+
{xs : Std.Legacy.Range} {init : β} {f : (a : Nat) → a ∈ xs → β → m (ForInStep β)}
722722
(inv : Invariant xs.toList β ps)
723723
(step : ∀ pref cur suff (h : xs.toList = pref ++ cur :: suff) b,
724724
Triple
725-
(f cur (by simp [Std.Range.mem_of_mem_range', h]) b)
725+
(f cur (by simp [Std.Legacy.Range.mem_of_mem_range', h]) b)
726726
(inv.1 (⟨pref, cur::suff, h.symm⟩, b))
727727
(fun r => match r with
728728
| .yield b' => inv.1 (⟨pref ++ [cur], suff, by simp [h]⟩, b')
729729
| .done b' => inv.1 (⟨xs.toList, [], by simp⟩, b'), inv.2)) :
730730
Triple (forIn' xs init f) (inv.1 (⟨[], xs.toList, rfl⟩, init)) (fun b => inv.1 (⟨xs.toList, [], by simp⟩, b), inv.2) := by
731-
simp only [Std.Range.forIn'_eq_forIn'_range', Std.Range.size, Std.Range.size.eq_1]
731+
simp only [Std.Legacy.Range.forIn'_eq_forIn'_range', Std.Legacy.Range.size, Std.Legacy.Range.size.eq_1]
732732
apply Spec.forIn'_list inv (fun c hcur b => step c hcur b)
733733

734734
@[spec]
735735
theorem Spec.forIn_range {β : Type u} {m : Type u → Type v} {ps : PostShape}
736736
[Monad m] [WPMonad m ps]
737-
{xs : Std.Range} {init : β} {f : Nat → β → m (ForInStep β)}
737+
{xs : Std.Legacy.Range} {init : β} {f : Nat → β → m (ForInStep β)}
738738
(inv : Invariant xs.toList β ps)
739739
(step : ∀ pref cur suff (h : xs.toList = pref ++ cur :: suff) b,
740740
Triple
@@ -744,7 +744,7 @@ theorem Spec.forIn_range {β : Type u} {m : Type u → Type v} {ps : PostShape}
744744
| .yield b' => inv.1 (⟨pref ++ [cur], suff, by simp [h]⟩, b')
745745
| .done b' => inv.1 (⟨xs.toList, [], by simp⟩, b'), inv.2)) :
746746
Triple (forIn xs init f) (inv.1 (⟨[], xs.toList, rfl⟩, init)) (fun b => inv.1 (⟨xs.toList, [], by simp⟩, b), inv.2) := by
747-
simp only [Std.Range.forIn_eq_forIn_range', Std.Range.size]
747+
simp only [Std.Legacy.Range.forIn_eq_forIn_range', Std.Legacy.Range.size]
748748
apply Spec.forIn_list inv step
749749

750750
open Std.PRange in

tests/lean/run/delabStdRange.lean

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
/-!
2-
# Tests for delaborators for Std.Range and Std.PRange
2+
# Tests for delaborators for Std.Legacy.Range and Std.PRange
33
-/
44

55
/-!
6-
## Tests for `Std.Range`
6+
## Tests for `Std.Legacy.Range`
77
-/
88

99
/-!
1010
Default lower bound and step
1111
-/
12-
/-- info: [:10] : Std.Range -/
13-
#guard_msgs in #check Std.Range.mk 0 10 1 (by grind)
12+
/-- info: [:10] : Std.Legacy.Range -/
13+
#guard_msgs in #check Std.Legacy.Range.mk 0 10 1 (by grind)
1414

1515
/-!
1616
Default step
1717
-/
18-
/-- info: [5:10] : Std.Range -/
19-
#guard_msgs in #check Std.Range.mk 5 10 1 (by grind)
18+
/-- info: [5:10] : Std.Legacy.Range -/
19+
#guard_msgs in #check Std.Legacy.Range.mk 5 10 1 (by grind)
2020

2121
/-!
2222
Default lower bound
2323
-/
24-
/-- info: [:10:2] : Std.Range -/
25-
#guard_msgs in #check Std.Range.mk 0 10 2 (by grind)
24+
/-- info: [:10:2] : Std.Legacy.Range -/
25+
#guard_msgs in #check Std.Legacy.Range.mk 0 10 2 (by grind)
2626

2727
/-!
2828
No defaults
2929
-/
30-
/-- info: [5:10:2] : Std.Range -/
31-
#guard_msgs in #check Std.Range.mk 5 10 2 (by grind)
30+
/-- info: [5:10:2] : Std.Legacy.Range -/
31+
#guard_msgs in #check Std.Legacy.Range.mk 5 10 2 (by grind)
3232

3333
/-!
3434
Disable notation
3535
-/
36-
/-- info: { stop := 10, step_pos := _check._proof_1 } : Std.Range -/
37-
#guard_msgs in set_option pp.notation false in #check Std.Range.mk 0 10 1 (by grind)
36+
/-- info: { stop := 10, step_pos := _check._proof_1 } : Std.Legacy.Range -/
37+
#guard_msgs in set_option pp.notation false in #check Std.Legacy.Range.mk 0 10 1 (by grind)
3838

3939
/-!
4040
## Tests for `Std.PRange`

tests/lean/run/grind_lint_std_misc.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ import Lean.Elab.Tactic.Grind.LintExceptions
44
/-! Check remaining Std sub-namespaces: -/
55

66
#guard_msgs in
7-
#grind_lint check (min := 20) in Std.Do Std.Range Std.Tactic
7+
#grind_lint check (min := 20) in Std.Do Std.Legacy.Range Std.Tactic

0 commit comments

Comments
 (0)