Skip to content

Commit 584eb1e

Browse files
committed
[ elab ] Make %runElab expressions to have unrestricted quantity
1 parent dd95026 commit 584eb1e

File tree

10 files changed

+93
-3
lines changed

10 files changed

+93
-3
lines changed

CHANGELOG_NEXT.md

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ This CHANGELOG describes the merged but unreleased changes. Please see [CHANGELO
2828

2929
### Compiler changes
3030

31+
* Elaborator script's expression under the `%runElab` is now typechecked in the context
32+
of quantity `0`, because it is present and works only at the compile time
33+
3134
#### RefC Backend
3235

3336
* Fix invalid memory read onf strSubStr.

src/Algebra/Preorder.idr

+6
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ public export
2929
interface Preorder a => Top a where
3030
top : a
3131
topAbs : {x : a} -> x <= top = True
32+
33+
||| The least bound of a bounded lattice
34+
public export
35+
interface Preorder a => Bot a where
36+
bot : a
37+
botAbs : {x : a} -> bot <= x = True

src/Algebra/ZeroOneOmega.idr

+8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ Top ZeroOneOmega where
7272
topAbs {x = Rig1} = Refl
7373
topAbs {x = RigW} = Refl
7474

75+
||| The bottom value of a lattice
76+
export
77+
Bot ZeroOneOmega where
78+
bot = Rig0
79+
botAbs {x = Rig0} = Refl
80+
botAbs {x = Rig1} = Refl
81+
botAbs {x = RigW} = Refl
82+
7583
----------------------------------------
7684

7785
rigPlusAssociative : (x, y, z : ZeroOneOmega) ->

src/TTImp/Elab/RunElab.idr

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ checkRunElab rig elabinfo nest env fc reqExt script exp
367367
throw (GenericMsg fc "%language ElabReflection not enabled")
368368
let n = NS reflectionNS (UN $ Basic "Elab")
369369
elabtt <- appCon fc defs n [expected]
370-
(stm, sty) <- runDelays (const True) $
371-
check rig elabinfo nest env script (Just (gnf env elabtt))
370+
(stm, _) <- runDelays (const True) $
371+
check bot elabinfo nest env script (Just (gnf env elabtt))
372372
solveConstraints inTerm Normal
373373
defs <- get Ctxt -- checking might have resolved some holes
374374
ntm <- elabScript rig fc nest env

src/TTImp/ProcessRunElab.idr

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ processRunElab eopts nest env fc tm
3838
unit <- getCon fc defs (builtin "Unit")
3939
exp <- appCon fc defs n [unit]
4040

41-
stm <- checkTerm tidx InExpr eopts nest env tm (gnf env exp)
41+
e <- newRef EST $ initEStateSub tidx env Refl
42+
(stm, _) <- check bot (initElabInfo InExpr) nest env tm $ Just $ gnf env exp
4243
ignore $ elabScript top fc nest env !(nfOpts withAll defs env stm) Nothing
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module NoEscape
2+
3+
import Language.Reflection
4+
5+
%language ElabReflection
6+
7+
0 n : Nat
8+
n = 3
9+
10+
0 elabScript : Elab Nat
11+
elabScript = pure n
12+
13+
failing "n is not accessible in this context"
14+
15+
m : Nat
16+
m = %runElab elabScript
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
||| Check that we cannot implement function illegally escaping zero quantity using elaboration reflection
2+
module NoEscapePar
3+
4+
import Language.Reflection
5+
6+
%language ElabReflection
7+
8+
escScr : Elab $ (0 _ : a) -> a
9+
escScr = check $ ILam EmptyFC M0 ExplicitArg (Just `{x}) `(a) `(x)
10+
11+
failing "x is not accessible in this context"
12+
13+
esc : (0 _ : a) -> a
14+
esc = %runElab escScr
15+
16+
escd : (0 _ : a) -> a
17+
18+
0 escd' : (0 _ : a) -> a
19+
20+
escDecl : Name -> Elab Unit
21+
escDecl name = declare [
22+
IDef EmptyFC name [
23+
PatClause EmptyFC
24+
-- lhs
25+
(IApp EmptyFC (IVar EmptyFC name) (IBindVar EmptyFC "x"))
26+
-- rhs
27+
`(x)
28+
]
29+
]
30+
31+
%runElab escDecl `{escd'}
32+
33+
failing "x is not accessible in this context"
34+
35+
%runElab escDecl `{escd}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module RunElab0
2+
3+
import Language.Reflection
4+
5+
%language ElabReflection
6+
7+
0 elabScript : Elab Unit
8+
elabScript = pure ()
9+
10+
x : Unit
11+
x = %runElab elabScript
12+
13+
%runElab elabScript
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1/1: Building RunElab0 (RunElab0.idr)
2+
1/1: Building NoEscape (NoEscape.idr)
3+
1/1: Building NoEscapePar (NoEscapePar.idr)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
. ../../../testutils.sh
2+
3+
check RunElab0.idr
4+
check NoEscape.idr
5+
check NoEscapePar.idr

0 commit comments

Comments
 (0)