Skip to content

Commit a991795

Browse files
authored
Merge pull request #3615 from andrevidela/impTy-refactor
replace ImpTy
2 parents 9b74ccf + 1870960 commit a991795

20 files changed

+67
-106
lines changed

src/Core/WithData.idr

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ setFC : {n : Nat} ->
109109
WithData fields a -> WithData fields a
110110
setFC fc = WithData.set "fc" fc @{inRange}
111111

112-
||| Attach binding and file context information to a type
113-
public export
114-
FCBind : Type -> Type
115-
FCBind = WithData [ Bind', FC' ]
116-
117112
||| A wrapper for a value with a file context.
118113
public export
119114
MkFCVal : FC -> ty -> WithFC ty
@@ -194,16 +189,16 @@ public export
194189
WithName : Type -> Type
195190
WithName = AddMetadata Name'
196191

197-
||| the "tyname" label containing a `FCBind Name` for metadata records
192+
||| the "tyname" label containing a `WithFC Name` for metadata records. Typically used for type names.
198193
public export
199194
TyName' : KeyVal
200-
TyName' = "tyname" :-: FCBind Name
195+
TyName' = "tyname" :-: WithFC Name
201196

202197
||| Extract the "tyname" value from the metadata record
203198
export
204199
(.tyName) : {n : Nat} ->
205-
(inRange : NameInRange "tyname" fields === Just (n, FCBind Name)) =>
206-
WithData fields a -> FCBind Name
200+
(inRange : NameInRange "tyname" fields === Just (n, WithFC Name)) =>
201+
WithData fields a -> WithFC Name
207202
(.tyName) = WithData.get "tyname" @{inRange}
208203

209204

