Skip to content

Commit 9b903ec

Browse files
committed
WIP delete me later (it compiles with holes, need filling)
(cherry picked from commit 3578f70)
1 parent b2575c6 commit 9b903ec

File tree

15 files changed

+162
-138
lines changed

15 files changed

+162
-138
lines changed

src/Compiler/ANF.idr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ mlet fc val sc
194194

195195
bindAsFresh :
196196
{auto v : Ref Next Int} ->
197-
(args : List Name) -> AVars vars' ->
198-
Core (List Int, AVars (Scope.ext vars' args))
199-
bindAsFresh [] vs = pure ([], vs)
200-
bindAsFresh (n :: ns) vs
197+
(args : Scope) -> AVars vars' ->
198+
Core (List Int, AVars (vars' ++ args))
199+
bindAsFresh [<] vs = pure ([], vs)
200+
bindAsFresh (ns :< n) vs
201201
= do i <- nextVar
202-
mapFst (i ::) <$> bindAsFresh ns (vs :< i)
202+
bimap (i ::) (:< i) <$> bindAsFresh ns vs
203203

204204
mutual
205205
anfArgs : {auto v : Ref Next Int} ->
@@ -211,7 +211,7 @@ mutual
211211

212212
anf : {auto v : Ref Next Int} ->
213213
AVars vars -> Lifted vars -> Core ANF
214-
anf vs (LLocal fc p) = pure $ AV fc (ALocal (lookup p vs))
214+
anf vs (LLocal fc p) = pure $ AV fc (ALocal (lookup vs p))
215215
anf vs (LAppName fc lazy n args)
216216
= anfArgs fc vs args (AAppName fc lazy n)
217217
anf vs (LUnderApp fc n m args)
@@ -264,12 +264,12 @@ export
264264
toANF : LiftedDef -> Core ANFDef
265265
toANF (MkLFun args scope sc)
266266
= do v <- newRef Next (the Int 0)
267-
(iargs, vsNil) <- bindAsFresh (cast args) AVars.empty
267+
(iargs, vsNil) <- bindAsFresh args AVars.empty
268268
let vs : AVars args
269269
:= rewrite sym $ appendLinLeftNeutral args in
270-
rewrite snocAppendAsFish Scope.empty args in vsNil
271-
(iargs', vs) <- bindAsFresh (cast scope) vs
272-
sc' <- anf (rewrite snocAppendAsFish args scope in vs) sc
270+
vsNil
271+
(iargs', vs) <- bindAsFresh scope vs
272+
sc' <- anf vs sc
273273
pure $ MkAFun (iargs ++ iargs') sc'
274274
toANF (MkLCon t a ns) = pure $ MkACon t a ns
275275
toANF (MkLForeign ccs fargs t) = pure $ MkAForeign ccs fargs t

src/Compiler/CaseOpts.idr

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ shiftVar : {outer : Scope} -> {args : List Name} ->
4747
NVar n ((vars :< x <>< args) ++ outer)
4848
shiftVar nvar
4949
= let out = mkSizeOf outer in
50-
case locateNVar out nvar of
50+
case locateNVar out (?sdfd nvar) of
5151
Left nvar => embed nvar
52-
Right (MkNVar p) => weakenNs out (shiftUndersN (mkSizeOf _) p)
52+
Right (MkNVar p) => weakenNs out (shiftUndersN (mkSizeOf _) (?sdf p))
5353

5454
mutual
5555
shiftBinder : {outer, args : _} ->
@@ -95,11 +95,13 @@ mutual
9595
CConAlt (((vars <>< args) :< old) ++ outer) ->
9696
CConAlt ((vars :< new <>< args) ++ outer)
9797
shiftBinderConAlt new (MkConAlt n ci t args' sc)
98-
= let sc' : CExp (((vars <>< args) :< old) ++ (outer <>< args'))
99-
= rewrite sym $ snocAppendFishAssociative (vars <>< args :< old) outer args' in sc in
98+
= let sc' : CExp (((vars <>< args) :< old) ++ (Scope.addInner outer args'))
99+
-- = rewrite sym $ snocAppendFishAssociative (vars <>< args :< old) outer (?sdfdf args') in sc in
100+
= (?sdfd2 sc) in
100101
MkConAlt n ci t args' $
101-
rewrite snocAppendFishAssociative (vars :< new <>< args) outer args'
102-
in shiftBinder new {outer = outer <>< args'} sc'
102+
-- rewrite snocAppendFishAssociative (vars :< new <>< args) outer (?fdgdfg args')
103+
-- in shiftBinder new {outer = outer <>< args'} sc'
104+
?sdfdsf $ shiftBinder new (?vbnvvbn sc')
103105

104106
shiftBinderConstAlt : {outer, args : _} ->
105107
(new : Name) ->
@@ -123,8 +125,8 @@ tryLiftOut : (new : Name) ->
123125
tryLiftOut new [] = Just []
124126
tryLiftOut new (MkConAlt n ci t args (CLam fc x sc) :: as)
125127
= do as' <- tryLiftOut new as
126-
let sc' = liftOutLambda new sc
127-
pure (MkConAlt n ci t args sc' :: as')
128+
let sc' = liftOutLambda new (?sdfdf sc)
129+
pure (MkConAlt n ci t args (?sfdfgdfg sc') :: as')
128130
tryLiftOut _ _ = Nothing
129131

130132
tryLiftOutConst : (new : Name) ->
@@ -318,8 +320,8 @@ doCaseOfCase fc x xalts xdef alts def
318320
updateAlt (MkConAlt n ci t args sc)
319321
= MkConAlt n ci t args $
320322
CConCase fc sc
321-
(map (weakensN (mkSizeOf args)) alts)
322-
(map (weakensN (mkSizeOf args)) def)
323+
(?bvnvbnvbnbn (map (weakensN (mkSizeOf (?cvbcbcvb args))) alts))
324+
(?sdfsdf (map (weakensN (mkSizeOf (?sdffsdf args))) def))
323325

324326
updateDef : CExp vars -> CExp vars
325327
updateDef sc = CConCase fc sc alts def

src/Compiler/CompileExpr.idr

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Core.Name
1010
import Core.Normalise
1111
import Core.Options
1212
import Core.TT
13+
import Core.TT.Subst
1314
import Core.Value
1415

1516
import Data.List
@@ -66,7 +67,7 @@ etaExpand i Z exp args = mkApp exp (map (mkLocal (getFC exp)) (reverse args))
6667
etaExpand i (S k) exp args
6768
= CLam (getFC exp) (MN "eta" i)
6869
(etaExpand (i + 1) k (weaken exp)
69-
(first :: map weakenVar args))
70+
(first :: map later args))
7071

7172
export
7273
expandToArity : Nat -> CExp vars -> List (CExp vars) -> CExp vars
@@ -229,7 +230,7 @@ mutual
229230
Just gdef <- lookupCtxtExact x (gamma defs)
230231
| Nothing => -- primitive type match
231232
do xn <- getFullName x
232-
pure $ MkConAlt xn TYCON Nothing args !(toCExpTree n sc)
233+
pure $ MkConAlt xn TYCON Nothing (cast args) !(?sdfds $ toCExpTree n sc)
233234
:: !(conCases n ns)
234235
case (definition gdef) of
235236
DCon _ arity (Just pos) => conCases n ns -- skip it
@@ -239,8 +240,13 @@ mutual
239240
sc' <- toCExpTree n sc
240241
ns' <- conCases n ns
241242
if dcon (definition gdef)
242-
then pure $ MkConAlt xn !(dconFlag xn) (Just tag) (toList args') (?dfsdf $ shrinkCExp sub (?bfdgdfg sc')) :: ns'
243-
else pure $ MkConAlt xn !(dconFlag xn) Nothing (toList args') (?cbcbcv $ shrinkCExp sub (?gffgh sc')) :: ns'
243+
then pure $ MkConAlt xn !(dconFlag xn) (Just tag) args' (?dfsdf $ shrinkCExp sub (?bfdgdfg (?sdfdf sc'))) :: ns'
244+
else pure $ MkConAlt xn !(dconFlag xn) Nothing args' (?cbcbcv $ shrinkCExp sub (?gffgh (?sdfsdfd sc'))) :: ns'
245+
-- $ rewrite sym $ snocAppendAsFish vars args in
246+
-- rewrite fishAsSnocAppend vars args in
247+
-- embed th
248+
249+
244250
where
245251
dcon : Def -> Bool
246252
dcon (DCon {}) = True
@@ -307,11 +313,13 @@ mutual
307313
:= rewrite sym $ fishAsSnocAppend vars args in sc'
308314

309315
let scope : CExp ((vars ++ [<MN "eff" 0]) ++ cast args)
316+
-- scope = rewrite sym $ appendAssociative vars [<MN "eff" 0] (cast args) in
317+
-- insertNames {outer=cast args}
318+
-- {inner=vars}
319+
-- {ns = [<MN "eff" 0]}
320+
-- (mkSizeOf _) (mkSizeOf _) sc''
310321
scope = rewrite sym $ appendAssociative vars [<MN "eff" 0] (cast args) in
311-
insertNames {outer=cast args}
312-
{inner=vars}
313-
{ns = [<MN "eff" 0]}
314-
(mkSizeOf _) (mkSizeOf _) sc''
322+
?sdfdsf $ insertNames (mkSizeOf _) (mkSizeOf _) sc''
315323
let tm = CLet fc (MN "eff" 0) NotInline scr (substs (cast s) env scope)
316324
log "compiler.newtype.world" 50 "Kept the scrutinee \{show tm}, scope: \{show scope}"
317325
pure (Just tm)
@@ -546,7 +554,7 @@ lamRHS ns tm
546554
tmExp = substs s env (rewrite appendLinLeftNeutral ns in tm)
547555
newArgs = getNewArgs env
548556
bounds = mkBounds newArgs
549-
expLocs = mkLocals zero {vars = Scope.empty} bounds tmExp in
557+
expLocs = mkLocals bounds zero tmExp in
550558
lamBind (getFC tm) _ expLocs
551559
where
552560
lamBind : FC -> (ns : Scope) -> CExp ns -> ClosedCExp
@@ -578,7 +586,7 @@ toCDef n ty _ (ExternDef arity)
578586
-- TODO has quadratic runtime
579587
getVars : ArgList k ns -> List (Var ns)
580588
getVars Z = []
581-
getVars (S rest) = first :: map weakenVar (getVars rest)
589+
getVars (S rest) = first :: map later (getVars rest)
582590

583591
toCDef n ty _ (ForeignDef arity cs)
584592
= do defs <- get Ctxt
@@ -591,7 +599,7 @@ toCDef n ty _ (Builtin {arity} op)
591599
-- TODO has quadratic runtime
592600
getVars : ArgList k ns -> Vect k (Var ns)
593601
getVars Z = []
594-
getVars (S rest) = first :: map weakenVar (getVars rest)
602+
getVars (S rest) = first :: map later (getVars rest)
595603

596604
toCDef n _ _ (DCon tag arity pos)
597605
= do let nt = snd <$> pos

src/Compiler/ES/TailRec.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ tcDoneName gi = MN "TcDone" gi
249249
conAlt : TcGroup -> TcFunction -> NamedConAlt
250250
conAlt (MkTcGroup tcIx funs) (MkTcFunction n ix args exp) =
251251
let name = tcContinueName tcIx ix
252-
in MkNConAlt name DATACON (Just ix) args (toTc exp)
252+
in MkNConAlt name DATACON (Just ix) (?dfgdfg args) (toTc exp)
253253

254254
where
255255
mutual

src/Compiler/ES/ToAst.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ mutual
223223
-- We map the list of args to the corresponding
224224
-- data projections (field accessors). They'll
225225
-- be then properly inlined when converting `x`.
226-
projections sc args
226+
projections sc (?sdfsdf args)
227227
MkEConAlt (tag n tg) ci <$> stmt e x
228228

229229
-- a single branch in a pattern match on a constant

src/Compiler/Inline.idr

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ mutual
130130
usedCon : {free : _} ->
131131
{idx : Nat} -> (0 p : IsVar n idx free) -> CConAlt free -> Int
132132
usedCon n (MkConAlt _ _ _ args sc)
133-
= let MkVar n' = weakensN (mkSizeOf args) (MkVar n) in
134-
used n' sc
133+
= let MkVar n' = weakensN (mkSizeOf (?sdfsdf args)) (MkVar n) in
134+
used n' (?sdfsddgff sc)
135135

136136
usedConst : {free : _} ->
137137
{idx : Nat} -> (0 p : IsVar n idx free) -> CConstAlt free -> Int
@@ -313,10 +313,12 @@ mutual
313313
FC -> List Name -> EEnv free vars -> Stack free -> CConAlt (Scope.addInner free vars) ->
314314
Core (CConAlt free)
315315
evalAlt {free} {vars} fc rec env stk (MkConAlt n ci t args sc)
316-
= do (bs, env') <- extendLoc fc env args
316+
= do (bs, env') <- extendLoc fc env (?gdffdg args)
317317
scEval <- eval rec env' stk
318-
(rewrite sym $ snocAppendFishAssociative free vars args in sc)
319-
pure $ MkConAlt n ci t args (rewrite snocAppendFishAssociative free Scope.empty args in refsToLocals bs scEval)
318+
-- (rewrite sym $ snocAppendFishAssociative free vars (?vcbb args) in sc)
319+
(?vbcvb sc)
320+
-- pure $ MkConAlt n ci t args (rewrite snocAppendFishAssociative free Scope.empty (?adsasd args) in refsToLocals bs scEval)
321+
pure $ MkConAlt n ci t args (?sdfsdf2 $ refsToLocals bs scEval)
320322

321323
evalConstAlt : {vars, free : _} ->
322324
{auto c : Ref Ctxt Defs} ->
@@ -338,12 +340,13 @@ mutual
338340
pickAlt {vars} {free} rec env stk con@(CCon fc n ci t args) (MkConAlt n' _ t' args' sc :: alts) def
339341
=
340342
if matches n t n' t'
341-
then case checkLengthMatch args' args of
343+
then case checkLengthMatch (?fsdf args') args of
342344
Nothing => pure Nothing
343345
Just m =>
344-
do let env' = extend env args' args m
346+
do let env' = extend env (?vcb args') args (?vdfdfg m)
345347
pure $ Just !(eval rec env' stk
346-
(rewrite sym $ snocAppendFishAssociative free vars args' in sc))
348+
-- (rewrite sym $ snocAppendFishAssociative free vars (?sdfsdf5 args') in sc))
349+
(?fdfgdfg sc))
347350
else pickAlt rec env stk con alts def
348351
where
349352
matches : Name -> Maybe Int -> Name -> Maybe Int -> Bool

0 commit comments

Comments
 (0)