2020-05-18 18:57:43 +03:00
|
|
|
module Language.Reflection.TTImp
|
|
|
|
|
2020-05-31 03:36:54 +03:00
|
|
|
import public Language.Reflection.TT
|
2020-05-18 18:57:43 +03:00
|
|
|
|
2021-05-13 14:58:56 +03:00
|
|
|
%default total
|
|
|
|
|
2020-05-18 18:57:43 +03:00
|
|
|
-- Unchecked terms and declarations in the intermediate language
|
|
|
|
mutual
|
|
|
|
public export
|
2021-10-17 20:21:35 +03:00
|
|
|
data BindMode = PI Count | PATTERN | COVERAGE | NONE
|
2020-05-18 18:57:43 +03:00
|
|
|
|
|
|
|
-- For as patterns matching linear arguments, select which side is
|
|
|
|
-- consumed
|
|
|
|
public export
|
|
|
|
data UseSide = UseLeft | UseRight
|
|
|
|
|
|
|
|
public export
|
|
|
|
data DotReason = NonLinearVar
|
|
|
|
| VarApplied
|
|
|
|
| NotConstructor
|
|
|
|
| ErasedArg
|
|
|
|
| UserDotted
|
|
|
|
| UnknownDot
|
2021-02-26 12:33:07 +03:00
|
|
|
| UnderAppliedCon
|
2020-05-18 18:57:43 +03:00
|
|
|
|
|
|
|
public export
|
|
|
|
data TTImp : Type where
|
|
|
|
IVar : FC -> Name -> TTImp
|
2020-05-30 00:40:29 +03:00
|
|
|
IPi : FC -> Count -> PiInfo TTImp -> Maybe Name ->
|
2020-05-18 18:57:43 +03:00
|
|
|
(argTy : TTImp) -> (retTy : TTImp) -> TTImp
|
2020-05-30 00:40:29 +03:00
|
|
|
ILam : FC -> Count -> PiInfo TTImp -> Maybe Name ->
|
2020-05-18 18:57:43 +03:00
|
|
|
(argTy : TTImp) -> (lamTy : TTImp) -> TTImp
|
2021-02-05 19:15:40 +03:00
|
|
|
ILet : FC -> (lhsFC : FC) -> Count -> Name ->
|
2020-05-18 18:57:43 +03:00
|
|
|
(nTy : TTImp) -> (nVal : TTImp) ->
|
|
|
|
(scope : TTImp) -> TTImp
|
|
|
|
ICase : FC -> TTImp -> (ty : TTImp) ->
|
|
|
|
List Clause -> TTImp
|
|
|
|
ILocal : FC -> List Decl -> TTImp -> TTImp
|
|
|
|
IUpdate : FC -> List IFieldUpdate -> TTImp -> TTImp
|
|
|
|
|
|
|
|
IApp : FC -> TTImp -> TTImp -> TTImp
|
2020-10-01 12:41:30 +03:00
|
|
|
INamedApp : FC -> TTImp -> Name -> TTImp -> TTImp
|
|
|
|
IAutoApp : FC -> TTImp -> TTImp -> TTImp
|
2020-05-18 18:57:43 +03:00
|
|
|
IWithApp : FC -> TTImp -> TTImp -> TTImp
|
|
|
|
|
|
|
|
ISearch : FC -> (depth : Nat) -> TTImp
|
|
|
|
IAlternative : FC -> AltType -> List TTImp -> TTImp
|
|
|
|
IRewrite : FC -> TTImp -> TTImp -> TTImp
|
|
|
|
|
|
|
|
-- Any implicit bindings in the scope should be bound here, using
|
|
|
|
-- the given binder
|
|
|
|
IBindHere : FC -> BindMode -> TTImp -> TTImp
|
|
|
|
-- A name which should be implicitly bound
|
|
|
|
IBindVar : FC -> String -> TTImp
|
|
|
|
-- An 'as' pattern, valid on the LHS of a clause only
|
2021-02-05 19:15:40 +03:00
|
|
|
IAs : FC -> (nameFC : FC) -> UseSide -> Name -> TTImp -> TTImp
|
2020-05-18 18:57:43 +03:00
|
|
|
-- A 'dot' pattern, i.e. one which must also have the given value
|
|
|
|
-- by unification
|
|
|
|
IMustUnify : FC -> DotReason -> TTImp -> TTImp
|
|
|
|
|
|
|
|
-- Laziness annotations
|
|
|
|
IDelayed : FC -> LazyReason -> TTImp -> TTImp -- the type
|
|
|
|
IDelay : FC -> TTImp -> TTImp -- delay constructor
|
|
|
|
IForce : FC -> TTImp -> TTImp
|
|
|
|
|
|
|
|
-- Quasiquotation
|
|
|
|
IQuote : FC -> TTImp -> TTImp
|
2020-06-01 15:39:18 +03:00
|
|
|
IQuoteName : FC -> Name -> TTImp
|
2021-07-15 20:28:07 +03:00
|
|
|
IQuoteDecl : FC -> List Decl -> TTImp
|
2020-05-18 18:57:43 +03:00
|
|
|
IUnquote : FC -> TTImp -> TTImp
|
|
|
|
|
|
|
|
IPrimVal : FC -> (c : Constant) -> TTImp
|
|
|
|
IType : FC -> TTImp
|
|
|
|
IHole : FC -> String -> TTImp
|
|
|
|
|
|
|
|
-- An implicit value, solved by unification, but which will also be
|
|
|
|
-- bound (either as a pattern variable or a type variable) if unsolved
|
|
|
|
-- at the end of elaborator
|
|
|
|
Implicit : FC -> (bindIfUnsolved : Bool) -> TTImp
|
2020-05-30 00:40:29 +03:00
|
|
|
IWithUnambigNames : FC -> List Name -> TTImp -> TTImp
|
2020-05-18 18:57:43 +03:00
|
|
|
|
|
|
|
public export
|
|
|
|
data IFieldUpdate : Type where
|
|
|
|
ISetField : (path : List String) -> TTImp -> IFieldUpdate
|
|
|
|
ISetFieldApp : (path : List String) -> TTImp -> IFieldUpdate
|
|
|
|
|
|
|
|
public export
|
|
|
|
data AltType : Type where
|
|
|
|
FirstSuccess : AltType
|
|
|
|
Unique : AltType
|
|
|
|
UniqueDefault : TTImp -> AltType
|
|
|
|
|
|
|
|
public export
|
|
|
|
data FnOpt : Type where
|
|
|
|
Inline : FnOpt
|
2021-10-19 17:22:36 +03:00
|
|
|
NoInline : FnOpt
|
2020-05-30 00:40:29 +03:00
|
|
|
TCInline : FnOpt
|
2020-05-18 18:57:43 +03:00
|
|
|
-- Flag means the hint is a direct hint, not a function which might
|
|
|
|
-- find the result (e.g. chasing parent interface dictionaries)
|
|
|
|
Hint : Bool -> FnOpt
|
|
|
|
-- Flag means to use as a default if all else fails
|
|
|
|
GlobalHint : Bool -> FnOpt
|
|
|
|
ExternFn : FnOpt
|
|
|
|
-- Defined externally, list calling conventions
|
2020-09-07 06:30:16 +03:00
|
|
|
ForeignFn : List TTImp -> FnOpt
|
2020-05-18 18:57:43 +03:00
|
|
|
-- assume safe to cancel arguments in unification
|
|
|
|
Invertible : FnOpt
|
2020-10-01 12:41:30 +03:00
|
|
|
Totality : TotalReq -> FnOpt
|
2020-05-18 18:57:43 +03:00
|
|
|
Macro : FnOpt
|
2020-05-30 00:40:29 +03:00
|
|
|
SpecArgs : List Name -> FnOpt
|
2020-05-18 18:57:43 +03:00
|
|
|
|
|
|
|
public export
|
|
|
|
data ITy : Type where
|
2021-02-05 19:15:40 +03:00
|
|
|
MkTy : FC -> (nameFC : FC) -> (n : Name) -> (ty : TTImp) -> ITy
|
2020-05-18 18:57:43 +03:00
|
|
|
|
|
|
|
public export
|
|
|
|
data DataOpt : Type where
|
|
|
|
SearchBy : List Name -> DataOpt -- determining arguments
|
|
|
|
NoHints : DataOpt -- Don't generate search hints for constructors
|
2021-07-15 20:28:07 +03:00
|
|
|
UniqueSearch : DataOpt -- auto implicit search must check result is unique
|
|
|
|
External : DataOpt -- implemented externally
|
|
|
|
NoNewtype : DataOpt -- don't apply newtype optimisation
|
2020-05-18 18:57:43 +03:00
|
|
|
|
|
|
|
public export
|
|
|
|
data Data : Type where
|
|
|
|
MkData : FC -> (n : Name) -> (tycon : TTImp) ->
|
|
|
|
(opts : List DataOpt) ->
|
|
|
|
(datacons : List ITy) -> Data
|
|
|
|
MkLater : FC -> (n : Name) -> (tycon : TTImp) -> Data
|
|
|
|
|
|
|
|
public export
|
|
|
|
data IField : Type where
|
2020-05-30 00:40:29 +03:00
|
|
|
MkIField : FC -> Count -> PiInfo TTImp -> Name -> TTImp ->
|
2020-05-18 18:57:43 +03:00
|
|
|
IField
|
|
|
|
|
|
|
|
public export
|
|
|
|
data Record : Type where
|
|
|
|
MkRecord : FC -> (n : Name) ->
|
2021-07-15 20:28:07 +03:00
|
|
|
(params : List (Name, Count, PiInfo TTImp, TTImp)) ->
|
2020-06-11 22:30:16 +03:00
|
|
|
(conName : Name) ->
|
2020-05-18 18:57:43 +03:00
|
|
|
(fields : List IField) ->
|
|
|
|
Record
|
|
|
|
|
2021-07-15 20:28:07 +03:00
|
|
|
public export
|
|
|
|
data WithFlag = Syntactic
|
|
|
|
|
2020-05-18 18:57:43 +03:00
|
|
|
public export
|
|
|
|
data Clause : Type where
|
|
|
|
PatClause : FC -> (lhs : TTImp) -> (rhs : TTImp) -> Clause
|
|
|
|
WithClause : FC -> (lhs : TTImp) -> (wval : TTImp) ->
|
2021-07-15 20:28:07 +03:00
|
|
|
(prf : Maybe Name) -> (flags : List WithFlag) ->
|
2020-05-18 18:57:43 +03:00
|
|
|
List Clause -> Clause
|
|
|
|
ImpossibleClause : FC -> (lhs : TTImp) -> Clause
|
|
|
|
|
|
|
|
public export
|
|
|
|
data Decl : Type where
|
|
|
|
IClaim : FC -> Count -> Visibility -> List FnOpt ->
|
|
|
|
ITy -> Decl
|
|
|
|
IData : FC -> Visibility -> Data -> Decl
|
|
|
|
IDef : FC -> Name -> List Clause -> Decl
|
2021-07-15 20:28:07 +03:00
|
|
|
IParameters : FC -> List (Name, Count, PiInfo TTImp, TTImp) ->
|
2020-05-18 18:57:43 +03:00
|
|
|
List Decl -> Decl
|
2021-07-15 20:28:07 +03:00
|
|
|
IRecord : FC ->
|
|
|
|
Maybe String -> -- nested namespace
|
|
|
|
Visibility -> Record -> Decl
|
2021-01-17 13:10:00 +03:00
|
|
|
INamespace : FC -> Namespace -> List Decl -> Decl
|
2020-05-30 00:40:29 +03:00
|
|
|
ITransform : FC -> Name -> TTImp -> TTImp -> Decl
|
2021-07-15 20:28:07 +03:00
|
|
|
IRunElabDecl : FC -> TTImp -> Decl
|
|
|
|
ILog : Maybe (List String, Nat) -> Decl
|
|
|
|
IBuiltin : FC -> BuiltinType -> Name -> Decl
|
2021-08-11 14:26:45 +03:00
|
|
|
|
|
|
|
public export
|
|
|
|
getFC : TTImp -> FC
|
|
|
|
getFC (IVar fc y) = fc
|
|
|
|
getFC (IPi fc _ _ _ _ _) = fc
|
|
|
|
getFC (ILam fc _ _ _ _ _) = fc
|
|
|
|
getFC (ILet fc _ _ _ _ _ _) = fc
|
|
|
|
getFC (ICase fc _ _ _) = fc
|
|
|
|
getFC (ILocal fc _ _) = fc
|
|
|
|
getFC (IUpdate fc _ _) = fc
|
|
|
|
getFC (IApp fc _ _) = fc
|
|
|
|
getFC (INamedApp fc _ _ _) = fc
|
|
|
|
getFC (IAutoApp fc _ _) = fc
|
|
|
|
getFC (IWithApp fc _ _) = fc
|
|
|
|
getFC (ISearch fc _) = fc
|
|
|
|
getFC (IAlternative fc _ _) = fc
|
|
|
|
getFC (IRewrite fc _ _) = fc
|
|
|
|
getFC (IBindHere fc _ _) = fc
|
|
|
|
getFC (IBindVar fc _) = fc
|
|
|
|
getFC (IAs fc _ _ _ _) = fc
|
|
|
|
getFC (IMustUnify fc _ _) = fc
|
|
|
|
getFC (IDelayed fc _ _) = fc
|
|
|
|
getFC (IDelay fc _) = fc
|
|
|
|
getFC (IForce fc _) = fc
|
|
|
|
getFC (IQuote fc _) = fc
|
|
|
|
getFC (IQuoteName fc _) = fc
|
|
|
|
getFC (IQuoteDecl fc _) = fc
|
|
|
|
getFC (IUnquote fc _) = fc
|
|
|
|
getFC (IPrimVal fc _) = fc
|
|
|
|
getFC (IType fc) = fc
|
|
|
|
getFC (IHole fc _) = fc
|
|
|
|
getFC (Implicit fc _) = fc
|
|
|
|
getFC (IWithUnambigNames fc _ _) = fc
|