src/Idris/Desugar.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ mutual
906906
= flip Core.traverse (forget names) $ \(doc, n) : (String, WithFC Name) =>
907907
do addDocString n.val (d ++ doc)
908908
syn <- get Syn
909-
pure $ MkImpTy pty.fc n !(bindTypeNames pty.fc (usingImpl syn)
909+
pure $ Mk [pty.fc, n] !(bindTypeNames pty.fc (usingImpl syn)
910910
ps !(desugar AnyExpr ps ty))
911911

912912
-- Attempt to get the function name from a function pattern. For example,

src/Idris/Elab/Implementation.idr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ elabImplementation {vars} ifc vis opts_in pass env nest is cons iname ps named i
185185
let impTy = doBind paramBinds initTy
186186

187187
let impTyDecl
188-
= IClaim (MkFCVal vfc $ MkIClaimData top vis opts (MkImpTy EmptyFC (NoFC impName) impTy))
188+
= IClaim (MkFCVal vfc $ MkIClaimData top vis opts (Mk [EmptyFC, NoFC impName] impTy))
189189

190190
log "elab.implementation" 5 $ "Implementation type: " ++ show impTy
191191

@@ -472,7 +472,7 @@ elabImplementation {vars} ifc vis opts_in pass env nest is cons iname ps named i
472472
= do let opts = if isJust $ findTotality opts_in
473473
then opts_in
474474
else maybe opts_in (\t => Totality t :: opts_in) treq
475-
IClaim $ MkFCVal vfc $ MkIClaimData c vis opts $ MkImpTy EmptyFC (NoFC n) mty
475+
IClaim $ MkFCVal vfc $ MkIClaimData c vis opts $ Mk [EmptyFC, NoFC n] mty
476476

477477
-- Given the method type (result of topMethType) return the mapping from
478478
-- top level method name to current implementation's method name

src/Idris/Elab/Interface.idr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ namePis i (IBindHere fc m ty) = IBindHere fc m (namePis i ty)
5151
namePis i ty = ty
5252

5353
getSig : ImpDecl -> Maybe Signature
54-
getSig (IClaim (MkWithData _ $ MkIClaimData c _ opts (MkImpTy fc n ty)))
54+
getSig (IClaim (MkWithData _ $ MkIClaimData c _ opts ty))
5555
= Just $ MkSignature { count = c
5656
, flags = opts
57-
, name = n
57+
, name = ty.tyName
5858
, isData = False
59-
, type = namePis 0 ty
59+
, type = namePis 0 ty.val
6060
}
6161
getSig (IData _ _ _ (MkImpLater fc n ty))
6262
= Just $ MkSignature { count = erased
@@ -121,7 +121,7 @@ mkIfaceData {vars} ifc def_vis env constraints n conName ps dets meths
121121
conty = mkTy vfc Implicit (map jname ps) $
122122
mkTy vfc AutoImplicit (map bhere constraints) $
123123
mkTy vfc Explicit (map bname meths) retty
124-
con = MkImpTy vfc (NoFC conName) !(bindTypeNames ifc [] (pNames ++ map fst meths ++ toList vars) conty)
124+
con = Mk [vfc, NoFC conName] !(bindTypeNames ifc [] (pNames ++ map fst meths ++ toList vars) conty)
125125
bound = pNames ++ map fst meths ++ toList vars in
126126

127127
pure $ IData vfc def_vis Nothing {- ?? -}
@@ -189,7 +189,7 @@ getMethToplevel {vars} env vis iname cname constraints allmeths bindNames params
189189
cn <- traverse inCurrentNS sig.name
190190
let tydecl = IClaim (MkFCVal vfc $ MkIClaimData sig.count vis (if sig.isData then [Inline, Invertible]
191191
else [Inline])
192-
(MkImpTy vfc cn ty_imp))
192+
(Mk [vfc, cn] ty_imp))
193193
let conapp = apply (IVar vfc cname) (map (IBindVar EmptyFC) bindNames)
194194
let argns = getExplicitArgs 0 sig.type
195195
-- eta expand the RHS so that we put implicits in the right place
@@ -250,7 +250,7 @@ getConstraintHint {vars} fc env vis iname cname constraints meths params (cn, co
250250
(UN (Basic $ "__" ++ show iname ++ "_" ++ show con))
251251

252252
let tydecl = IClaim (MkFCVal fc $ MkIClaimData top vis [Inline, Hint False]
253-
(MkImpTy EmptyFC (NoFC hintname) ty_imp))
253+
(Mk [EmptyFC, NoFC hintname] ty_imp))
254254

255255
let conapp = apply (impsBind (IVar fc cname) constraints)
256256
(map (const (Implicit fc True)) meths)
@@ -436,7 +436,7 @@ elabInterface {vars} ifc def_vis env nest constraints iname params dets mcon bod
436436

437437
let dtydecl = IClaim $ MkFCVal vdfc
438438
$ MkIClaimData rig (collapseDefault def_vis) []
439-
$ MkImpTy EmptyFC (NoFC dn) dty_imp
439+
$ Mk [EmptyFC, NoFC dn] dty_imp
440440

441441
processDecl [] nest env dtydecl
442442

src/Idris/REPL.idr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ getItDecls
408408
let it = UN $ Basic "it" in
409409
pure [ IClaim
410410
(MkFCVal replFC $ MkIClaimData top Private []
411-
$ MkImpTy replFC (NoFC it) (Implicit replFC False))
411+
$ Mk [replFC, NoFC it] (Implicit replFC False))
412412
, IDef replFC it [PatClause replFC (IVar replFC it) (IVar replFC n)]]
413413

414414
||| Produce the elaboration of a PTerm, along with its inferred type

src/Idris/Resugar.idr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ mutual
473473
toPTypeDecl : {auto c : Ref Ctxt Defs} ->
474474
{auto s : Ref Syn SyntaxInfo} ->
475475
ImpTy' KindedName -> Core (PTypeDecl' KindedName)
476-
toPTypeDecl (MkImpTy fc n ty)
477-
= pure (MkFCVal fc $ MkPTy (pure ("", n)) "" !(toPTerm startPrec ty))
476+
toPTypeDecl impTy
477+
= pure (MkFCVal impTy.fc $ MkPTy (pure ("", impTy.tyName)) "" !(toPTerm startPrec impTy.val))
478478

479479
toPData : {auto c : Ref Ctxt Defs} ->
480480
{auto s : Ref Syn SyntaxInfo} ->

