@@ -12,17 +12,35 @@ import Lean.Language.Basic
12
12
13
13
namespace Lean.Elab.Command
14
14
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
+ -/
15
26
structure Scope where
16
27
header : String
17
28
opts : Options := {}
29
+ /-- The current namespace: by default, this is an anonymous namespace -/
18
30
currNamespace : Name := Name.anonymous
31
+ /-- All currently `open`ed namespaces -/
19
32
openDecls : List OpenDecl := []
33
+ /-- All universe levels which apply in the current scope -/
20
34
levelNames : List Name := []
21
- /-- section variables -/
35
+ /-- All variable binders which apply in the current scope -/
22
36
varDecls : Array (TSyntax ``Parser.Term.bracketedBinder) := #[]
23
37
/-- Globally unique internal identifiers for the `varDecls` -/
24
38
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
+ -/
26
44
isNoncomputable : Bool := false
27
45
deriving Inhabited
28
46
@@ -230,6 +248,7 @@ private def ioErrorToMessage (ctx : Context) (ref : Syntax) (err : IO.Error) : M
230
248
instance : MonadLiftT IO CommandElabM where
231
249
monadLift := liftIO
232
250
251
+ /-- Return the current scope. -/
233
252
def getScope : CommandElabM Scope := do pure (← get).scopes.head!
234
253
235
254
instance : MonadResolveName CommandElabM where
@@ -612,6 +631,9 @@ Interrupt and abort exceptions are caught but not logged.
612
631
private def liftAttrM {α} (x : AttrM α) : CommandElabM α := do
613
632
liftCoreM x
614
633
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. -/
615
637
def getScopes : CommandElabM (List Scope) := do
616
638
pure (← get).scopes
617
639
0 commit comments