Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2d62195
[ refactor ] replace showSep and join by `Data.String.joinBy`
GulinSS Nov 2, 2025
8e08e8f
[ refactor ] Introduce `NestedNames.empty`
GulinSS Dec 26, 2025
6255301
[ refactor, linearity ] Optimize erased variable tracking with VarSet
GulinSS Jan 3, 2026
ce842f1
[ refactor ] ScopedSnocList: Swap Scope on SnocList (Phase 2)
GulinSS Jun 2, 2025
d07b9a3
[ refactor ] ScopedSnocList: Review-flavoured squashed refactor
mjustus Jul 30, 2025
e1afd04
Remove `SchemeEval`
GulinSS May 5, 2025
8c1783e
[ refactor ] Add cached mulitplicities
spcfox May 13, 2025
0388019
[ refactor ] Remove `tag` from `TCon`
spcfox May 28, 2025
1488d1c
[ fix ] Early evaluation of external functions
spcfox Jun 24, 2025
03773e6
Disable Resugar for `Builtin` / `PrimOp`
GulinSS Mar 24, 2026
65fc703
Introduce Yaffle Value
GulinSS Apr 24, 2025
70074f9
[ fix ] Revert back `ImpossibleCase` to `impossibleErrOK`
GulinSS Mar 27, 2026
bc20d90
more logs
GulinSS Mar 27, 2026
4047445
[ fix ] align `allM` for SnocList with List version
GulinSS Mar 27, 2026
04442e3
[ fix ] return missed `mightMatch`s
GulinSS Mar 31, 2026
3c377df
add missed cases
GulinSS Mar 31, 2026
9124650
[ ci, tmp ] Run tests in quick check
GulinSS Feb 21, 2025
736918e
[ libs, tmp ] Add 2 minutes timeout in Golden, use bsd/linux timeout
GulinSS Feb 21, 2025
c6a432a
fix trivial expected
GulinSS Apr 2, 2026
8229a77
fix
GulinSS Apr 3, 2026
d646f81
fix
GulinSS Apr 3, 2026
ff92b77
fix better naming
GulinSS Apr 5, 2026
794c264
fix
GulinSS Apr 5, 2026
86a5a43
fix: use expandApps vs expandCases
GulinSS Apr 6, 2026
dd370dc
fix expandApps
GulinSS Apr 6, 2026
1c502c3
fix
GulinSS Apr 9, 2026
f04d71f
logs
GulinSS Apr 11, 2026
c2401b4
logs
GulinSS May 21, 2026
843767a
makeup
GulinSS May 21, 2026
601c58c
logs
GulinSS May 21, 2026
1b7a414
makeup
GulinSS May 21, 2026
17d63b1
Fix irrefutable detection at CallGraph
GulinSS May 21, 2026
0dc1a29
fix
GulinSS May 22, 2026
fca2d1b
main update, remove `renameVars` and `renameTop`
GulinSS May 23, 2026
d8710a6
[ fix #1066 ] reapply: do not insert `TForce` on LHS
mjustus May 26, 2023
eb3728c
Fix no inline for lazy ref
GulinSS Jul 3, 2026
52d7ca1
disable hanging logs
GulinSS Jul 8, 2026
c861dda
Fix `idris2/perf/perf002`
GulinSS Jul 10, 2026
42a8bc0
Fix for `idris2/total/total029`
GulinSS Jul 14, 2026
fc36dbe
[ perf ] Do not wrap local argument in closure
spcfox Jul 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci-idris2-and-libs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ jobs:
- name: Build current version
run: |
make && make install
- name: Test
run: make ci-ubuntu-test INTERACTIVE=''
- name: Artifact Idris2 from previous version
uses: actions/upload-artifact@v4
with:
Expand Down
23 changes: 8 additions & 15 deletions idris2api.ipkg
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ modules =
Core.Binary.Prims,
Core.Case.CaseBuilder,
Core.Case.CaseTree,
Core.Case.CaseTree.Pretty,
Core.Case.Util,
Core.CompileExpr,
Core.CompileExpr.Pretty,
Expand All @@ -62,12 +61,18 @@ modules =
Core.Context.Log,
Core.Context.Pretty,
Core.Context.TTC,
Core.Evaluate,
Core.Evaluate.Convert,
Core.Evaluate.Expand,
Core.Evaluate.Normalise,
Core.Evaluate.Value,
Core.Evaluate.Quote,
Core.Core,
Core.Coverage,
Core.Directory,
Core.Env,
Core.Erase,
Core.FC,
Core.GetType,
Core.Hash,
Core.InitPrimitives,
Core.LinearCheck,
Expand All @@ -76,16 +81,11 @@ modules =
Core.Name.CompatibleVars,
Core.Name.Namespace,
Core.Name.Scoped,
Core.Normalise,
Core.Normalise.Convert,
Core.Normalise.Eval,
Core.Normalise.Quote,
Core.Options,
Core.Options.Log,
Core.Ord,
Core.Primitives,
Core.Reflect,
Core.SchemeEval,
Core.Termination.CallGraph,
Core.Termination.SizeChange,
Core.Termination.Positivity,
Expand All @@ -104,15 +104,8 @@ modules =
Core.TTC,
Core.Unify,
Core.UnifyState,
Core.Value,
Core.WithData,

Core.SchemeEval.Builtins,
Core.SchemeEval.Compile,
Core.SchemeEval.Evaluate,
Core.SchemeEval.Quote,
Core.SchemeEval.ToScheme,

IdrisPaths,

Idris.CommandLine,
Expand Down Expand Up @@ -198,6 +191,7 @@ modules =
Libraries.Data.SnocList.HasLength,
Libraries.Data.SnocList.LengthMatch,
Libraries.Data.SnocList.SizeOf,
Libraries.Data.SnocList.Quantifiers.Extra,
Libraries.Data.Span,
Libraries.Data.SparseMatrix,
Libraries.Data.String,
Expand Down Expand Up @@ -273,7 +267,6 @@ modules =
TTImp.Elab,
TTImp.Impossible,
TTImp.Parser,
TTImp.PartialEval,
TTImp.ProcessBuiltin,
TTImp.ProcessData,
TTImp.ProcessDecls,
Expand Down
6 changes: 2 additions & 4 deletions libs/contrib/Data/List/TailRec.idr
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,15 @@ partitionOnto_ext : (lfts, rgts : List a) -> (p : a -> Bool) -> (xs : List a) ->
partitionOnto_ext lfts rgts p [] = Refl
partitionOnto_ext lfts rgts p (x::xs) with (@@(p x), @@(List.partition p xs))
partitionOnto_ext lfts rgts p (x::xs) | ((True **px_tru), ((dl_l, dl_r)**dl_pf))
= rewrite px_tru in
rewrite dl_pf in
= rewrite dl_pf in
rewrite px_tru in
let u = partitionOnto_ext (x :: lfts) rgts p xs in
coe (\u => (reverseOnto (x :: fst u) lfts
,reverseOnto ( snd u) rgts)
= partitionOnto (x :: lfts) rgts p xs) dl_pf u

partitionOnto_ext lfts rgts p (x::xs) | ((False**px_fls), ((dl_l, dl_r)**dl_pf))
= rewrite px_fls in
rewrite dl_pf in
= rewrite dl_pf in
rewrite px_fls in
let u = partitionOnto_ext lfts (x :: rgts) p xs in
coe (\u => (reverseOnto ( fst u) lfts
Expand Down
4 changes: 3 additions & 1 deletion libs/test/Test/Golden.idr
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,10 @@ runTest opts testPath = do
start <- clockTime UTC
let cg = maybe "" (" --cg " ++) (codegen opts)
let exe = "\"" ++ exeUnderTest opts ++ cg ++ "\""
putStrLn $ "Running " ++ testPath
fflush stdout
ignore $ system $ "cd " ++ escapeArg testPath ++ " && " ++
"sh ./run " ++ exe ++ " | tr -d '\\r' > output"
"timeout 120s sh ./run " ++ exe ++ " | tr -d '\\r' > output"
end <- clockTime UTC

Right out <- readFile $ testPath ++ "/output"
Expand Down
4 changes: 4 additions & 0 deletions src/Algebra/Semiring.idr
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ branchOne yes no rig = if isLinear rig then yes else no
export
branchVal : (Semiring a, Eq a) => Lazy b -> Lazy b -> a -> b
branchVal yes no rig = if isRigOther rig then yes else no

export
presence : Semiring a => Eq a => a -> a
presence = elimSemi erased linear (const linear)
94 changes: 53 additions & 41 deletions src/Compiler/ANF.idr
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import Compiler.LambdaLift

import Core.CompileExpr
import Core.Context
import Core.Context.Log

import Data.SnocList.Quantifiers
import Data.String
import Data.SortedSet
import Data.Vect

import Libraries.Data.SnocList.Extra

%default covering

-- Convert the lambda lifted form to ANF, with variable names made explicit.
Expand Down Expand Up @@ -82,26 +87,26 @@ mutual
Show ANF where
show (AV _ v) = show v
show (AAppName fc lazy n args)
= show n ++ showLazy lazy ++ "(" ++ showSep ", " (map show args) ++ ")"
= show n ++ showLazy lazy ++ "(" ++ joinBy ", " (map show args) ++ ")"
show (AUnderApp fc n m args)
= "<" ++ show n ++ " underapp " ++ show m ++ ">(" ++
showSep ", " (map show args) ++ ")"
joinBy ", " (map show args) ++ ")"
show (AApp fc lazy c arg)
= show c ++ showLazy lazy ++ " @ (" ++ show arg ++ ")"
show (ALet fc x val sc)
= "%let v" ++ show x ++ " = (" ++ show val ++ ") in (" ++ show sc ++ ")"
show (ACon fc n _ t args)
= "%con " ++ show n ++ "(" ++ showSep ", " (map show args) ++ ")"
= "%con " ++ show n ++ "(" ++ joinBy ", " (map show args) ++ ")"
show (AOp fc lazy op args)
= "%op " ++ show op ++ showLazy lazy ++ "(" ++ showSep ", " (toList (map show args)) ++ ")"
= "%op " ++ show op ++ showLazy lazy ++ "(" ++ joinBy ", " (toList (map show args)) ++ ")"
show (AExtPrim fc lazy p args)
= "%extprim " ++ show p ++ showLazy lazy ++ "(" ++ showSep ", " (map show args) ++ ")"
= "%extprim " ++ show p ++ showLazy lazy ++ "(" ++ joinBy ", " (map show args) ++ ")"
show (AConCase fc sc alts def)
= "%case " ++ show sc ++ " of { "
++ showSep "| " (map show alts) ++ " " ++ show def ++ " }"
++ joinBy "| " (map show alts) ++ " " ++ show def ++ " }"
show (AConstCase fc sc alts def)
= "%case " ++ show sc ++ " of { "
++ showSep "| " (map show alts) ++ " " ++ show def ++ " }"
++ joinBy "| " (map show alts) ++ " " ++ show def ++ " }"
show (APrimVal _ x) = show x
show (AErased _) = "___"
show (ACrash _ x) = "%CRASH(" ++ show x ++ ")"
Expand All @@ -111,7 +116,7 @@ mutual
Show AConAlt where
show (MkAConAlt n _ t args sc)
= "%conalt " ++ show n ++
"(" ++ showSep ", " (map showArg args) ++ ") => " ++ show sc
"(" ++ joinBy ", " (map showArg args) ++ ") => " ++ show sc
where
showArg : Int -> String
showArg i = "v" ++ show i
Expand All @@ -136,6 +141,12 @@ Show ANFDef where
AVars : Scope -> Type
AVars = All (\_ => Int)

namespace AVars
public export
empty : AVars Scope.empty
empty = [<]


data Next : Type where

nextVar : {auto v : Ref Next Int} ->
Expand All @@ -145,10 +156,6 @@ nextVar
put Next (i + 1)
pure i

lookup : {idx : _} -> (0 p : IsVar x idx vs) -> AVars vs -> Int
lookup First (x :: xs) = x
lookup (Later p) (x :: xs) = lookup p xs

bindArgs : {auto v : Ref Next Int} ->
List ANF -> Core (List (AVar, Maybe ANF))
bindArgs [] = pure []
Expand Down Expand Up @@ -183,6 +190,15 @@ mlet fc val sc
= do i <- nextVar
pure $ ALet fc i val (sc (ALocal i))

bindAsFresh :
{auto v : Ref Next Int} ->
(args : List Name) -> AVars vars' ->
Core (List Int, AVars (Scope.ext vars' args))
bindAsFresh [] vs = pure ([], vs)
bindAsFresh (n :: ns) vs
= do i <- nextVar
mapFst (i ::) <$> bindAsFresh ns (vs :< i)

mutual
anfArgs : {auto v : Ref Next Int} ->
FC -> AVars vars ->
Expand All @@ -193,7 +209,7 @@ mutual

anf : {auto v : Ref Next Int} ->
AVars vars -> Lifted vars -> Core ANF
anf vs (LLocal fc p) = pure $ AV fc (ALocal (lookup p vs))
anf vs (LLocal fc p) = pure $ AV fc (ALocal (lookup vs p))
anf vs (LAppName fc lazy n args)
= anfArgs fc vs args (AAppName fc lazy n)
anf vs (LUnderApp fc n m args)
Expand All @@ -205,7 +221,7 @@ mutual
_ => ACrash fc "Can't happen (AApp)"
anf vs (LLet fc x val sc)
= do i <- nextVar
let vs' = i :: vs
let vs' = vs :< i
pure $ ALet fc i !(anf vs val) !(anf vs' sc)
anf vs (LCon fc n ci t args)
= anfArgs fc vs args (ACon fc n ci t)
Expand All @@ -231,48 +247,44 @@ mutual
anf vs (LErased fc) = pure $ AErased fc
anf vs (LCrash fc err) = pure $ ACrash fc err

anfConScope : {auto v : Ref Next Int} ->
AVars vars -> LiftedCaseScope vars ->
Core (List Int, ANF)
anfConScope vs (LRHS sc) = pure ([], !(anf vs sc))
anfConScope vs (LArg x sc)
= do i <- nextVar
(args, sc') <- anfConScope (vs :< i) sc
pure (i :: args, sc')

anfConAlt : {auto v : Ref Next Int} ->
AVars vars -> LiftedConAlt vars -> Core AConAlt
anfConAlt vs (MkLConAlt n ci t args sc)
= do (is, vs') <- bindArgs args vs
pure $ MkAConAlt n ci t is !(anf vs' sc)
where
bindArgs : (args : List Name) -> AVars vars' ->
Core (List Int, AVars (args ++ vars'))
bindArgs [] vs = pure ([], vs)
bindArgs (n :: ns) vs
= do i <- nextVar
(is, vs') <- bindArgs ns vs
pure (i :: is, i :: vs')
anfConAlt vs (MkLConAlt n ci t sc)
= do (args, sc') <- anfConScope vs sc
pure $ MkAConAlt n ci t args sc'

anfConstAlt : {auto v : Ref Next Int} ->
AVars vars -> LiftedConstAlt vars -> Core AConstAlt
anfConstAlt vs (MkLConstAlt c sc)
= pure $ MkAConstAlt c !(anf vs sc)

export
toANF : LiftedDef -> Core ANFDef
toANF : {auto c : Ref Ctxt Defs} -> LiftedDef -> Core ANFDef
toANF (MkLFun args scope sc)
= do v <- newRef Next (the Int 0)
(iargs, vsNil) <- bindArgs args []
let vs : AVars args = rewrite sym (appendNilRightNeutral args) in
vsNil
(iargs', vs) <- bindArgs scope vs
pure $ MkAFun (iargs ++ reverse iargs') !(anf vs sc)
where
bindArgs : {auto v : Ref Next Int} ->
(args : List Name) -> AVars vars' ->
Core (List Int, AVars (args ++ vars'))
bindArgs [] vs = pure ([], vs)
bindArgs (n :: ns) vs
= do i <- nextVar
(is, vs') <- bindArgs ns vs
pure (i :: is, i :: vs')
log "compile.execute" 40 $ "toANF args: \{show $ toList args}, scope: \{show $ asList scope}, lifted: \{show sc}"
(iargs, vsNil) <- bindAsFresh args AVars.empty
(iargs', vs) <- bindAsFresh (toList scope) vsNil
sc' <- anf vs $
do rewrite fishAsSnocAppend (cast args) (toList scope)
rewrite castToList scope
sc
log "compile.execute" 40 $ "toANF iargs: \{show iargs}, iargs': \{show iargs'}, lifted: \{show sc'}"
pure $ MkAFun (iargs ++ iargs') sc'
toANF (MkLCon t a ns) = pure $ MkACon t a ns
toANF (MkLForeign ccs fargs t) = pure $ MkAForeign ccs fargs t
toANF (MkLError err)
= do v <- newRef Next (the Int 0)
pure $ MkAError !(anf [] err)
pure $ MkAError !(anf AVars.empty err)

export
freeVariables : ANF -> SortedSet AVar
Expand Down
Loading
Loading