Skip to content

Commit 01dbbee

Browse files
KhaTwoFX
andauthored
feat: do not export def bodies by default (#8221)
This PR adjusts the experimental module system to not export the bodies of `def`s unless opted out by the new attribute `@[expose]` on the `def` or on a surrounding `section`. --------- Co-authored-by: Markus Himmel <[email protected]>
1 parent 9486421 commit 01dbbee

File tree

139 files changed

+449
-251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+449
-251
lines changed

script/benchReelabRss.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ open Lean.JsonRpc
88
Tests language server memory use by repeatedly re-elaborate a given file.
99
1010
NOTE: only works on Linux for now.
11-
ot to touch the imports for usual files.
1211
-/
1312

1413
def main (args : List String) : IO Unit := do
1514
let leanCmd :: file :: iters :: args := args | panic! "usage: script <lean> <file> <#iterations> <server-args>..."
16-
let uri := s!"file:///{file}"
15+
let file ← IO.FS.realPath file
16+
let uri := s!"file://{file}"
1717
Ipc.runWith leanCmd (#["--worker", "-DstderrAsMessages=false"] ++ args ++ #[uri]) do
1818
-- for use with heaptrack:
1919
--Ipc.runWith "heaptrack" (#[leanCmd, "--worker", "-DstderrAsMessages=false"] ++ args ++ #[uri]) do

src/Init/BinderNameHint.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ This gadget is supported by
4040
It is ineffective in other positions (hyptheses of rewrite rules) or when used by other tactics
4141
(e.g. `apply`).
4242
-/
43-
@[simp ↓]
43+
@[simp ↓, expose]
4444
def binderNameHint {α : Sort u} {β : Sort v} {γ : Sort w} (v : α) (binder : β) (e : γ) : γ := e

src/Init/Control/Except.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ end Except
127127
/--
128128
Adds exceptions of type `ε` to a monad `m`.
129129
-/
130-
def ExceptT (ε : Type u) (m : Type u → Type v) (α : Type u) : Type v :=
130+
@[expose] def ExceptT (ε : Type u) (m : Type u → Type v) (α : Type u) : Type v :=
131131
m (Except ε α)
132132

133133
/--

src/Init/Control/ExceptCps.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Adds exceptions of type `ε` to a monad `m`.
1818
Instead of using `Except ε` to model exceptions, this implementation uses continuation passing
1919
style. This has different performance characteristics from `ExceptT ε`.
2020
-/
21-
def ExceptCpsT (ε : Type u) (m : Type u → Type v) (α : Type u) := (β : Type u) → (α → m β) → (ε → m β) → m β
21+
@[expose] def ExceptCpsT (ε : Type u) (m : Type u → Type v) (α : Type u) := (β : Type u) → (α → m β) → (ε → m β) → m β
2222

2323
namespace ExceptCpsT
2424

src/Init/Control/Id.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def containsFive (xs : List Nat) : Bool := Id.run do
3434
true
3535
```
3636
-/
37-
def Id (type : Type u) : Type u := type
37+
@[expose] def Id (type : Type u) : Type u := type
3838

3939
namespace Id
4040

@@ -56,7 +56,7 @@ Runs a computation in the identity monad.
5656
This function is the identity function. Because its parameter has type `Id α`, it causes
5757
`do`-notation in its arguments to use the `Monad Id` instance.
5858
-/
59-
@[always_inline, inline]
59+
@[always_inline, inline, expose]
6060
protected def run (x : Id α) : α := x
6161

6262
instance [OfNat α n] : OfNat (Id α) n :=

src/Init/Control/Lawful/Instances.lean

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module
77

88
prelude
99
import Init.Control.Lawful.Basic
10-
import Init.Control.Except
10+
import all Init.Control.Except
11+
import all Init.Control.State
1112
import Init.Control.StateRef
1213
import Init.Ext
1314

@@ -98,7 +99,7 @@ end ExceptT
9899

99100
instance : LawfulMonad (Except ε) := LawfulMonad.mk'
100101
(id_map := fun x => by cases x <;> rfl)
101-
(pure_bind := fun _ _ => rfl)
102+
(pure_bind := fun _ _ => by rfl)
102103
(bind_assoc := fun a _ _ => by cases a <;> rfl)
103104

104105
instance : LawfulApplicative (Except ε) := inferInstance
@@ -247,7 +248,7 @@ instance : LawfulMonad (EStateM ε σ) := .mk'
247248
match x s with
248249
| .ok _ _ => rfl
249250
| .error _ _ => rfl)
250-
(pure_bind := fun _ _ => rfl)
251+
(pure_bind := fun _ _ => by rfl)
251252
(bind_assoc := fun x _ _ => funext <| fun s => by
252253
dsimp only [EStateM.instMonad, EStateM.bind]
253254
match x s with

src/Init/Control/Option.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ instance : ToBool (Option α) := ⟨Option.isSome⟩
2020
Adds the ability to fail to a monad. Unlike ordinary exceptions, there is no way to signal why a
2121
failure occurred.
2222
-/
23-
def OptionT (m : Type u → Type v) (α : Type u) : Type v :=
23+
@[expose] def OptionT (m : Type u → Type v) (α : Type u) : Type v :=
2424
m (Option α)
2525

2626
/--

src/Init/Control/State.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Adds a mutable state of type `σ` to a monad.
2222
Actions in the resulting monad are functions that take an initial state and return, in `m`, a tuple
2323
of a value and a state.
2424
-/
25-
def StateT (σ : Type u) (m : Type u → Type v) (α : Type u) : Type (max u v) :=
25+
@[expose] def StateT (σ : Type u) (m : Type u → Type v) (α : Type u) : Type (max u v) :=
2626
σ → m (α × σ)
2727

2828
/--
@@ -47,7 +47,7 @@ A tuple-based state monad.
4747
Actions in `StateM σ` are functions that take an initial state and return a value paired with a
4848
final state.
4949
-/
50-
@[reducible]
50+
@[expose, reducible]
5151
def StateM (σ α : Type u) : Type u := StateT σ Id α
5252

5353
instance {σ α} [Subsingleton σ] [Subsingleton α] : Subsingleton (StateM σ α) where

src/Init/Control/StateCps.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The State monad transformer using CPS style.
1818
An alternative implementation of a state monad transformer that internally uses continuation passing
1919
style instead of tuples.
2020
-/
21-
def StateCpsT (σ : Type u) (m : Type u → Type v) (α : Type u) := (δ : Type u) → σ → (α → σ → m δ) → m δ
21+
@[expose] def StateCpsT (σ : Type u) (m : Type u → Type v) (α : Type u) := (δ : Type u) → σ → (α → σ → m δ) → m δ
2222

2323
namespace StateCpsT
2424

src/Init/Control/StateRef.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ A state monad that uses an actual mutable reference cell (i.e. an `ST.Ref ω σ`
1717
1818
The macro `StateRefT σ m α` infers `ω` from `m`. It should normally be used instead.
1919
-/
20-
def StateRefT' (ω : Type) (σ : Type) (m : TypeType) (α : Type) : Type := ReaderT (ST.Ref ω σ) m α
20+
@[expose] def StateRefT' (ω : Type) (σ : Type) (m : TypeType) (α : Type) : Type := ReaderT (ST.Ref ω σ) m α
2121

2222
/-! Recall that `StateRefT` is a macro that infers `ω` from the `m`. -/
2323

0 commit comments

Comments
 (0)