Skip to content

Commit a051dd5

Browse files
committed
doc: document Scope
or extend existing documentation
1 parent de96b6d commit a051dd5

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/Lean/Elab/Command.lean

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,35 @@ import Lean.Language.Basic
1212

1313
namespace Lean.Elab.Command
1414

15+
/--
16+
A `Scope` collects context information which is inherently scoped: this contains
17+
the current namespace and information about `open`, `universe` or `variable` declarations.
18+
There is always a base scope; scopes can be nested.
19+
20+
`universe`, `open` and `variable` declarations only modify the current scope
21+
(and all scopes nested below it): these declarations usually *append* to the
22+
context in the current scope; `variable` statements can also change existing items.
23+
(XXX Is shadowing possible? If so, this sentence should be reworded.)
24+
Unclosed scopes are automatically closed at the end of the current module.
25+
-/
1526
structure Scope where
1627
header : String
1728
opts : Options := {}
29+
/-- The current namespace: by default, this is an anonymous namespace -/
1830
currNamespace : Name := Name.anonymous
31+
/-- All currently `open`ed namespaces -/
1932
openDecls : List OpenDecl := []
33+
/-- All universe levels which apply in the current scope -/
2034
levelNames : List Name := []
21-
/-- section variables -/
35+
/-- All variable binders which apply in the current scope -/
2236
varDecls : Array (TSyntax ``Parser.Term.bracketedBinder) := #[]
2337
/-- Globally unique internal identifiers for the `varDecls` -/
2438
varUIds : Array Name := #[]
25-
/-- noncomputable sections automatically add the `noncomputable` modifier to any declaration we cannot generate code for. -/
39+
/-- Whether the current scope is (or is nested inside) a `noncomputable` `section`:
40+
in this case, automatically add the `noncomputable` modifier to any declaration
41+
we cannot generate code for.
42+
A scope is noncomputable if it is a noncomputable section or its parent is noncomputable.
43+
-/
2644
isNoncomputable : Bool := false
2745
deriving Inhabited
2846

@@ -230,6 +248,7 @@ private def ioErrorToMessage (ctx : Context) (ref : Syntax) (err : IO.Error) : M
230248
instance : MonadLiftT IO CommandElabM where
231249
monadLift := liftIO
232250

251+
/-- Return the current scope. -/
233252
def getScope : CommandElabM Scope := do pure (← get).scopes.head!
234253

235254
instance : MonadResolveName CommandElabM where
@@ -612,6 +631,9 @@ Interrupt and abort exceptions are caught but not logged.
612631
private def liftAttrM {α} (x : AttrM α) : CommandElabM α := do
613632
liftCoreM x
614633

634+
/-- Return the stack of all currently active scopes:
635+
the base scope always comes last; new scopes are prepended in the front.
636+
In particular, the current scope is always the first element. -/
615637
def getScopes : CommandElabM (List Scope) := do
616638
pure (← get).scopes
617639

0 commit comments

Comments
 (0)