src/TTImp/Elab/Local.idr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ localHelper {vars} nest env nestdecls_in func
9999
-- When we encounter the names in elaboration, we'll update to an
100100
-- application of the nested name.
101101
updateTyName : NestedNames vars -> ImpTy -> ImpTy
102-
updateTyName nest (MkImpTy loc' n ty)
103-
= MkImpTy loc' (map (mapNestedName nest) n) ty
102+
updateTyName nest ty
103+
= update "tyname" (map (mapNestedName nest)) ty
104104

105105
updateDataName : NestedNames vars -> ImpData -> ImpData
106106
updateDataName nest (MkImpData loc' n tycons dopts dcons)

src/TTImp/Elab/Quote.idr

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,6 @@ mutual
104104
getUnquoteUpdate (ISetField p t) = pure $ ISetField p !(getUnquote t)
105105
getUnquoteUpdate (ISetFieldApp p t) = pure $ ISetFieldApp p !(getUnquote t)
106106

107-
getUnquoteTy : {auto c : Ref Ctxt Defs} ->
108-
{auto q : Ref Unq (List (Name, FC, RawImp))} ->
109-
{auto u : Ref UST UState} ->
110-
ImpTy ->
111-
Core ImpTy
112-
getUnquoteTy (MkImpTy fc n t) = pure $ MkImpTy fc n !(getUnquote t)
113-
114107
getUnquoteRecord : {auto c : Ref Ctxt Defs} ->
115108
{auto q : Ref Unq (List (Name, FC, RawImp))} ->
116109
{auto u : Ref UST UState} ->
@@ -128,7 +121,7 @@ mutual
128121
Core ImpData
129122
getUnquoteData (MkImpData fc n tc opts cs)
130123
= pure $ MkImpData fc n !(traverseOpt getUnquote tc) opts
131-
!(traverse getUnquoteTy cs)
124+
!(traverse (traverse getUnquote) cs)
132125
getUnquoteData (MkImpLater fc n tc)
133126
= pure $ MkImpLater fc n !(getUnquote tc)
134127

@@ -138,7 +131,7 @@ mutual
138131
ImpDecl ->
139132
Core ImpDecl
140133
getUnquoteDecl (IClaim (MkWithData fc (MkIClaimData c v opts ty)))
141-
= pure $ IClaim (MkWithData fc (MkIClaimData c v opts !(getUnquoteTy ty)))
134+
= pure $ IClaim (MkWithData fc (MkIClaimData c v opts !(traverse getUnquote ty)))
142135
getUnquoteDecl (IData fc v mbt d)
143136
= pure $ IData fc v mbt !(getUnquoteData d)
144137
getUnquoteDecl (IDef fc v d)

src/TTImp/Parser.idr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,14 @@ mutual
501501
tyDecl : OriginDesc -> IndentInfo -> Rule ImpTy
502502
tyDecl fname indents
503503
= do start <- location
504-
n <- name
504+
n <- withFC name
505505
nameEnd <- location
506506
symbol ":"
507507
ty <- expr fname indents
508508
end <- location
509509
atEnd indents
510-
pure (MkImpTy (MkFC fname start end) (MkFCVal (MkFC fname start nameEnd) n) ty)
510+
let fc = MkFC fname start end
511+
pure (Mk [fc, n] ty)
511512

512513
mutual
513514
parseRHS : (withArgs : Nat) ->

src/TTImp/ProcessData.idr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ checkCon : {vars : _} ->
9494
List ElabOpt -> NestedNames vars ->
9595
Env Term vars -> Visibility -> (orig : Name) -> (resolved : Name) ->
9696
ImpTy -> Core Constructor
97-
checkCon {vars} opts nest env vis tn_in tn (MkImpTy fc cn_in ty_raw)
98-
= do cn <- inCurrentNS cn_in.val
99-
let ty_raw = updateNS tn_in tn ty_raw
97+
checkCon {vars} opts nest env vis tn_in tn ty_raw
98+
= do let cn_in = ty_raw.tyName
99+
let fc = ty_raw.fc
100+
cn <- inCurrentNS cn_in.val
101+
let ty_raw = updateNS tn_in tn ty_raw.val
100102
log "declare.data.constructor" 5 $ "Checking constructor type " ++ show cn ++ " : " ++ show ty_raw
101103
log "declare.data.constructor" 10 $ "Updated " ++ show (tn_in, tn)
102104

0 commit comments

Comments
 (0)