Skip to content

Commit 491629c

Browse files
committed
[ elab ] Make %runElab expressions to have unrestricted quantity
1 parent 0029257 commit 491629c

File tree

9 files changed

+90
-3
lines changed

9 files changed

+90
-3
lines changed

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
@@ -254,8 +254,8 @@ checkRunElab rig elabinfo nest env fc script exp
254254
throw (GenericMsg fc "%language ElabReflection not enabled")
255255
let n = NS reflectionNS (UN $ Basic "Elab")
256256
elabtt <- appCon fc defs n [expected]
257-
(stm, sty) <- runDelays (const True) $
258-
check rig elabinfo nest env script (Just (gnf env elabtt))
257+
(stm, _) <- runDelays (const True) $
258+
check bot elabinfo nest env script (Just (gnf env elabtt))
259259
solveConstraints inTerm Normal
260260
defs <- get Ctxt -- checking might have resolved some holes
261261
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 SubRefl
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)