Skip to content

Commit 49c039b

Browse files
committed
implement binding application
1 parent e20861a commit 49c039b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+861
-501
lines changed

libs/prelude/Prelude/Interfaces.idr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,9 @@ sequence : Applicative f => Traversable t => t (f a) -> f (t a)
551551
sequence = traverse id
552552

553553
||| Like `traverse` but with the arguments flipped.
554+
||| You can call this function using binding syntax.
555+
||| Instead of writing `for xs (\x => f x)` you can write
556+
||| `for (x := xs) ; f x`
554557
%inline %tcinline public export
555558
for : Applicative f => Traversable t => t a -> (a -> f b) -> f (t b)
556559
for = flip traverse

src/Compiler/Common.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ getMinimalDef (Coded ns bin)
156156
= MkGlobalDef fc name (Erased fc Placeholder) NatSet.empty NatSet.empty NatSet.empty NatSet.empty mul
157157
Scope.empty (specified Public) (MkTotality Unchecked IsCovering) False
158158
[] Nothing refsR False False True
159-
None cdef Nothing [] Nothing
159+
None cdef Nothing [] Nothing NotBinding
160160
pure (def, Just (ns, bin))
161161

162162
-- ||| Recursively get all calls in a function definition

src/Core/Binary.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import public Libraries.Utils.Binary
3030
||| version number if you're changing the version more than once in the same day.
3131
export
3232
ttcVersion : Int
33-
ttcVersion = 2025_08_08_00
33+
ttcVersion = 2025_08_14_00
3434

3535
export
3636
checkTTCVersion : String -> Int -> Int -> Core ()

src/Core/Context.idr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import public Core.Name
1010
import Core.Options
1111
import public Core.Options.Log
1212
import public Core.TT
13+
import public Core.WithData
1314

1415
import Libraries.Utils.Binary
1516
import Libraries.Utils.Path
@@ -325,10 +326,11 @@ commitCtxt ctxt
325326
||| @vis Visibility, defaulting to private
326327
||| @def actual definition
327328
export
328-
newDef : (fc : FC) -> (n : Name) -> (rig : RigCount) -> (vars : Scope) ->
329+
newDef : {default NotBinding bind : BindingModifier} ->
330+
(fc : FC) -> (n : Name) -> (rig : RigCount) -> (vars : Scope) ->
329331
(ty : ClosedTerm) -> (vis : WithDefault Visibility Private) -> (def : Def) -> GlobalDef
330332
newDef fc n rig vars ty vis def
331-
= MkGlobalDef
333+
= MkGlobalDef
332334
{ location = fc
333335
, fullname = n
334336
, type = ty
@@ -352,6 +354,7 @@ newDef fc n rig vars ty vis def
352354
, namedcompexpr = Nothing
353355
, sizeChange = []
354356
, schemeExpr = Nothing
357+
, bindingMode = bind
355358
}
356359

357360
-- Rewrite rules, applied after type checking, for runtime code only
@@ -1368,6 +1371,7 @@ addBuiltin n ty tot op
13681371
, namedcompexpr = Nothing
13691372
, sizeChange = []
13701373
, schemeExpr = Nothing
1374+
, bindingMode = NotBinding
13711375
}
13721376

13731377
export

src/Core/Context/Context.idr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Show Def where
177177

178178
public export
179179
Constructor' : Type -> Type
180-
Constructor' = AddFC . WithName . WithArity
180+
Constructor' = AddFC . WithName . WithArity . AddMetadata Bind'
181181

182182
public export
183183
Constructor : Type
@@ -331,6 +331,7 @@ record GlobalDef where
331331
namedcompexpr : Maybe NamedDef
332332
sizeChange : List SCCall
333333
schemeExpr : Maybe (SchemeMode, SchemeObj Write)
334+
bindingMode : BindingModifier
334335

335336
export
336337
getDefNameType : GlobalDef -> NameType

src/Core/Context/Data.idr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ addData vars vis tidx (MkData con datacons)
101101
log "declare.data.parameters" 20 $
102102
"Positions of parameters for datatype" ++ show tyName ++
103103
": " ++ show paramPositions
104-
let tydef = newDef con.fc tyName top vars con.val (specified vis)
104+
let tydef = newDef {bind = con.bind} con.fc tyName top vars con.val (specified vis)
105105
(TCon con.arity
106106
paramPositions
107107
allPos
@@ -120,7 +120,7 @@ addData vars vis tidx (MkData con datacons)
120120
addDataConstructors tag [] gam = pure gam
121121
addDataConstructors tag (con :: cs) gam
122122
= do let conName = con.name.val
123-
let condef = newDef con.fc conName top vars con.val (specified $ conVisibility vis) (DCon tag con.arity Nothing)
123+
let condef = newDef {bind = con.bind} con.fc conName top vars con.val (specified $ conVisibility vis) (DCon tag con.arity Nothing)
124124
-- Check 'n' is undefined
125125
Nothing <- lookupCtxtExact conName gam
126126
| Just gdef => throw (AlreadyDefined con.fc conName)

src/Core/Core.idr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,14 @@ namespace Binder
890890
traverse f (PLet fc c val ty) = pure $ PLet fc c !(f val) !(f ty)
891891
traverse f (PVTy fc c ty) = pure $ PVTy fc c !(f ty)
892892

893+
namespace BindingInfo
894+
export
895+
traverse : (a -> Core b) -> BindingInfo a -> Core (BindingInfo b)
896+
traverse f (BindType name type) = BindType <$> f name <*> f type
897+
traverse f (BindExpr name expr) = BindExpr <$> f name <*> f expr
898+
traverse f (BindExplicitType name type expr)
899+
= BindExplicitType <$> f name <*> f type <*> f expr
900+
893901
export
894902
mapTermM : ({vars : _} -> Term vars -> Core (Term vars)) ->
895903
({vars : _} -> Term vars -> Core (Term vars))

src/Core/FC.idr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,4 @@ Pretty Void FC where
230230
pretty (MkVirtualFC ident startPos endPos) = byShow ident <+> colon
231231
<+> prettyPos startPos <+> pretty "--"
232232
<+> prettyPos endPos
233+

src/Core/Name/Namespace.idr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,7 @@ dpairNS = mkNamespace "Builtin.DPair"
304304
export
305305
natNS : Namespace
306306
natNS = mkNamespace "Data.Nat"
307+
308+
export
309+
allQuantifiersNS : Namespace
310+
allQuantifiersNS = mkNamespace "Data.List.Quantifiers.All"

src/Core/Options/Log.idr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ knownTopics = [
106106
("elab.as", Nothing),
107107
("elab.bindnames", Nothing),
108108
("elab.binder", Nothing),
109+
("elab.bindApp", Just "Elaborating binding application"),
109110
("elab.case", Nothing),
110111
("elab.def.local", Nothing),
111112
("elab.delay", Nothing),

0 commit comments

Comments
 (0)